Passed
Pull Request — master (#2)
by Michael
07:10 queued 03:28
created
class/Utf8map.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 
7 7
 \defined('XOOPS_ROOT_PATH') || exit('Restricted access');
8 8
 
9
-require_once \dirname(__DIR__) . '/include/songlist.object.php';
9
+require_once \dirname(__DIR__).'/include/songlist.object.php';
10 10
 // require_once \dirname(__DIR__) . '/include/songlist.form.php';
11 11
 use  XoopsModules\Songlist\Form\FormController;
12 12
 
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
             $ret['form'][$key] = $element->render();
49 49
         }
50 50
         foreach (['created', 'updated'] as $key) {
51
-            if ($this->getVar($key) > 0) {
51
+            if ($this->getVar($key)>0) {
52 52
                 $ret['form'][$key] = \date(_DATESTRING, $this->getVar($key));
53 53
                 $ret[$key]         = \date(_DATESTRING, $this->getVar($key));
54 54
             }
Please login to merge, or discard this patch.
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -16,51 +16,51 @@
 block discarded – undo
16 16
  */
17 17
 class Utf8map extends XoopsObject
18 18
 {
19
-    public $utfid;
20
-    public $from;
21
-    public $to;
22
-    public $created;
23
-    public $updated;
19
+	public $utfid;
20
+	public $from;
21
+	public $to;
22
+	public $created;
23
+	public $updated;
24 24
 
25
-    /**
26
-     * Utf8map constructor.
27
-     * @param null $fid
28
-     */
29
-    public function __construct($fid = null)
30
-    {
31
-        $this->initVar('utfid', \XOBJ_DTYPE_INT, 0, false);
32
-        $this->initVar('from', \XOBJ_DTYPE_TXTBOX, null, false, 2);
33
-        $this->initVar('to', \XOBJ_DTYPE_TXTBOX, null, false, 2);
34
-        $this->initVar('created', \XOBJ_DTYPE_INT, 0, false);
35
-        $this->initVar('updated', \XOBJ_DTYPE_INT, 0, false);
36
-    }
25
+	/**
26
+	 * Utf8map constructor.
27
+	 * @param null $fid
28
+	 */
29
+	public function __construct($fid = null)
30
+	{
31
+		$this->initVar('utfid', \XOBJ_DTYPE_INT, 0, false);
32
+		$this->initVar('from', \XOBJ_DTYPE_TXTBOX, null, false, 2);
33
+		$this->initVar('to', \XOBJ_DTYPE_TXTBOX, null, false, 2);
34
+		$this->initVar('created', \XOBJ_DTYPE_INT, 0, false);
35
+		$this->initVar('updated', \XOBJ_DTYPE_INT, 0, false);
36
+	}
37 37
 
38
-    /**
39
-     * @param bool $as_array
40
-     * @return array|string
41
-     */
42
-    public function getForm($as_array = false)
43
-    {
44
-        return FormController::getFormUtf8map($this, $as_array);
45
-    }
38
+	/**
39
+	 * @param bool $as_array
40
+	 * @return array|string
41
+	 */
42
+	public function getForm($as_array = false)
43
+	{
44
+		return FormController::getFormUtf8map($this, $as_array);
45
+	}
46 46
 
47
-    /**
48
-     * @return array
49
-     */
50
-    public function toArray(): array
51
-    {
52
-        $ret  = parent::toArray();
53
-        $form = $this->getForm(true);
54
-        foreach ($form as $key => $element) {
55
-            $ret['form'][$key] = $element->render();
56
-        }
57
-        foreach (['created', 'updated'] as $key) {
58
-            if ($this->getVar($key) > 0) {
59
-                $ret['form'][$key] = \date(_DATESTRING, $this->getVar($key));
60
-                $ret[$key]         = \date(_DATESTRING, $this->getVar($key));
61
-            }
62
-        }
47
+	/**
48
+	 * @return array
49
+	 */
50
+	public function toArray(): array
51
+	{
52
+		$ret  = parent::toArray();
53
+		$form = $this->getForm(true);
54
+		foreach ($form as $key => $element) {
55
+			$ret['form'][$key] = $element->render();
56
+		}
57
+		foreach (['created', 'updated'] as $key) {
58
+			if ($this->getVar($key) > 0) {
59
+				$ret['form'][$key] = \date(_DATESTRING, $this->getVar($key));
60
+				$ret[$key]         = \date(_DATESTRING, $this->getVar($key));
61
+			}
62
+		}
63 63
 
64
-        return $ret;
65
-    }
64
+		return $ret;
65
+	}
66 66
 }
Please login to merge, or discard this patch.
class/VoiceHandler.php 2 patches
Indentation   +162 added lines, -162 removed lines patch added patch discarded remove patch
@@ -11,121 +11,121 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class VoiceHandler extends \XoopsPersistableObjectHandler
13 13
 {
14
-    /**
15
-     * VoiceHandler constructor.
16
-     * @param \XoopsDatabase $db
17
-     */
18
-    public function __construct(\XoopsDatabase $db)
19
-    {
20
-        parent::__construct($db, 'songlist_voice', Voice::class, 'vcid', 'name');
21
-    }
22
-
23
-    /**
24
-     * @return array
25
-     */
26
-    public function filterFields(): array
27
-    {
28
-        return ['vcid', 'name', 'artists', 'albums', 'songs', 'hits', 'rank', 'votes', 'created', 'updated'];
29
-    }
30
-
31
-    /**
32
-     * @param $filter
33
-     * @return \CriteriaCompo
34
-     */
35
-    public function getFilterCriteria($filter): \CriteriaCompo
36
-    {
37
-        $parts    = \explode('|', $filter);
38
-        $criteria = new \CriteriaCompo();
39
-        foreach ($parts as $part) {
40
-            $var = \explode(',', $part);
41
-            if (!empty($var[1]) && !\is_numeric($var[0])) {
42
-                $object = $this->create();
43
-                if (\XOBJ_DTYPE_TXTBOX == $object->vars[$var[0]]['data_type']
44
-                    || \XOBJ_DTYPE_TXTAREA == $object->vars[$var[0]]['data_type']) {
45
-                    $criteria->add(new \Criteria('`' . $var[0] . '`', '%' . $var[1] . '%', ($var[2] ?? 'LIKE')));
46
-                } elseif (in_array($object->vars[$var[0]]['data_type'], [XOBJ_DTYPE_INT, XOBJ_DTYPE_DECIMAL, XOBJ_DTYPE_FLOAT])) {
47
-                    $criteria->add(new \Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '=')));
48
-                } elseif (\XOBJ_DTYPE_ENUM == $object->vars[$var[0]]['data_type']) {
49
-                    $criteria->add(new \Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '=')));
50
-                } elseif (\XOBJ_DTYPE_ARRAY == $object->vars[$var[0]]['data_type']) {
51
-                    $criteria->add(new \Criteria('`' . $var[0] . '`', '%"' . $var[1] . '";%', ($var[2] ?? 'LIKE')));
52
-                }
53
-            } elseif (!empty($var[1]) && \is_numeric($var[0])) {
54
-                $criteria->add(new \Criteria($var[0], $var[1]));
55
-            }
56
-        }
57
-
58
-        return $criteria;
59
-    }
60
-
61
-    /**
62
-     * @param        $filter
63
-     * @param        $field
64
-     * @param string $sort
65
-     * @param string $op
66
-     * @param string $fct
67
-     * @return string
68
-     */
69
-    public function getFilterForm($filter, $field, $sort = 'created', $op = 'dashboard', $fct = 'list'): string
70
-    {
71
-        $ele = Utility::getFilterElement($filter, $field, $sort, $op, $fct);
72
-        if (\is_object($ele)) {
73
-            return $ele->render();
74
-        }
75
-
76
-        return ' ';
77
-    }
78
-
79
-    /**
80
-     * @param bool $force
81
-     * @return bool|mixed
82
-     */
83
-    public function insert(\XoopsObject $obj, $force = true)
84
-    {
85
-        if ($obj->isNew()) {
86
-            $obj->setVar('created', \time());
87
-        } else {
88
-            $obj->setVar('updated', \time());
89
-        }
90
-        if ('' == $obj->getVar('name')) {
91
-            return false;
92
-        }
93
-
94
-        return parent::insert($obj, $force);
95
-    }
96
-
97
-    public $_objects = ['object' => [], 'array' => []];
98
-
99
-    /**
100
-     * @param null $id
101
-     * @param null $fields
102
-     * @return \XoopsObject
103
-     */
104
-    public function get($id = null, $fields = null): \XoopsObject//get($id, $fields = '*')
105
-    {
106
-        $fields = $fields ?: '*';
107
-        if (!isset($this->_objects['object'][$id])) {
108
-            $this->_objects['object'][$id] = parent::get($id, $fields);
109
-            if (!isset($GLOBALS['songlistAdmin']) && \is_object($this->_objects['object'][$id])) {
110
-                $sql = 'UPDATE `' . $this->table . '` set hits=hits+1 where `' . $this->keyName . '` = ' . $this->_objects['object'][$id]->getVar($this->keyName);
111
-                $GLOBALS['xoopsDB']->queryF($sql);
112
-            }
113
-        }
114
-
115
-        return $this->_objects['object'][$id];
116
-    }
117
-
118
-    /**
119
-     * @param \CriteriaElement|\CriteriaCompo $criteria
120
-     * @param bool $id_as_key
121
-     * @param bool $as_object
122
-     * @return array
123
-     */
124
-    public function &getObjects($criteria = null, $id_as_key = false, $as_object = true): array
125
-    {
126
-        $ret = parent::getObjects($criteria, $id_as_key, $as_object);
127
-
128
-        /*if (!isset($GLOBALS['songlistAdmin'])) {
14
+	/**
15
+	 * VoiceHandler constructor.
16
+	 * @param \XoopsDatabase $db
17
+	 */
18
+	public function __construct(\XoopsDatabase $db)
19
+	{
20
+		parent::__construct($db, 'songlist_voice', Voice::class, 'vcid', 'name');
21
+	}
22
+
23
+	/**
24
+	 * @return array
25
+	 */
26
+	public function filterFields(): array
27
+	{
28
+		return ['vcid', 'name', 'artists', 'albums', 'songs', 'hits', 'rank', 'votes', 'created', 'updated'];
29
+	}
30
+
31
+	/**
32
+	 * @param $filter
33
+	 * @return \CriteriaCompo
34
+	 */
35
+	public function getFilterCriteria($filter): \CriteriaCompo
36
+	{
37
+		$parts    = \explode('|', $filter);
38
+		$criteria = new \CriteriaCompo();
39
+		foreach ($parts as $part) {
40
+			$var = \explode(',', $part);
41
+			if (!empty($var[1]) && !\is_numeric($var[0])) {
42
+				$object = $this->create();
43
+				if (\XOBJ_DTYPE_TXTBOX == $object->vars[$var[0]]['data_type']
44
+					|| \XOBJ_DTYPE_TXTAREA == $object->vars[$var[0]]['data_type']) {
45
+					$criteria->add(new \Criteria('`' . $var[0] . '`', '%' . $var[1] . '%', ($var[2] ?? 'LIKE')));
46
+				} elseif (in_array($object->vars[$var[0]]['data_type'], [XOBJ_DTYPE_INT, XOBJ_DTYPE_DECIMAL, XOBJ_DTYPE_FLOAT])) {
47
+					$criteria->add(new \Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '=')));
48
+				} elseif (\XOBJ_DTYPE_ENUM == $object->vars[$var[0]]['data_type']) {
49
+					$criteria->add(new \Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '=')));
50
+				} elseif (\XOBJ_DTYPE_ARRAY == $object->vars[$var[0]]['data_type']) {
51
+					$criteria->add(new \Criteria('`' . $var[0] . '`', '%"' . $var[1] . '";%', ($var[2] ?? 'LIKE')));
52
+				}
53
+			} elseif (!empty($var[1]) && \is_numeric($var[0])) {
54
+				$criteria->add(new \Criteria($var[0], $var[1]));
55
+			}
56
+		}
57
+
58
+		return $criteria;
59
+	}
60
+
61
+	/**
62
+	 * @param        $filter
63
+	 * @param        $field
64
+	 * @param string $sort
65
+	 * @param string $op
66
+	 * @param string $fct
67
+	 * @return string
68
+	 */
69
+	public function getFilterForm($filter, $field, $sort = 'created', $op = 'dashboard', $fct = 'list'): string
70
+	{
71
+		$ele = Utility::getFilterElement($filter, $field, $sort, $op, $fct);
72
+		if (\is_object($ele)) {
73
+			return $ele->render();
74
+		}
75
+
76
+		return ' ';
77
+	}
78
+
79
+	/**
80
+	 * @param bool $force
81
+	 * @return bool|mixed
82
+	 */
83
+	public function insert(\XoopsObject $obj, $force = true)
84
+	{
85
+		if ($obj->isNew()) {
86
+			$obj->setVar('created', \time());
87
+		} else {
88
+			$obj->setVar('updated', \time());
89
+		}
90
+		if ('' == $obj->getVar('name')) {
91
+			return false;
92
+		}
93
+
94
+		return parent::insert($obj, $force);
95
+	}
96
+
97
+	public $_objects = ['object' => [], 'array' => []];
98
+
99
+	/**
100
+	 * @param null $id
101
+	 * @param null $fields
102
+	 * @return \XoopsObject
103
+	 */
104
+	public function get($id = null, $fields = null): \XoopsObject//get($id, $fields = '*')
105
+	{
106
+		$fields = $fields ?: '*';
107
+		if (!isset($this->_objects['object'][$id])) {
108
+			$this->_objects['object'][$id] = parent::get($id, $fields);
109
+			if (!isset($GLOBALS['songlistAdmin']) && \is_object($this->_objects['object'][$id])) {
110
+				$sql = 'UPDATE `' . $this->table . '` set hits=hits+1 where `' . $this->keyName . '` = ' . $this->_objects['object'][$id]->getVar($this->keyName);
111
+				$GLOBALS['xoopsDB']->queryF($sql);
112
+			}
113
+		}
114
+
115
+		return $this->_objects['object'][$id];
116
+	}
117
+
118
+	/**
119
+	 * @param \CriteriaElement|\CriteriaCompo $criteria
120
+	 * @param bool $id_as_key
121
+	 * @param bool $as_object
122
+	 * @return array
123
+	 */
124
+	public function &getObjects($criteria = null, $id_as_key = false, $as_object = true): array
125
+	{
126
+		$ret = parent::getObjects($criteria, $id_as_key, $as_object);
127
+
128
+		/*if (!isset($GLOBALS['songlistAdmin'])) {
129 129
             $id = [];
130 130
             foreach($ret as $data) {
131 131
                 if ($as_object==true) {
@@ -146,51 +146,51 @@  discard block
 block discarded – undo
146 146
             $GLOBALS['xoopsDB']->queryF($sql);
147 147
         }*/
148 148
 
149
-        return $ret;
150
-    }
151
-
152
-    /**
153
-     * @return string
154
-     */
155
-    public function getURL(): string
156
-    {
157
-        global $file, $op, $fct, $id, $value, $gid, $cid, $start, $limit;
158
-        if ($GLOBALS['songlistModuleConfig']['htaccess']) {
159
-            return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseurl'] . '/' . $file . '/' . $start . '-' . $op . '-' . $fct . '-' . $id . '-' . \urlencode($value) . '-' . $gid . '-' . $cid . $GLOBALS['songlistModuleConfig']['endofurl'];
160
-        }
161
-
162
-        return XOOPS_URL . '/modules/songlist/' . $file . '.php?op=' . $op . '&fct=' . $fct . '&id=' . $id . '&value=' . \urlencode($value ?? '') . '&gid=' . $gid . '&cid=' . $cid . '&start=' . $start;
163
-    }
164
-
165
-    /**
166
-     * @param int $limit
167
-     * @return array
168
-     */
169
-    public function getTop($limit = 1): array
170
-    {
171
-        $sql     = 'SELECT * FROM `' . $this->table . '` WHERE `rank`>=0 ORDER BY (`rank`/`votes`) DESC LIMIT ' . $limit;
172
-        $results = $GLOBALS['xoopsDB']->queryF($sql);
173
-        $ret     = [];
174
-        $i       = 0;
175
-        while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($results))) {
176
-            $ret[$i] = $this->create();
177
-            $ret[$i]->assignVars($row);
178
-            ++$i;
179
-        }
180
-
181
-        return $ret;
182
-    }
183
-
184
-    /**
185
-     * @param \XoopsObject $object
186
-     * @param bool         $force
187
-     * @return bool
188
-     */
189
-    public function delete(\XoopsObject $object, $force = true): bool
190
-    {
191
-        parent::delete($object, $force);
192
-        $sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('songlist_songs') . ' SET `vcid` = 0 WHERE `vcid` = ' . $object->getVar('vcid');
193
-
194
-        return $GLOBALS['xoopsDB']->queryF($sql);
195
-    }
149
+		return $ret;
150
+	}
151
+
152
+	/**
153
+	 * @return string
154
+	 */
155
+	public function getURL(): string
156
+	{
157
+		global $file, $op, $fct, $id, $value, $gid, $cid, $start, $limit;
158
+		if ($GLOBALS['songlistModuleConfig']['htaccess']) {
159
+			return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseurl'] . '/' . $file . '/' . $start . '-' . $op . '-' . $fct . '-' . $id . '-' . \urlencode($value) . '-' . $gid . '-' . $cid . $GLOBALS['songlistModuleConfig']['endofurl'];
160
+		}
161
+
162
+		return XOOPS_URL . '/modules/songlist/' . $file . '.php?op=' . $op . '&fct=' . $fct . '&id=' . $id . '&value=' . \urlencode($value ?? '') . '&gid=' . $gid . '&cid=' . $cid . '&start=' . $start;
163
+	}
164
+
165
+	/**
166
+	 * @param int $limit
167
+	 * @return array
168
+	 */
169
+	public function getTop($limit = 1): array
170
+	{
171
+		$sql     = 'SELECT * FROM `' . $this->table . '` WHERE `rank`>=0 ORDER BY (`rank`/`votes`) DESC LIMIT ' . $limit;
172
+		$results = $GLOBALS['xoopsDB']->queryF($sql);
173
+		$ret     = [];
174
+		$i       = 0;
175
+		while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($results))) {
176
+			$ret[$i] = $this->create();
177
+			$ret[$i]->assignVars($row);
178
+			++$i;
179
+		}
180
+
181
+		return $ret;
182
+	}
183
+
184
+	/**
185
+	 * @param \XoopsObject $object
186
+	 * @param bool         $force
187
+	 * @return bool
188
+	 */
189
+	public function delete(\XoopsObject $object, $force = true): bool
190
+	{
191
+		parent::delete($object, $force);
192
+		$sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('songlist_songs') . ' SET `vcid` = 0 WHERE `vcid` = ' . $object->getVar('vcid');
193
+
194
+		return $GLOBALS['xoopsDB']->queryF($sql);
195
+	}
196 196
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 
3 3
 namespace XoopsModules\Songlist;
4 4
 
5
-require_once \dirname(__DIR__) . '/include/songlist.object.php';
5
+require_once \dirname(__DIR__).'/include/songlist.object.php';
6 6
 // require_once \dirname(__DIR__) . '/include/songlist.form.php';
7 7
 use  XoopsModules\Songlist\Form\FormController;
8 8
 
@@ -40,15 +40,15 @@  discard block
 block discarded – undo
