|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Songlist; |
|
4
|
|
|
|
|
5
|
|
|
use Criteria; |
|
6
|
|
|
use CriteriaCompo; |
|
7
|
|
|
use XoopsDatabase; |
|
8
|
|
|
use XoopsObject; |
|
9
|
|
|
use XoopsPersistableObjectHandler; |
|
10
|
|
|
|
|
11
|
|
|
require_once \dirname(__DIR__) . '/include/songlist.object.php'; |
|
12
|
|
|
// require_once \dirname(__DIR__) . '/include/songlist.form.php'; |
|
13
|
|
|
use XoopsModules\Songlist\Form\FormController; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class Utf8mapHandler |
|
17
|
|
|
*/ |
|
18
|
|
|
class Utf8mapHandler extends XoopsPersistableObjectHandler |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* Utf8mapHandler constructor. |
|
22
|
|
|
* @param \XoopsDatabase $db |
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct(XoopsDatabase $db) |
|
25
|
|
|
{ |
|
26
|
|
|
parent::__construct($db, 'songlist_utf8map', Utf8map::class, 'utfid', 'from'); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @return array |
|
31
|
|
|
*/ |
|
32
|
|
|
public function filterFields(): array |
|
33
|
|
|
{ |
|
34
|
|
|
return ['utfid', 'from', 'to', 'created', 'updated']; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param $filter |
|
39
|
|
|
* @return \CriteriaCompo |
|
40
|
|
|
*/ |
|
41
|
|
|
public function getFilterCriteria($filter): CriteriaCompo |
|
42
|
|
|
{ |
|
43
|
|
|
$parts = \explode('|', $filter); |
|
44
|
|
|
$criteria = new CriteriaCompo(); |
|
45
|
|
|
foreach ($parts as $part) { |
|
46
|
|
|
$var = \explode(',', $part); |
|
47
|
|
|
if (!empty($var[1]) && !\is_numeric($var[0])) { |
|
48
|
|
|
$object = $this->create(); |
|
49
|
|
|
if (\XOBJ_DTYPE_TXTBOX == $object->vars[$var[0]]['data_type'] |
|
50
|
|
|
|| \XOBJ_DTYPE_TXTAREA == $object->vars[$var[0]]['data_type']) { |
|
51
|
|
|
$criteria->add(new Criteria('`' . $var[0] . '`', '%' . $var[1] . '%', ($var[2] ?? 'LIKE'))); |
|
52
|
|
|
} elseif (in_array($object->vars[$var[0]]['data_type'], [XOBJ_DTYPE_INT, XOBJ_DTYPE_DECIMAL, XOBJ_DTYPE_FLOAT])) { |
|
53
|
|
|
$criteria->add(new Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '='))); |
|
54
|
|
|
} elseif (\XOBJ_DTYPE_ENUM == $object->vars[$var[0]]['data_type']) { |
|
55
|
|
|
$criteria->add(new Criteria('`' . $var[0] . '`', $var[1], ($var[2] ?? '='))); |
|
56
|
|
|
} elseif (\XOBJ_DTYPE_ARRAY == $object->vars[$var[0]]['data_type']) { |
|
57
|
|
|
$criteria->add(new Criteria('`' . $var[0] . '`', '%"' . $var[1] . '";%', ($var[2] ?? 'LIKE'))); |
|
58
|
|
|
} |
|
59
|
|
|
} elseif (!empty($var[1]) && \is_numeric($var[0])) { |
|
60
|
|
|
$criteria->add(new Criteria($var[0], $var[1])); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
return $criteria; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param $filter |
|
69
|
|
|
* @param $field |
|
70
|
|
|
* @param string $sort |
|
71
|
|
|
* @param string $op |
|
72
|
|
|
* @param string $fct |
|
73
|
|
|
* @return string |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getFilterForm($filter, $field, $sort = 'created', $op = 'dashboard', $fct = 'list'): string |
|
76
|
|
|
{ |
|
77
|
|
|
$ele = Utility::getFilterElement($filter, $field, $sort, $op, $fct); |
|
78
|
|
|
if (\is_object($ele)) { |
|
79
|
|
|
return $ele->render(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return ' '; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param bool $force |
|
87
|
|
|
* @return mixed |
|
88
|
|
|
*/ |
|
89
|
|
|
public function insert(XoopsObject $obj, $force = true) |
|
90
|
|
|
{ |
|
91
|
|
|
if ($obj->isNew()) { |
|
92
|
|
|
$obj->setVar('created', \time()); |
|
93
|
|
|
} else { |
|
94
|
|
|
$obj->setVar('updated', \time()); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
return parent::insert($obj, $force); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @param string $phrase |
|
102
|
|
|
* @param null $criteria |
|
|
|
|
|
|
103
|
|
|
* @return string|string[] |
|
104
|
|
|
*/ |
|
105
|
|
|
public function convert($phrase = '', $criteria = null) |
|
106
|
|
|
{ |
|
107
|
|
|
foreach ($this->getObjects($criteria, true) as $utfid => $utf8) { |
|
108
|
|
|
$phrase = \str_replace(mb_strtolower($utf8->getVar('from')), \mb_strtolower($utf8->getVar('to')), $phrase); |
|
109
|
|
|
$phrase = \str_replace(mb_strtoupper($utf8->getVar('from')), \mb_strtoupper($utf8->getVar('to')), $phrase); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
return $phrase; |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|