| 1 | 
           efrain | 
           1 | 
           <?php
  | 
        
        
            | 
            | 
           2 | 
           declare(strict_types=1);
  | 
        
        
            | 
            | 
           3 | 
              | 
        
        
            | 
            | 
           4 | 
           namespace LeadersLinked\Mapper;
  | 
        
        
            | 
            | 
           5 | 
              | 
        
        
            | 
            | 
           6 | 
           use LeadersLinked\Mapper\Common\MapperCommon;
  | 
        
        
            | 
            | 
           7 | 
           use Laminas\Db\Adapter\AdapterInterface;
  | 
        
        
            | 
            | 
           8 | 
           use LeadersLinked\Model\RecruitmentSelectionCandidate;
  | 
        
        
            | 
            | 
           9 | 
           use LeadersLinked\Hydrator\ObjectPropertyHydrator;
  | 
        
        
            | 
            | 
           10 | 
           use Laminas\Paginator\Paginator;
  | 
        
        
            | 
            | 
           11 | 
           use Laminas\Db\ResultSet\HydratingResultSet;
  | 
        
        
            | 
            | 
           12 | 
           use Laminas\Paginator\Adapter\DbSelect;
  | 
        
        
            | 
            | 
           13 | 
              | 
        
        
            | 
            | 
           14 | 
              | 
        
        
            | 
            | 
           15 | 
           class RecruitmentSelectionCandidateMapper extends MapperCommon
  | 
        
        
            | 
            | 
           16 | 
           {
  | 
        
        
            | 
            | 
           17 | 
               const _TABLE = 'tbl_recruitment_selection_candidates';
  | 
        
        
            | 
            | 
           18 | 
              | 
        
        
            | 
            | 
           19 | 
               /**
  | 
        
        
            | 
            | 
           20 | 
                *
  | 
        
        
            | 
            | 
           21 | 
                * @var RecruitmentSelectionCandidateMapper
  | 
        
        
            | 
            | 
           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 RecruitmentSelectionCandidateMapper
  | 
        
        
            | 
            | 
           38 | 
                */
  | 
        
        
            | 
            | 
           39 | 
               public static function getInstance($adapter)
  | 
        
        
            | 
            | 
           40 | 
               {
  | 
        
        
            | 
            | 
           41 | 
                   if(self::$_instance == null) {
  | 
        
        
            | 
            | 
           42 | 
                       self::$_instance = new RecruitmentSelectionCandidateMapper($adapter);
  | 
        
        
            | 
            | 
           43 | 
                   }
  | 
        
        
            | 
            | 
           44 | 
                   return self::$_instance;
  | 
        
        
            | 
            | 
           45 | 
               }
  | 
        
        
            | 
            | 
           46 | 
              | 
        
        
            | 
            | 
           47 | 
               /**
  | 
        
        
            | 
            | 
           48 | 
                *
  | 
        
        
            | 
            | 
           49 | 
                * @param int $id
  | 
        
        
            | 
            | 
           50 | 
                * @return RecruitmentSelectionCandidate
  | 
        
        
            | 
            | 
           51 | 
                */
  | 
        
        
            | 
            | 
           52 | 
               public function fetchOne($id)
  | 
        
        
            | 
            | 
           53 | 
               {
  | 
        
        
            | 
            | 
           54 | 
                   $prototype = new RecruitmentSelectionCandidate();
  | 
        
        
            | 
            | 
           55 | 
              | 
        
        
            | 
            | 
           56 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           57 | 
                   $select->where->equalTo('id', $id);
  | 
        
        
            | 
            | 
           58 | 
              | 
        
        
            | 
            | 
           59 | 
                   return $this->executeFetchOneObject($select, $prototype);
  | 
        
        
            | 
            | 
           60 | 
               }
  | 
        
        
            | 
            | 
           61 | 
              | 
        
        
            | 
            | 
           62 | 
              | 
        
        
            | 
            | 
           63 | 
               /**
  | 
        
        
            | 
            | 
           64 | 
                *
  | 
        
        
            | 
            | 
           65 | 
                * @param string $uuid
  | 
        
        
            | 
            | 
           66 | 
                * @return RecruitmentSelectionCandidate
  | 
        
        
            | 
            | 
           67 | 
                */
  | 
        
        
            | 
            | 
           68 | 
               public function fetchOneByUuid($uuid)
  | 
        
        
            | 
            | 
           69 | 
               {
  | 
        
        
            | 
            | 
           70 | 
                   $prototype = new RecruitmentSelectionCandidate();
  | 
        
        
            | 
            | 
           71 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           72 | 
                   $select->where->equalTo('uuid', $uuid);
  | 
        
        
            | 
            | 
           73 | 
              | 
        
        
            | 
            | 
           74 | 
                   return $this->executeFetchOneObject($select, $prototype);
  | 
        
        
            | 
            | 
           75 | 
               }
  | 
        
        
            | 
            | 
           76 | 
              | 
        
        
            | 
            | 
           77 | 
              | 
        
        
            | 
            | 
           78 | 
               /**
  | 
        
        
            | 
            | 
           79 | 
                *
  | 
        
        
            | 
            | 
           80 | 
                * @param string $email
  | 
        
        
            | 
            | 
           81 | 
                * @return RecruitmentSelectionCandidate
  | 
        
        
            | 
            | 
           82 | 
                */
  | 
        
        
            | 
            | 
           83 | 
               public function fetchOneByEmail($email)
  | 
        
        
            | 
            | 
           84 | 
               {
  | 
        
        
            | 
            | 
           85 | 
                   $prototype = new RecruitmentSelectionCandidate();
  | 
        
        
            | 
            | 
           86 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           87 | 
                   $select->where->equalTo('email', $email);
  | 
        
        
            | 
            | 
           88 | 
              | 
        
        
            | 
            | 
           89 | 
                   return $this->executeFetchOneObject($select, $prototype);
  | 
        
        
            | 
            | 
           90 | 
               }
  | 
        
        
            | 
            | 
           91 | 
              | 
        
        
            | 
            | 
           92 | 
               /**
  | 
        
        
            | 
            | 
           93 | 
                *
  | 
        
        
            | 
            | 
           94 | 
                * @param string $email
  | 
        
        
            | 
            | 
           95 | 
                * @param int $company_id
  | 
        
        
            | 
            | 
           96 | 
                * @return RecruitmentSelectionCandidate
  | 
        
        
            | 
            | 
           97 | 
                */
  | 
        
        
            | 
            | 
           98 | 
               public function fetchOneActiveByEmailAndCompanyId($email, $company_id)
  | 
        
        
            | 
            | 
           99 | 
               {
  | 
        
        
            | 
            | 
           100 | 
                   $prototype = new RecruitmentSelectionCandidate();
  | 
        
        
            | 
            | 
           101 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           102 | 
                   $select->where->equalTo('email', $email);
  | 
        
        
            | 
            | 
           103 | 
                   $select->where->equalTo('company_id', $company_id);
  | 
        
        
            | 
            | 
           104 | 
              | 
        
        
            | 
            | 
           105 | 
                   //echo $select->getSqlString($this->adapter->platform); exit;
  | 
        
        
            | 
            | 
           106 | 
              | 
        
        
            | 
            | 
           107 | 
                   return $this->executeFetchOneObject($select, $prototype);
  | 
        
        
            | 
            | 
           108 | 
               }
  | 
        
        
            | 
            | 
           109 | 
              | 
        
        
            | 
            | 
           110 | 
               /**
  | 
        
        
            | 
            | 
           111 | 
                *
  | 
        
        
            | 
            | 
           112 | 
                * @param int $company_id
  | 
        
        
            | 
            | 
           113 | 
                * @return RecruitmentSelectionCandidate
  | 
        
        
            | 
            | 
           114 | 
                */
  | 
        
        
            | 
            | 
           115 | 
               public function fetchAllByCompanyId($company_id)
  | 
        
        
            | 
            | 
           116 | 
               {
  | 
        
        
            | 
            | 
           117 | 
                   $prototype = new RecruitmentSelectionCandidate();
  | 
        
        
            | 
            | 
           118 | 
              | 
        
        
            | 
            | 
           119 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           120 | 
                   $select->where->equalTo('company_id', $company_id);
  | 
        
        
            | 
            | 
           121 | 
                   $select->order('first_name');
  | 
        
        
            | 
            | 
           122 | 
              | 
        
        
            | 
            | 
           123 | 
                   return $this->executeFetchAllObject($select, $prototype);
  | 
        
        
            | 
            | 
           124 | 
               }
  | 
        
        
            | 
            | 
           125 | 
              | 
        
        
            | 
            | 
           126 | 
              | 
        
        
            | 
            | 
           127 | 
              | 
        
        
            | 
            | 
           128 | 
              | 
        
        
            | 
            | 
           129 | 
               /**
  | 
        
        
            | 
            | 
           130 | 
                *
  | 
        
        
            | 
            | 
           131 | 
                * @param RecruitmentSelectionCandidate $record
  | 
        
        
            | 
            | 
           132 | 
                * @return boolean
  | 
        
        
            | 
            | 
           133 | 
                */
  | 
        
        
            | 
            | 
           134 | 
               public function insert($record)
  | 
        
        
            | 
            | 
           135 | 
               {
  | 
        
        
            | 
            | 
           136 | 
                   $hydrator = new ObjectPropertyHydrator();
  | 
        
        
            | 
            | 
           137 | 
                   $values = $hydrator->extract($record);
  | 
        
        
            | 
            | 
           138 | 
                   $values = $this->removeEmpty($values);
  | 
        
        
            | 
            | 
           139 | 
              | 
        
        
            | 
            | 
           140 | 
                   $insert = $this->sql->insert(self::_TABLE);
  | 
        
        
            | 
            | 
           141 | 
                   $insert->values($values);
  | 
        
        
            | 
            | 
           142 | 
              | 
        
        
            | 
            | 
           143 | 
                   $result = $this->executeInsert($insert);
  | 
        
        
            | 
            | 
           144 | 
                   if($result) {
  | 
        
        
            | 
            | 
           145 | 
                       $record->id = $this->lastInsertId;
  | 
        
        
            | 
            | 
           146 | 
                   }
  | 
        
        
            | 
            | 
           147 | 
                   return $result;
  | 
        
        
            | 
            | 
           148 | 
               }
  | 
        
        
            | 
            | 
           149 | 
              | 
        
        
            | 
            | 
           150 | 
               /**
  | 
        
        
            | 
            | 
           151 | 
                *
  | 
        
        
            | 
            | 
           152 | 
                * @param RecruitmentSelectionCandidate $record
  | 
        
        
            | 
            | 
           153 | 
                * @return boolean
  | 
        
        
            | 
            | 
           154 | 
                */
  | 
        
        
            | 
            | 
           155 | 
               public function update($record)
  | 
        
        
            | 
            | 
           156 | 
               {
  | 
        
        
            | 
            | 
           157 | 
                   $hydrator = new ObjectPropertyHydrator();
  | 
        
        
            | 
            | 
           158 | 
                   $values = $hydrator->extract($record);
  | 
        
        
            | 
            | 
           159 | 
                   $values = $this->removeEmpty($values);
  | 
        
        
            | 
            | 
           160 | 
              | 
        
        
            | 
            | 
           161 | 
                   $update = $this->sql->update(self::_TABLE);
  | 
        
        
            | 
            | 
           162 | 
                   $update->set($values);
  | 
        
        
            | 
            | 
           163 | 
                   $update->where->equalTo('id', $record->id);
  | 
        
        
            | 
            | 
           164 | 
              | 
        
        
            | 
            | 
           165 | 
                   return $this->executeUpdate($update);
  | 
        
        
            | 
            | 
           166 | 
               }
  | 
        
        
            | 
            | 
           167 | 
              | 
        
        
            | 
            | 
           168 | 
               /**
  | 
        
        
            | 
            | 
           169 | 
                *
  | 
        
        
            | 
            | 
           170 | 
                * @param int $id
  | 
        
        
            | 
            | 
           171 | 
                * @return boolean
  | 
        
        
            | 
            | 
           172 | 
                */
  | 
        
        
            | 
            | 
           173 | 
               public function delete($id)
  | 
        
        
            | 
            | 
           174 | 
               {
  | 
        
        
            | 
            | 
           175 | 
                   $delete = $this->sql->delete(self::_TABLE);
  | 
        
        
            | 
            | 
           176 | 
                   $delete->where->equalTo('id', $id);
  | 
        
        
            | 
            | 
           177 | 
              | 
        
        
            | 
            | 
           178 | 
                   return $this->executeDelete($delete);
  | 
        
        
            | 
            | 
           179 | 
               }
  | 
        
        
            | 
            | 
           180 | 
              | 
        
        
            | 
            | 
           181 | 
              | 
        
        
            | 
            | 
           182 | 
               /**
  | 
        
        
            | 
            | 
           183 | 
                *
  | 
        
        
            | 
            | 
           184 | 
                * @param int $companyId
  | 
        
        
            | 
            | 
           185 | 
                * @param string $search
  | 
        
        
            | 
            | 
           186 | 
                * @param int $page
  | 
        
        
            | 
            | 
           187 | 
                * @param int $records_per_page
  | 
        
        
            | 
            | 
           188 | 
                * @param string $order_field
  | 
        
        
            | 
            | 
           189 | 
                * @param string $order_direction
  | 
        
        
            | 
            | 
           190 | 
                * @return Paginator
  | 
        
        
            | 
            | 
           191 | 
                */
  | 
        
        
            | 
            | 
           192 | 
               public function fetchAllDataTableByCompanyId($companyId, $search, $page = 1, $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
  | 
        
        
            | 
            | 
           193 | 
               {
  | 
        
        
            | 
            | 
           194 | 
                   $prototype = new RecruitmentSelectionCandidate();
  | 
        
        
            | 
            | 
           195 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           196 | 
                   $select->where->equalTo('company_id', $companyId);
  | 
        
        
            | 
            | 
           197 | 
              | 
        
        
            | 
            | 
           198 | 
                   if($search) {
  | 
        
        
            | 
            | 
           199 | 
                       $select->where->like('name', '%' . $search . '%');
  | 
        
        
            | 
            | 
           200 | 
                   }
  | 
        
        
            | 
            | 
           201 | 
                   $select->order($order_field . ' ' . $order_direction);
  | 
        
        
            | 
            | 
           202 | 
              | 
        
        
            | 
            | 
           203 | 
                   //echo $select->getSqlString($this->adapter->platform); exit;
  | 
        
        
            | 
            | 
           204 | 
              | 
        
        
            | 
            | 
           205 | 
                   $hydrator   = new ObjectPropertyHydrator();
  | 
        
        
            | 
            | 
           206 | 
                   $resultset  = new HydratingResultSet($hydrator, $prototype);
  | 
        
        
            | 
            | 
           207 | 
              | 
        
        
            | 
            | 
           208 | 
                   $adapter = new DbSelect($select, $this->sql, $resultset);
  | 
        
        
            | 
            | 
           209 | 
                   $paginator = new Paginator($adapter);
  | 
        
        
            | 
            | 
           210 | 
                   $paginator->setItemCountPerPage($records_per_page);
  | 
        
        
            | 
            | 
           211 | 
                   $paginator->setCurrentPageNumber($page);
  | 
        
        
            | 
            | 
           212 | 
              | 
        
        
            | 
            | 
           213 | 
              | 
        
        
            | 
            | 
           214 | 
                   return $paginator;
  | 
        
        
            | 
            | 
           215 | 
               }
  | 
        
        
            | 
            | 
           216 | 
              | 
        
        
            | 
            | 
           217 | 
              | 
        
        
            | 
            | 
           218 | 
           }
  |