40 40
             $var = \explode(',', $part);
41 41
             if (!empty($var[1]) && !\is_numeric($var[0])) {
42 42
                 $object = $this->create();
43
-                if (\XOBJ_DTYPE_TXTBOX == $object->vars[$var[0]]['data_type']
44
-                    || \XOBJ_DTYPE_TXTAREA == $object->vars[$var[0]]['data_type']) {
45
-                    $criteria->add(new \Criteria('`' . $var[0] . '`', '%' . $var[1] . '%', ($var[2] ?? 'LIKE')));
43
+                if (\XOBJ_DTYPE_TXTBOX==$object->vars[$var[0]]['data_type']
44
+                    || \XOBJ_DTYPE_TXTAREA==$object->vars[$var[0]]['data_type']) {
45
+                    $criteria->add(new \Criteria('`'.$var[0].'`', '%'.$var[1].'%', ($var[2] ?? 'LIKE')));
46 46
                 } elseif (in_array($object->vars[$var[0]]['data_type'], [XOBJ_DTYPE_INT, XOBJ_DTYPE_DECIMAL, XOBJ_DTYPE_FLOAT])) {
47
-                    $criteria->add(new \Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '=')));
48
-                } elseif (\XOBJ_DTYPE_ENUM == $object->vars[$var[0]]['data_type']) {
49
-                    $criteria->add(new \Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '=')));
50
-                } elseif (\XOBJ_DTYPE_ARRAY == $object->vars[$var[0]]['data_type']) {
51
-                    $criteria->add(new \Criteria('`' . $var[0] . '`', '%"' . $var[1] . '";%', ($var[2] ?? 'LIKE')));
47
+                    $criteria->add(new \Criteria('`'.$var[0].'`', $var[1], ($var[2] ?? '=')));
48
+                } elseif (\XOBJ_DTYPE_ENUM==$object->vars[$var[0]]['data_type']) {
49
+                    $criteria->add(new \Criteria('`'.$var[0].'`', $var[1], ($var[2] ?? '=')));
50
+                } elseif (\XOBJ_DTYPE_ARRAY==$object->vars[$var[0]]['data_type']) {
51
+                    $criteria->add(new \Criteria('`'.$var[0].'`', '%"'.$var[1].'";%', ($var[2] ?? 'LIKE')));
52 52
                 }
53 53
             } elseif (!empty($var[1]) && \is_numeric($var[0])) {
54 54
                 $criteria->add(new \Criteria($var[0], $var[1]));
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
         } else {
88 88
             $obj->setVar('updated', \time());
89 89
         }
