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