trunk /sally/core/lib/sly/Form/Widget/LinkBase.php

Language PHP Lines 86
MD5 Hash e7075e2322ef0911326ceb5d5bd40d10 Estimated Cost $872 (why?)
Repository https://bitbucket.org/SallyCMS/trunk View Raw File
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/*
 * Copyright (c) 2012, webvariants GbR, http://www.webvariants.de
 *
 * This file is released under the terms of the MIT license. You can find the
 * complete text in the attached LICENSE file or online at:
 *
 * http://www.opensource.org/licenses/mit-license.php
 */

/**
 * Link widget
 *
 * This element will render a special widget that allows the user to select
 * one article. The article will be returned without any language information,
 * so only its ID is returned.
 * Selection will be performed in the so-called 'linkmap', a special popup for
 * browsing through the article structure.
 *
 * @ingroup form
 * @author  Christoph
 */
abstract class sly_Form_Widget_LinkBase extends sly_Form_ElementBase {
	protected $types      = array();
	protected $categories = array();

	/**
	 * @return sly_Form_Widget_LinkBase  the widget itself
	 */
	public function filterByCategories(array $cats, $recursive = false) {
		foreach ($cats as $cat) $this->filterByCategory($cat, $recursive);
		return $this;
	}

	/**
	 * @return sly_Form_Widget_LinkBase  the widget itself
	 */
	public function filterByCategory($cat, $recursive = false) {
		$catID = $cat instanceof sly_Model_Category ? $cat->getId() : (int) $cat;

		if (!$recursive) {
			if (!in_array($catID, $this->categories)) {
				$this->categories[] = $catID;
			}
		}
		else {
			$serv = sly_Core::getContainer()->getCategoryService();
			$tree = $serv->findTree($catID);

			foreach ($tree as $cat) {
				$this->categories[] = $cat->getId();
			}

			$this->categories = array_unique($this->categories);
		}

		return $this;
	}

	/**
	 * @return sly_Form_Widget_LinkBase  the widget itself
	 */
	public function filterByArticleTypes(array $types) {
		foreach ($types as $type) $this->types[] = $type;
		$this->types = array_unique($this->types);

		return $this;
	}

	/**
	 * @return sly_Form_Widget_LinkBase  the widget itself
	 */
	public function clearCategoryFilter() {
		$this->categories = array();
		return $this;
	}

	/**
	 * @return sly_Form_Widget_LinkBase  the widget itself
	 */
	public function clearArticleTypeFilter() {
		$this->types = array();
		return $this;
	}
}
Back to Top