90
-        if ('' == $obj->getVar('name')) {
90
+        if (''==$obj->getVar('name')) {
91 91
             return false;
92 92
         }
93 93
 
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
         if (!isset($this->_objects['object'][$id])) {
108 108
             $this->_objects['object'][$id] = parent::get($id, $fields);
109 109
             if (!isset($GLOBALS['songlistAdmin']) && \is_object($this->_objects['object'][$id])) {
110
-                $sql = 'UPDATE `' . $this->table . '` set hits=hits+1 where `' . $this->keyName . '` = ' . $this->_objects['object'][$id]->getVar($this->keyName);
110
+                $sql = 'UPDATE `'.$this->table.'` set hits=hits+1 where `'.$this->keyName.'` = '.$this->_objects['object'][$id]->getVar($this->keyName);
111 111
                 $GLOBALS['xoopsDB']->queryF($sql);
112 112
             }
113 113
         }
@@ -156,10 +156,10 @@  discard block
 block discarded – undo
156 156
     {
157 157
         global $file, $op, $fct, $id, $value, $gid, $cid, $start, $limit;
158 158
         if ($GLOBALS['songlistModuleConfig']['htaccess']) {
159
-            return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseurl'] . '/' . $file . '/' . $start . '-' . $op . '-' . $fct . '-' . $id . '-' . \urlencode($value) . '-' . $gid . '-' . $cid . $GLOBALS['songlistModuleConfig']['endofurl'];
159
+            return XOOPS_URL.'/'.$GLOBALS['songlistModuleConfig']['baseurl'].'/'.$file.'/'.$start.'-'.$op.'-'.$fct.'-'.$id.'-'.\urlencode($value).'-'.$gid.'-'.$cid.$GLOBALS['songlistModuleConfig']['endofurl'];
160 160
         }
161 161
 
162
-        return XOOPS_URL . '/modules/songlist/' . $file . '.php?op=' . $op . '&fct=' . $fct . '&id=' . $id . '&value=' . \urlencode($value ?? '') . '&gid=' . $gid . '&cid=' . $cid . '&start=' . $start;
162
+        return XOOPS_URL.'/modules/songlist/'.$file.'.php?op='.$op.'&fct='.$fct.'&id='.$id.'&value='.\urlencode($value ?? '').'&gid='.$gid.'&cid='.$cid.'&start='.$start;
163 163
     }
164 164
 
165 165
     /**
@@ -168,11 +168,11 @@  discard block
 block discarded – undo
168 168
      */
169 169
     public function getTop($limit = 1): array
170 170
     {
171
-        $sql     = 'SELECT * FROM `' . $this->table . '` WHERE `rank`>=0 ORDER BY (`rank`/`votes`) DESC LIMIT ' . $limit;
171
+        $sql     = 'SELECT * FROM `'.$this->table.'` WHERE `rank`>=0 ORDER BY (`rank`/`votes`) DESC LIMIT '.$limit;
172 172
         $results = $GLOBALS['xoopsDB']->queryF($sql);
173 173
         $ret     = [];
174 174
         $i       = 0;
175
-        while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($results))) {
175
+        while (false!==($row = $GLOBALS['xoopsDB']->fetchArray($results))) {
176 176
             $ret[$i] = $this->create();
177 177
             $ret[$i]->assignVars($row);
178 178
             ++$i;
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
     public function delete(\XoopsObject $object, $force = true): bool
190 190
     {
191 191
         parent::delete($object, $force);
192
-        $sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('songlist_songs') . ' SET `vcid` = 0 WHERE `vcid` = ' . $object->getVar('vcid');
192
+        $sql = 'UPDATE '.$GLOBALS['xoopsDB']->prefix('songlist_songs').' SET `vcid` = 0 WHERE `vcid` = '.$object->getVar('vcid');
193 193
 
194 194
         return $GLOBALS['xoopsDB']->queryF($sql);
195 195
     }
Please login to merge, or discard this patch.
class/Form/SelectGenreForm.php 2 patches
Indentation   +207 added lines, -207 removed lines patch added patch discarded remove patch
@@ -53,230 +53,230 @@
 block discarded – undo
53 53
  */
54 54
 class SelectGenreForm extends XoopsFormElement
55 55
 {
56
-    /**
57
-     * Options
58
-     *
59
-     * @var array
60
-     */
61
-    public $_options = [];
62
-    /**
63
-     * Allow multiple selections?
64
-     *
65
-     * @var bool
66
-     */
67
-    public $_multiple = false;
68
-    /**
69
-     * Number of rows. "1" makes a dropdown list.
70
-     *
71
-     * @var int
72
-     */
73
-    public $_size;
74
-    /**
75
-     * Pre-selcted values
76
-     *
77
-     * @var array
78
-     */
79
-    public $_value = [];
56
+	/**
57
+	 * Options
58
+	 *
59
+	 * @var array
60
+	 */
61
+	public $_options = [];
62
+	/**
63
+	 * Allow multiple selections?
64
+	 *
65
+	 * @var bool
66
+	 */
67
+	public $_multiple = false;
68
+	/**
69
+	 * Number of rows. "1" makes a dropdown list.
70
+	 *
71
+	 * @var int
72
+	 */
73
+	public $_size;
74
+	/**
75
+	 * Pre-selcted values
76
+	 *
77
+	 * @var array
78
+	 */
79
+	public $_value = [];
80 80
 
81
-    /**
82
-     * Constructor
83
-     *
84
-     * @param string $caption  Caption
85
-     * @param string $name     "name" attribute
86
-     * @param mixed  $value    Pre-selected value (or array of them).
87
-     * @param int    $size     Number or rows. "1" makes a drop-down-list
88
-     * @param bool   $multiple Allow multiple selections?
89
-     */
90
-    public function __construct($caption, $name, $value = null, $size = 1, $multiple = false)
91
-    {
92
-        global $_form_object_options;
93
-        \xoops_loadLanguage('modinfo', 'songlist');
81
+	/**
82
+	 * Constructor
83
+	 *
84
+	 * @param string $caption  Caption
85
+	 * @param string $name     "name" attribute
86
+	 * @param mixed  $value    Pre-selected value (or array of them).
87
+	 * @param int    $size     Number or rows. "1" makes a drop-down-list
88
+	 * @param bool   $multiple Allow multiple selections?
89
+	 */
90
+	public function __construct($caption, $name, $value = null, $size = 1, $multiple = false)
91
+	{
92
+		global $_form_object_options;
93
+		\xoops_loadLanguage('modinfo', 'songlist');
94 94
 
95
-        $this->setCaption($caption);
96
-        $this->setName($name);
97
-        $this->_multiple = $multiple;
98
-        $this->_size     = (int)$size;
99
-        if (isset($value)) {
100
-            $this->setValue($value);
101
-        }
102
-        $this->addOption('0', \_MI_SONGLIST_ALL);
103
-        if (!isset($_form_object_options['genre'])) {
104
-            $genreHandler = Helper::getInstance()->getHandler('Genre');
105
-            $criteria     = new Criteria('');
106
-            $criteria->setSort('name');
107
-            $criteria->setOrder('ASC');
108
-            foreach ($genreHandler->getObjects($criteria, true) as $id => $obj) {
109
-                $_form_object_options['genre'][$id] = $obj->getVar('name');
110
-            }
111
-        }
112
-        //        if (Request::hasVar('genre', 'form_object_options')) {
113
-        if (isset($_form_object_options['genre'])) {
114
-            foreach ($_form_object_options['genre'] as $id => $value) {
115
-                $this->addOption($id, $value);
116
-            }
117
-        }
118
-    }
95
+		$this->setCaption($caption);
96
+		$this->setName($name);
97
+		$this->_multiple = $multiple;
98
+		$this->_size     = (int)$size;
99
+		if (isset($value)) {
100
+			$this->setValue($value);
101
+		}
102
+		$this->addOption('0', \_MI_SONGLIST_ALL);
103
+		if (!isset($_form_object_options['genre'])) {
104
+			$genreHandler = Helper::getInstance()->getHandler('Genre');
105
+			$criteria     = new Criteria('');
106
+			$criteria->setSort('name');
107
+			$criteria->setOrder('ASC');
108
+			foreach ($genreHandler->getObjects($criteria, true) as $id => $obj) {
109
+				$_form_object_options['genre'][$id] = $obj->getVar('name');
110
+			}
111
+		}
112
+		//        if (Request::hasVar('genre', 'form_object_options')) {
113
+		if (isset($_form_object_options['genre'])) {
114
+			foreach ($_form_object_options['genre'] as $id => $value) {
115
+				$this->addOption($id, $value);
116
+			}
117
+		}
118
+	}
119 119
 
120
-    /**
121
-     * Are multiple selections allowed?
122
-     *
123
-     * @return bool
124
-     */
125
-    public function isMultiple(): bool
126
-    {
127
-        return $this->_multiple;
128
-    }
120
+	/**
121
+	 * Are multiple selections allowed?
122
+	 *
123
+	 * @return bool
124
+	 */
125
+	public function isMultiple(): bool
126
+	{
127
+		return $this->_multiple;
128
+	}
129 129
 
130
-    /**
131
-     * Get the size
132
-     *
133
-     * @return int
134
-     */
135
-    public function getSize(): int
136
-    {
137
-        return $this->_size;
138
-    }
130
+	/**
131
+	 * Get the size
132
+	 *
133
+	 * @return int
134
+	 */
135
+	public function getSize(): int
136
+	{
137
+		return $this->_size;
138
+	}
139 139
 
140
-    /**
141
-     * Get an array of pre-selected values
142
-     *
143
-     * @param bool $encode To sanitizer the text?
144
-     * @return array
145
-     */
146
-    public function getValue($encode = false): array
147
-    {
148
-        if (!$encode) {
149
-            return $this->_value;
150
-        }
151
-        $value = [];
152
-        foreach ($this->_value as $val) {
153
-            $value[] = $val ? \htmlspecialchars($val, \ENT_QUOTES) : $val;
154
-        }
140
+	/**
141
+	 * Get an array of pre-selected values
142
+	 *
143
+	 * @param bool $encode To sanitizer the text?
144
+	 * @return array
145
+	 */
146
+	public function getValue($encode = false): array
147
+	{
148
+		if (!$encode) {
149
+			return $this->_value;
150
+		}
151
+		$value = [];
152
+		foreach ($this->_value as $val) {
153
+			$value[] = $val ? \htmlspecialchars($val, \ENT_QUOTES) : $val;
154
+		}
155 155
 
156
-        return $value;
157
-    }
156
+		return $value;
157
+	}
158 158
 
159
-    /**
160
-     * Set pre-selected values
161
-     *
162
-     * @param mixed $value
163
-     */
164
-    public function setValue($value): void
165
-    {
166
-        if (\is_array($value)) {
167
-            foreach ($value as $v) {
168
-                $this->_value[] = (int)$v;
169
-            }
159
+	/**
160
+	 * Set pre-selected values
161
+	 *
162
+	 * @param mixed $value
163
+	 */
164
+	public function setValue($value): void
165
+	{
166
+		if (\is_array($value)) {
167
+			foreach ($value as $v) {
168
+				$this->_value[] = (int)$v;
169
+			}
170 170
 
171 171
 //            $this->_value[] = array_values($value);
172
-        } elseif (isset($value)) {
173
-            $this->_value[] = $value;
174
-        }
175
-    }
172
+		} elseif (isset($value)) {
173
+			$this->_value[] = $value;
174
+		}
175
+	}
176 176
 
177
-    /**
178
-     * Add an option
179
-     *
180
-     * @param string $value "value" attribute
181
-     * @param string $name  "name" attribute
182
-     */
183
-    public function addOption($value, $name = ''): void
184
-    {
185
-        if ('' != $name) {
186
-            $this->_options[$value] = $name;
187
-        } else {
188
-            $this->_options[$value] = $value;
189
-        }
190
-    }
177
+	/**
178
+	 * Add an option
179
+	 *
180
+	 * @param string $value "value" attribute
181
+	 * @param string $name  "name" attribute
182
+	 */
183
+	public function addOption($value, $name = ''): void
184
+	{
185
+		if ('' != $name) {
186
+			$this->_options[$value] = $name;
187
+		} else {
188
+			$this->_options[$value] = $value;
189
+		}
190
+	}
191 191
 
192
-    /**
193
-     * Add multiple options
194
-     *
195
-     * @param array $options Associative array of value->name pairs
196
-     */
197
-    public function addOptionArray($options): void
198
-    {
199
-        if (\is_array($options)) {
200
-            foreach ($options as $k => $v) {
201
-                $this->addOption($k, $v);
202
-            }
203
-        }
204
-    }
192
+	/**
193
+	 * Add multiple options
194
+	 *
195
+	 * @param array $options Associative array of value->name pairs
196
+	 */
197
+	public function addOptionArray($options): void
198
+	{
199
+		if (\is_array($options)) {
200
+			foreach ($options as $k => $v) {
201
+				$this->addOption($k, $v);
202
+			}
203
+		}
204
+	}
205 205
 
206
-    /**
207
-     * Get an array with all the options
208
-     *
209
-     * Note: both name and value should be sanitized. However for backward compatibility, only value is sanitized for now.
210
-     *
211
-     * @param bool|int $encode To sanitizer the text? potential values: 0 - skip; 1 - only for value; 2 - for both value and name
212
-     * @return array Associative array of value->name pairs
213
-     */
214
-    public function getOptions($encode = false): array
215
-    {
216
-        if (!$encode) {
217
-            return $this->_options;
218
-        }
219
-        $value = [];
220
-        foreach ($this->_options as $val => $name) {
221
-            $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name;
222
-        }
206
+	/**
207
+	 * Get an array with all the options
208
+	 *
209
+	 * Note: both name and value should be sanitized. However for backward compatibility, only value is sanitized for now.
210
+	 *
211
+	 * @param bool|int $encode To sanitizer the text? potential values: 0 - skip; 1 - only for value; 2 - for both value and name
212
+	 * @return array Associative array of value->name pairs
213
+	 */
214
+	public function getOptions($encode = false): array
215
+	{
216
+		if (!$encode) {
217
+			return $this->_options;
218
+		}
219
+		$value = [];
220
+		foreach ($this->_options as $val => $name) {
221
+			$value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name;
222
+		}
223 223
 
224
-        return $value;
225
-    }
224
+		return $value;
225
+	}
226 226
 
227
-    /**
228
-     * Prepare HTML for output
229
-     *
230
-     * @return string HTML
231
-     */
232
-    public function render(): string
233
-    {
234
-        $ele_name    = $this->getName();
235
-        $ele_title   = $this->getTitle();
236
-        $ele_value   = $this->getValue();
237
-        $ele_options = $this->getOptions();
238
-        $ret         = '<select size="' . $this->getSize() . '"' . $this->getExtra();
239
-        if ($this->isMultiple()) {
240
-            $ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">';
241
-        } else {
242
-            $ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">';
243
-        }
244
-        foreach ($ele_options as $value => $name) {
245
-            $ret .= '<option value="' . \htmlspecialchars((string)$value, \ENT_QUOTES) . '"';
246
-            if (\count($ele_value) > 0 && \in_array($value, $ele_value, true)) {
247
-                $ret .= ' selected';
248
-            }
249
-            $ret .= '>' . $name . '</option>';
250
-        }
251
-        $ret .= '</select>';
227
+	/**
228
+	 * Prepare HTML for output
229
+	 *
230
+	 * @return string HTML
231
+	 */
232
+	public function render(): string
233
+	{
234
+		$ele_name    = $this->getName();
235
+		$ele_title   = $this->getTitle();
236
+		$ele_value   = $this->getValue();
237
+		$ele_options = $this->getOptions();
238
+		$ret         = '<select size="' . $this->getSize() . '"' . $this->getExtra();
239
+		if ($this->isMultiple()) {
240
+			$ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">';
241
+		} else {
242
+			$ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">';
243
+		}
244
+		foreach ($ele_options as $value => $name) {
245
+			$ret .= '<option value="' . \htmlspecialchars((string)$value, \ENT_QUOTES) . '"';
246
+			if (\count($ele_value) > 0 && \in_array($value, $ele_value, true)) {
247
+				$ret .= ' selected';
248
+			}
249
+			$ret .= '>' . $name . '</option>';
250
+		}
251
+		$ret .= '</select>';
252 252
 
253
-        return $ret;
254
-    }
253
+		return $ret;
254
+	}
255 255
 
256
-    /**
257
-     * Render custom javascript validation code
258
-     *
259
-     * @seealso XoopsForm::renderValidationJS
260
-     */
261
-    public function renderValidationJS()
262
-    {
263
-        // render custom validation code if any
264
-        if (!empty($this->customValidationCode)) {
265
-            return \implode("\n", $this->customValidationCode);
266
-            // generate validation code if required
267
-        }
256
+	/**
257
+	 * Render custom javascript validation code
258
+	 *
259
+	 * @seealso XoopsForm::renderValidationJS
260
+	 */
261
+	public function renderValidationJS()
262
+	{
263
+		// render custom validation code if any
264
+		if (!empty($this->customValidationCode)) {
265
+			return \implode("\n", $this->customValidationCode);
266
+			// generate validation code if required
267
+		}
268 268
 
269
-        if ($this->isRequired()) {
270
-            $eltname    = $this->getName();
271
-            $eltcaption = $this->getCaption();
272
-            $eltmsg     = empty($eltcaption) ? \sprintf(_FORM_ENTER, $eltname) : \sprintf(_FORM_ENTER, $eltcaption);
273
-            $eltmsg     = \str_replace('"', '\"', \stripslashes($eltmsg));
269
+		if ($this->isRequired()) {
270
+			$eltname    = $this->getName();
271
+			$eltcaption = $this->getCaption();
272
+			$eltmsg     = empty($eltcaption) ? \sprintf(_FORM_ENTER, $eltname) : \sprintf(_FORM_ENTER, $eltcaption);
273
+			$eltmsg     = \str_replace('"', '\"', \stripslashes($eltmsg));
274 274
 
275
-            return "\nvar hasSelected = false; var selectBox = myform.{$eltname};"
276
-                   . 'for (i = 0; i < selectBox.options.length; i++ ) { if (selectBox.options[i].selected === true) { hasSelected = true; break; } }'
277
-                   . "if (!hasSelected) { window.alert(\"{$eltmsg}\"); selectBox.focus(); return false; }";
278
-        }
275
+			return "\nvar hasSelected = false; var selectBox = myform.{$eltname};"
276
+				   . 'for (i = 0; i < selectBox.options.length; i++ ) { if (selectBox.options[i].selected === true) { hasSelected = true; break; } }'
277
+				   . "if (!hasSelected) { window.alert(\"{$eltmsg}\"); selectBox.focus(); return false; }";
278
+		}
279 279
 
280
-        return '';
281
-    }
280
+		return '';
281
+	}
282 282
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
         $this->setCaption($caption);
96 96
         $this->setName($name);
97 97
         $this->_multiple = $multiple;
98
-        $this->_size     = (int)$size;
98
+        $this->_size     = (int) $size;
99 99
         if (isset($value)) {
100 100
             $this->setValue($value);
101 101
         }
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
     {
166 166
         if (\is_array($value)) {
167 167
             foreach ($value as $v) {
168
-                $this->_value[] = (int)$v;
168
+                $this->_value[] = (int) $v;
169 169
             }
170 170
 
171 171
 //            $this->_value[] = array_values($value);
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
      */
183 183
     public function addOption($value, $name = ''): void
184 184
     {
185
-        if ('' != $name) {
185
+        if (''!=$name) {
186 186
             $this->_options[$value] = $name;
187 187
         } else {
188 188
             $this->_options[$value] = $value;
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
         }
219 219
         $value = [];
220 220
         foreach ($this->_options as $val => $name) {
221
-            $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name;
221
+            $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode>1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name;
222 222
         }
223 223
 
224 224
         return $value;
@@ -235,18 +235,18 @@  discard block
 block discarded – undo
235 235
         $ele_title   = $this->getTitle();
236 236
         $ele_value   = $this->getValue();
237 237
         $ele_options = $this->getOptions();
238
-        $ret         = '<select size="' . $this->getSize() . '"' . $this->getExtra();
238
+        $ret         = '<select size="'.$this->getSize().'"'.$this->getExtra();
239 239
         if ($this->isMultiple()) {
240
-            $ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">';
240
+            $ret .= ' name="'.$ele_name.'[]" id="'.$ele_name.'" title="'.$ele_title.'" multiple="multiple">';
241 241
         } else {
242
-            $ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">';
242
+            $ret .= ' name="'.$ele_name.'" id="'.$ele_name.'" title="'.$ele_title.'">';
243 243
         }
244 244
         foreach ($ele_options as $value => $name) {
245
-            $ret .= '<option value="' . \htmlspecialchars((string)$value, \ENT_QUOTES) . '"';
246
-            if (\count($ele_value) > 0 && \in_array($value, $ele_value, true)) {
245
+            $ret .= '<option value="'.\htmlspecialchars((string) $value, \ENT_QUOTES).'"';
246
+            if (\count($ele_value)>0 && \in_array($value, $ele_value, true)) {
247 247
                 $ret .= ' selected';
248 248
             }
249
-            $ret .= '>' . $name . '</option>';
249
+            $ret .= '>'.$name.'</option>';
250 250
         }
251 251
         $ret .= '</select>';
252 252
 
Please login to merge, or discard this patch.
class/Form/SelectAlbumForm.php 2 patches
Indentation   +208 added lines, -208 removed lines patch added patch discarded remove patch
@@ -53,230 +53,230 @@
 block discarded – undo
53 53
  */
54 54
 class SelectAlbumForm extends XoopsFormElement
55 55
 {
56
-    /**
57
-     * Options
58
-     *
59
-     * @var array
60
-     */
61
-    public $_options = [];
62
-    /**
63
-     * Allow multiple selections?
64
-     *
65
-     * @var bool
66
-     */
67
-    public $_multiple = false;
68
-    /**
69
-     * Number of rows. "1" makes a dropdown list.
70
-     *
71
-     * @var int
72
-     */
73
-    public $_size;
74
-    /**
75
-     * Pre-selcted values
76
-     *
77
-     * @var array
78
-     */
79
-    public $_value = [];
56
+	/**
57
+	 * Options
58
+	 *
59
+	 * @var array
60
+	 */
61
+	public $_options = [];
62
+	/**
63
+	 * Allow multiple selections?
64
+	 *
65
+	 * @var bool
66
+	 */
67
+	public $_multiple = false;
68
+	/**
69
+	 * Number of rows. "1" makes a dropdown list.
70
+	 *
71
+	 * @var int
72
+	 */
73
+	public $_size;
74
+	/**
75
+	 * Pre-selcted values
76
+	 *
77
+	 * @var array
78
+	 */
79
+	public $_value = [];
80 80
 
81
-    /**
82
-     * Constructor
83
-     *
84
-     * @param string $caption  Caption
85
-     * @param string $name     "name" attribute
86
-     * @param mixed  $value    Pre-selected value (or array of them).
87
-     * @param int    $size     Number or rows. "1" makes a drop-down-list
88
-     * @param bool   $multiple Allow multiple selections?
89
-     * @param int    $ownid
90
-     */
91
-    public function __construct($caption, $name, $value = null, $size = 1, $multiple = false, $ownid = 0)
92
-    {
93
-        global $_form_object_options;
94
-        \xoops_loadLanguage('modinfo', 'songlist');
81
+	/**
82
+	 * Constructor
83
+	 *
84
+	 * @param string $caption  Caption
85
+	 * @param string $name     "name" attribute
86
+	 * @param mixed  $value    Pre-selected value (or array of them).
87
+	 * @param int    $size     Number or rows. "1" makes a drop-down-list
88
+	 * @param bool   $multiple Allow multiple selections?
89
+	 * @param int    $ownid
90
+	 */
91
+	public function __construct($caption, $name, $value = null, $size = 1, $multiple = false, $ownid = 0)
92
+	{
93
+		global $_form_object_options;
94
+		\xoops_loadLanguage('modinfo', 'songlist');
95 95
 
96
-        $this->setCaption($caption);
97
-        $this->setName($name);
98
-        $this->_multiple = $multiple;
99
-        $this->_size     = (int)$size;
100
-        if (isset($value)) {
101
-            $this->setValue($value);
102
-        }
103
-        $this->addOption('0', \_MI_SONGLIST_NONE);
104
-        if (!isset($_form_object_options['albums'])) {
105
-            $albumsHandler = Helper::getInstance()->getHandler('Albums');
106
-            $criteria      = new Criteria('');
107
-            $criteria->setSort('title');
108
-            $criteria->setOrder('ASC');
109
-            foreach ($albumsHandler->getObjects($criteria, true) as $id => $obj) {
110
-                $_form_object_options['albums'][$id] = $obj->getVar('title');
111
-            }
112
-        }
113
-        //        if (Request::hasVar('albums', 'form_object_options')) {
114
-        if (isset($_form_object_options['albums'])) {
115
-            foreach ($_form_object_options['albums'] as $id => $value) {
116
-                $this->addOption($id, $value);
117
-            }
118
-        }
119
-    }
96
+		$this->setCaption($caption);
97
+		$this->setName($name);
98
+		$this->_multiple = $multiple;
99
+		$this->_size     = (int)$size;
100
+		if (isset($value)) {
101
+			$this->setValue($value);
102
+		}
103
+		$this->addOption('0', \_MI_SONGLIST_NONE);
104
+		if (!isset($_form_object_options['albums'])) {
105
+			$albumsHandler = Helper::getInstance()->getHandler('Albums');
106
+			$criteria      = new Criteria('');
107
+			$criteria->setSort('title');
108
+			$criteria->setOrder('ASC');
109
+			foreach ($albumsHandler->getObjects($criteria, true) as $id => $obj) {
110
+				$_form_object_options['albums'][$id] = $obj->getVar('title');
111
+			}
112
+		}
113
+		//        if (Request::hasVar('albums', 'form_object_options')) {
114
+		if (isset($_form_object_options['albums'])) {
115
+			foreach ($_form_object_options['albums'] as $id => $value) {
116
+				$this->addOption($id, $value);
117
+			}
118
+		}
119
+	}
120 120
 
121
-    /**
122
-     * Are multiple selections allowed?
123
-     *
124
-     * @return bool
125
-     */
126
-    public function isMultiple(): bool
127
-    {
128
-        return $this->_multiple;
129
-    }
121
+	/**
122
+	 * Are multiple selections allowed?
123
+	 *
124
+	 * @return bool
125
+	 */
126
+	public function isMultiple(): bool
127
+	{
128
+		return $this->_multiple;
129
+	}
130 130
 
131
-    /**
132
-     * Get the size
133
-     *
134
-     * @return int
135
-     */
136
-    public function getSize(): int
137
-    {
138
-        return $this->_size;
139
-    }
131
+	/**
132
+	 * Get the size
133
+	 *
134
+	 * @return int
135
+	 */
136
+	public function getSize(): int
137
+	{
138
+		return $this->_size;
139
+	}
140 140
 
141
-    /**
142
-     * Get an array of pre-selected values
143
-     *
144
-     * @param bool $encode To sanitizer the text?
145
-     * @return array
146
-     */
147
-    public function getValue($encode = false): array
148
-    {
149
-        if (!$encode) {
150
-            return $this->_value;
151
-        }
152
-        $value = [];
153
-        foreach ($this->_value as $val) {
154
-            $value[] = $val ? \htmlspecialchars($val, \ENT_QUOTES) : $val;
155
-        }
141
+	/**
142
+	 * Get an array of pre-selected values
143
+	 *
144
+	 * @param bool $encode To sanitizer the text?
145
+	 * @return array
146
+	 */
147
+	public function getValue($encode = false): array
148
+	{
149
+		if (!$encode) {
150
+			return $this->_value;
151
+		}
152
+		$value = [];
153
+		foreach ($this->_value as $val) {
154
+			$value[] = $val ? \htmlspecialchars($val, \ENT_QUOTES) : $val;
155
+		}
156 156
 
157
-        return $value;
158
-    }
157
+		return $value;
158
+	}
159 159
 
160
-    /**
161
-     * Set pre-selected values
162
-     *
163
-     * @param mixed $value
164
-     */
165
-    public function setValue($value): void
166
-    {
167
-        if (\is_array($value)) {
168
-            foreach ($value as $v) {
169
-                $this->_value[] = (int)$v;
170
-            }
160
+	/**
161
+	 * Set pre-selected values
162
+	 *
163
+	 * @param mixed $value
164
+	 */
165
+	public function setValue($value): void
166
+	{
167
+		if (\is_array($value)) {
168
+			foreach ($value as $v) {
169
+				$this->_value[] = (int)$v;
170
+			}
171 171
 //            $this->_value[] = array_values($value);
172
-        } elseif (isset($value)) {
173
-            $this->_value[] = $value;
174
-        }
175
-    }
172
+		} elseif (isset($value)) {
173
+			$this->_value[] = $value;
174
+		}
175
+	}
176 176
 
177
-    /**
178
-     * Add an option
179
-     *
180
-     * @param string $value "value" attribute
181
-     * @param string $name  "name" attribute
182
-     */
183
-    public function addOption($value, $name = ''): void
184
-    {
185
-        if ('' != $name) {
186
-            $this->_options[$value] = $name;
187
-        } else {
188
-            $this->_options[$value] = $value;
189
-        }
190
-    }
177
+	/**
178
+	 * Add an option
179
+	 *
180
+	 * @param string $value "value" attribute
181
+	 * @param string $name  "name" attribute
182
+	 */
183
+	public function addOption($value, $name = ''): void
184
+	{
185
+		if ('' != $name) {
186
+			$this->_options[$value] = $name;
187
+		} else {
188
+			$this->_options[$value] = $value;
189
+		}
190
+	}
191 191
 
192
-    /**
193
-     * Add multiple options
194
-     *
195
-     * @param array $options Associative array of value->name pairs
196
-     */
197
-    public function addOptionArray($options): void
198
-    {
199
-        if (\is_array($options)) {
200
-            foreach ($options as $k => $v) {
201
-                $this->addOption($k, $v);
202
-            }
203
-        }
204
-    }
192
+	/**
193
+	 * Add multiple options
194
+	 *
195
+	 * @param array $options Associative array of value->name pairs
196
+	 */
197
+	public function addOptionArray($options): void
198
+	{
199
+		if (\is_array($options)) {
200
+			foreach ($options as $k => $v) {
201
+				$this->addOption($k, $v);
202
+			}
203
+		}
204
+	}
205 205
 
206
-    /**
207
-     * Get an array with all the options
208
-     *
209
-     * Note: both name and value should be sanitized. However for backward compatibility, only value is sanitized for now.
210
-     *
211
-     * @param bool|int $encode To sanitizer the text? potential values: 0 - skip; 1 - only for value; 2 - for both value and name
212
-     * @return array Associative array of value->name pairs
213
-     */
214
-    public function getOptions($encode = false): array
215
-    {
216
-        if (!$encode) {
217
-            return $this->_options;
218
-        }
219
-        $value = [];
220
-        foreach ($this->_options as $val => $name) {
221
-            $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name;
222
-        }
206
+	/**
207
+	 * Get an array with all the options
208
+	 *
209
+	 * Note: both name and value should be sanitized. However for backward compatibility, only value is sanitized for now.
210
+	 *
211
+	 * @param bool|int $encode To sanitizer the text? potential values: 0 - skip; 1 - only for value; 2 - for both value and name
212
+	 * @return array Associative array of value->name pairs
213
+	 */
214
+	public function getOptions($encode = false): array
215
+	{
216
+		if (!$encode) {
217
+			return $this->_options;
218
+		}
219
+		$value = [];
220
+		foreach ($this->_options as $val => $name) {
221
+			$value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name;
222
+		}
223 223
 
224
-        return $value;
225
-    }
224
+		return $value;
225
+	}
226 226
 
227
-    /**
228
-     * Prepare HTML for output
229
-     *
230
-     * @return string HTML
231
-     */
232
-    public function render(): string
233
-    {
234
-        $ele_name    = $this->getName();
235
-        $ele_title   = $this->getTitle();
236
-        $ele_value   = $this->getValue();
237
-        $ele_options = $this->getOptions();
238
-        $ret         = '<select size="' . $this->getSize() . '"' . $this->getExtra();
239
-        if ($this->isMultiple()) {
240
-            $ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">';
241
-        } else {
242
-            $ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">';
243
-        }
244
-        foreach ($ele_options as $value => $name) {
245
-            $ret .= '<option value="' . \htmlspecialchars((string)$value, \ENT_QUOTES) . '"';
246
-            if (\count($ele_value) > 0 && \in_array($value, $ele_value, true)) {
247
-                $ret .= ' selected';
248
-            }
249
-            $ret .= '>' . $name . '</option>';
250
-        }
251
-        $ret .= '</select>';
227
+	/**
228
+	 * Prepare HTML for output
229
+	 *
230
+	 * @return string HTML
231
+	 */
232
+	public function render(): string
233
+	{
234
+		$ele_name    = $this->getName();
235
+		$ele_title   = $this->getTitle();
236
+		$ele_value   = $this->getValue();
237
+		$ele_options = $this->getOptions();
238
+		$ret         = '<select size="' . $this->getSize() . '"' . $this->getExtra();
239
+		if ($this->isMultiple()) {
240
+			$ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">';
241
+		} else {
242
+			$ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">';
243
+		}
244
+		foreach ($ele_options as $value => $name) {
245
+			$ret .= '<option value="' . \htmlspecialchars((string)$value, \ENT_QUOTES) . '"';
246
+			if (\count($ele_value) > 0 && \in_array($value, $ele_value, true)) {
247
+				$ret .= ' selected';
248
+			}
249
+			$ret .= '>' . $name . '</option>';
250
+		}
251
+		$ret .= '</select>';
252 252
 
253
-        return $ret;
254
-    }
253
+		return $ret;
254
+	}
255 255
 
256
-    /**
257
-     * Render custom javascript validation code
258
-     *
259
-     * @seealso XoopsForm::renderValidationJS
260
-     */
261
-    public function renderValidationJS()
262
-    {
263
-        // render custom validation code if any
264
-        if (!empty($this->customValidationCode)) {
265
-            return \implode("\n", $this->customValidationCode);
266
-            // generate validation code if required
267
-        }
256
+	/**
257
+	 * Render custom javascript validation code
258
+	 *
259
+	 * @seealso XoopsForm::renderValidationJS
260
+	 */
261
+	public function renderValidationJS()
262
+	{
263
+		// render custom validation code if any
264
+		if (!empty($this->customValidationCode)) {
265
+			return \implode("\n", $this->customValidationCode);
266
+			// generate validation code if required
267
+		}
268 268
 
269
-        if ($this->isRequired()) {
270
-            $eltname    = $this->getName();
271
-            $eltcaption = $this->getCaption();
272
-            $eltmsg     = empty($eltcaption) ? \sprintf(_FORM_ENTER, $eltname) : \sprintf(_FORM_ENTER, $eltcaption);
273
-            $eltmsg     = \str_replace('"', '\"', \stripslashes($eltmsg));
269
+		if ($this->isRequired()) {
270
+			$eltname    = $this->getName();
271
+			$eltcaption = $this->getCaption();
272
+			$eltmsg     = empty($eltcaption) ? \sprintf(_FORM_ENTER, $eltname) : \sprintf(_FORM_ENTER, $eltcaption);
273
+			$eltmsg     = \str_replace('"', '\"', \stripslashes($eltmsg));
274 274
 
275
-            return "\nvar hasSelected = false; var selectBox = myform.{$eltname};"
276
-                   . 'for (i = 0; i < selectBox.options.length; i++ ) { if (selectBox.options[i].selected === true) { hasSelected = true; break; } }'
277
-                   . "if (!hasSelected) { window.alert(\"{$eltmsg}\"); selectBox.focus(); return false; }";
278
-        }
275
+			return "\nvar hasSelected = false; var selectBox = myform.{$eltname};"
276
+				   . 'for (i = 0; i < selectBox.options.length; i++ ) { if (selectBox.options[i].selected === true) { hasSelected = true; break; } }'
277
+				   . "if (!hasSelected) { window.alert(\"{$eltmsg}\"); selectBox.focus(); return false; }";
278
+		}
279 279
 
280
-        return '';
281
-    }
280
+		return '';
281
+	}
282 282
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
         $this->setCaption($caption);
97 97
         $this->setName($name);
98 98
         $this->_multiple = $multiple;
99
-        $this->_size     = (int)$size;
99
+        $this->_size     = (int) $size;
100 100
         if (isset($value)) {
101 101
             $this->setValue($value);
102 102
         }
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
     {
167 167
         if (\is_array($value)) {
168 168
             foreach ($value as $v) {
169
-                $this->_value[] = (int)$v;
169
+                $this->_value[] = (int) $v;
170 170
             }
171 171
 //            $this->_value[] = array_values($value);
172 172
         } elseif (isset($value)) {
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
      */
183 183
     public function addOption($value, $name = ''): void
184 184
     {
185
-        if ('' != $name) {
185
+        if (''!=$name) {
186 186
             $this->_options[$value] = $name;
187 187
         } else {
188 188
             $this->_options[$value] = $value;
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
         }
219 219
         $value = [];
220 220
         foreach ($this->_options as $val => $name) {
221
-            $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name;
221
+            $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode>1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name;
222 222
         }
223 223
 
224 224
         return $value;
@@ -235,18 +235,18 @@  discard block
 block discarded – undo
235 235
         $ele_title   = $this->getTitle();
236 236
         $ele_value   = $this->getValue();
237 237
         $ele_options = $this->getOptions();
238
-        $ret         = '<select size="' . $this->getSize() . '"' . $this->getExtra();
238
+        $ret         = '<select size="'.$this->getSize().'"'.$this->getExtra();
239 239
         if ($this->isMultiple()) {
240
-            $ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">';
240
+            $ret .= ' name="'.$ele_name.'[]" id="'.$ele_name.'" title="'.$ele_title.'" multiple="multiple">';
241 241
         } else {
242
-            $ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">';
242
+            $ret .= ' name="'.$ele_name.'" id="'.$ele_name.'" title="'.$ele_title.'">';
243 243
         }
244 244
         foreach ($ele_options as $value => $name) {
245
-            $ret .= '<option value="' . \htmlspecialchars((string)$value, \ENT_QUOTES) . '"';
246
-            if (\count($ele_value) > 0 && \in_array($value, $ele_value, true)) {
245
+            $ret .= '<option value="'.\htmlspecialchars((string) $value, \ENT_QUOTES).'"';
246
+            if (\count($ele_value)>0 && \in_array($value, $ele_value, true)) {
247 247
                 $ret .= ' selected';
248 248
             }
249
-            $ret .= '>' . $name . '</option>';
249
+            $ret .= '>'.$name.'</option>';
250 250
         }
251 251
         $ret .= '</select>';
252 252
 
Please login to merge, or discard this patch.
class/Form/SelectSongForm.php 2 patches
Indentation   +218 added lines, -218 removed lines patch added patch discarded remove patch
@@ -50,240 +50,240 @@
 block discarded – undo
50 50
  */
51 51
 class SelectSongForm extends \XoopsFormElement
52 52
 {
53
-    /**
54
-     * Options
55
-     *
56
-     * @var array
57
-     */
58
-    public $_options = [];
59
-    /**
60
-     * Allow multiple selections?
61
-     *
62
-     * @var bool
63
-     */
64
-    public $_multiple = false;
65
-    /**
66
-     * Number of rows. "1" makes a dropdown list.
67
-     *
68
-     * @var int
69
-     */
70
-    public $_size;
71
-    /**
72
-     * Pre-selcted values
73
-     *
74
-     * @var array
75
-     */
76
-    public $_value = [];
53
+	/**
54
+	 * Options
55
+	 *
56
+	 * @var array
57
+	 */
58
+	public $_options = [];
59
+	/**
60
+	 * Allow multiple selections?
61
+	 *
62
+	 * @var bool
63
+	 */
64
+	public $_multiple = false;
65
+	/**
66
+	 * Number of rows. "1" makes a dropdown list.
67
+	 *
68
+	 * @var int
69
+	 */
70
+	public $_size;
71
+	/**
72
+	 * Pre-selcted values
73
+	 *
74
+	 * @var array
75
+	 */
76
+	public $_value = [];
77 77
 
78
-    /**
79
-     * Constructor
80
-     *
81
-     * @param string $caption  Caption
82
-     * @param string $name     "name" attribute
83
-     * @param mixed  $value    Pre-selected value (or array of them).
84
-     * @param int    $size     Number or rows. "1" makes a drop-down-list
85
-     * @param bool   $multiple Allow multiple selections?
86
-     * @param int    $id
87
-     * @param string $field
88
-     */
89
-    public function __construct($caption, $name, $value = null, $size = 1, $multiple = false, $id = -1, $field = 'cid')
90
-    {
91
-        global $_form_object_options;
92
-        \xoops_loadLanguage('modinfo', 'songlist');
78
+	/**
79
+	 * Constructor
80
+	 *
81
+	 * @param string $caption  Caption
82
+	 * @param string $name     "name" attribute
83
+	 * @param mixed  $value    Pre-selected value (or array of them).
84
+	 * @param int    $size     Number or rows. "1" makes a drop-down-list
85
+	 * @param bool   $multiple Allow multiple selections?
86
+	 * @param int    $id
87
+	 * @param string $field
88
+	 */
89
+	public function __construct($caption, $name, $value = null, $size = 1, $multiple = false, $id = -1, $field = 'cid')
90
+	{
91
+		global $_form_object_options;
92
+		\xoops_loadLanguage('modinfo', 'songlist');
93 93
 
94
-        $this->setCaption($caption);
95
-        $this->setName($name);
96
-        $this->_multiple = $multiple;
97
-        $this->_size     = (int)$size;
98
-        if (isset($value)) {
99
-            $this->setValue($value);
100
-        }
101
-        $this->addOption('0', \_MI_SONGLIST_NONE);
102
-        if (-1 == $id) {
103
-            if (!isset($_form_object_options['songs'][$field][$id])) {
104
-                $songsHandler = Helper::getInstance()->getHandler('Songs');
105
-                $criteria     = new \Criteria('');
106
-                $criteria->setSort('title');
107
-                $criteria->setOrder('ASC');
108
-                foreach ($songsHandler->getObjects($criteria, true) as $id => $obj) {
109
-                    $_form_object_options['songs'][$field][$id][$id] = $obj->getVar('title');
110
-                }
111
-            }
112
-        } elseif (!isset($_form_object_options['songs'][$field][$id])) {
113
-                $songsHandler = Helper::getInstance()->getHandler('Songs');
114
-                $criteria     = new \Criteria('`' . $field . '`', $id);
115
-                $criteria->setSort('title');
116
-                $criteria->setOrder('ASC');
117
-                foreach ($songsHandler->getObjects($criteria) as $id => $obj) {
118
-                    $_form_object_options['songs'][$field][$id][$id] = $obj->getVar('title');
119
-                }
120
-        }
121
-        if (isset($_form_object_options['songs'][$field][$id])) {
122
-            foreach ($_form_object_options['songs'][$field][$id] as $id => $value) {
123
-                $this->addOption($id, $value);
124
-            }
125
-        }
126
-    }
94
+		$this->setCaption($caption);
95
+		$this->setName($name);
96
+		$this->_multiple = $multiple;
97
+		$this->_size     = (int)$size;
98
+		if (isset($value)) {
99
+			$this->setValue($value);
100
+		}
101
+		$this->addOption('0', \_MI_SONGLIST_NONE);
102
+		if (-1 == $id) {
103
+			if (!isset($_form_object_options['songs'][$field][$id])) {
104
+				$songsHandler = Helper::getInstance()->getHandler('Songs');
105
+				$criteria     = new \Criteria('');
106
+				$criteria->setSort('title');
107
+				$criteria->setOrder('ASC');
108
+				foreach ($songsHandler->getObjects($criteria, true) as $id => $obj) {
109
+					$_form_object_options['songs'][$field][$id][$id] = $obj->getVar('title');
110
+				}
111
+			}
112
+		} elseif (!isset($_form_object_options['songs'][$field][$id])) {
113
+				$songsHandler = Helper::getInstance()->getHandler('Songs');
114
+				$criteria     = new \Criteria('`' . $field . '`', $id);
115
+				$criteria->setSort('title');
116
+				$criteria->setOrder('ASC');
117
+				foreach ($songsHandler->getObjects($criteria) as $id => $obj) {
118
+					$_form_object_options['songs'][$field][$id][$id] = $obj->getVar('title');
119
+				}
120
+		}
121
+		if (isset($_form_object_options['songs'][$field][$id])) {
122
+			foreach ($_form_object_options['songs'][$field][$id] as $id => $value) {
123
+				$this->addOption($id, $value);
124
+			}
125
+		}
126
+	}
127 127
 
128
-    /**
129
-     * Are multiple selections allowed?
130
-     *
131
-     * @return bool
132
-     */
133
-    public function isMultiple(): bool
134
-    {
135
-        return $this->_multiple;
136
-    }
128
+	/**
129
+	 * Are multiple selections allowed?
130
+	 *
131
+	 * @return bool
132
+	 */
133
+	public function isMultiple(): bool
134
+	{
135
+		return $this->_multiple;
136
+	}
137 137
 
138
-    /**
139
-     * Get the size
140
-     *
141
-     * @return int
142
-     */
143
-    public function getSize(): int
144
-    {
145
-        return $this->_size;
146
-    }
138
+	/**
139
+	 * Get the size
140
+	 *
141
+	 * @return int
142
+	 */
143
+	public function getSize(): int
144
+	{
145
+		return $this->_size;
146
+	}
147 147
 
148
-    /**
149
-     * Get an array of pre-selected values
150
-     *
151
-     * @param bool $encode To sanitizer the text?
152
-     * @return array
153
-     */
154
-    public function getValue($encode = false): array
155
-    {
156
-        if (!$encode) {
157
-            return $this->_value;
158
-        }
159
-        $value = [];
160
-        foreach ($this->_value as $val) {
161
-            $value[] = $val ? \htmlspecialchars($val, \ENT_QUOTES) : $val;
162
-        }
148
+	/**
149
+	 * Get an array of pre-selected values
150
+	 *
151
+	 * @param bool $encode To sanitizer the text?
152
+	 * @return array
153
+	 */
154
+	public function getValue($encode = false): array
155
+	{
156
+		if (!$encode) {
157
+			return $this->_value;
158
+		}
159
+		$value = [];
160
+		foreach ($this->_value as $val) {
161
+			$value[] = $val ? \htmlspecialchars($val, \ENT_QUOTES) : $val;
162
+		}
163 163
 
164
-        return $value;
165
-    }
164
+		return $value;
165
+	}
166 166
 
167
-    /**
168
-     * Set pre-selected values
169
-     *
170
-     * @param mixed $value
171
-     */
172
-    public function setValue($value): void
173
-    {
174
-        if (\is_array($value)) {
175
-            foreach ($value as $v) {
176
-                $this->_value[] = (int)$v;
177
-            }
167
+	/**
168
+	 * Set pre-selected values
169
+	 *
170
+	 * @param mixed $value
171
+	 */
172
+	public function setValue($value): void
173
+	{
174
+		if (\is_array($value)) {
175
+			foreach ($value as $v) {
176
+				$this->_value[] = (int)$v;
177
+			}
178 178
 //            $this->_value[] = array_values($value);
179
-        } elseif (isset($value)) {
180
-            $this->_value[] = $value;
181
-        }
182
-    }
179
+		} elseif (isset($value)) {
180
+			$this->_value[] = $value;
181
+		}
182
+	}
183 183
 
184
-    /**
185
-     * Add an option
186
-     *
187
-     * @param string $value "value" attribute
188
-     * @param string $name  "name" attribute
189
-     */
190
-    public function addOption($value, $name = ''): void
191
-    {
192
-        if ('' != $name) {
193
-            $this->_options[$value] = $name;
194
-        } else {
195
-            $this->_options[$value] = $value;
196
-        }
197
-    }
184
+	/**
185
+	 * Add an option
186
+	 *
187
+	 * @param string $value "value" attribute
188
+	 * @param string $name  "name" attribute
189
+	 */
190
+	public function addOption($value, $name = ''): void
191
+	{
192
+		if ('' != $name) {
193
+			$this->_options[$value] = $name;
194
+		} else {
195
+			$this->_options[$value] = $value;
196
+		}
197
+	}
198 198
 
199
-    /**
200
-     * Add multiple options
201
-     *
202
-     * @param array $options Associative array of value->name pairs
203
-     */
204
-    public function addOptionArray($options): void
205
-    {
206
-        if (\is_array($options)) {
207
-            foreach ($options as $k => $v) {
208
-                $this->addOption($k, $v);
209
-            }
210
-        }
211
-    }
199
+	/**
200
+	 * Add multiple options
201
+	 *
202
+	 * @param array $options Associative array of value->name pairs
203
+	 */
204
+	public function addOptionArray($options): void
205
+	{
206
+		if (\is_array($options)) {
207
+			foreach ($options as $k => $v) {
208
+				$this->addOption($k, $v);
209
+			}
210
+		}
211
+	}
212 212
 
213
-    /**
214
-     * Get an array with all the options
215
-     *
216
-     * Note: both name and value should be sanitized. However for backward compatibility, only value is sanitized for now.
217
-     *
218
-     * @param bool|int $encode To sanitizer the text? potential values: 0 - skip; 1 - only for value; 2 - for both value and name
219
-     * @return array Associative array of value->name pairs
220
-     */
221
-    public function getOptions($encode = false): array
222
-    {
223
-        if (!$encode) {
224
-            return $this->_options;
225
-        }
226
-        $value = [];
227
-        foreach ($this->_options as $val => $name) {
228
-            $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name;
229
-        }
213
+	/**
214
+	 * Get an array with all the options
215
+	 *
216
+	 * Note: both name and value should be sanitized. However for backward compatibility, only value is sanitized for now.
217
+	 *
218
+	 * @param bool|int $encode To sanitizer the text? potential values: 0 - skip; 1 - only for value; 2 - for both value and name
219
+	 * @return array Associative array of value->name pairs
220
+	 */
221
+	public function getOptions($encode = false): array
222
+	{
223
+		if (!$encode) {
224
+			return $this->_options;
225
+		}
226
+		$value = [];
227
+		foreach ($this->_options as $val => $name) {
228
+			$value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name;
229
+		}
230 230
 
231
-        return $value;
232
-    }
231
+		return $value;
232
+	}
233 233
 
234
-    /**
235
-     * Prepare HTML for output
236
-     *
237
-     * @return string HTML
238
-     */
239
-    public function render(): string
240
-    {
241
-        $ele_name    = $this->getName();
242
-        $ele_title   = $this->getTitle();
243
-        $ele_value   = $this->getValue();
244
-        $ele_options = $this->getOptions();
245
-        $ret         = '<select size="' . $this->getSize() . '"' . $this->getExtra();
246
-        if ($this->isMultiple()) {
247
-            $ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">';
248
-        } else {
249
-            $ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">';
250
-        }
251
-        foreach ($ele_options as $value => $name) {
252
-            $ret .= '<option value="' . \htmlspecialchars((string)$value, \ENT_QUOTES) . '"';
253
-            if (\count($ele_value) > 0 && \in_array($value, $ele_value, true)) {
254
-                $ret .= ' selected';
255
-            }
256
-            $ret .= '>' . $name . '</option>';
257
-        }
258
-        $ret .= '</select>';
234
+	/**
235
+	 * Prepare HTML for output
236
+	 *
237
+	 * @return string HTML
238
+	 */
239
+	public function render(): string
240
+	{
241
+		$ele_name    = $this->getName();
242
+		$ele_title   = $this->getTitle();
243
+		$ele_value   = $this->getValue();
244
+		$ele_options = $this->getOptions();
245
+		$ret         = '<select size="' . $this->getSize() . '"' . $this->getExtra();
246
+		if ($this->isMultiple()) {
247
+			$ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">';
248
+		} else {
249
+			$ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">';
250
+		}
251
+		foreach ($ele_options as $value => $name) {
252
+			$ret .= '<option value="' . \htmlspecialchars((string)$value, \ENT_QUOTES) . '"';
253
+			if (\count($ele_value) > 0 && \in_array($value, $ele_value, true)) {
254
+				$ret .= ' selected';
255
+			}
256
+			$ret .= '>' . $name . '</option>';
257
+		}
258
+		$ret .= '</select>';
259 259
 
260
-        return $ret;
261
-    }
260
+		return $ret;
261
+	}
262 262
 
263
-    /**
264
-     * Render custom javascript validation code
265
-     *
266
-     * @seealso XoopsForm::renderValidationJS
267
-     */
268
-    public function renderValidationJS()
269
-    {
270
-        // render custom validation code if any
271
-        if (!empty($this->customValidationCode)) {
272
-            return \implode("\n", $this->customValidationCode);
273
-            // generate validation code if required
274
-        }
263
+	/**
264
+	 * Render custom javascript validation code
265
+	 *
266
+	 * @seealso XoopsForm::renderValidationJS
267
+	 */
268
+	public function renderValidationJS()
269
+	{
270
+		// render custom validation code if any
271
+		if (!empty($this->customValidationCode)) {
272
+			return \implode("\n", $this->customValidationCode);
273
+			// generate validation code if required
274
+		}
275 275
 
276
-        if ($this->isRequired()) {
277
-            $eltname    = $this->getName();
278
-            $eltcaption = $this->getCaption();
279
-            $eltmsg     = empty($eltcaption) ? \sprintf(_FORM_ENTER, $eltname) : \sprintf(_FORM_ENTER, $eltcaption);
280
-            $eltmsg     = \str_replace('"', '\"', \stripslashes($eltmsg));
276
+		if ($this->isRequired()) {
277
+			$eltname    = $this->getName();
278
+			$eltcaption = $this->getCaption();
279
+			$eltmsg     = empty($eltcaption) ? \sprintf(_FORM_ENTER, $eltname) : \sprintf(_FORM_ENTER, $eltcaption);
280
+			$eltmsg     = \str_replace('"', '\"', \stripslashes($eltmsg));
281 281
 
282
-            return "\nvar hasSelected = false; var selectBox = myform.{$eltname};"
283
-                   . 'for (i = 0; i < selectBox.options.length; i++ ) { if (selectBox.options[i].selected === true) { hasSelected = true; break; } }'
284
-                   . "if (!hasSelected) { window.alert(\"{$eltmsg}\"); selectBox.focus(); return false; }";
285
-        }
282
+			return "\nvar hasSelected = false; var selectBox = myform.{$eltname};"
283
+				   . 'for (i = 0; i < selectBox.options.length; i++ ) { if (selectBox.options[i].selected === true) { hasSelected = true; break; } }'
284
+				   . "if (!hasSelected) { window.alert(\"{$eltmsg}\"); selectBox.focus(); return false; }";
285
+		}
286 286
 
287
-        return '';
288
-    }
287
+		return '';
288
+	}
289 289
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -94,12 +94,12 @@  discard block
 block discarded – undo
94 94
         $this->setCaption($caption);
95 95
         $this->setName($name);
96 96
         $this->_multiple = $multiple;
97
-        $this->_size     = (int)$size;
97
+        $this->_size     = (int) $size;
98 98
         if (isset($value)) {
99 99
             $this->setValue($value);
100 100
         }
101 101
         $this->addOption('0', \_MI_SONGLIST_NONE);
102
-        if (-1 == $id) {
102
+        if (-1==$id) {
103 103
             if (!isset($_form_object_options['songs'][$field][$id])) {
104 104
                 $songsHandler = Helper::getInstance()->getHandler('Songs');
105 105
                 $criteria     = new \Criteria('');
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
             }
112 112
         } elseif (!isset($_form_object_options['songs'][$field][$id])) {
113 113
                 $songsHandler = Helper::getInstance()->getHandler('Songs');
114
-                $criteria     = new \Criteria('`' . $field . '`', $id);
114
+                $criteria     = new \Criteria('`'.$field.'`', $id);
115 115
                 $criteria->setSort('title');
116 116
                 $criteria->setOrder('ASC');
117 117
                 foreach ($songsHandler->getObjects($criteria) as $id => $obj) {
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
     {
174 174
         if (\is_array($value)) {
175 175
             foreach ($value as $v) {
176
-                $this->_value[] = (int)$v;
176
+                $this->_value[] = (int) $v;
177 177
             }
178 178
 //            $this->_value[] = array_values($value);
179 179
         } elseif (isset($value)) {
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
      */
190 190
     public function addOption($value, $name = ''): void
191 191
     {
192
-        if ('' != $name) {
192
+        if (''!=$name) {
193 193
             $this->_options[$value] = $name;
194 194
         } else {
195 195
             $this->_options[$value] = $value;
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
         }
226 226
         $value = [];
227 227
         foreach ($this->_options as $val => $name) {
228
-            $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name;
228
+            $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode>1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name;
229 229
         }
230 230
 
231 231
         return $value;
@@ -242,18 +242,18 @@  discard block
 block discarded – undo
242 242
         $ele_title   = $this->getTitle();
243 243
         $ele_value   = $this->getValue();
244 244
         $ele_options = $this->getOptions();
245
-        $ret         = '<select size="' . $this->getSize() . '"' . $this->getExtra();
245
+        $ret         = '<select size="'.$this->getSize().'"'.$this->getExtra();
246 246
         if ($this->isMultiple()) {
247
-            $ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">';
247
+            $ret .= ' name="'.$ele_name.'[]" id="'.$ele_name.'" title="'.$ele_title.'" multiple="multiple">';
248 248
         } else {
249
-            $ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">';
249
+            $ret .= ' name="'.$ele_name.'" id="'.$ele_name.'" title="'.$ele_title.'">';
250 250
         }
251 251
         foreach ($ele_options as $value => $name) {
252
-            $ret .= '<option value="' . \htmlspecialchars((string)$value, \ENT_QUOTES) . '"';
253
-            if (\count($ele_value) > 0 && \in_array($value, $ele_value, true)) {
252
+            $ret .= '<option value="'.\htmlspecialchars((string) $value, \ENT_QUOTES).'"';
253
+            if (\count($ele_value)>0 && \in_array($value, $ele_value, true)) {
254 254
                 $ret .= ' selected';
255 255
             }
256
-            $ret .= '>' . $name . '</option>';
256
+            $ret .= '>'.$name.'</option>';
257 257
         }
258 258
         $ret .= '</select>';
259 259
 
Please login to merge, or discard this patch.
class/Form/SelectSingerForm.php 2 patches
Indentation   +194 added lines, -194 removed lines patch added patch discarded remove patch
@@ -50,216 +50,216 @@
 block discarded – undo
50 50
  */
51 51
 class SelectSingerForm extends XoopsFormElement
52 52
 {
53
-    /**
54
-     * Options
55
-     *
56
-     * @var array
57
-     */
58
-    public $_options = [];
59
-    /**
60
-     * Allow multiple selections?
61
-     *
62
-     * @var bool
63
-     */
64
-    public $_multiple = false;
65
-    /**
66
-     * Number of rows. "1" makes a dropdown list.
67
-     *
68
-     * @var int
69
-     */
70
-    public $_size;
71
-    /**
72
-     * Pre-selcted values
73
-     *
74
-     * @var array
75
-     */
76
-    public $_value = [];
53
+	/**
54
+	 * Options
55
+	 *
56
+	 * @var array
57
+	 */
58
+	public $_options = [];
59
+	/**
60
+	 * Allow multiple selections?
61
+	 *
62
+	 * @var bool
63
+	 */
64
+	public $_multiple = false;
65
+	/**
66
+	 * Number of rows. "1" makes a dropdown list.
67
+	 *
68
+	 * @var int
69
+	 */
70
+	public $_size;
71
+	/**
72
+	 * Pre-selcted values
73
+	 *
74
+	 * @var array
75
+	 */
76
+	public $_value = [];
77 77
 
78
-    /**
79
-     * Constructor
80
-     *
81
-     * @param string $caption  Caption
82
-     * @param string $name     "name" attribute
83
-     * @param mixed  $value    Pre-selected value (or array of them).
84
-     * @param int    $size     Number or rows. "1" makes a drop-down-list
85
-     * @param bool   $multiple Allow multiple selections?
86
-     */
87
-    public function __construct($caption, $name, $value = null, $size = 1, $multiple = false)
88
-    {
89
-        \xoops_loadLanguage('enum', 'songlist');
78
+	/**
79
+	 * Constructor
80
+	 *
81
+	 * @param string $caption  Caption
82
+	 * @param string $name     "name" attribute
83
+	 * @param mixed  $value    Pre-selected value (or array of them).
84
+	 * @param int    $size     Number or rows. "1" makes a drop-down-list
85
+	 * @param bool   $multiple Allow multiple selections?
86
+	 */
87
+	public function __construct($caption, $name, $value = null, $size = 1, $multiple = false)
88
+	{
89
+		\xoops_loadLanguage('enum', 'songlist');
90 90
 
91
-        $this->setCaption($caption);
92
-        $this->setName($name);
93
-        $this->_multiple = $multiple;
94
-        $this->_size     = (int)$size;
95
-        if (isset($value)) {
96
-            $this->setValue($value);
97
-        }
98
-        $this->addOption('_', \_MI_SONGLIST_NONE);
99
-        foreach (['_ENUM_SONGLIST_SOLO', '_ENUM_SONGLIST_DUET'] as $enum) {
100
-            $this->addOption($enum, \constant($enum));
101
-        }
102
-    }
91
+		$this->setCaption($caption);
92
+		$this->setName($name);
93
+		$this->_multiple = $multiple;
94
+		$this->_size     = (int)$size;
95
+		if (isset($value)) {
96
+			$this->setValue($value);
97
+		}
98
+		$this->addOption('_', \_MI_SONGLIST_NONE);
99
+		foreach (['_ENUM_SONGLIST_SOLO', '_ENUM_SONGLIST_DUET'] as $enum) {
100
+			$this->addOption($enum, \constant($enum));
101
+		}
102
+	}
103 103
 
104
-    /**
105
-     * Are multiple selections allowed?
106
-     *
107
-     * @return bool
108
-     */
109
-    public function isMultiple(): bool
110
-    {
111
-        return $this->_multiple;
112
-    }
104
+	/**
105
+	 * Are multiple selections allowed?
106
+	 *
107
+	 * @return bool
108
+	 */
109
+	public function isMultiple(): bool
110
+	{
111
+		return $this->_multiple;
112
+	}
113 113
 
114
-    /**
115
-     * Get the size
116
-     *
117
-     * @return int
118
-     */
119
-    public function getSize(): int
120
-    {
121
-        return $this->_size;
122
-    }
114
+	/**
115
+	 * Get the size
116
+	 *
117
+	 * @return int
118
+	 */
119
+	public function getSize(): int
120
+	{
121
+		return $this->_size;
122
+	}
123 123
 
124
-    /**
125
-     * Get an array of pre-selected values
126
-     *
127
-     * @param bool $encode To sanitizer the text?
128
-     * @return array
129
-     */
130
-    public function getValue($encode = false): array
131
-    {
132
-        if (!$encode) {
133
-            return $this->_value;
134
-        }
135
-        $value = [];
136
-        foreach ($this->_value as $val) {
137
-            $value[] = $val ? \htmlspecialchars($val, \ENT_QUOTES) : $val;
138
-        }
124
+	/**
125
+	 * Get an array of pre-selected values
126
+	 *
127
+	 * @param bool $encode To sanitizer the text?
128
+	 * @return array
129
+	 */
130
+	public function getValue($encode = false): array
131
+	{
132
+		if (!$encode) {
133
+			return $this->_value;
134
+		}
135
+		$value = [];
136
+		foreach ($this->_value as $val) {
137
+			$value[] = $val ? \htmlspecialchars($val, \ENT_QUOTES) : $val;
138
+		}
139 139
 
140
-        return $value;
141
-    }
140
+		return $value;
141
+	}
142 142
 
143
-    /**
144
-     * Set pre-selected values
145
-     *
146
-     * @param mixed $value
147
-     */
148
-    public function setValue($value): void
149
-    {
150
-        if (\is_array($value)) {
151
-            foreach ($value as $v) {
152
-                $this->_value[] = (int)$v;
153
-            }
143
+	/**
144
+	 * Set pre-selected values
145
+	 *
146
+	 * @param mixed $value
147
+	 */
148
+	public function setValue($value): void
149
+	{
150
+		if (\is_array($value)) {
151
+			foreach ($value as $v) {
152
+				$this->_value[] = (int)$v;
153
+			}
154 154
 //            $this->_value[] = array_values($value);
155
-        } elseif (isset($value)) {
156
-            $this->_value[] = $value;
157
-        }
158
-    }
155
+		} elseif (isset($value)) {
156
+			$this->_value[] = $value;
157
+		}
158
+	}
159 159
 
160
-    /**
161
-     * Add an option
162
-     *
163
-     * @param string $value "value" attribute
164
-     * @param string $name  "name" attribute
165
-     */
166
-    public function addOption($value, $name = ''): void
167
-    {
168
-        if ('' != $name) {
169
-            $this->_options[$value] = $name;
170
-        } else {
171
-            $this->_options[$value] = $value;
172
-        }
173
-    }
160
+	/**
161
+	 * Add an option
162
+	 *
163
+	 * @param string $value "value" attribute
164
+	 * @param string $name  "name" attribute
165
+	 */
166
+	public function addOption($value, $name = ''): void
167
+	{
168
+		if ('' != $name) {
169
+			$this->_options[$value] = $name;
170
+		} else {
171
+			$this->_options[$value] = $value;
172
+		}
173
+	}
174 174
 
175
-    /**
176
-     * Add multiple options
177
-     *
178
-     * @param array $options Associative array of value->name pairs
179
-     */
180
-    public function addOptionArray($options): void
181
-    {
182
-        if (\is_array($options)) {
183
-            foreach ($options as $k => $v) {
184
-                $this->addOption($k, $v);
185
-            }
186
-        }
187
-    }
175
+	/**
176
+	 * Add multiple options
177
+	 *
178
+	 * @param array $options Associative array of value->name pairs
179
+	 */
180
+	public function addOptionArray($options): void
181
+	{
182
+		if (\is_array($options)) {
183
+			foreach ($options as $k => $v) {
184
+				$this->addOption($k, $v);
185
+			}
186
+		}
187
+	}
188 188
 
189
-    /**
190
-     * Get an array with all the options
191
-     *
192
-     * Note: both name and value should be sanitized. However for backward compatibility, only value is sanitized for now.
193
-     *
194
-     * @param bool|int $encode To sanitizer the text? potential values: 0 - skip; 1 - only for value; 2 - for both value and name
195
-     * @return array Associative array of value->name pairs
196
-     */
197
-    public function getOptions($encode = false): array
198
-    {
199
-        if (!$encode) {
200
-            return $this->_options;
201
-        }
202
-        $value = [];
203
-        foreach ($this->_options as $val => $name) {
204
-            $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name;
205
-        }
189
+	/**
190
+	 * Get an array with all the options
191
+	 *
192
+	 * Note: both name and value should be sanitized. However for backward compatibility, only value is sanitized for now.
193
+	 *
194
+	 * @param bool|int $encode To sanitizer the text? potential values: 0 - skip; 1 - only for value; 2 - for both value and name
195
+	 * @return array Associative array of value->name pairs
196
+	 */
197
+	public function getOptions($encode = false): array
198
+	{
199
+		if (!$encode) {
200
+			return $this->_options;
201
+		}
202
+		$value = [];
203
+		foreach ($this->_options as $val => $name) {
204
+			$value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name;
205
+		}
206 206
 
207
-        return $value;
208
-    }
207
+		return $value;
208
+	}
209 209
 
210
-    /**
211
-     * Prepare HTML for output
212
-     *
213
-     * @return string HTML
214
-     */
215
-    public function render(): string
216
-    {
217
-        $ele_name    = $this->getName();
218
-        $ele_title   = $this->getTitle();
219
-        $ele_value   = $this->getValue();
220
-        $ele_options = $this->getOptions();
221
-        $ret         = '<select size="' . $this->getSize() . '"' . $this->getExtra();
222
-        if ($this->isMultiple()) {
223
-            $ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">';
224
-        } else {
225
-            $ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">';
226
-        }
227
-        foreach ($ele_options as $value => $name) {
228
-            $ret .= '<option value="' . \htmlspecialchars((string)$value, \ENT_QUOTES) . '"';
229
-            if (\count($ele_value) > 0 && \in_array($value, $ele_value, true)) {
230
-                $ret .= ' selected';
231
-            }
232
-            $ret .= '>' . $name . '</option>';
233
-        }
234
-        $ret .= '</select>';
210
+	/**
211
+	 * Prepare HTML for output
212
+	 *
213
+	 * @return string HTML
214
+	 */
215
+	public function render(): string
216
+	{
217
+		$ele_name    = $this->getName();
218
+		$ele_title   = $this->getTitle();
219
+		$ele_value   = $this->getValue();
220
+		$ele_options = $this->getOptions();
221
+		$ret         = '<select size="' . $this->getSize() . '"' . $this->getExtra();
222
+		if ($this->isMultiple()) {
223
+			$ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">';
224
+		} else {
225
+			$ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">';
226
+		}
227
+		foreach ($ele_options as $value => $name) {
228
+			$ret .= '<option value="' . \htmlspecialchars((string)$value, \ENT_QUOTES) . '"';
229
+			if (\count($ele_value) > 0 && \in_array($value, $ele_value, true)) {
230
+				$ret .= ' selected';
231
+			}
232
+			$ret .= '>' . $name . '</option>';
233
+		}
234
+		$ret .= '</select>';
235 235
 
236
-        return $ret;
237
-    }
236
+		return $ret;
237
+	}
238 238
 
239
-    /**
240
-     * Render custom javascript validation code
241
-     *
242
-     * @seealso XoopsForm::renderValidationJS
243
-     */
244
-    public function renderValidationJS()
245
-    {
246
-        // render custom validation code if any
247
-        if (!empty($this->customValidationCode)) {
248
-            return \implode("\n", $this->customValidationCode);
249
-            // generate validation code if required
250
-        }
239
+	/**
240
+	 * Render custom javascript validation code
241
+	 *
242
+	 * @seealso XoopsForm::renderValidationJS
243
+	 */
244
+	public function renderValidationJS()
245
+	{
246
+		// render custom validation code if any
247
+		if (!empty($this->customValidationCode)) {
248
+			return \implode("\n", $this->customValidationCode);
249
+			// generate validation code if required
250
+		}
251 251
 
252
-        if ($this->isRequired()) {
253
-            $eltname    = $this->getName();
254
-            $eltcaption = $this->getCaption();
255
-            $eltmsg     = empty($eltcaption) ? \sprintf(_FORM_ENTER, $eltname) : \sprintf(_FORM_ENTER, $eltcaption);
256
-            $eltmsg     = \str_replace('"', '\"', \stripslashes($eltmsg));
252
+		if ($this->isRequired()) {
253
+			$eltname    = $this->getName();
254
+			$eltcaption = $this->getCaption();
255
+			$eltmsg     = empty($eltcaption) ? \sprintf(_FORM_ENTER, $eltname) : \sprintf(_FORM_ENTER, $eltcaption);
256
+			$eltmsg     = \str_replace('"', '\"', \stripslashes($eltmsg));
257 257
 
258
-            return "\nvar hasSelected = false; var selectBox = myform.{$eltname};"
259
-                   . 'for (i = 0; i < selectBox.options.length; i++ ) { if (selectBox.options[i].selected === true) { hasSelected = true; break; } }'
260
-                   . "if (!hasSelected) { window.alert(\"{$eltmsg}\"); selectBox.focus(); return false; }";
261
-        }
258
+			return "\nvar hasSelected = false; var selectBox = myform.{$eltname};"
259
+				   . 'for (i = 0; i < selectBox.options.length; i++ ) { if (selectBox.options[i].selected === true) { hasSelected = true; break; } }'
260
+				   . "if (!hasSelected) { window.alert(\"{$eltmsg}\"); selectBox.focus(); return false; }";
261
+		}
262 262
 
263
-        return '';
264
-    }
263
+		return '';
264
+	}
265 265
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
         $this->setCaption($caption);
97 97
         $this->setName($name);
98 98
         $this->_multiple = $multiple;
99
-        $this->_size     = (int)$size;
99
+        $this->_size     = (int) $size;
100 100
         if (isset($value)) {
101 101
             $this->setValue($value);
102 102
         }
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
     {
167 167
         if (\is_array($value)) {
168 168
             foreach ($value as $v) {
169
-                $this->_value[] = (int)$v;
169
+                $this->_value[] = (int) $v;
170 170
             }
171 171
 //            $this->_value[] = array_values($value);
172 172
         } elseif (isset($value)) {
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
      */
183 183
     public function addOption($value, $name = ''): void
184 184
     {
185
-        if ('' != $name) {
185
+        if (''!=$name) {
186 186
             $this->_options[$value] = $name;
187 187
         } else {
188 188
             $this->_options[$value] = $value;
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
         }
219 219
         $value = [];
220 220
         foreach ($this->_options as $val => $name) {
221
-            $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name;
221
+            $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode>1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name;
222 222
         }
223 223
 
224 224
         return $value;
@@ -235,18 +235,18 @@  discard block
 block discarded – undo
235 235
         $ele_title   = $this->getTitle();
236 236
         $ele_value   = $this->getValue();
237 237
         $ele_options = $this->getOptions();
238
-        $ret         = '<select size="' . $this->getSize() . '"' . $this->getExtra();
238
+        $ret         = '<select size="'.$this->getSize().'"'.$this->getExtra();
239 239
         if ($this->isMultiple()) {
240
-            $ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">';
240
+            $ret .= ' name="'.$ele_name.'[]" id="'.$ele_name.'" title="'.$ele_title.'" multiple="multiple">';
241 241
         } else {
242
-            $ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">';
242
+            $ret .= ' name="'.$ele_name.'" id="'.$ele_name.'" title="'.$ele_title.'">';
243 243
         }
244 244
         foreach ($ele_options as $value => $name) {
245
-            $ret .= '<option value="' . \htmlspecialchars((string)$value, \ENT_QUOTES) . '"';
246
-            if (\count($ele_value) > 0 && \in_array($value, $ele_value, true)) {
245
+            $ret .= '<option value="'.\htmlspecialchars((string) $value, \ENT_QUOTES).'"';
246
+            if (\count($ele_value)>0 && \in_array($value, $ele_value, true)) {
247 247
                 $ret .= ' selected';
248 248
             }
249
-            $ret .= '>' . $name . '</option>';
249
+            $ret .= '>'.$name.'</option>';
250 250
         }
251 251
         $ret .= '</select>';
252 252
 
Please login to merge, or discard this patch.
class/Form/SelectArtistForm.php 2 patches
Indentation   +208 added lines, -208 removed lines patch added patch discarded remove patch
@@ -51,230 +51,230 @@
 block discarded – undo
51 51
  */
52 52
 class SelectArtistForm extends \XoopsFormElement
53 53
 {
54
-    /**
55
-     * Options
56
-     *
57
-     * @var array
58
-     */
59
-    public $_options = [];
60
-    /**
61
-     * Allow multiple selections?
62
-     *
63
-     * @var bool
64
-     */
65
-    public $_multiple = false;
66
-    /**
67
-     * Number of rows. "1" makes a dropdown list.
68
-     *
69
-     * @var int
70
-     */
71
-    public $_size;
72
-    /**
73
-     * Pre-selcted values
74
-     *
75
-     * @var array
76
-     */
77
-    public $_value = [];
54
+	/**
55
+	 * Options
56
+	 *
57
+	 * @var array
58
+	 */
59
+	public $_options = [];
60
+	/**
61
+	 * Allow multiple selections?
62
+	 *
63
+	 * @var bool
64
+	 */
65
+	public $_multiple = false;
66
+	/**
67
+	 * Number of rows. "1" makes a dropdown list.
68
+	 *
69
+	 * @var int
70
+	 */
71
+	public $_size;
72
+	/**
73
+	 * Pre-selcted values
74
+	 *
75
+	 * @var array
76
+	 */
77
+	public $_value = [];
78 78
 
79
-    /**
80
-     * Constructor
81
-     *
82
-     * @param string $caption  Caption
83
-     * @param string $name     "name" attribute
84
-     * @param mixed  $value    Pre-selected value (or array of them).
85
-     * @param int    $size     Number or rows. "1" makes a drop-down-list
86
-     * @param bool   $multiple Allow multiple selections?
87
-     * @param int    $ownid
88
-     */
89
-    public function __construct($caption, $name, $value = null, $size = 1, $multiple = false, $ownid = 0)
90
-    {
91
-        global $_form_object_options;
92
-        \xoops_loadLanguage('modinfo', 'songlist');
79
+	/**
80
+	 * Constructor
81
+	 *
82
+	 * @param string $caption  Caption
83
+	 * @param string $name     "name" attribute
84
+	 * @param mixed  $value    Pre-selected value (or array of them).
85
+	 * @param int    $size     Number or rows. "1" makes a drop-down-list
86
+	 * @param bool   $multiple Allow multiple selections?
87
+	 * @param int    $ownid
88
+	 */
89
+	public function __construct($caption, $name, $value = null, $size = 1, $multiple = false, $ownid = 0)
90
+	{
91
+		global $_form_object_options;
92
+		\xoops_loadLanguage('modinfo', 'songlist');
93 93
 
94
-        $this->setCaption($caption);
95
-        $this->setName($name);
96
-        $this->_multiple = $multiple;
97
-        $this->_size     = (int)$size;
98
-        if (isset($value)) {
99
-            $this->setValue($value);
100
-        }
101
-        $this->addOption('0', \_MI_SONGLIST_NONE);
102
-        if (!isset($_form_object_options['artists'])) {
103
-            $artistsHandler = Helper::getInstance()->getHandler('Artists');
104
-            $criteria       = new \Criteria('');
105
-            $criteria->setSort('name');
106
-            $criteria->setOrder('ASC');
107
-            foreach ($artistsHandler->getObjects($criteria, true) as $id => $obj) {
108
-                $_form_object_options['artists'][$id] = $obj->getVar('name');
109
-            }
110
-        }
111
-        //        if (Request::hasVar('artists', 'form_object_options')) {
112
-        if (isset($_form_object_options['artists'])) {
113
-            foreach ($_form_object_options['artists'] as $id => $value) {
114
-                $this->addOption($id, $value);
115
-            }
116
-        }
117
-    }
94
+		$this->setCaption($caption);
95
+		$this->setName($name);
96
+		$this->_multiple = $multiple;
97
+		$this->_size     = (int)$size;
98
+		if (isset($value)) {
99
+			$this->setValue($value);
100
+		}
101
+		$this->addOption('0', \_MI_SONGLIST_NONE);
102
+		if (!isset($_form_object_options['artists'])) {
103
+			$artistsHandler = Helper::getInstance()->getHandler('Artists');
104
+			$criteria       = new \Criteria('');
105
+			$criteria->setSort('name');
106
+			$criteria->setOrder('ASC');
107
+			foreach ($artistsHandler->getObjects($criteria, true) as $id => $obj) {
108
+				$_form_object_options['artists'][$id] = $obj->getVar('name');
109
+			}
110
+		}
111
+		//        if (Request::hasVar('artists', 'form_object_options')) {
112
+		if (isset($_form_object_options['artists'])) {
113
+			foreach ($_form_object_options['artists'] as $id => $value) {
114
+				$this->addOption($id, $value);
115
+			}
116
+		}
117
+	}
118 118
 
119
-    /**
120
-     * Are multiple selections allowed?
121
-     *
122
-     * @return bool
123
-     */
124
-    public function isMultiple(): bool
125
-    {
126
-        return $this->_multiple;
127
-    }
119
+	/**
120
+	 * Are multiple selections allowed?
121
+	 *
122
+	 * @return bool
123
+	 */
124
+	public function isMultiple(): bool
125
+	{
126
+		return $this->_multiple;
127
+	}
128 128
 
129
-    /**
130
-     * Get the size
131
-     *
132
-     * @return int
133
-     */
134
-    public function getSize(): int
135
-    {
136
-        return $this->_size;
137
-    }
129
+	/**
130
+	 * Get the size
131
+	 *
132
+	 * @return int
133
+	 */
134
+	public function getSize(): int
135
+	{
136
+		return $this->_size;
137
+	}
138 138
 
139
-    /**
140
-     * Get an array of pre-selected values
141
-     *
142
-     * @param bool $encode To sanitizer the text?
143
-     * @return array
144
-     */
145
-    public function getValue($encode = false): array
146
-    {
147
-        if (!$encode) {
148
-            return $this->_value;
149
-        }
150
-        $value = [];
151
-        foreach ($this->_value as $val) {
152
-            $value[] = $val ? \htmlspecialchars($val, \ENT_QUOTES) : $val;
153
-        }
139
+	/**
140
+	 * Get an array of pre-selected values
141
+	 *
142
+	 * @param bool $encode To sanitizer the text?
143
+	 * @return array
144
+	 */
145
+	public function getValue($encode = false): array
146
+	{
147
+		if (!$encode) {
148
+			return $this->_value;
149
+		}
150
+		$value = [];
151
+		foreach ($this->_value as $val) {
152
+			$value[] = $val ? \htmlspecialchars($val, \ENT_QUOTES) : $val;
153
+		}
154 154
 
155
-        return $value;
156
-    }
155
+		return $value;
156
+	}
157 157
 
158
-    /**
159
-     * Set pre-selected values
160
-     *
161
-     * @param mixed $value
162
-     */
163
-    public function setValue($value): void
164
-    {
165
-        if (\is_array($value)) {
166
-            foreach ($value as $v) {
167
-                $this->_value[] = (int)$v;
168
-            }
158
+	/**
159
+	 * Set pre-selected values
160
+	 *
161
+	 * @param mixed $value
162
+	 */
163
+	public function setValue($value): void
164
+	{
165
+		if (\is_array($value)) {
166
+			foreach ($value as $v) {
167
+				$this->_value[] = (int)$v;
168
+			}
169 169
 //            $this->_value[] = array_values($value);
170
-        } elseif (isset($value)) {
171
-            $this->_value[] = $value;
172
-        }
173
-    }
170
+		} elseif (isset($value)) {
171
+			$this->_value[] = $value;
172
+		}
173
+	}
174 174
 
175
-    /**
176
-     * Add an option
177
-     *
178
-     * @param string $value "value" attribute
179
-     * @param string $name  "name" attribute
180
-     */
181
-    public function addOption($value, $name = ''): void
182
-    {
183
-        if ('' != $name) {
184
-            $this->_options[$value] = $name;
185
-        } else {
186
-            $this->_options[$value] = $value;
187
-        }
188
-    }
175
+	/**
176
+	 * Add an option
177
+	 *
178
+	 * @param string $value "value" attribute
179
+	 * @param string $name  "name" attribute
180
+	 */
181
+	public function addOption($value, $name = ''): void
182
+	{
183
+		if ('' != $name) {
184
+			$this->_options[$value] = $name;
185
+		} else {
186
+			$this->_options[$value] = $value;
187
+		}
188
+	}
189 189
 
190
-    /**
191
-     * Add multiple options
192
-     *
193
-     * @param array $options Associative array of value->name pairs
194
-     */
195
-    public function addOptionArray($options): void
196
-    {
197
-        if (\is_array($options)) {
198
-            foreach ($options as $k => $v) {
199
-                $this->addOption($k, $v);
200
-            }
201
-        }
202
-    }
190
+	/**
191
+	 * Add multiple options
192
+	 *
193
+	 * @param array $options Associative array of value->name pairs
194
+	 */
195
+	public function addOptionArray($options): void
196
+	{
197
+		if (\is_array($options)) {
198
+			foreach ($options as $k => $v) {
199
+				$this->addOption($k, $v);
200
+			}
201
+		}
202
+	}
203 203
 
204
-    /**
205
-     * Get an array with all the options
206
-     *
207
-     * Note: both name and value should be sanitized. However for backward compatibility, only value is sanitized for now.
208
-     *
209
-     * @param bool|int $encode To sanitizer the text? potential values: 0 - skip; 1 - only for value; 2 - for both value and name
210
-     * @return array Associative array of value->name pairs
211
-     */
212
-    public function getOptions($encode = false): array
213
-    {
214
-        if (!$encode) {
215
-            return $this->_options;
216
-        }
217
-        $value = [];
218
-        foreach ($this->_options as $val => $name) {
219
-            $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name;
220
-        }
204
+	/**
205
+	 * Get an array with all the options
206
+	 *
207
+	 * Note: both name and value should be sanitized. However for backward compatibility, only value is sanitized for now.
208
+	 *
209
+	 * @param bool|int $encode To sanitizer the text? potential values: 0 - skip; 1 - only for value; 2 - for both value and name
210
+	 * @return array Associative array of value->name pairs
211
+	 */
212
+	public function getOptions($encode = false): array
213
+	{
214
+		if (!$encode) {
215
+			return $this->_options;
216
+		}
217
+		$value = [];
218
+		foreach ($this->_options as $val => $name) {
219
+			$value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name;
220
+		}
221 221
 
222
-        return $value;
223
-    }
222
+		return $value;
223
+	}
224 224
 
225
-    /**
226
-     * Prepare HTML for output
227
-     *
228
-     * @return string HTML
229
-     */
230
-    public function render(): string
231
-    {
232
-        $ele_name    = $this->getName();
233
-        $ele_title   = $this->getTitle();
234
-        $ele_value   = $this->getValue();
235
-        $ele_options = $this->getOptions();
236
-        $ret         = '<select size="' . $this->getSize() . '"' . $this->getExtra();
237
-        if ($this->isMultiple()) {
238
-            $ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">';
239
-        } else {
240
-            $ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">';
241
-        }
242
-        foreach ($ele_options as $value => $name) {
243
-            $ret .= '<option value="' . \htmlspecialchars((string)$value, \ENT_QUOTES) . '"';
244
-            if (\count($ele_value) > 0 && \in_array($value, $ele_value, true)) {
245
-                $ret .= ' selected';
246
-            }
247
-            $ret .= '>' . $name . '</option>';
248
-        }
249
-        $ret .= '</select>';
225
+	/**
226
+	 * Prepare HTML for output
227
+	 *
228
+	 * @return string HTML
229
+	 */
230
+	public function render(): string
231
+	{
232
+		$ele_name    = $this->getName();
233
+		$ele_title   = $this->getTitle();
234
+		$ele_value   = $this->getValue();
235
+		$ele_options = $this->getOptions();
236
+		$ret         = '<select size="' . $this->getSize() . '"' . $this->getExtra();
237
+		if ($this->isMultiple()) {
238
+			$ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">';
239
+		} else {
240
+			$ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">';
241
+		}
242
+		foreach ($ele_options as $value => $name) {
243
+			$ret .= '<option value="' . \htmlspecialchars((string)$value, \ENT_QUOTES) . '"';
244
+			if (\count($ele_value) > 0 && \in_array($value, $ele_value, true)) {
245
+				$ret .= ' selected';
246
+			}
247
+			$ret .= '>' . $name . '</option>';
248
+		}
249
+		$ret .= '</select>';
250 250
 
251
-        return $ret;
252
-    }
251
+		return $ret;
252
+	}
253 253
 
254
-    /**
255
-     * Render custom javascript validation code
256
-     *
257
-     * @seealso XoopsForm::renderValidationJS
258
-     */
259
-    public function renderValidationJS()
260
-    {
261
-        // render custom validation code if any
262
-        if (!empty($this->customValidationCode)) {
263
-            return \implode("\n", $this->customValidationCode);
264
-            // generate validation code if required
265
-        }
254
+	/**
255
+	 * Render custom javascript validation code
256
+	 *
257
+	 * @seealso XoopsForm::renderValidationJS
258
+	 */
259
+	public function renderValidationJS()
260
+	{
261
+		// render custom validation code if any
262
+		if (!empty($this->customValidationCode)) {
263
+			return \implode("\n", $this->customValidationCode);
264
+			// generate validation code if required
265
+		}
266 266
 
267
-        if ($this->isRequired()) {
268
-            $eltname    = $this->getName();
269
-            $eltcaption = $this->getCaption();
270
-            $eltmsg     = empty($eltcaption) ? \sprintf(_FORM_ENTER, $eltname) : \sprintf(_FORM_ENTER, $eltcaption);
271
-            $eltmsg     = \str_replace('"', '\"', \stripslashes($eltmsg));
267
+		if ($this->isRequired()) {
268
+			$eltname    = $this->getName();
269
+			$eltcaption = $this->getCaption();
270
+			$eltmsg     = empty($eltcaption) ? \sprintf(_FORM_ENTER, $eltname) : \sprintf(_FORM_ENTER, $eltcaption);
271
+			$eltmsg     = \str_replace('"', '\"', \stripslashes($eltmsg));
272 272
 
273
-            return "\nvar hasSelected = false; var selectBox = myform.{$eltname};"
274
-                   . 'for (i = 0; i < selectBox.options.length; i++ ) { if (selectBox.options[i].selected === true) { hasSelected = true; break; } }'
275
-                   . "if (!hasSelected) { window.alert(\"{$eltmsg}\"); selectBox.focus(); return false; }";
276
-        }
273
+			return "\nvar hasSelected = false; var selectBox = myform.{$eltname};"
274
+				   . 'for (i = 0; i < selectBox.options.length; i++ ) { if (selectBox.options[i].selected === true) { hasSelected = true; break; } }'
275
+				   . "if (!hasSelected) { window.alert(\"{$eltmsg}\"); selectBox.focus(); return false; }";
276
+		}
277 277
 
278
-        return '';
279
-    }
278
+		return '';
279
+	}
280 280
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
         $this->setCaption($caption);
97 97
         $this->setName($name);
98 98
         $this->_multiple = $multiple;
99
-        $this->_size     = (int)$size;
99
+        $this->_size     = (int) $size;
100 100
         if (isset($value)) {
101 101
             $this->setValue($value);
102 102
         }
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
     {
167 167
         if (\is_array($value)) {
168 168
             foreach ($value as $v) {
169
-                $this->_value[] = (int)$v;
169
+                $this->_value[] = (int) $v;
170 170
             }
171 171
 //            $this->_value[] = array_values($value);
172 172
         } elseif (isset($value)) {
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
      */
183 183
     public function addOption($value, $name = ''): void
184 184
     {
185
-        if ('' != $name) {
185
+        if (''!=$name) {
186 186
             $this->_options[$value] = $name;
187 187
         } else {
188 188
             $this->_options[$value] = $value;
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
         }
219 219
         $value = [];
220 220
         foreach ($this->_options as $val => $name) {
221
-            $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name;
221
+            $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode>1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name;
222 222
         }
223 223
 
224 224
         return $value;
@@ -235,18 +235,18 @@  discard block
 block discarded – undo
235 235
         $ele_title   = $this->getTitle();
236 236
         $ele_value   = $this->getValue();
237 237
         $ele_options = $this->getOptions();
238
-        $ret         = '<select size="' . $this->getSize() . '"' . $this->getExtra();
238
+        $ret         = '<select size="'.$this->getSize().'"'.$this->getExtra();
239 239
         if ($this->isMultiple()) {
240
-            $ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">';
240
+            $ret .= ' name="'.$ele_name.'[]" id="'.$ele_name.'" title="'.$ele_title.'" multiple="multiple">';
241 241
         } else {
242
-            $ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">';
242
+            $ret .= ' name="'.$ele_name.'" id="'.$ele_name.'" title="'.$ele_title.'">';
243 243
         }
244 244
         foreach ($ele_options as $value => $name) {
245
-            $ret .= '<option value="' . \htmlspecialchars((string)$value, \ENT_QUOTES) . '"';
246
-            if (\count($ele_value) > 0 && \in_array($value, $ele_value, true)) {
245
+            $ret .= '<option value="'.\htmlspecialchars((string) $value, \ENT_QUOTES).'"';
246
+            if (\count($ele_value)>0 && \in_array($value, $ele_value, true)) {
247 247
                 $ret .= ' selected';
248 248
             }
249
-            $ret .= '>' . $name . '</option>';
249
+            $ret .= '>'.$name.'</option>';
250 250
         }
251 251
         $ret .= '</select>';
252 252
 
Please login to merge, or discard this patch.
class/Form/SelectCategoryForm.php 2 patches
Indentation   +260 added lines, -260 removed lines patch added patch discarded remove patch
@@ -47,287 +47,287 @@
 block discarded – undo
47 47
  */
48 48
 class SelectCategoryForm extends XoopsFormElement
49 49
 {
50
-    /**
51
-     * Options
52
-     *
53
-     * @var array
54
-     */
55
-    public $_options = [];
56
-    /**
57
-     * Allow multiple selections?
58
-     *
59
-     * @var bool
60
-     */
61
-    public $_multiple = false;
62
-    /**
63
-     * Number of rows. "1" makes a dropdown list.
64
-     *
65
-     * @var int
66
-     */
67
-    public $_size;
68
-    /**
69
-     * Pre-selcted values
70
-     *
71
-     * @var array
72
-     */
73
-    public $_value = [];
50
+	/**
51
+	 * Options
52
+	 *
53
+	 * @var array
54
+	 */
55
+	public $_options = [];
56
+	/**
57
+	 * Allow multiple selections?
58
+	 *
59
+	 * @var bool
60
+	 */
61
+	public $_multiple = false;
62
+	/**
63
+	 * Number of rows. "1" makes a dropdown list.
64
+	 *
65
+	 * @var int
66
+	 */
67
+	public $_size;
68
+	/**
69
+	 * Pre-selcted values
70
+	 *
71
+	 * @var array
72
+	 */
73
+	public $_value = [];
74 74
 
75
-    /**
76
-     * Constructor
77
-     *
78
-     * @param string $caption  Caption
79
-     * @param string $name     "name" attribute
80
-     * @param mixed  $value    Pre-selected value (or array of them).
81
-     * @param int    $size     Number of rows. "1" makes a drop-down-list
82
-     * @param bool   $multiple Allow multiple selections?
83
-     * @param int    $ownid
84
-     */
85
-    public function __construct($caption, $name, $value = null, $size = 1, $multiple = false, $ownid = 0)
86
-    {
87
-        global $_form_object_options;
88
-        \xoops_loadLanguage('modinfo', 'songlist');
75
+	/**
76
+	 * Constructor
77
+	 *
78
+	 * @param string $caption  Caption
79
+	 * @param string $name     "name" attribute
80
+	 * @param mixed  $value    Pre-selected value (or array of them).
81
+	 * @param int    $size     Number of rows. "1" makes a drop-down-list
82
+	 * @param bool   $multiple Allow multiple selections?
83
+	 * @param int    $ownid
84
+	 */
85
+	public function __construct($caption, $name, $value = null, $size = 1, $multiple = false, $ownid = 0)
86
+	{
87
+		global $_form_object_options;
88
+		\xoops_loadLanguage('modinfo', 'songlist');
89 89
 
90
-        $this->setCaption($caption);
91
-        $this->setName($name);
92
-        $this->_multiple = $multiple;
93
-        $this->_size     = (int)$size;
94
-        if (isset($value)) {
95
-            $this->setValue($value);
96
-        }
97
-        $this->addOption('0', \_MI_SONGLIST_ALL);
98
-        if (!isset($_form_object_options['category'])) {
99
-            $_form_object_options['category'] = $this->getCategory(0);
100
-        }
101
-        //        if (Request::hasVar('category', 'form_object_options')) {
102
-        if (isset($_form_object_options['category'])) {
103
-            $this->populateList($_form_object_options['category'], $ownid);
104
-        }
105
-    }
90
+		$this->setCaption($caption);
91
+		$this->setName($name);
92
+		$this->_multiple = $multiple;
93
+		$this->_size     = (int)$size;
94
+		if (isset($value)) {
95
+			$this->setValue($value);
96
+		}
97
+		$this->addOption('0', \_MI_SONGLIST_ALL);
98
+		if (!isset($_form_object_options['category'])) {
99
+			$_form_object_options['category'] = $this->getCategory(0);
100
+		}
101
+		//        if (Request::hasVar('category', 'form_object_options')) {
102
+		if (isset($_form_object_options['category'])) {
103
+			$this->populateList($_form_object_options['category'], $ownid);
104
+		}
105
+	}
106 106
 
107
-    /**
108
-     * @param     $vars
109
-     * @param int $ownid
110
-     */
111
-    public function populateList($vars, $ownid = 0): void
112
-    {
113
-        foreach ($vars as $previd => $cats) {
114
-            if ($previd != $ownid || 0 == $ownid) {
115
-                foreach ($cats as $catid => $title) {
116
-                    if ($catid != $ownid || 0 == $ownid) {
117
-                        $this->addOption($catid, $title['item']);
118
-                        if (isset($title['sub'])) {
119
-                            $this->populateList($title['sub'], $ownid);
120
-                        }
121
-                    }
122
-                }
123
-            }
124
-        }
125
-    }
107
+	/**
108
+	 * @param     $vars
109
+	 * @param int $ownid
110
+	 */
111
+	public function populateList($vars, $ownid = 0): void
112
+	{
113
+		foreach ($vars as $previd => $cats) {
114
+			if ($previd != $ownid || 0 == $ownid) {
115
+				foreach ($cats as $catid => $title) {
116
+					if ($catid != $ownid || 0 == $ownid) {
117
+						$this->addOption($catid, $title['item']);
118
+						if (isset($title['sub'])) {
119
+							$this->populateList($title['sub'], $ownid);
120
+						}
121
+					}
122
+				}
123
+			}
124
+		}
125
+	}
126 126
 
127
-    /**
128
-     * @param $ownid
129
-     * @return array
130
-     */
131
-    public function getCategory($ownid): array
132
-    {
133
-        $categoryHandler = Helper::getInstance()->getHandler('Category');
134
-        $criteria        = new \Criteria('pid', '0');
135
-        $criteria->setSort('name');
136
-        $criteria->setOrder('ASC');
137
-        $categories  = $categoryHandler->getObjects($criteria, true);
138
-        $langs_array = $this->treeMenu([], $categories, -1, $ownid);
127
+	/**
128
+	 * @param $ownid
129
+	 * @return array
130
+	 */
131
+	public function getCategory($ownid): array
132
+	{
133
+		$categoryHandler = Helper::getInstance()->getHandler('Category');
134
+		$criteria        = new \Criteria('pid', '0');
135
+		$criteria->setSort('name');
136
+		$criteria->setOrder('ASC');
137
+		$categories  = $categoryHandler->getObjects($criteria, true);
138
+		$langs_array = $this->treeMenu([], $categories, -1, $ownid);
139 139
 
140
-        return $langs_array;
141
-    }
140
+		return $langs_array;
141
+	}
142 142
 
143
-    /**
144
-     * @param     $langs_array
145
-     * @param     $categories
146
-     * @param     $level
147
-     * @param     $ownid
148
-     * @param int $previd
149
-     * @return array
150
-     */
151
-    public function treeMenu($langs_array, $categories, $level, $ownid, $previd = 0): array
152
-    {
153
-        ++$level;
154
-        $categoryHandler = Helper::getInstance()->getHandler('Category');
155
-        foreach ($categories as $catid => $category) {
156
-            if ($catid != $ownid) {
157
-                $langs_array[$previd][$catid]['item'] = \str_repeat('--', $level) . $category->getVar('name');
158
-                $criteria                             = new \Criteria('pid', $catid);
159
-                $criteria->setSort('name');
160
-                $criteria->setOrder('ASC');
161
-                $categoriesb = $categoryHandler->getObjects($criteria, true);
162
-                if ($categoriesb) {
163
-                    $langs_array[$previd][$catid]['sub'] = $this->treeMenu($langs_array, $categoriesb, $level, $ownid, $catid);
164
-                }
165
-            }
166
-        }
167
-        $level--;
143
+	/**
144
+	 * @param     $langs_array
145
+	 * @param     $categories
146
+	 * @param     $level
147
+	 * @param     $ownid
148
+	 * @param int $previd
149
+	 * @return array
150
+	 */
151
+	public function treeMenu($langs_array, $categories, $level, $ownid, $previd = 0): array
152
+	{
153
+		++$level;
154
+		$categoryHandler = Helper::getInstance()->getHandler('Category');
155
+		foreach ($categories as $catid => $category) {
156
+			if ($catid != $ownid) {
157
+				$langs_array[$previd][$catid]['item'] = \str_repeat('--', $level) . $category->getVar('name');
158
+				$criteria                             = new \Criteria('pid', $catid);
159
+				$criteria->setSort('name');
160
+				$criteria->setOrder('ASC');
161
+				$categoriesb = $categoryHandler->getObjects($criteria, true);
162
+				if ($categoriesb) {
163
+					$langs_array[$previd][$catid]['sub'] = $this->treeMenu($langs_array, $categoriesb, $level, $ownid, $catid);
164
+				}
165
+			}
166
+		}
167
+		$level--;
168 168
 
169
-        return $langs_array;
170
-    }
169
+		return $langs_array;
170
+	}
171 171
 
172
-    /**
173
-     * Are multiple selections allowed?
174
-     *
175
-     * @return bool
176
-     */
177
-    public function isMultiple(): bool
178
-    {
179
-        return $this->_multiple;
180
-    }
172
+	/**
173
+	 * Are multiple selections allowed?
174
+	 *
175
+	 * @return bool
176
+	 */
177
+	public function isMultiple(): bool
178
+	{
179
+		return $this->_multiple;
180
+	}
181 181
 
182
-    /**
183
-     * Get the size
184
-     *
185
-     * @return int
186
-     */
187
-    public function getSize(): int
188
-    {
189
-        return $this->_size;
190
-    }
182
+	/**
183
+	 * Get the size
184
+	 *
185
+	 * @return int
186
+	 */
187
+	public function getSize(): int
188
+	{
189
+		return $this->_size;
190
+	}
191 191
 
192
-    /**
193
-     * Get an array of pre-selected values
194
-     *
195
-     * @param bool $encode To sanitizer the text?
196
-     * @return array
197
-     */
198
-    public function getValue($encode = false): array
199
-    {
200
-        if (!$encode) {
201
-            return $this->_value;
202
-        }
203
-        $value = [];
204
-        foreach ($this->_value as $val) {
205
-            $value[] = $val ? \htmlspecialchars($val, \ENT_QUOTES) : $val;
206
-        }
192
+	/**
193
+	 * Get an array of pre-selected values
194
+	 *
195
+	 * @param bool $encode To sanitizer the text?
196
+	 * @return array
197
+	 */
198
+	public function getValue($encode = false): array
199
+	{
200
+		if (!$encode) {
201
+			return $this->_value;
202
+		}
203
+		$value = [];
204
+		foreach ($this->_value as $val) {
205
+			$value[] = $val ? \htmlspecialchars($val, \ENT_QUOTES) : $val;
206
+		}
207 207
 
208
-        return $value;
209
-    }
208
+		return $value;
209
+	}
210 210
 
211
-    /**
212
-     * Set pre-selected values
213
-     *
214
-     * @param mixed $value
215
-     */
216
-    public function setValue($value): void
217
-    {
218
-        if (\is_array($value)) {
219
-            foreach ($value as $v) {
220
-                $this->_value[] = (int)$v;
221
-            }
211
+	/**
212
+	 * Set pre-selected values
213
+	 *
214
+	 * @param mixed $value
215
+	 */
216
+	public function setValue($value): void
217
+	{
218
+		if (\is_array($value)) {
219
+			foreach ($value as $v) {
220
+				$this->_value[] = (int)$v;
221
+			}
222 222
 //            $this->_value[] = array_values($value);
223
-        } elseif (isset($value)) {
224
-            $this->_value[] = $value;
225
-        }
226
-    }
223
+		} elseif (isset($value)) {
224
+			$this->_value[] = $value;
225
+		}
226
+	}
227 227
 
228
-    /**
229
-     * Add an option
230
-     *
231
-     * @param string $value "value" attribute
232
-     * @param string $name  "name" attribute
233
-     */
234
-    public function addOption($value, $name = ''): void
235
-    {
236
-        if ('' != $name) {
237
-            $this->_options[$value] = $name;
238
-        } else {
239
-            $this->_options[$value] = $value;
240
-        }
241
-    }
228
+	/**
229
+	 * Add an option
230
+	 *
231
+	 * @param string $value "value" attribute
232
+	 * @param string $name  "name" attribute
233
+	 */
234
+	public function addOption($value, $name = ''): void
235
+	{
236
+		if ('' != $name) {
237
+			$this->_options[$value] = $name;
238
+		} else {
239
+			$this->_options[$value] = $value;
240
+		}
241
+	}
242 242
 
243
-    /**
244
-     * Add multiple options
245
-     *
246
-     * @param array $options Associative array of value->name pairs
247
-     */
248
-    public function addOptionArray($options): void
249
-    {
250
-        if (\is_array($options)) {
251
-            foreach ($options as $k => $v) {
252
-                $this->addOption($k, $v);
253
-            }
254
-        }
255
-    }
243
+	/**
244
+	 * Add multiple options
245
+	 *
246
+	 * @param array $options Associative array of value->name pairs
247
+	 */
248
+	public function addOptionArray($options): void
249
+	{
250
+		if (\is_array($options)) {
251
+			foreach ($options as $k => $v) {
252
+				$this->addOption($k, $v);
253
+			}
254
+		}
255
+	}
256 256
 
257
-    /**
258
-     * Get an array with all the options
259
-     *
260
-     * Note: both name and value should be sanitized. However for backward compatibility, only value is sanitized for now.
261
-     *
262
-     * @param bool|int $encode To sanitizer the text? potential values: 0 - skip; 1 - only for value; 2 - for both value and name
263
-     * @return array Associative array of value->name pairs
264
-     */
265
-    public function getOptions($encode = false): array
266
-    {
267
-        if (!$encode) {
268
-            return $this->_options;
269
-        }
270
-        $value = [];
271
-        foreach ($this->_options as $val => $name) {
272
-            $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name;
273
-        }
257
+	/**
258
+	 * Get an array with all the options
259
+	 *
260
+	 * Note: both name and value should be sanitized. However for backward compatibility, only value is sanitized for now.
261
+	 *
262
+	 * @param bool|int $encode To sanitizer the text? potential values: 0 - skip; 1 - only for value; 2 - for both value and name
263
+	 * @return array Associative array of value->name pairs
264
+	 */
265
+	public function getOptions($encode = false): array
266
+	{
267
+		if (!$encode) {
268
+			return $this->_options;
269
+		}
270
+		$value = [];
271
+		foreach ($this->_options as $val => $name) {
272
+			$value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name;
273
+		}
274 274
 
275
-        return $value;
276
-    }
275
+		return $value;
276
+	}
277 277
 
278
-    /**
279
-     * Prepare HTML for output
280
-     *
281
-     * @return string HTML
282
-     */
283
-    public function render(): string
284
-    {
285
-        $ele_name    = $this->getName();
286
-        $ele_title   = $this->getTitle();
287
-        $ele_value   = $this->getValue();
288
-        $ele_options = $this->getOptions();
289
-        $ret         = '<select size="' . $this->getSize() . '"' . $this->getExtra();
290
-        if ($this->isMultiple()) {
291
-            $ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">';
292
-        } else {
293
-            $ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">';
294
-        }
295
-        foreach ($ele_options as $value => $name) {
296
-            $ret .= '<option value="' . \htmlspecialchars((string)$value, \ENT_QUOTES) . '"';
297
-            if (\count($ele_value) > 0 && \in_array($value, $ele_value, true)) {
298
-                $ret .= ' selected';
299
-            }
300
-            $ret .= '>' . $name . '</option>';
301
-        }
302
-        $ret .= '</select>';
278
+	/**
279
+	 * Prepare HTML for output
280
+	 *
281
+	 * @return string HTML
282
+	 */
283
+	public function render(): string
284
+	{
285
+		$ele_name    = $this->getName();
286
+		$ele_title   = $this->getTitle();
287
+		$ele_value   = $this->getValue();
288
+		$ele_options = $this->getOptions();
289
+		$ret         = '<select size="' . $this->getSize() . '"' . $this->getExtra();
290
+		if ($this->isMultiple()) {
291
+			$ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">';
292
+		} else {
293
+			$ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">';
294
+		}
295
+		foreach ($ele_options as $value => $name) {
296
+			$ret .= '<option value="' . \htmlspecialchars((string)$value, \ENT_QUOTES) . '"';
297
+			if (\count($ele_value) > 0 && \in_array($value, $ele_value, true)) {
298
+				$ret .= ' selected';
299
+			}
300
+			$ret .= '>' . $name . '</option>';
301
+		}
302
+		$ret .= '</select>';
303 303
 
304
-        return $ret;
305
-    }
304
+		return $ret;
305
+	}
306 306
 
307
-    /**
308
-     * Render custom javascript validation code
309
-     *
310
-     * @seealso XoopsForm::renderValidationJS
311
-     */
312
-    public function renderValidationJS()
313
-    {
314
-        // render custom validation code if any
315
-        if (!empty($this->customValidationCode)) {
316
-            return \implode("\n", $this->customValidationCode);
317
-            // generate validation code if required
318
-        }
307
+	/**
308
+	 * Render custom javascript validation code
309
+	 *
310
+	 * @seealso XoopsForm::renderValidationJS
311
+	 */
312
+	public function renderValidationJS()
313
+	{
314
+		// render custom validation code if any
315
+		if (!empty($this->customValidationCode)) {
316
+			return \implode("\n", $this->customValidationCode);
317
+			// generate validation code if required
318
+		}
319 319
 
320
-        if ($this->isRequired()) {
321
-            $eltname    = $this->getName();
322
-            $eltcaption = $this->getCaption();
323
-            $eltmsg     = empty($eltcaption) ? \sprintf(_FORM_ENTER, $eltname) : \sprintf(_FORM_ENTER, $eltcaption);
324
-            $eltmsg     = \str_replace('"', '\"', \stripslashes($eltmsg));
320
+		if ($this->isRequired()) {
321
+			$eltname    = $this->getName();
322
+			$eltcaption = $this->getCaption();
323
+			$eltmsg     = empty($eltcaption) ? \sprintf(_FORM_ENTER, $eltname) : \sprintf(_FORM_ENTER, $eltcaption);
324
+			$eltmsg     = \str_replace('"', '\"', \stripslashes($eltmsg));
325 325
 
326
-            return "\nvar hasSelected = false; var selectBox = myform.{$eltname};"
327
-                   . 'for (i = 0; i < selectBox.options.length; i++ ) { if (selectBox.options[i].selected === true) { hasSelected = true; break; } }'
328
-                   . "if (!hasSelected) { window.alert(\"{$eltmsg}\"); selectBox.focus(); return false; }";
329
-        }
326
+			return "\nvar hasSelected = false; var selectBox = myform.{$eltname};"
327
+				   . 'for (i = 0; i < selectBox.options.length; i++ ) { if (selectBox.options[i].selected === true) { hasSelected = true; break; } }'
328
+				   . "if (!hasSelected) { window.alert(\"{$eltmsg}\"); selectBox.focus(); return false; }";
329
+		}
330 330
 
331
-        return '';
332
-    }
331
+		return '';
332
+	}
333 333
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
         $this->setCaption($caption);
91 91
         $this->setName($name);
92 92
         $this->_multiple = $multiple;
93
-        $this->_size     = (int)$size;
93
+        $this->_size     = (int) $size;
94 94
         if (isset($value)) {
95 95
             $this->setValue($value);
96 96
         }
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
     public function populateList($vars, $ownid = 0): void
112 112
     {
113 113
         foreach ($vars as $previd => $cats) {
114
-            if ($previd != $ownid || 0 == $ownid) {
114
+            if ($previd!=$ownid || 0==$ownid) {
115 115
                 foreach ($cats as $catid => $title) {
116
-                    if ($catid != $ownid || 0 == $ownid) {
116
+                    if ($catid!=$ownid || 0==$ownid) {
117 117
                         $this->addOption($catid, $title['item']);
118 118
                         if (isset($title['sub'])) {
119 119
                             $this->populateList($title['sub'], $ownid);
@@ -153,8 +153,8 @@  discard block
 block discarded – undo
153 153
         ++$level;
154 154
         $categoryHandler = Helper::getInstance()->getHandler('Category');
155 155
         foreach ($categories as $catid => $category) {
156
-            if ($catid != $ownid) {
157
-                $langs_array[$previd][$catid]['item'] = \str_repeat('--', $level) . $category->getVar('name');
156
+            if ($catid!=$ownid) {
157
+                $langs_array[$previd][$catid]['item'] = \str_repeat('--', $level).$category->getVar('name');
158 158
                 $criteria                             = new \Criteria('pid', $catid);
159 159
                 $criteria->setSort('name');
160 160
                 $criteria->setOrder('ASC');
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
     {
218 218
         if (\is_array($value)) {
219 219
             foreach ($value as $v) {
220
-                $this->_value[] = (int)$v;
220
+                $this->_value[] = (int) $v;
221 221
             }
222 222
 //            $this->_value[] = array_values($value);
223 223
         } elseif (isset($value)) {
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
      */
234 234
     public function addOption($value, $name = ''): void
235 235
     {
236
-        if ('' != $name) {
236
+        if (''!=$name) {
237 237
             $this->_options[$value] = $name;
238 238
         } else {
239 239
             $this->_options[$value] = $value;
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
         }
270 270
         $value = [];
271 271
         foreach ($this->_options as $val => $name) {
272
-            $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name;
272
+            $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode>1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name;
273 273
         }
274 274
 
275 275
         return $value;
@@ -286,18 +286,18 @@  discard block
 block discarded – undo
286 286
         $ele_title   = $this->getTitle();
287 287
         $ele_value   = $this->getValue();
288 288
         $ele_options = $this->getOptions();
289
-        $ret         = '<select size="' . $this->getSize() . '"' . $this->getExtra();
289
+        $ret         = '<select size="'.$this->getSize().'"'.$this->getExtra();
290 290
         if ($this->isMultiple()) {
291
-            $ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">';
291
+            $ret .= ' name="'.$ele_name.'[]" id="'.$ele_name.'" title="'.$ele_title.'" multiple="multiple">';
292 292
         } else {
293
-            $ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">';
293
+            $ret .= ' name="'.$ele_name.'" id="'.$ele_name.'" title="'.$ele_title.'">';
294 294
         }
295 295
         foreach ($ele_options as $value => $name) {
296
-            $ret .= '<option value="' . \htmlspecialchars((string)$value, \ENT_QUOTES) . '"';
297
-            if (\count($ele_value) > 0 && \in_array($value, $ele_value, true)) {
296
+            $ret .= '<option value="'.\htmlspecialchars((string) $value, \ENT_QUOTES).'"';
297
+            if (\count($ele_value)>0 && \in_array($value, $ele_value, true)) {
298 298
                 $ret .= ' selected';
299 299
             }
300
-            $ret .= '>' . $name . '</option>';
300
+            $ret .= '>'.$name.'</option>';
301 301
         }
302 302
         $ret .= '</select>';
303 303
 
Please login to merge, or discard this patch.
class/Form/SelectVoiceForm.php 2 patches
Indentation   +207 added lines, -207 removed lines patch added patch discarded remove patch
@@ -53,229 +53,229 @@
 block discarded – undo
53 53
  */
54 54
 class SelectVoiceForm extends XoopsFormElement
55 55
 {
56
-    /**
57
-     * Options
58
-     *
59
-     * @var array
60
-     */
61
-    public $_options = [];
62
-    /**
63
-     * Allow multiple selections?
64
-     *
65
-     * @var bool
66
-     */
67
-    public $_multiple = false;
68
-    /**
69
-     * Number of rows. "1" makes a dropdown list.
70
-     *
71
-     * @var int
72
-     */
73
-    public $_size;
74
-    /**
75
-     * Pre-selcted values
76
-     *
77
-     * @var array
78
-     */
79
-    public $_value = [];
56
+	/**
57
+	 * Options
58
+	 *
59
+	 * @var array
60
+	 */
61
+	public $_options = [];
62
+	/**
63
+	 * Allow multiple selections?
64
+	 *
65
+	 * @var bool
66
+	 */
67
+	public $_multiple = false;
68
+	/**
69
+	 * Number of rows. "1" makes a dropdown list.
70
+	 *
71
+	 * @var int
72
+	 */
73
+	public $_size;
74
+	/**
75
+	 * Pre-selcted values
76
+	 *
77
+	 * @var array
78
+	 */
79
+	public $_value = [];
80 80
 
81
-    /**
82
-     * Constructor
83
-     *
84
-     * @param string $caption  Caption
85
-     * @param string $name     "name" attribute
86
-     * @param mixed  $value    Pre-selected value (or array of them).
87
-     * @param int    $size     Number or rows. "1" makes a drop-down-list
88
-     * @param bool   $multiple Allow multiple selections?
89
-     */
90
-    public function __construct($caption, $name, $value = null, $size = 1, $multiple = false)
91
-    {
92
-        global $_form_object_options;
93
-        \xoops_loadLanguage('modinfo', 'songlist');
81
+	/**
82
+	 * Constructor
83
+	 *
84
+	 * @param string $caption  Caption
85
+	 * @param string $name     "name" attribute
86
+	 * @param mixed  $value    Pre-selected value (or array of them).
87
+	 * @param int    $size     Number or rows. "1" makes a drop-down-list
88
+	 * @param bool   $multiple Allow multiple selections?
89
+	 */
90
+	public function __construct($caption, $name, $value = null, $size = 1, $multiple = false)
91
+	{
92
+		global $_form_object_options;
93
+		\xoops_loadLanguage('modinfo', 'songlist');
94 94
 
95
-        $this->setCaption($caption);
96
-        $this->setName($name);
97
-        $this->_multiple = $multiple;
98
-        $this->_size     = (int)$size;
99
-        if (isset($value)) {
100
-            $this->setValue($value);
101
-        }
102
-        $this->addOption('0', \_MI_SONGLIST_ALL);
103
-        if (!isset($_form_object_options['voice'])) {
104
-            $voiceHandler = Helper::getInstance()->getHandler('Voice');
105
-            $criteria     = new Criteria('');
106
-            $criteria->setSort('name');
107
-            $criteria->setOrder('ASC');
108
-            foreach ($voiceHandler->getObjects($criteria, true) as $id => $obj) {
109
-                $_form_object_options['voice'][$id] = $obj->getVar('name');
110
-            }
111
-        }
112
-        //        if (Request::hasVar('voice', 'form_object_options')) {
113
-        if (isset($_form_object_options['voice'])) {
114
-            foreach ($_form_object_options['voice'] as $id => $value) {
115
-                $this->addOption($id, $value);
116
-            }
117
-        }
118
-    }
95
+		$this->setCaption($caption);
96
+		$this->setName($name);
97
+		$this->_multiple = $multiple;
98
+		$this->_size     = (int)$size;
99
+		if (isset($value)) {
100
+			$this->setValue($value);
101
+		}
102
+		$this->addOption('0', \_MI_SONGLIST_ALL);
103
+		if (!isset($_form_object_options['voice'])) {
104
+			$voiceHandler = Helper::getInstance()->getHandler('Voice');
105
+			$criteria     = new Criteria('');
106
+			$criteria->setSort('name');
107
+			$criteria->setOrder('ASC');
108
+			foreach ($voiceHandler->getObjects($criteria, true) as $id => $obj) {
109
+				$_form_object_options['voice'][$id] = $obj->getVar('name');
110
+			}
111
+		}
112
+		//        if (Request::hasVar('voice', 'form_object_options')) {
113
+		if (isset($_form_object_options['voice'])) {
114
+			foreach ($_form_object_options['voice'] as $id => $value) {
115
+				$this->addOption($id, $value);
116
+			}
117
+		}
118
+	}
119 119
 
120
-    /**
121
-     * Are multiple selections allowed?
122
-     *
123
-     * @return bool
124
-     */
125
-    public function isMultiple(): bool
126
-    {
127
-        return $this->_multiple;
128
-    }
120
+	/**
121
+	 * Are multiple selections allowed?
122
+	 *
123
+	 * @return bool
124
+	 */
125
+	public function isMultiple(): bool
126
+	{
127
+		return $this->_multiple;
128
+	}
129 129
 
130
-    /**
131
-     * Get the size
132
-     *
133
-     * @return int
134
-     */
135
-    public function getSize(): int
136
-    {
137
-        return $this->_size;
138
-    }
130
+	/**
131
+	 * Get the size
132
+	 *
133
+	 * @return int
134
+	 */
135
+	public function getSize(): int
136
+	{
137
+		return $this->_size;
138
+	}
139 139
 
140
-    /**
141
-     * Get an array of pre-selected values
142
-     *
143
-     * @param bool $encode To sanitizer the text?
144
-     * @return array
145
-     */
146
-    public function getValue($encode = false): array
147
-    {
148
-        if (!$encode) {
149
-            return $this->_value;
150
-        }
151
-        $value = [];
152
-        foreach ($this->_value as $val) {
153
-            $value[] = $val ? \htmlspecialchars($val, \ENT_QUOTES) : $val;
154
-        }
140
+	/**
141
+	 * Get an array of pre-selected values
142
+	 *
143
+	 * @param bool $encode To sanitizer the text?
144
+	 * @return array
145
+	 */
146
+	public function getValue($encode = false): array
147
+	{
148
+		if (!$encode) {
149
+			return $this->_value;
150
+		}
151
+		$value = [];
152
+		foreach ($this->_value as $val) {
153
+			$value[] = $val ? \htmlspecialchars($val, \ENT_QUOTES) : $val;
154
+		}
155 155
 
156
-        return $value;
157
-    }
156
+		return $value;
157
+	}
158 158
 
159
-    /**
160
-     * Set pre-selected values
161
-     *
162
-     * @param mixed $value
163
-     */
164
-    public function setValue($value): void
165
-    {
166
-        if (\is_array($value)) {
167
-            foreach ($value as $v) {
168
-                $this->_value[] = (int)$v;
169
-            }
159
+	/**
160
+	 * Set pre-selected values
161
+	 *
162
+	 * @param mixed $value
163
+	 */
164
+	public function setValue($value): void
165
+	{
166
+		if (\is_array($value)) {
167
+			foreach ($value as $v) {
168
+				$this->_value[] = (int)$v;
169
+			}
170 170
 //            $this->_value[] = array_values($value);
171
-        } elseif (isset($value)) {
172
-            $this->_value[] = $value;
173
-        }
174
-    }
171
+		} elseif (isset($value)) {
172
+			$this->_value[] = $value;
173
+		}
174
+	}
175 175
 
176
-    /**
177
-     * Add an option
178
-     *
179
-     * @param string $value "value" attribute
180
-     * @param string $name  "name" attribute
181
-     */
182
-    public function addOption($value, $name = ''): void
183
-    {
184
-        if ('' != $name) {
185
-            $this->_options[$value] = $name;
186
-        } else {
187
-            $this->_options[$value] = $value;
188
-        }
189
-    }
176
+	/**
177
+	 * Add an option
178
+	 *
179
+	 * @param string $value "value" attribute
180
+	 * @param string $name  "name" attribute
181
+	 */
182
+	public function addOption($value, $name = ''): void
183
+	{
184
+		if ('' != $name) {
185
+			$this->_options[$value] = $name;
186
+		} else {
187
+			$this->_options[$value] = $value;
188
+		}
189
+	}
190 190
 
191
-    /**
192
-     * Add multiple options
193
-     *
194
-     * @param array $options Associative array of value->name pairs
195
-     */
196
-    public function addOptionArray($options): void
197
-    {
198
-        if (\is_array($options)) {
199
-            foreach ($options as $k => $v) {
200
-                $this->addOption($k, $v);
201
-            }
202
-        }
203
-    }
191
+	/**
192
+	 * Add multiple options
193
+	 *
194
+	 * @param array $options Associative array of value->name pairs
195
+	 */
196
+	public function addOptionArray($options): void
197
+	{
198
+		if (\is_array($options)) {
199
+			foreach ($options as $k => $v) {
200
+				$this->addOption($k, $v);
201
+			}
202
+		}
203
+	}
204 204
 
205
-    /**
206
-     * Get an array with all the options
207
-     *
208
-     * Note: both name and value should be sanitized. However for backward compatibility, only value is sanitized for now.
209
-     *
210
-     * @param bool|int $encode To sanitizer the text? potential values: 0 - skip; 1 - only for value; 2 - for both value and name
211
-     * @return array Associative array of value->name pairs
212
-     */
213
-    public function getOptions($encode = false): array
214
-    {
215
-        if (!$encode) {
216
-            return $this->_options;
217
-        }
218
-        $value = [];
219
-        foreach ($this->_options as $val => $name) {
220
-            $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name;
221
-        }
205
+	/**
206
+	 * Get an array with all the options
207
+	 *
208
+	 * Note: both name and value should be sanitized. However for backward compatibility, only value is sanitized for now.
209
+	 *
210
+	 * @param bool|int $encode To sanitizer the text? potential values: 0 - skip; 1 - only for value; 2 - for both value and name
211
+	 * @return array Associative array of value->name pairs
212
+	 */
213
+	public function getOptions($encode = false): array
214
+	{
215
+		if (!$encode) {
216
+			return $this->_options;
217
+		}
218
+		$value = [];
219
+		foreach ($this->_options as $val => $name) {
220
+			$value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name;
221
+		}
222 222
 
223
-        return $value;
224
-    }
223
+		return $value;
224
+	}
225 225
 
226
-    /**
227
-     * Prepare HTML for output
228
-     *
229
-     * @return string HTML
230
-     */
231
-    public function render(): string
232
-    {
233
-        $ele_name    = $this->getName();
234
-        $ele_title   = $this->getTitle();
235
-        $ele_value   = $this->getValue();
236
-        $ele_options = $this->getOptions();
237
-        $ret         = '<select size="' . $this->getSize() . '"' . $this->getExtra();
238
-        if ($this->isMultiple()) {
239
-            $ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">';
240
-        } else {
241
-            $ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">';
242
-        }
243
-        foreach ($ele_options as $value => $name) {
244
-            $ret .= '<option value="' . \htmlspecialchars((string)$value, \ENT_QUOTES) . '"';
245
-            if (\count($ele_value) > 0 && \in_array($value, $ele_value, true)) {
246
-                $ret .= ' selected';
247
-            }
248
-            $ret .= '>' . $name . '</option>';
249
-        }
250
-        $ret .= '</select>';
226
+	/**
227
+	 * Prepare HTML for output
228
+	 *
229
+	 * @return string HTML
230
+	 */
231
+	public function render(): string
232
+	{
233
+		$ele_name    = $this->getName();
234
+		$ele_title   = $this->getTitle();
235
+		$ele_value   = $this->getValue();
236
+		$ele_options = $this->getOptions();
237
+		$ret         = '<select size="' . $this->getSize() . '"' . $this->getExtra();
238
+		if ($this->isMultiple()) {
239
+			$ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">';
240
+		} else {
241
+			$ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">';
242
+		}
243
+		foreach ($ele_options as $value => $name) {
244
+			$ret .= '<option value="' . \htmlspecialchars((string)$value, \ENT_QUOTES) . '"';
245
+			if (\count($ele_value) > 0 && \in_array($value, $ele_value, true)) {
246
+				$ret .= ' selected';
247
+			}
248
+			$ret .= '>' . $name . '</option>';
249
+		}
250
+		$ret .= '</select>';
251 251
 
252
-        return $ret;
253
-    }
252
+		return $ret;
253
+	}
254 254
 
255
-    /**
256
-     * Render custom javascript validation code
257
-     *
258
-     * @seealso XoopsForm::renderValidationJS
259
-     */
260
-    public function renderValidationJS()
261
-    {
262
-        // render custom validation code if any
263
-        if (!empty($this->customValidationCode)) {
264
-            return \implode("\n", $this->customValidationCode);
265
-            // generate validation code if required
266
-        }
255
+	/**
256
+	 * Render custom javascript validation code
257
+	 *
258
+	 * @seealso XoopsForm::renderValidationJS
259
+	 */
260
+	public function renderValidationJS()
261
+	{
262
+		// render custom validation code if any
263
+		if (!empty($this->customValidationCode)) {
264
+			return \implode("\n", $this->customValidationCode);
265
+			// generate validation code if required
266
+		}
267 267
 
268
-        if ($this->isRequired()) {
269
-            $eltname    = $this->getName();
270
-            $eltcaption = $this->getCaption();
271
-            $eltmsg     = empty($eltcaption) ? \sprintf(_FORM_ENTER, $eltname) : \sprintf(_FORM_ENTER, $eltcaption);
272
-            $eltmsg     = \str_replace('"', '\"', \stripslashes($eltmsg));
268
+		if ($this->isRequired()) {
269
+			$eltname    = $this->getName();
270
+			$eltcaption = $this->getCaption();
271
+			$eltmsg     = empty($eltcaption) ? \sprintf(_FORM_ENTER, $eltname) : \sprintf(_FORM_ENTER, $eltcaption);
272
+			$eltmsg     = \str_replace('"', '\"', \stripslashes($eltmsg));
273 273
 
274
-            return "\nvar hasSelected = false; var selectBox = myform.{$eltname};"
275
-                   . 'for (i = 0; i < selectBox.options.length; i++ ) { if (selectBox.options[i].selected === true) { hasSelected = true; break; } }'
276
-                   . "if (!hasSelected) { window.alert(\"{$eltmsg}\"); selectBox.focus(); return false; }";
277
-        }
274
+			return "\nvar hasSelected = false; var selectBox = myform.{$eltname};"
275
+				   . 'for (i = 0; i < selectBox.options.length; i++ ) { if (selectBox.options[i].selected === true) { hasSelected = true; break; } }'
276
+				   . "if (!hasSelected) { window.alert(\"{$eltmsg}\"); selectBox.focus(); return false; }";
277
+		}
278 278
 
279
-        return '';
280
-    }
279
+		return '';
280
+	}
281 281
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
         $this->setCaption($caption);
97 97
         $this->setName($name);
98 98
         $this->_multiple = $multiple;
99
-        $this->_size     = (int)$size;
99
+        $this->_size     = (int) $size;
100 100
         if (isset($value)) {
101 101
             $this->setValue($value);
102 102
         }
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
     {
167 167
         if (\is_array($value)) {
168 168
             foreach ($value as $v) {
169
-                $this->_value[] = (int)$v;
169
+                $this->_value[] = (int) $v;
170 170
             }
171 171
 //            $this->_value[] = array_values($value);
172 172
         } elseif (isset($value)) {
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
      */
183 183
     public function addOption($value, $name = ''): void
184 184
     {
185
-        if ('' != $name) {
185
+        if (''!=$name) {
186 186
             $this->_options[$value] = $name;
187 187
         } else {
188 188
             $this->_options[$value] = $value;
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
         }
219 219
         $value = [];
220 220
         foreach ($this->_options as $val => $name) {
221
-            $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name;
221
+            $value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode>1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name;
222 222
         }
223 223
 
224 224
         return $value;
@@ -235,18 +235,18 @@  discard block
 block discarded – undo
235 235
         $ele_title   = $this->getTitle();
236 236
         $ele_value   = $this->getValue();
237 237
         $ele_options = $this->getOptions();
238
-        $ret         = '<select size="' . $this->getSize() . '"' . $this->getExtra();
238
+        $ret         = '<select size="'.$this->getSize().'"'.$this->getExtra();
239 239
         if ($this->isMultiple()) {
240
-            $ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">';
240
+            $ret .= ' name="'.$ele_name.'[]" id="'.$ele_name.'" title="'.$ele_title.'" multiple="multiple">';
241 241
         } else {
242
-            $ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">';
242
+            $ret .= ' name="'.$ele_name.'" id="'.$ele_name.'" title="'.$ele_title.'">';
243 243
         }
244 244
         foreach ($ele_options as $value => $name) {
245
-            $ret .= '<option value="' . \htmlspecialchars((string)$value, \ENT_QUOTES) . '"';
246
-            if (\count($ele_value) > 0 && \in_array($value, $ele_value, true)) {
245
+            $ret .= '<option value="'.\htmlspecialchars((string) $value, \ENT_QUOTES).'"';
246
+            if (\count($ele_value)>0 && \in_array($value, $ele_value, true)) {
247 247
                 $ret .= ' selected';
248 248
             }
249
-            $ret .= '>' . $name . '</option>';
249
+            $ret .= '>'.$name.'</option>';
250 250
         }
251 251
         $ret .= '</select>';
252 252
 
Please login to merge, or discard this patch.