| 16248 |
efrain |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
declare(strict_types=1);
|
|
|
4 |
|
|
|
5 |
namespace LeadersLinked\Form\KnowledgeArea;
|
|
|
6 |
|
|
|
7 |
use Laminas\Form\Form;
|
|
|
8 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
9 |
|
|
|
10 |
use LeadersLinked\Mapper\UserMapper;
|
|
|
11 |
use LeadersLinked\Model\KnowledgeAreaCategory;
|
|
|
12 |
use LeadersLinked\Model\KnowledgeAreaCategoryUser;
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
|
16 |
class KnowledgeAreaCategoryUserForm extends Form
|
|
|
17 |
{
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
*
|
|
|
21 |
* @param AdapterInterface $adapter
|
|
|
22 |
* @param int $company_id
|
|
|
23 |
* @param string $privacy
|
|
|
24 |
*/
|
|
|
25 |
public function __construct($adapter, $company_id, $privacy) {
|
|
|
26 |
parent::__construct();
|
|
|
27 |
$this->setInputFilter(new KnowledgeAreaCategoryUserFilter());
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
if($privacy == KnowledgeAreaCategory::PRIVACY_COMPANY) {
|
|
|
31 |
$roles = [
|
|
|
32 |
KnowledgeAreaCategoryUser::ROLE_USER => 'LABEL_USER',
|
|
|
33 |
KnowledgeAreaCategoryUser::ROLE_EDITOR => 'LABEL_EDITOR',
|
|
|
34 |
KnowledgeAreaCategoryUser::ROLE_ADMINISTRATOR => 'LABEL_ADMINISTRATOR',
|
|
|
35 |
];
|
|
|
36 |
} else {
|
|
|
37 |
$roles = [
|
|
|
38 |
KnowledgeAreaCategoryUser::ROLE_EDITOR => 'LABEL_EDITOR',
|
|
|
39 |
KnowledgeAreaCategoryUser::ROLE_ADMINISTRATOR => 'LABEL_ADMINISTRATOR',
|
|
|
40 |
];
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
$this->add([
|
|
|
48 |
'name' => 'user_id',
|
|
|
49 |
'type' => \Laminas\Form\Element\Select::class,
|
|
|
50 |
'attributes' => [
|
|
|
51 |
'id' => 'user_id',
|
|
|
52 |
],
|
|
|
53 |
'options' => [
|
|
|
54 |
//'disable_inarray_validator' => true,
|
|
|
55 |
'value_options' => $this->getUsers($adapter, $company_id)
|
|
|
56 |
]
|
|
|
57 |
]);
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
$this->add([
|
|
|
62 |
'name' => 'role',
|
|
|
63 |
'type' => \Laminas\Form\Element\Select::class,
|
|
|
64 |
'attributes' => [
|
|
|
65 |
'id' => 'role',
|
|
|
66 |
],
|
|
|
67 |
'options' => [
|
|
|
68 |
//'disable_inarray_validator' => true,
|
|
|
69 |
'value_options' => $roles
|
|
|
70 |
]
|
|
|
71 |
]);
|
|
|
72 |
|
|
|
73 |
|
|
|
74 |
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
private function getUsers($adapter, $company_id)
|
|
|
78 |
{
|
|
|
79 |
$items = [];
|
|
|
80 |
$userMapper = UserMapper::getInstance($adapter);
|
|
|
81 |
$records = $userMapper->fetchAllByCompanyId($company_id);
|
|
|
82 |
|
|
|
83 |
foreach($records as $record)
|
|
|
84 |
{
|
|
|
85 |
$items[ $record->uuid ] = $record->first_name . ' ' . $record->last_name . ' (' . $record->email . ')';
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
return $items;
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
|
|
|
92 |
}
|
|
|
93 |
|