17002 |
efrain |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
declare(strict_types=1);
|
|
|
4 |
|
|
|
5 |
namespace LeadersLinked\Form\Microlearning;
|
|
|
6 |
|
|
|
7 |
use Laminas\Form\Form;
|
|
|
8 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
9 |
use LeadersLinked\Mapper\MicrolearningTopicMapper;
|
|
|
10 |
use LeadersLinked\Mapper\MicrolearningCapsuleMapper;
|
|
|
11 |
use LeadersLinked\Mapper\QueryMapper;
|
|
|
12 |
use LeadersLinked\Mapper\MicrolearningCapsuleUserMapper;
|
|
|
13 |
use Laminas\Db\Sql\Expression;
|
|
|
14 |
use LeadersLinked\Mapper\UserMapper;
|
|
|
15 |
use LeadersLinked\Model\User;
|
|
|
16 |
|
|
|
17 |
class StudentReportForm extends Form
|
|
|
18 |
{
|
|
|
19 |
|
|
|
20 |
/**
|
|
|
21 |
*
|
|
|
22 |
* @param AdapterInterface $adapter
|
|
|
23 |
* @param int $company_id
|
|
|
24 |
*/
|
|
|
25 |
public function __construct($adapter, $company_id)
|
|
|
26 |
{
|
|
|
27 |
parent::__construct();
|
|
|
28 |
$this->setInputFilter(new StudentReportFilter($adapter));
|
|
|
29 |
|
|
|
30 |
$this->add([
|
|
|
31 |
'name' => 'student_uuid',
|
|
|
32 |
'type' => \Laminas\Form\Element\Select::class,
|
|
|
33 |
'attributes' => [
|
|
|
34 |
'id' => 'student_uuid',
|
|
|
35 |
],
|
|
|
36 |
'options' => [
|
|
|
37 |
'value_options' => $this->getSelectStudentOptions($adapter, $company_id)
|
|
|
38 |
]
|
|
|
39 |
]);
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
|
43 |
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
/**
|
|
|
47 |
*
|
|
|
48 |
* @param AdapterInterface $adapter
|
|
|
49 |
*/
|
|
|
50 |
private function getSelectStudentOptions($adapter, $company_id)
|
|
|
51 |
{
|
|
|
52 |
|
|
|
53 |
$user_ids = [];
|
|
|
54 |
$options = [];
|
|
|
55 |
|
|
|
56 |
$mapper = QueryMapper::getInstance($adapter);
|
|
|
57 |
$select = $mapper->getSql()->select();
|
|
|
58 |
$select->columns(['user_id' => new Expression('DISTINCT(user_id)')]);
|
|
|
59 |
$select->from(['tb1' => MicrolearningCapsuleUserMapper::_TABLE]);
|
|
|
60 |
$select->where->equalTo('company_id', $company_id);
|
|
|
61 |
|
|
|
62 |
$records = $mapper->fetchAll($select);
|
|
|
63 |
foreach($records as $record)
|
|
|
64 |
{
|
|
|
65 |
array_push($user_ids, $record['user_id']);
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
$mapper = QueryMapper::getInstance($adapter);
|
|
|
69 |
$select = $mapper->getSql()->select();
|
|
|
70 |
$select->columns(['uuid', 'first_name', 'last_name', 'email']);
|
|
|
71 |
$select->from(['tb1' => UserMapper::_TABLE]);
|
|
|
72 |
$select->where->in('id', $user_ids);
|
|
|
73 |
$select->where->equalTo('status', User::STATUS_ACTIVE);
|
|
|
74 |
$select->order('first_name ASC, last_name ASC');
|
|
|
75 |
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
$records = $mapper->fetchAll($select);
|
|
|
79 |
foreach($records as $record)
|
|
|
80 |
{
|
|
|
81 |
$options[ $record['uuid'] ] = ucwords(strtolower(trim($record['first_name'] . ' ' . $record['last_name']))) . ' (' . strtolower($record['email']) . ')';
|
|
|
82 |
}
|
|
|
83 |
return $options;
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
|
|
|
87 |
}
|