| 1714 | eleazar | 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\Model\RecruitmentSelectionVacancy;
 | 
        
           |  |  | 10 | use LeadersLinked\Model\RecruitmentSelectionInterview;
 | 
        
           |  |  | 11 | use LeadersLinked\Model\RecruitmentSelectionInterviewFile;
 | 
        
           |  |  | 12 | use LeadersLinked\Hydrator\ObjectPropertyHydrator;
 | 
        
           |  |  | 13 | use Laminas\Paginator\Paginator;
 | 
        
           |  |  | 14 | use Laminas\Db\ResultSet\HydratingResultSet;
 | 
        
           |  |  | 15 | use Laminas\Paginator\Adapter\DbSelect;
 | 
        
           |  |  | 16 |   | 
        
           |  |  | 17 |   | 
        
           |  |  | 18 | class RecruitmentSelectionInterviewFileMapper extends MapperCommon
 | 
        
           |  |  | 19 | {
 | 
        
           |  |  | 20 |     const _TABLE = 'tbl_recruitment_selection_candidate_interviews_file';
 | 
        
           |  |  | 21 |   | 
        
           |  |  | 22 |     /**
 | 
        
           |  |  | 23 |      *
 | 
        
           |  |  | 24 |      * @var RecruitmentInterviewMapper
 | 
        
           |  |  | 25 |      */
 | 
        
           |  |  | 26 |     private static $_instance;
 | 
        
           |  |  | 27 |   | 
        
           |  |  | 28 |     /**
 | 
        
           |  |  | 29 |      *
 | 
        
           |  |  | 30 |      * @param AdapterInterface $adapter
 | 
        
           |  |  | 31 |      */
 | 
        
           |  |  | 32 |     private function __construct($adapter)
 | 
        
           |  |  | 33 |     {
 | 
        
           |  |  | 34 |         parent::__construct($adapter);
 | 
        
           |  |  | 35 |     }
 | 
        
           |  |  | 36 |   | 
        
           |  |  | 37 |     /**
 | 
        
           |  |  | 38 |      *
 | 
        
           |  |  | 39 |      * @param AdapterInterface $adapter
 | 
        
           |  |  | 40 |      * @return RecruitmentSelectionInterviewFileMapper
 | 
        
           |  |  | 41 |      */
 | 
        
           |  |  | 42 |     public static function getInstance($adapter)
 | 
        
           |  |  | 43 |     {
 | 
        
           |  |  | 44 |         if(self::$_instance == null) {
 | 
        
           |  |  | 45 |             self::$_instance = new RecruitmentSelectionInterviewFileMapper($adapter);
 | 
        
           |  |  | 46 |         }
 | 
        
           |  |  | 47 |         return self::$_instance;
 | 
        
           |  |  | 48 |     }
 | 
        
           |  |  | 49 |   | 
        
           |  |  | 50 |     /**
 | 
        
           |  |  | 51 |      *
 | 
        
           |  |  | 52 |      * @param int $id
 | 
        
           |  |  | 53 |      * @return RecruitmentSelectionInterviewFile
 | 
        
           |  |  | 54 |      */
 | 
        
           |  |  | 55 |     public function fetchOne($id)
 | 
        
           |  |  | 56 |     {
 | 
        
           |  |  | 57 |         $prototype = new RecruitmentSelectionInterviewFile();
 | 
        
           |  |  | 58 |   | 
        
           |  |  | 59 |         $select = $this->sql->select(self::_TABLE);
 | 
        
           |  |  | 60 |         $select->where->equalTo('id', $id);
 | 
        
           |  |  | 61 |   | 
        
           |  |  | 62 |         return $this->executeFetchOneObject($select, $prototype);
 | 
        
           |  |  | 63 |     }
 | 
        
           |  |  | 64 |   | 
        
           |  |  | 65 |   | 
        
           |  |  | 66 |     /**
 | 
        
           |  |  | 67 |      *
 | 
        
           |  |  | 68 |      * @param int $uuid
 | 
        
           |  |  | 69 |      * @return RecruitmentSelectionInterviewFile
 | 
        
           |  |  | 70 |      */
 | 
        
           |  |  | 71 |     public function fetchOneByUuid($uuid)
 | 
        
           |  |  | 72 |     {
 | 
        
           |  |  | 73 |         $prototype = new RecruitmentSelectionInterviewFile();
 | 
        
           |  |  | 74 |         $select = $this->sql->select(self::_TABLE);
 | 
        
           |  |  | 75 |         $select->where->equalTo('uuid', $uuid);
 | 
        
           |  |  | 76 |   | 
        
           |  |  | 77 |         return $this->executeFetchOneObject($select, $prototype);
 | 
        
           |  |  | 78 |     }
 | 
        
           |  |  | 79 |   | 
        
           |  |  | 80 |   | 
        
           |  |  | 81 |     /**
 | 
        
           |  |  | 82 |      *
 | 
        
           |  |  | 83 |      * @param int $company_id
 | 
        
           |  |  | 84 |      * @return RecruitmentSelectionInterviewFile
 | 
        
           |  |  | 85 |      */
 | 
        
           |  |  | 86 |     public function fetchAllByCompanyId($company_id)
 | 
        
           |  |  | 87 |     {
 | 
        
           |  |  | 88 |         $prototype = new RecruitmentSelectionInterviewFile();
 | 
        
           |  |  | 89 |   | 
        
           |  |  | 90 |         $select = $this->sql->select(self::_TABLE);
 | 
        
           |  |  | 91 |         $select->where->equalTo('company_id', $company_id);
 | 
        
           |  |  | 92 |         $select->order('name');
 | 
        
           |  |  | 93 |   | 
        
           |  |  | 94 |         return $this->executeFetchAllObject($select, $prototype);
 | 
        
           |  |  | 95 |     }
 | 
        
           |  |  | 96 |   | 
        
           |  |  | 97 |      /**
 | 
        
           |  |  | 98 |      *
 | 
        
           |  |  | 99 |      * @param int $candidate_id
 | 
        
           |  |  | 100 |      * @return RecruitmentSelectionInterviewFile
 | 
        
           |  |  | 101 |      */
 | 
        
           |  |  | 102 |     public function fetchAllByVacancyId($vacancy_id)
 | 
        
           |  |  | 103 |     {
 | 
        
           |  |  | 104 |         $prototype = new RecruitmentSelectionInterviewFile();
 | 
        
           |  |  | 105 |   | 
        
           |  |  | 106 |         $select = $this->sql->select(self::_TABLE);
 | 
        
           |  |  | 107 |         $select->where->equalTo('vacancy_id', $vacancy_id);
 | 
        
           |  |  | 108 |         $select->order('first_name');
 | 
        
           |  |  | 109 |   | 
        
           |  |  | 110 |         return $this->executeFetchAllObject($select, $prototype);
 | 
        
           |  |  | 111 |     }
 | 
        
           |  |  | 112 |   | 
        
           |  |  | 113 |      /**
 | 
        
           |  |  | 114 |      *
 | 
        
           |  |  | 115 |      * @param int $company_id
 | 
        
           |  |  | 116 |      * @return RecruitmentSelectionInterviewFile
 | 
        
           |  |  | 117 |      */
 | 
        
           |  |  | 118 |     public function fetchOneByCompanyId($company_id)
 | 
        
           |  |  | 119 |     {
 | 
        
           |  |  | 120 |         $prototype = new RecruitmentSelectionInterviewFile();
 | 
        
           |  |  | 121 |   | 
        
           |  |  | 122 |         $select = $this->sql->select(self::_TABLE);
 | 
        
           |  |  | 123 |         $select->where->equalTo('company_id', $company_id);
 | 
        
           |  |  | 124 |         $select->order('name');
 | 
        
           |  |  | 125 |   | 
        
           |  |  | 126 |         return $this->executeFetchOneObject($select, $prototype);
 | 
        
           |  |  | 127 |     }
 | 
        
           |  |  | 128 |   | 
        
           |  |  | 129 |      /**
 | 
        
           |  |  | 130 |      *
 | 
        
           |  |  | 131 |      * @param int $company_id
 | 
        
           |  |  | 132 |      * @param int $topic_id
 | 
        
           |  |  | 133 |      * @return RecruitmentSelectionVacancy[]
 | 
        
           |  |  | 134 |      */
 | 
        
           |  |  | 135 |     public function fetchAllByCompanyIdAndVacancyId($company_id, $vancacy_id)
 | 
        
           |  |  | 136 |     {
 | 
        
           |  |  | 137 |         $prototype = new RecruitmentSelectionVacancy();
 | 
        
           |  |  | 138 |   | 
        
           |  |  | 139 |         $select = $this->sql->select(self::_TABLE);
 | 
        
           |  |  | 140 |         $select->where->equalTo('company_id', $company_id);
 | 
        
           |  |  | 141 |         $select->where->equalTo('vacancy_id', $vacancy_id);
 | 
        
           |  |  | 142 |         $select->order(['name']);
 | 
        
           |  |  | 143 |   | 
        
           |  |  | 144 |         //echo $select->getSqlString($this->adapter->platform); exit;
 | 
        
           |  |  | 145 |   | 
        
           |  |  | 146 |         return $this->executeFetchAllObject($select, $prototype);
 | 
        
           |  |  | 147 |     }
 | 
        
           |  |  | 148 |   | 
        
           |  |  | 149 |     /**
 | 
        
           |  |  | 150 |      * @param int $vacancy_id
 | 
        
           |  |  | 151 |      * @param int $candidate_id
 | 
        
           |  |  | 152 |      * @return RecruitmentSelectionInterviewFile
 | 
        
           |  |  | 153 |      */
 | 
        
           |  |  | 154 |     public function fetchOneByCandidateIdAndVacancyId($candidate_id, $vacancy_id)
 | 
        
           |  |  | 155 |     {
 | 
        
           |  |  | 156 |         $prototype = new RecruitmentSelectionInterviewFile();
 | 
        
           |  |  | 157 |   | 
        
           |  |  | 158 |         $select = $this->sql->select(self::_TABLE);
 | 
        
           |  |  | 159 |         $select->where->equalTo('candidate_id', $candidate_id);
 | 
        
           |  |  | 160 |         $select->where->equalTo('vacancy_id', $vacancy_id);
 | 
        
           |  |  | 161 |         $select->order(['uuid']);
 | 
        
           |  |  | 162 |   | 
        
           |  |  | 163 |         return $this->executeFetchOneObject($select, $prototype);
 | 
        
           |  |  | 164 |     }
 | 
        
           |  |  | 165 |   | 
        
           |  |  | 166 |     /**
 | 
        
           |  |  | 167 |      *
 | 
        
           |  |  | 168 |      * @param RecruitmentSelectionInterviewFile $form
 | 
        
           |  |  | 169 |      * @return boolean
 | 
        
           |  |  | 170 |      */
 | 
        
           |  |  | 171 |     public function insert($form)
 | 
        
           |  |  | 172 |     {
 | 
        
           |  |  | 173 |         $hydrator = new ObjectPropertyHydrator();
 | 
        
           |  |  | 174 |         $values = $hydrator->extract($form);
 | 
        
           |  |  | 175 |         $values = $this->removeEmpty($values);
 | 
        
           |  |  | 176 |   | 
        
           |  |  | 177 |         $insert = $this->sql->insert(self::_TABLE);
 | 
        
           |  |  | 178 |         $insert->values($values);
 | 
        
           |  |  | 179 |   | 
        
           | 1744 | eleazar | 180 |        // echo $insert->getSqlString($this->adapter->platform); exit;
 | 
        
           | 1714 | eleazar | 181 |   | 
        
           |  |  | 182 |         $result = $this->executeInsert($insert);
 | 
        
           |  |  | 183 |         if($result) {
 | 
        
           |  |  | 184 |             $form->id = $this->lastInsertId;
 | 
        
           |  |  | 185 |         }
 | 
        
           |  |  | 186 |         return $result;
 | 
        
           |  |  | 187 |     }
 | 
        
           |  |  | 188 |   | 
        
           |  |  | 189 |     /**
 | 
        
           |  |  | 190 |      *
 | 
        
           |  |  | 191 |      * @param RecruitmentInterview $form
 | 
        
           |  |  | 192 |      * @return boolean
 | 
        
           |  |  | 193 |      */
 | 
        
           |  |  | 194 |     public function update($form)
 | 
        
           |  |  | 195 |     {
 | 
        
           |  |  | 196 |         $hydrator = new ObjectPropertyHydrator();
 | 
        
           |  |  | 197 |         $values = $hydrator->extract($form);
 | 
        
           |  |  | 198 |         $values = $this->removeEmpty($values);
 | 
        
           |  |  | 199 |   | 
        
           |  |  | 200 |         $update = $this->sql->update(self::_TABLE);
 | 
        
           |  |  | 201 |         $update->set($values);
 | 
        
           |  |  | 202 |         $update->where->equalTo('id', $form->id);
 | 
        
           |  |  | 203 |   | 
        
           |  |  | 204 |         return $this->executeUpdate($update);
 | 
        
           |  |  | 205 |     }
 | 
        
           |  |  | 206 |   | 
        
           |  |  | 207 |     /**
 | 
        
           |  |  | 208 |      *
 | 
        
           |  |  | 209 |      * @param int $form_id
 | 
        
           |  |  | 210 |      * @return boolean
 | 
        
           |  |  | 211 |      */
 | 
        
           |  |  | 212 |     public function delete($form_id)
 | 
        
           |  |  | 213 |     {
 | 
        
           |  |  | 214 |         $delete = $this->sql->delete(self::_TABLE);
 | 
        
           |  |  | 215 |         $delete->where->equalTo('id', $form_id);
 | 
        
           |  |  | 216 |   | 
        
           |  |  | 217 |         return $this->executeDelete($delete);
 | 
        
           |  |  | 218 |     }
 | 
        
           |  |  | 219 |   | 
        
           |  |  | 220 |   | 
        
           |  |  | 221 |     /**
 | 
        
           |  |  | 222 |      *
 | 
        
           | 1746 | eleazar | 223 |      * @param int $interviewId
 | 
        
           | 1714 | eleazar | 224 |      * @param string $search
 | 
        
           |  |  | 225 |      * @param int $page
 | 
        
           |  |  | 226 |      * @param int $records_per_page
 | 
        
           |  |  | 227 |      * @param string $order_field
 | 
        
           |  |  | 228 |      * @param string $order_direction
 | 
        
           |  |  | 229 |      * @return Paginator
 | 
        
           |  |  | 230 |      */
 | 
        
           | 1746 | eleazar | 231 |     public function fetchAllDataTableByInterviewId($interviewId, $search, $page = 1, $records_per_page = 10, $order_field= 'title', $order_direction = 'ASC')
 | 
        
           | 1714 | eleazar | 232 |     {
 | 
        
           | 1745 | eleazar | 233 |         $prototype = new RecruitmentSelectionInterviewFile();
 | 
        
           | 1714 | eleazar | 234 |         $select = $this->sql->select(self::_TABLE);
 | 
        
           | 1729 | eleazar | 235 |         $select->where->equalTo('interview_id', $interviewId);
 | 
        
           | 1714 | eleazar | 236 |   | 
        
           |  |  | 237 |         if($search) {
 | 
        
           | 1738 | eleazar | 238 |             $select->where->like('title', '%' . $search . '%');
 | 
        
           | 1714 | eleazar | 239 |         }
 | 
        
           |  |  | 240 |         $select->order($order_field . ' ' . $order_direction);
 | 
        
           |  |  | 241 |   | 
        
           | 1747 | eleazar | 242 |         //echo $select->getSqlString($this->adapter->platform); exit;
 | 
        
           | 1714 | eleazar | 243 |   | 
        
           |  |  | 244 |         $hydrator   = new ObjectPropertyHydrator();
 | 
        
           |  |  | 245 |         $resultset  = new HydratingResultSet($hydrator, $prototype);
 | 
        
           |  |  | 246 |   | 
        
           |  |  | 247 |         $adapter = new DbSelect($select, $this->sql, $resultset);
 | 
        
           |  |  | 248 |         $paginator = new Paginator($adapter);
 | 
        
           |  |  | 249 |         $paginator->setItemCountPerPage($records_per_page);
 | 
        
           |  |  | 250 |         $paginator->setCurrentPageNumber($page);
 | 
        
           |  |  | 251 |   | 
        
           |  |  | 252 |   | 
        
           |  |  | 253 |         return $paginator;
 | 
        
           |  |  | 254 |     }
 | 
        
           |  |  | 255 |   | 
        
           |  |  | 256 |   | 
        
           |  |  | 257 | }
 |