| 1050 | nelberth | 1 | <?php
 | 
        
           |  |  | 2 |   | 
        
           |  |  | 3 | declare(strict_types=1);
 | 
        
           |  |  | 4 |   | 
        
           |  |  | 5 | namespace LeadersLinked\Mapper;
 | 
        
           |  |  | 6 |   | 
        
           |  |  | 7 | use LeadersLinked\Model\PlanningObjectivesAndGoalsTask;
 | 
        
           |  |  | 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;
 | 
        
           | 1211 | nelberth | 14 | use Laminas\Db\Adapter\Driver\ResultInterface;
 | 
        
           | 1050 | nelberth | 15 |   | 
        
           |  |  | 16 |   | 
        
           |  |  | 17 | class PlanningObjectivesAndGoalsTaskMapper extends MapperCommon{
 | 
        
           | 1104 | nelberth | 18 |     const _TABLE = 'tbl_planning_objectives_and_goals_tasks';
 | 
        
           | 1050 | nelberth | 19 |   | 
        
           |  |  | 20 |     /**
 | 
        
           |  |  | 21 |      *
 | 
        
           |  |  | 22 |      * @var PlanningObjectivesAndGoalsTaskMapper
 | 
        
           |  |  | 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\PlanningObjectivesAndGoalsTaskMapper
 | 
        
           |  |  | 39 |      */
 | 
        
           |  |  | 40 |     public static function getInstance($adapter)
 | 
        
           |  |  | 41 |     {
 | 
        
           |  |  | 42 |         if(self::$_instance == null) {
 | 
        
           |  |  | 43 |             self::$_instance = new PlanningObjectivesAndGoalsTaskMapper($adapter);
 | 
        
           |  |  | 44 |         }
 | 
        
           |  |  | 45 |         return self::$_instance;
 | 
        
           |  |  | 46 |     }
 | 
        
           |  |  | 47 |   | 
        
           |  |  | 48 |   | 
        
           |  |  | 49 |   | 
        
           | 1445 | efrain | 50 |     public function fetchAllDataTable($search, $page = 1, $records_per_page = 10, $order_field= 'title', $order_direction = 'ASC', $goal_id)
 | 
        
           | 1050 | nelberth | 51 |     {
 | 
        
           |  |  | 52 |         $prototype = new PlanningObjectivesAndGoalsTask();
 | 
        
           |  |  | 53 |         $select = $this->sql->select(self::_TABLE);
 | 
        
           | 1445 | efrain | 54 |         $select->where->equalTo('goal_id', $goal_id);
 | 
        
           | 1050 | nelberth | 55 |         $select->where->notEqualTo('status', PlanningObjectivesAndGoalsTask::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 |     }
 | 
        
           | 1445 | efrain | 76 |     public function fetchAll($goal_id)
 | 
        
           | 1184 | nelberth | 77 |     {
 | 
        
           |  |  | 78 |         $prototype = new PlanningObjectivesAndGoalsTask();
 | 
        
           |  |  | 79 |         $select = $this->sql->select(self::_TABLE);
 | 
        
           | 1445 | efrain | 80 |         $select->where->equalTo('goal_id', $goal_id)->equalTo('status', 'a');
 | 
        
           | 1184 | nelberth | 81 |         $select->where->notEqualTo('status', PlanningObjectivesAndGoalsTask::STATUS_DELETE);
 | 
        
           | 1213 | nelberth | 82 |         return $this->executeFetchAllObject($select, $prototype);
 | 
        
           | 1184 | nelberth | 83 |   | 
        
           |  |  | 84 |     }
 | 
        
           | 1050 | nelberth | 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 PlanningObjectivesAndGoalsTask();
 | 
        
           |  |  | 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 | }
 |