Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 7016 | Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
6749 efrain 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Mapper;
6
 
7
use LeadersLinked\Model\PlanningTask;
8
use LeadersLinked\Mapper\Common\MapperCommon;
9
use Laminas\Db\Adapter\AdapterInterface;
10
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
11
use Laminas\Db\ResultSet\HydratingResultSet;
12
use Laminas\Paginator\Adapter\DbSelect;
13
use Laminas\Paginator\Paginator;
14
use Laminas\Db\Adapter\Driver\ResultInterface;
15
 
16
 
17
class PlanningTaskMapper extends MapperCommon{
18
    const _TABLE = 'tbl_planning_tasks';
19
 
20
    /**
21
     *
22
     * @var PlanningTaskMapper
23
     */
24
    private static $_instance;
25
 
26
    /**
27
     *
28
     * @param AdapterInterface $adapter
29
     */
30
    private function __construct($adapter)
31
    {
32
        parent::__construct($adapter);
33
    }
34
 
35
    /**
36
     *
37
     * @param AdapterInterface $adapter
38
     * @return \LeadersLinked\Mapper\PlanningTaskMapper
39
     */
40
    public static function getInstance($adapter)
41
    {
42
        if(self::$_instance == null) {
43
            self::$_instance = new PlanningTaskMapper($adapter);
44
        }
45
        return self::$_instance;
46
    }
47
 
48
 
49
 
50
    public function fetchAllDataTable($search, $page = 1, $records_per_page = 10, $order_field= 'title', $order_direction = 'ASC', $goal_id)
51
    {
52
        $prototype = new PlanningTask();
53
        $select = $this->sql->select(self::_TABLE);
54
        $select->where->equalTo('goal_id', $goal_id);
55
        $select->where->notEqualTo('status', PlanningTask::STATUS_DELETE);
56
 
57
 
58
        if($search) {
59
            $select->where->like('title', '%' . $search . '%');
60
        }
61
        $select->order($order_field . ' ' . $order_direction);
62
 
63
 
64
 
65
        $hydrator   = new ObjectPropertyHydrator();
66
        $resultset  = new HydratingResultSet($hydrator, $prototype);
67
 
68
        $adapter = new DbSelect($select, $this->sql, $resultset);
69
        $paginator = new Paginator($adapter);
70
        $paginator->setItemCountPerPage($records_per_page);
71
        $paginator->setCurrentPageNumber($page);
72
 
73
 
74
        return $paginator;
75
    }
76
    public function fetchAll($goal_id)
77
    {
78
        $prototype = new PlanningTask();
79
        $select = $this->sql->select(self::_TABLE);
80
        $select->where->equalTo('goal_id', $goal_id)->equalTo('status', 'a');
81
        $select->where->notEqualTo('status', PlanningTask::STATUS_DELETE);
82
        return $this->executeFetchAllObject($select, $prototype);
83
 
84
    }
85
 
86
    public function insert($datos)
87
    {
88
        $hydrator = new ObjectPropertyHydrator();
89
        $values = $hydrator->extract($datos);
90
        $values = $this->removeEmpty($values);
91
        $insert = $this->sql->insert(self::_TABLE);
92
        $insert->values($values);
93
 
94
 
95
        $result = $this->executeInsert($insert);
96
        if($result) {
97
            $datos->id = $this->lastInsertId;
98
        }
99
 
100
        return $result;
101
 
102
    }
103
 
104
    public function update($form)
105
    {
106
        $hydrator = new ObjectPropertyHydrator();
107
        $values = $hydrator->extract($form);
108
        $values = $this->removeEmpty($values);
109
 
110
        $update = $this->sql->update(self::_TABLE);
111
        $update->set($values);
112
        $update->where->equalTo('id', $form->id);
113
        return $this->executeUpdate($update);
114
    }
115
 
116
    public function delete($form_id)
117
    {
118
        $delete = $this->sql->delete(self::_TABLE);
119
        $delete->where->equalTo('id', $form_id);
120
 
121
        return $this->executeDelete($delete);
122
    }
123
 
124
    public function fetchOneByUuid($uuid)
125
    {
126
        $prototype = new PlanningTask();
127
        $select = $this->sql->select(self::_TABLE);
128
        $select->where->equalTo('uuid', $uuid);
129
 
130
        return $this->executeFetchOneObject($select, $prototype);
131
    }
132
 
133
 
134
 
135
}