1: <?php
2: /*
3: You may not change or alter any portion of this comment or credits
4: of supporting developers from this source code or any supporting source code
5: which is considered copyrighted (c) material of the original comment or credit authors.
6:
7: This program is distributed in the hope that it will be useful,
8: but WITHOUT ANY WARRANTY; without even the implied warranty of
9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: */
11:
12: namespace Xoops\Core\Lists;
13:
14: use Xoops\Form\OptionElement;
15:
16: /**
17: * ImageFiles - provide list of image file names from a directory
18: *
19: * @category Xoops\Core\Lists\ImageFiles
20: * @package Xoops\Core
21: * @author Richard Griffith <richard@geekwright.com>
22: * @copyright 2015 XOOPS Project (http://xoops.org)/
23: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
24: * @link http://xoops.org
25: */
26: class SubjectIcon extends ListAbstract
27: {
28: /**
29: * gets list of image file names in a directory
30: *
31: * @param string $subDirectory subdirectory (deprecated)
32: *
33: * @return array
34: */
35: public static function getList($subDirectory = '')
36: {
37: $xoops = \Xoops::getInstance();
38: $subDirectory = trim($subDirectory, '/');
39: $path = 'images/subject/' . $subDirectory;
40: $subjects = ImageFile::getList($xoops->path($path), $subDirectory . '/');
41:
42: return $subjects;
43: }
44:
45: /**
46: * add list to a Xoops\Form\OptionElement
47: *
48: * @param OptionElement $element Form element to add options to
49: * @param string $subDirectory subdirectory (deprecated)
50: *
51: * @return void
52: */
53: public static function setOptionsArray(OptionElement $element, $subDirectory = '')
54: {
55: $xoops = \Xoops::getInstance();
56: $subjects = static::getList($subDirectory);
57: foreach (array_keys($subjects) as $name) {
58: $element->addOption(
59: $name,
60: '<img src="' . $xoops->url('images/subject/') . $name . '" alt="' . $name . '" />'
61: );
62: }
63: }
64: }
65: