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

Language PHP Lines 85
MD5 Hash 18c8a39fe9d206e50fd5c12cf8956130 Estimated Cost $920 (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
<?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
 */

/**
 * Media widget
 *
 * This element will render a special widget that allows the user to select
 * a file from the mediapool. The handled value is the file's name, not its ID.
 *
 * @ingroup form
 * @author  Christoph
 */
abstract class sly_Form_Widget_MediaBase extends sly_Form_ElementBase {
	protected $filetypes  = array();
	protected $categories = array();

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

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

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

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

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

		return $this;
	}

	/**
	 * @return sly_Form_Widget_MediaBase  the widget itself
	 */
	public function filterByFiletypes(array $types) {
		foreach ($types as $type) {
			$this->filetypes[] = sly_Util_Mime::getType('tmp.'.ltrim($type, '.'));
		}

		$this->filetypes = array_unique($this->filetypes);
		return $this;
	}

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

	/**
	 * @return sly_Form_Widget_MediaBase  the widget itself
	 */
	public function clearFiletypeFilter() {
		$this->filetypes = array();
		return $this;
	}
}
Back to Top