|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Gewaer\CustomFields; |
|
5
|
|
|
use Exception; |
|
6
|
|
|
use Gewaer\Models\Modules; |
|
7
|
|
|
|
|
8
|
|
|
abstract class AbstractCustomFieldsModel extends \Baka\Database\ModelCustomFields |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Get all custom fields of the given object |
|
12
|
|
|
* |
|
13
|
|
|
* @param array $fields |
|
14
|
|
|
* @return \Phalcon\Mvc\Model |
|
15
|
|
|
*/ |
|
16
|
1 |
|
public function getAllCustomFields(array $fields = [], int $company_id = 0) |
|
|
|
|
|
|
17
|
|
|
{ |
|
18
|
|
|
//We does it only find names in plural? We need to fix this or make a workaroun |
|
19
|
1 |
|
if (!$models = Modules::findFirstByName($this->getSource())) { |
|
|
|
|
|
|
20
|
|
|
return; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
1 |
|
$conditions = []; |
|
|
|
|
|
|
24
|
1 |
|
$fieldsIn = null; |
|
25
|
|
|
|
|
26
|
1 |
|
if (!empty($fields)) { |
|
27
|
|
|
$fieldsIn = " and name in ('" . implode("','", $fields) . ')'; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
1 |
|
$conditions = 'modules_id = ? ' . $fieldsIn; |
|
31
|
|
|
|
|
32
|
1 |
|
$bind = [$this->getId(),$this->di->getApp()->getId(), $models->getId(), $this->di->getUserData()->default_company]; |
|
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
// $customFieldsValueTable = $this->getSource() . '_custom_fields'; |
|
36
|
1 |
|
$customFieldsValueTable = $this->getSource() . '_custom_fields'; |
|
37
|
|
|
|
|
38
|
|
|
//We are to make a new query to replace old gewaer implementation. |
|
39
|
1 |
|
$result = $this->getReadConnection()->prepare("SELECT l.{$this->getSource()}_id, |
|
|
|
|
|
|
40
|
|
|
c.id as field_id, |
|
41
|
|
|
c.name, |
|
42
|
|
|
l.value , |
|
43
|
|
|
c.users_id, |
|
44
|
|
|
l.created_at, |
|
45
|
|
|
l.updated_at |
|
46
|
1 |
|
FROM {$customFieldsValueTable} l, |
|
47
|
|
|
custom_fields c |
|
48
|
|
|
WHERE c.id = l.custom_fields_id |
|
49
|
1 |
|
AND l.{$this->getSource()}_id = ? |
|
50
|
|
|
AND c.apps_id = ? |
|
51
|
|
|
AND c.modules_id = ? |
|
52
|
|
|
AND c.companies_id = ? |
|
53
|
|
|
AND l.companies_id = c.companies_id"); |
|
54
|
|
|
|
|
55
|
1 |
|
$result->execute($bind); |
|
56
|
|
|
|
|
57
|
|
|
// $listOfCustomFields = $result->fetchAll(); |
|
58
|
|
|
$listOfCustomFields = []; |
|
59
|
|
|
|
|
60
|
|
|
while ($row = $result->fetch(\PDO::FETCH_OBJ)) { |
|
61
|
|
|
$listOfCustomFields[$row->name] = $row->value; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
return $listOfCustomFields; |
|
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Get all custom fields of the given model |
|
69
|
|
|
* |
|
70
|
|
|
* @param array $fields |
|
71
|
|
|
* @return \Phalcon\Mvc\Model |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getCustomFieldsByModel($modelName) |
|
74
|
|
|
{ |
|
75
|
|
|
if (!$module = Modules::findFirstByName($modelName)) { |
|
76
|
|
|
return; |
|
77
|
|
|
} |
|
78
|
|
|
$allFields = []; |
|
79
|
|
|
if ($fields = \Incursio\Models\CustomFields::findByModulesId($module->id)->toArray()) { |
|
|
|
|
|
|
80
|
|
|
foreach ($fields as $field) { |
|
81
|
|
|
array_push($allFields, $field['name']); |
|
82
|
|
|
} |
|
83
|
|
|
return $allFields; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.