| 1 | 
           efrain | 
           1 | 
           <?php
  | 
        
        
            | 
            | 
           2 | 
              | 
        
        
            | 
            | 
           3 | 
           declare(strict_types=1);
  | 
        
        
            | 
            | 
           4 | 
              | 
        
        
            | 
            | 
           5 | 
           namespace LeadersLinked\Mapper;
  | 
        
        
            | 
            | 
           6 | 
              | 
        
        
            | 
            | 
           7 | 
           use Laminas\Db\Adapter\AdapterInterface;
  | 
        
        
            | 
            | 
           8 | 
           use Laminas\Db\ResultSet\HydratingResultSet;
  | 
        
        
            | 
            | 
           9 | 
           use Laminas\Db\Sql\Expression;
  | 
        
        
            | 
            | 
           10 | 
           use LeadersLinked\Hydrator\ObjectPropertyHydrator;
  | 
        
        
            | 
            | 
           11 | 
           use Laminas\Log\LoggerInterface;
  | 
        
        
            | 
            | 
           12 | 
           use Laminas\Paginator\Paginator;
  | 
        
        
            | 
            | 
           13 | 
           use Laminas\Paginator\Adapter\DbSelect;
  | 
        
        
            | 
            | 
           14 | 
           use LeadersLinked\Model\JobDescription;
  | 
        
        
            | 
            | 
           15 | 
           use LeadersLinked\Mapper\Common\MapperCommon;
  | 
        
        
            | 
            | 
           16 | 
           use Laminas\Hydrator\ArraySerializableHydrator;
  | 
        
        
            | 
            | 
           17 | 
              | 
        
        
            | 
            | 
           18 | 
           class JobDescriptionMapper extends MapperCommon {
  | 
        
        
            | 
            | 
           19 | 
              | 
        
        
            | 
            | 
           20 | 
               const _TABLE = 'tbl_jobs_description';
  | 
        
        
            | 
            | 
           21 | 
              | 
        
        
            | 
            | 
           22 | 
               /**
  | 
        
        
            | 
            | 
           23 | 
                *
  | 
        
        
            | 
            | 
           24 | 
                * @var JobDescriptionMapper
  | 
        
        
            | 
            | 
           25 | 
                */
  | 
        
        
            | 
            | 
           26 | 
               private static $_instance;
  | 
        
        
            | 
            | 
           27 | 
              | 
        
        
            | 
            | 
           28 | 
               /**
  | 
        
        
            | 
            | 
           29 | 
                *
  | 
        
        
            | 
            | 
           30 | 
                * @param AdapterInterface $adapter
  | 
        
        
            | 
            | 
           31 | 
                */
  | 
        
        
            | 
            | 
           32 | 
               private function __construct($adapter) {
  | 
        
        
            | 
            | 
           33 | 
                   parent::__construct($adapter);
  | 
        
        
            | 
            | 
           34 | 
               }
  | 
        
        
            | 
            | 
           35 | 
              | 
        
        
            | 
            | 
           36 | 
               /**
  | 
        
        
            | 
            | 
           37 | 
                *
  | 
        
        
            | 
            | 
           38 | 
                * @param AdapterInterface $adapter
  | 
        
        
            | 
            | 
           39 | 
                * @return JobDescriptionMapper
  | 
        
        
            | 
            | 
           40 | 
                */
  | 
        
        
            | 
            | 
           41 | 
               public static function getInstance($adapter) {
  | 
        
        
            | 
            | 
           42 | 
                   if (self::$_instance == null) {
  | 
        
        
            | 
            | 
           43 | 
                       self::$_instance = new JobDescriptionMapper($adapter);
  | 
        
        
            | 
            | 
           44 | 
                   }
  | 
        
        
            | 
            | 
           45 | 
                   return self::$_instance;
  | 
        
        
            | 
            | 
           46 | 
               }
  | 
        
        
            | 
            | 
           47 | 
              | 
        
        
            | 
            | 
           48 | 
               /**
  | 
        
        
            | 
            | 
           49 | 
                *
  | 
        
        
            | 
            | 
           50 | 
                * @param int $id
  | 
        
        
            | 
            | 
           51 | 
                * @return JobDescription
  | 
        
        
            | 
            | 
           52 | 
                */
  | 
        
        
            | 
            | 
           53 | 
               public function fetchOne($id) {
  | 
        
        
            | 
            | 
           54 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           55 | 
                   $select->where->equalTo('id', $id);
  | 
        
        
            | 
            | 
           56 | 
                   $select->limit(1);
  | 
        
        
            | 
            | 
           57 | 
              | 
        
        
            | 
            | 
           58 | 
                   $prototype = new JobDescription();
  | 
        
        
            | 
            | 
           59 | 
                   return $this->executeFetchOneObject($select, $prototype);
  | 
        
        
            | 
            | 
           60 | 
               }
  | 
        
        
            | 
            | 
           61 | 
              | 
        
        
            | 
            | 
           62 | 
              | 
        
        
            | 
            | 
           63 | 
              | 
        
        
            | 
            | 
           64 | 
               /**
  | 
        
        
            | 
            | 
           65 | 
                *
  | 
        
        
            | 
            | 
           66 | 
                * @return JobDescription[]
  | 
        
        
            | 
            | 
           67 | 
                */
  | 
        
        
            | 
            | 
           68 | 
               public function fetchAllByDefault() {
  | 
        
        
            | 
            | 
           69 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           70 | 
                   $select->where->isNull('company_id');
  | 
        
        
            | 
            | 
           71 | 
                   $select->order('name');
  | 
        
        
            | 
            | 
           72 | 
              | 
        
        
            | 
            | 
           73 | 
              | 
        
        
            | 
            | 
           74 | 
                   $prototype = new JobDescription();
  | 
        
        
            | 
            | 
           75 | 
                   return $this->executeFetchAllObject($select, $prototype);
  | 
        
        
            | 
            | 
           76 | 
               }
  | 
        
        
            | 
            | 
           77 | 
              | 
        
        
            | 
            | 
           78 | 
               /**
  | 
        
        
            | 
            | 
           79 | 
                *
  | 
        
        
            | 
            | 
           80 | 
                * @return JobDescription[]
  | 
        
        
            | 
            | 
           81 | 
                */
  | 
        
        
            | 
            | 
           82 | 
               public function fetchAllActiveByDefault() {
  | 
        
        
            | 
            | 
           83 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           84 | 
                   $select->where->isNull('company_id');
  | 
        
        
            | 
            | 
           85 | 
                   $select->where->equalTo('status', JobDescription::STATUS_ACTIVE);
  | 
        
        
            | 
            | 
           86 | 
                   $select->order('name');
  | 
        
        
            | 
            | 
           87 | 
              | 
        
        
            | 
            | 
           88 | 
              | 
        
        
            | 
            | 
           89 | 
                   $prototype = new JobDescription();
  | 
        
        
            | 
            | 
           90 | 
                   return $this->executeFetchAllObject($select, $prototype);
  | 
        
        
            | 
            | 
           91 | 
               }
  | 
        
        
            | 
            | 
           92 | 
              | 
        
        
            | 
            | 
           93 | 
               /**
  | 
        
        
            | 
            | 
           94 | 
                *
  | 
        
        
            | 
            | 
           95 | 
                * @param string $uuid
  | 
        
        
            | 
            | 
           96 | 
                * @return JobDescription
  | 
        
        
            | 
            | 
           97 | 
                */
  | 
        
        
            | 
            | 
           98 | 
               public function fetchOneByUuid($uuid) {
  | 
        
        
            | 
            | 
           99 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           100 | 
                   $select->where->equalTo('uuid', $uuid);
  | 
        
        
            | 
            | 
           101 | 
                   $select->limit(1);
  | 
        
        
            | 
            | 
           102 | 
              | 
        
        
            | 
            | 
           103 | 
                   $prototype = new JobDescription();
  | 
        
        
            | 
            | 
           104 | 
                   return $this->executeFetchOneObject($select, $prototype);
  | 
        
        
            | 
            | 
           105 | 
               }
  | 
        
        
            | 
            | 
           106 | 
              | 
        
        
            | 
            | 
           107 | 
               /**
  | 
        
        
            | 
            | 
           108 | 
                *
  | 
        
        
            | 
            | 
           109 | 
                * @param int $company_id
  | 
        
        
            | 
            | 
           110 | 
                * @return JobDescription
  | 
        
        
            | 
            | 
           111 | 
                */
  | 
        
        
            | 
            | 
           112 | 
               public function fetchAllByCompanyId($company_id)
  | 
        
        
            | 
            | 
           113 | 
               {
  | 
        
        
            | 
            | 
           114 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           115 | 
                   $select->where->equalTo('company_id', $company_id);
  | 
        
        
            | 
            | 
           116 | 
                   $select->order('name');
  | 
        
        
            | 
            | 
           117 | 
              | 
        
        
            | 
            | 
           118 | 
                   $prototype = new JobDescription();
  | 
        
        
            | 
            | 
           119 | 
                   return $this->executeFetchAllObject($select, $prototype);
  | 
        
        
            | 
            | 
           120 | 
               }
  | 
        
        
            | 
            | 
           121 | 
              | 
        
        
            | 
            | 
           122 | 
              | 
        
        
            | 
            | 
           123 | 
              | 
        
        
            | 
            | 
           124 | 
               /**
  | 
        
        
            | 
            | 
           125 | 
                *
  | 
        
        
            | 
            | 
           126 | 
                * @param int $company_id
  | 
        
        
            | 
            | 
           127 | 
                * @param string $search
  | 
        
        
            | 
            | 
           128 | 
                * @return JobDescription
  | 
        
        
            | 
            | 
           129 | 
                */
  | 
        
        
            | 
            | 
           130 | 
               public function fetchAllByCompanyIdAndSearch($company_id, $search) {
  | 
        
        
            | 
            | 
           131 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           132 | 
                   $select->where->equalTo('company_id', $company_id);
  | 
        
        
            | 
            | 
           133 | 
                   $select->where->like('name', '%' . $search . '%');
  | 
        
        
            | 
            | 
           134 | 
                   $select->order('name');
  | 
        
        
            | 
            | 
           135 | 
              | 
        
        
            | 
            | 
           136 | 
                   $prototype = new JobDescription();
  | 
        
        
            | 
            | 
           137 | 
                   return $this->executeFetchAllObject($select, $prototype);
  | 
        
        
            | 
            | 
           138 | 
               }
  | 
        
        
            | 
            | 
           139 | 
              | 
        
        
            | 
            | 
           140 | 
              | 
        
        
            | 
            | 
           141 | 
               /**
  | 
        
        
            | 
            | 
           142 | 
                *
  | 
        
        
            | 
            | 
           143 | 
                * @param int $company_id
  | 
        
        
            | 
            | 
           144 | 
                * @return JobDescription
  | 
        
        
            | 
            | 
           145 | 
                */
  | 
        
        
            | 
            | 
           146 | 
               public function fetchAllActiveByCompanyId($company_id) {
  | 
        
        
            | 
            | 
           147 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           148 | 
                   $select->where->equalTo('company_id', $company_id);
  | 
        
        
            | 
            | 
           149 | 
                   $select->where->equalTo('status', JobDescription::STATUS_ACTIVE);
  | 
        
        
            | 
            | 
           150 | 
                   $select->order('name');
  | 
        
        
            | 
            | 
           151 | 
              | 
        
        
            | 
            | 
           152 | 
                   //echo $select->getSqlString($this->adapter->platform); exit;
  | 
        
        
            | 
            | 
           153 | 
              | 
        
        
            | 
            | 
           154 | 
                   $prototype = new JobDescription();
  | 
        
        
            | 
            | 
           155 | 
                   return $this->executeFetchAllObject($select, $prototype);
  | 
        
        
            | 
            | 
           156 | 
               }
  | 
        
        
            | 
            | 
           157 | 
              | 
        
        
            | 
            | 
           158 | 
               /**
  | 
        
        
            | 
            | 
           159 | 
                *
  | 
        
        
            | 
            | 
           160 | 
                * @param int $company_id
  | 
        
        
            | 
            | 
           161 | 
                * @param int $job_description_id_default
  | 
        
        
            | 
            | 
           162 | 
                * @return JobDescription
  | 
        
        
            | 
            | 
           163 | 
                */
  | 
        
        
            | 
            | 
           164 | 
               public function fetchOneByCompanyId($company_id, $job_description_id_default) {
  | 
        
        
            | 
            | 
           165 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           166 | 
                   $select->where->equalTo('company_id', $company_id);
  | 
        
        
            | 
            | 
           167 | 
                   $select->where->equalTo('job_description_id_default', $job_description_id_default);
  | 
        
        
            | 
            | 
           168 | 
                   $select->limit(1);
  | 
        
        
            | 
            | 
           169 | 
              | 
        
        
            | 
            | 
           170 | 
                   $prototype = new JobDescription();
  | 
        
        
            | 
            | 
           171 | 
                   return $this->executeFetchOneObject($select, $prototype);
  | 
        
        
            | 
            | 
           172 | 
               }
  | 
        
        
            | 
            | 
           173 | 
              | 
        
        
            | 
            | 
           174 | 
               /**
  | 
        
        
            | 
            | 
           175 | 
                *
  | 
        
        
            | 
            | 
           176 | 
                * @param int $company_id
  | 
        
        
            | 
            | 
           177 | 
                * @param int $id
  | 
        
        
            | 
            | 
           178 | 
                * @return JobDescription
  | 
        
        
            | 
            | 
           179 | 
                */
  | 
        
        
            | 
            | 
           180 | 
               public function fetchAllByCompanyIdWhereIdNotEqual($company_id, $id) {
  | 
        
        
            | 
            | 
           181 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           182 | 
                   $select->where->equalTo('company_id', $company_id);
  | 
        
        
            | 
            | 
           183 | 
                   $select->where->notEqualTo('id', $id);
  | 
        
        
            | 
            | 
           184 | 
                   $select->order('name');
  | 
        
        
            | 
            | 
           185 | 
              | 
        
        
            | 
            | 
           186 | 
                   $prototype = new JobDescription();
  | 
        
        
            | 
            | 
           187 | 
                   return $this->executeFetchAllObject($select, $prototype);
  | 
        
        
            | 
            | 
           188 | 
               }
  | 
        
        
            | 
            | 
           189 | 
              | 
        
        
            | 
            | 
           190 | 
               /**
  | 
        
        
            | 
            | 
           191 | 
                *
  | 
        
        
            | 
            | 
           192 | 
                * @param int $company_id
  | 
        
        
            | 
            | 
           193 | 
                * @param int $id
  | 
        
        
            | 
            | 
           194 | 
                * @return JobDescription
  | 
        
        
            | 
            | 
           195 | 
                */
  | 
        
        
            | 
            | 
           196 | 
               public function fetchAllActiveByCompanyIdWhereIdNotEqual($company_id, $id) {
  | 
        
        
            | 
            | 
           197 | 
              | 
        
        
            | 
            | 
           198 | 
              | 
        
        
            | 
            | 
           199 | 
              | 
        
        
            | 
            | 
           200 | 
              | 
        
        
            | 
            | 
           201 | 
              | 
        
        
            | 
            | 
           202 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           203 | 
                   $select->where->equalTo('company_id', $company_id);
  | 
        
        
            | 
            | 
           204 | 
                   $select->where->notEqualTo('id', $id);
  | 
        
        
            | 
            | 
           205 | 
                   $select->where->equalTo('status', JobDescription::STATUS_ACTIVE);
  | 
        
        
            | 
            | 
           206 | 
                   $select->order('name');
  | 
        
        
            | 
            | 
           207 | 
              | 
        
        
            | 
            | 
           208 | 
                   $prototype = new JobDescription();
  | 
        
        
            | 
            | 
           209 | 
                   return $this->executeFetchAllObject($select, $prototype);
  | 
        
        
            | 
            | 
           210 | 
               }
  | 
        
        
            | 
            | 
           211 | 
              | 
        
        
            | 
            | 
           212 | 
                /**
  | 
        
        
            | 
            | 
           213 | 
                *
  | 
        
        
            | 
            | 
           214 | 
                * @param string $search
  | 
        
        
            | 
            | 
           215 | 
                * @param int $page
  | 
        
        
            | 
            | 
           216 | 
                * @param int $records_per_page
  | 
        
        
            | 
            | 
           217 | 
                * @param string $order_field
  | 
        
        
            | 
            | 
           218 | 
                * @param string $order_direction
  | 
        
        
            | 
            | 
           219 | 
                * @return Paginator
  | 
        
        
            | 
            | 
           220 | 
                */
  | 
        
        
            | 
            | 
           221 | 
               public function fetchAllDataTable($search, $page = 1, $records_per_page = 10, $order_field = 'name', $order_direction = 'ASC') {
  | 
        
        
            | 
            | 
           222 | 
                   $prototype = new JobDescription();
  | 
        
        
            | 
            | 
           223 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           224 | 
                   $select->where->isNull('company_id');
  | 
        
        
            | 
            | 
           225 | 
              | 
        
        
            | 
            | 
           226 | 
                   if ($search) {
  | 
        
        
            | 
            | 
           227 | 
                       $select->where->like('name', '%' . $search . '%');
  | 
        
        
            | 
            | 
           228 | 
                   }
  | 
        
        
            | 
            | 
           229 | 
                   $select->order($order_field . ' ' . $order_direction);
  | 
        
        
            | 
            | 
           230 | 
              | 
        
        
            | 
            | 
           231 | 
                   $hydrator = new ObjectPropertyHydrator();
  | 
        
        
            | 
            | 
           232 | 
                   $resultset = new HydratingResultSet($hydrator, $prototype);
  | 
        
        
            | 
            | 
           233 | 
              | 
        
        
            | 
            | 
           234 | 
                   $adapter = new DbSelect($select, $this->sql, $resultset);
  | 
        
        
            | 
            | 
           235 | 
                   $paginator = new Paginator($adapter);
  | 
        
        
            | 
            | 
           236 | 
                   $paginator->setItemCountPerPage($records_per_page);
  | 
        
        
            | 
            | 
           237 | 
                   $paginator->setCurrentPageNumber($page);
  | 
        
        
            | 
            | 
           238 | 
              | 
        
        
            | 
            | 
           239 | 
              | 
        
        
            | 
            | 
           240 | 
                   return $paginator;
  | 
        
        
            | 
            | 
           241 | 
               }
  | 
        
        
            | 
            | 
           242 | 
              | 
        
        
            | 
            | 
           243 | 
               /**
  | 
        
        
            | 
            | 
           244 | 
                *
  | 
        
        
            | 
            | 
           245 | 
                * @param int $companyId
  | 
        
        
            | 
            | 
           246 | 
                * @param string $search
  | 
        
        
            | 
            | 
           247 | 
                * @param int $page
  | 
        
        
            | 
            | 
           248 | 
                * @param int $records_per_page
  | 
        
        
            | 
            | 
           249 | 
                * @param string $order_field
  | 
        
        
            | 
            | 
           250 | 
                * @param string $order_direction
  | 
        
        
            | 
            | 
           251 | 
                * @return Paginator
  | 
        
        
            | 
            | 
           252 | 
                */
  | 
        
        
            | 
            | 
           253 | 
               public function fetchAllDataTableByCompanyId($companyId, $search, $page = 1, $records_per_page = 10, $order_field = 'name', $order_direction = 'ASC') {
  | 
        
        
            | 
            | 
           254 | 
                   $prototype = new JobDescription();
  | 
        
        
            | 
            | 
           255 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           256 | 
                   $select->where->equalTo('company_id', $companyId);
  | 
        
        
            | 
            | 
           257 | 
              | 
        
        
            | 
            | 
           258 | 
                   if ($search) {
  | 
        
        
            | 
            | 
           259 | 
                       $select->where->like('name', '%' . $search . '%');
  | 
        
        
            | 
            | 
           260 | 
                   }
  | 
        
        
            | 
            | 
           261 | 
                   $select->order($order_field . ' ' . $order_direction);
  | 
        
        
            | 
            | 
           262 | 
              | 
        
        
            | 
            | 
           263 | 
                   //echo $select->getSqlString($this->adapter->platform); exit;
  | 
        
        
            | 
            | 
           264 | 
              | 
        
        
            | 
            | 
           265 | 
                   $hydrator = new ObjectPropertyHydrator();
  | 
        
        
            | 
            | 
           266 | 
                   $resultset = new HydratingResultSet($hydrator, $prototype);
  | 
        
        
            | 
            | 
           267 | 
              | 
        
        
            | 
            | 
           268 | 
                   $adapter = new DbSelect($select, $this->sql, $resultset);
  | 
        
        
            | 
            | 
           269 | 
                   $paginator = new Paginator($adapter);
  | 
        
        
            | 
            | 
           270 | 
                   $paginator->setItemCountPerPage($records_per_page);
  | 
        
        
            | 
            | 
           271 | 
                   $paginator->setCurrentPageNumber($page);
  | 
        
        
            | 
            | 
           272 | 
              | 
        
        
            | 
            | 
           273 | 
              | 
        
        
            | 
            | 
           274 | 
                   return $paginator;
  | 
        
        
            | 
            | 
           275 | 
               }
  | 
        
        
            | 
            | 
           276 | 
              | 
        
        
            | 
            | 
           277 | 
              | 
        
        
            | 
            | 
           278 | 
              | 
        
        
            | 
            | 
           279 | 
              | 
        
        
            | 
            | 
           280 | 
               /**
  | 
        
        
            | 
            | 
           281 | 
                *
  | 
        
        
            | 
            | 
           282 | 
                * @return JobDescription[]
  | 
        
        
            | 
            | 
           283 | 
                */
  | 
        
        
            | 
            | 
           284 | 
               public function fetchAllDefaultOrderByPositionName()
  | 
        
        
            | 
            | 
           285 | 
               {
  | 
        
        
            | 
            | 
           286 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           287 | 
                   $select->order('job_description_id_boss, position, name');
  | 
        
        
            | 
            | 
           288 | 
              | 
        
        
            | 
            | 
           289 | 
                   $prototype = new JobDescription();
  | 
        
        
            | 
            | 
           290 | 
                   return $this->executeFetchAllObject($select, $prototype);
  | 
        
        
            | 
            | 
           291 | 
               }
  | 
        
        
            | 
            | 
           292 | 
              | 
        
        
            | 
            | 
           293 | 
              | 
        
        
            | 
            | 
           294 | 
               /**
  | 
        
        
            | 
            | 
           295 | 
                *
  | 
        
        
            | 
            | 
           296 | 
                * @param int $companyId
  | 
        
        
            | 
            | 
           297 | 
                * @return JobDescription[]
  | 
        
        
            | 
            | 
           298 | 
                */
  | 
        
        
            | 
            | 
           299 | 
               public function fetchAllByCompanyIdOrderByPositionName($companyId)
  | 
        
        
            | 
            | 
           300 | 
               {
  | 
        
        
            | 
            | 
           301 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           302 | 
                   $select->where->equalTo('company_id', $companyId);
  | 
        
        
            | 
            | 
           303 | 
                   $select->order('job_description_id_boss, position, name');
  | 
        
        
            | 
            | 
           304 | 
              | 
        
        
            | 
            | 
           305 | 
              | 
        
        
            | 
            | 
           306 | 
                   $prototype = new JobDescription();
  | 
        
        
            | 
            | 
           307 | 
                   return $this->executeFetchAllObject($select, $prototype);
  | 
        
        
            | 
            | 
           308 | 
              | 
        
        
            | 
            | 
           309 | 
               }
  | 
        
        
            | 
            | 
           310 | 
              | 
        
        
            | 
            | 
           311 | 
              | 
        
        
            | 
            | 
           312 | 
               /**
  | 
        
        
            | 
            | 
           313 | 
                *
  | 
        
        
            | 
            | 
           314 | 
                * @param int $job_description_id_boss
  | 
        
        
            | 
            | 
           315 | 
                * @return JobDescription[]
  | 
        
        
            | 
            | 
           316 | 
                */
  | 
        
        
            | 
            | 
           317 | 
               public function fetchAllDefaultAndJobDescriptionIdBoss($job_description_id_boss)
  | 
        
        
            | 
            | 
           318 | 
               {
  | 
        
        
            | 
            | 
           319 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           320 | 
                   if($job_description_id_boss) {
  | 
        
        
            | 
            | 
           321 | 
                       $select->where->equalTo('job_description_id_boss', $job_description_id_boss);
  | 
        
        
            | 
            | 
           322 | 
                   } else {
  | 
        
        
            | 
            | 
           323 | 
                       $select->where->isNull('job_description_id_boss');
  | 
        
        
            | 
            | 
           324 | 
                   }
  | 
        
        
            | 
            | 
           325 | 
                   $select->order('position, name');
  | 
        
        
            | 
            | 
           326 | 
              | 
        
        
            | 
            | 
           327 | 
                   $prototype = new JobDescription();
  | 
        
        
            | 
            | 
           328 | 
                   return $this->executeFetchAllObject($select, $prototype);
  | 
        
        
            | 
            | 
           329 | 
               }
  | 
        
        
            | 
            | 
           330 | 
              | 
        
        
            | 
            | 
           331 | 
              | 
        
        
            | 
            | 
           332 | 
               /**
  | 
        
        
            | 
            | 
           333 | 
                *
  | 
        
        
            | 
            | 
           334 | 
                * @param int $companyId
  | 
        
        
            | 
            | 
           335 | 
                * @return JobDescription[]
  | 
        
        
            | 
            | 
           336 | 
                */
  | 
        
        
            | 
            | 
           337 | 
               public function fetchAllByCompanyIdAndJobDescriptionIdBoss($companyId, $job_description_id_boss)
  | 
        
        
            | 
            | 
           338 | 
               {
  | 
        
        
            | 
            | 
           339 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           340 | 
                   $select->where->equalTo('company_id', $companyId);
  | 
        
        
            | 
            | 
           341 | 
                   if($job_description_id_boss) {
  | 
        
        
            | 
            | 
           342 | 
                       $select->where->equalTo('job_description_id_boss', $job_description_id_boss);
  | 
        
        
            | 
            | 
           343 | 
                   } else {
  | 
        
        
            | 
            | 
           344 | 
                       $select->where->isNull('job_description_id_boss');
  | 
        
        
            | 
            | 
           345 | 
                   }
  | 
        
        
            | 
            | 
           346 | 
                   $select->order('position, name');
  | 
        
        
            | 
            | 
           347 | 
              | 
        
        
            | 
            | 
           348 | 
              | 
        
        
            | 
            | 
           349 | 
                   //echo $select->getSqlString($this->adapter->platform); exit;
  | 
        
        
            | 
            | 
           350 | 
              | 
        
        
            | 
            | 
           351 | 
              | 
        
        
            | 
            | 
           352 | 
                   $prototype = new JobDescription();
  | 
        
        
            | 
            | 
           353 | 
                   return $this->executeFetchAllObject($select, $prototype);
  | 
        
        
            | 
            | 
           354 | 
              | 
        
        
            | 
            | 
           355 | 
               }
  | 
        
        
            | 
            | 
           356 | 
              | 
        
        
            | 
            | 
           357 | 
               /**
  | 
        
        
            | 
            | 
           358 | 
                *
  | 
        
        
            | 
            | 
           359 | 
                * @param JobDescription $jobDescription
  | 
        
        
            | 
            | 
           360 | 
                * @return boolean
  | 
        
        
            | 
            | 
           361 | 
                */
  | 
        
        
            | 
            | 
           362 | 
               public function insert($jobDescription)
  | 
        
        
            | 
            | 
           363 | 
               {
  | 
        
        
            | 
            | 
           364 | 
                   $hydrator = new ObjectPropertyHydrator();
  | 
        
        
            | 
            | 
           365 | 
                   $values = $hydrator->extract($jobDescription);
  | 
        
        
            | 
            | 
           366 | 
                   $values = $this->removeEmpty($values);
  | 
        
        
            | 
            | 
           367 | 
              | 
        
        
            | 
            | 
           368 | 
                   $values['job_description_id_boss'] = !empty($values['job_description_id_boss']) ? $values['job_description_id_boss'] : null;
  | 
        
        
            | 
            | 
           369 | 
              | 
        
        
            | 
            | 
           370 | 
                   $insert = $this->sql->insert(self::_TABLE);
  | 
        
        
            | 
            | 
           371 | 
                   $insert->values($values);
  | 
        
        
            | 
            | 
           372 | 
              | 
        
        
            | 
            | 
           373 | 
                   $result = $this->executeInsert($insert);
  | 
        
        
            | 
            | 
           374 | 
                   if ($result) {
  | 
        
        
            | 
            | 
           375 | 
                       $jobDescription->id = $this->getLastInsertId();
  | 
        
        
            | 
            | 
           376 | 
                   }
  | 
        
        
            | 
            | 
           377 | 
                   return $result;
  | 
        
        
            | 
            | 
           378 | 
               }
  | 
        
        
            | 
            | 
           379 | 
              | 
        
        
            | 
            | 
           380 | 
               /**
  | 
        
        
            | 
            | 
           381 | 
                *
  | 
        
        
            | 
            | 
           382 | 
                * @param JobDescription $jobDescription
  | 
        
        
            | 
            | 
           383 | 
                * @return boolean
  | 
        
        
            | 
            | 
           384 | 
                */
  | 
        
        
            | 
            | 
           385 | 
               public function update($jobDescription)
  | 
        
        
            | 
            | 
           386 | 
               {
  | 
        
        
            | 
            | 
           387 | 
                   $hydrator = new ObjectPropertyHydrator();
  | 
        
        
            | 
            | 
           388 | 
                   $values = $hydrator->extract($jobDescription);
  | 
        
        
            | 
            | 
           389 | 
                   $values = $this->removeEmpty($values);
  | 
        
        
            | 
            | 
           390 | 
              | 
        
        
            | 
            | 
           391 | 
                   $values['job_description_id_boss'] = !empty($values['job_description_id_boss']) ? $values['job_description_id_boss'] : null;
  | 
        
        
            | 
            | 
           392 | 
              | 
        
        
            | 
            | 
           393 | 
                   $update = $this->sql->update(self::_TABLE);
  | 
        
        
            | 
            | 
           394 | 
                   $update->set($values);
  | 
        
        
            | 
            | 
           395 | 
                   $update->where->equalTo('id', $jobDescription->id);
  | 
        
        
            | 
            | 
           396 | 
              | 
        
        
            | 
            | 
           397 | 
                   return $this->executeUpdate($update);
  | 
        
        
            | 
            | 
           398 | 
               }
  | 
        
        
            | 
            | 
           399 | 
              | 
        
        
            | 
            | 
           400 | 
               /**
  | 
        
        
            | 
            | 
           401 | 
                *
  | 
        
        
            | 
            | 
           402 | 
                * @param JobDescription $jobDescription
  | 
        
        
            | 
            | 
           403 | 
                * @return boolean
  | 
        
        
            | 
            | 
           404 | 
                */
  | 
        
        
            | 
            | 
           405 | 
               public function delete($jobDescription)
  | 
        
        
            | 
            | 
           406 | 
               {
  | 
        
        
            | 
            | 
           407 | 
                   $delete = $this->sql->delete(self::_TABLE);
  | 
        
        
            | 
            | 
           408 | 
                   $delete->where->equalTo('id', $jobDescription->id);
  | 
        
        
            | 
            | 
           409 | 
              | 
        
        
            | 
            | 
           410 | 
                   return $this->executeDelete($delete);
  | 
        
        
            | 
            | 
           411 | 
               }
  | 
        
        
            | 
            | 
           412 | 
              | 
        
        
            | 
            | 
           413 | 
              | 
        
        
            | 
            | 
           414 | 
               /**
  | 
        
        
            | 
            | 
           415 | 
                *
  | 
        
        
            | 
            | 
           416 | 
                * @param int $job_description_id
  | 
        
        
            | 
            | 
           417 | 
                * @param int $position
  | 
        
        
            | 
            | 
           418 | 
                * @return boolean
  | 
        
        
            | 
            | 
           419 | 
                */
  | 
        
        
            | 
            | 
           420 | 
               public function removeJobDescriptionIdBossByJobDescriptionId($job_description_id, $position)
  | 
        
        
            | 
            | 
           421 | 
               {
  | 
        
        
            | 
            | 
           422 | 
                   $values = [
  | 
        
        
            | 
            | 
           423 | 
                       'job_description_id_boss' => null,
  | 
        
        
            | 
            | 
           424 | 
                       'position' => $position,
  | 
        
        
            | 
            | 
           425 | 
                   ];
  | 
        
        
            | 
            | 
           426 | 
              | 
        
        
            | 
            | 
           427 | 
                   $update = $this->sql->update(self::_TABLE);
  | 
        
        
            | 
            | 
           428 | 
                   $update->set($values);
  | 
        
        
            | 
            | 
           429 | 
                   $update->where->equalTo('id', $job_description_id);
  | 
        
        
            | 
            | 
           430 | 
              | 
        
        
            | 
            | 
           431 | 
                   //error_log($update->getSqlString($this->adapter->platform));
  | 
        
        
            | 
            | 
           432 | 
              | 
        
        
            | 
            | 
           433 | 
                   return $this->executeUpdate($update);
  | 
        
        
            | 
            | 
           434 | 
               }
  | 
        
        
            | 
            | 
           435 | 
              | 
        
        
            | 
            | 
           436 | 
               /**
  | 
        
        
            | 
            | 
           437 | 
                *
  | 
        
        
            | 
            | 
           438 | 
                * @param int $job_description_id_boss
  | 
        
        
            | 
            | 
           439 | 
                * @return int
  | 
        
        
            | 
            | 
           440 | 
                */
  | 
        
        
            | 
            | 
           441 | 
               public function fetchMaxPositionByJobDescriptionIdBoss($job_description_id_boss)
  | 
        
        
            | 
            | 
           442 | 
               {
  | 
        
        
            | 
            | 
           443 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           444 | 
                   $select->columns(['max' => new Expression('MAX(position)')]);
  | 
        
        
            | 
            | 
           445 | 
                   $select->where->equalTo('id', $job_description_id_boss);
  | 
        
        
            | 
            | 
           446 | 
              | 
        
        
            | 
            | 
           447 | 
                   $record = $this->executeFetchOneArray($select);
  | 
        
        
            | 
            | 
           448 | 
              | 
        
        
            | 
            | 
           449 | 
                   return intval($record['max'], 10);
  | 
        
        
            | 
            | 
           450 | 
               }
  | 
        
        
            | 
            | 
           451 | 
              | 
        
        
            | 
            | 
           452 | 
              | 
        
        
            | 
            | 
           453 | 
               /**
  | 
        
        
            | 
            | 
           454 | 
                *
  | 
        
        
            | 
            | 
           455 | 
                * @param int $job_description_id
  | 
        
        
            | 
            | 
           456 | 
                * @param int $job_description_id_boss
  | 
        
        
            | 
            | 
           457 | 
                * @param int $position
  | 
        
        
            | 
            | 
           458 | 
                * @return boolean
  | 
        
        
            | 
            | 
           459 | 
                */
  | 
        
        
            | 
            | 
           460 | 
               public function setJobDescriptionIdBossByJobDescripcionId($job_description_id, $job_description_id_boss, $position)
  | 
        
        
            | 
            | 
           461 | 
               {
  | 
        
        
            | 
            | 
           462 | 
              | 
        
        
            | 
            | 
           463 | 
                   $values = [
  | 
        
        
            | 
            | 
           464 | 
                       'job_description_id_boss' => $job_description_id_boss,
  | 
        
        
            | 
            | 
           465 | 
                       'position' => $position
  | 
        
        
            | 
            | 
           466 | 
                   ];
  | 
        
        
            | 
            | 
           467 | 
              | 
        
        
            | 
            | 
           468 | 
                   $update = $this->sql->update(self::_TABLE);
  | 
        
        
            | 
            | 
           469 | 
                   $update->set($values);
  | 
        
        
            | 
            | 
           470 | 
                   $update->where->equalTo('id', $job_description_id);
  | 
        
        
            | 
            | 
           471 | 
              | 
        
        
            | 
            | 
           472 | 
                   //error_log($update->getSqlString($this->adapter->platform));
  | 
        
        
            | 
            | 
           473 | 
              | 
        
        
            | 
            | 
           474 | 
                   return $this->executeUpdate($update);
  | 
        
        
            | 
            | 
           475 | 
               }
  | 
        
        
            | 
            | 
           476 | 
              | 
        
        
            | 
            | 
           477 | 
              | 
        
        
            | 
            | 
           478 | 
               /**
  | 
        
        
            | 
            | 
           479 | 
                *
  | 
        
        
            | 
            | 
           480 | 
                * @param int $job_description_id
  | 
        
        
            | 
            | 
           481 | 
                * @return boolean
  | 
        
        
            | 
            | 
           482 | 
                */
  | 
        
        
            | 
            | 
           483 | 
               public function removeParentByJobDescriptionId($job_description_id)
  | 
        
        
            | 
            | 
           484 | 
               {
  | 
        
        
            | 
            | 
           485 | 
                   $values = [
  | 
        
        
            | 
            | 
           486 | 
                       'job_description_id_boss' => null,
  | 
        
        
            | 
            | 
           487 | 
                   ];
  | 
        
        
            | 
            | 
           488 | 
              | 
        
        
            | 
            | 
           489 | 
                   $update = $this->sql->update(self::_TABLE);
  | 
        
        
            | 
            | 
           490 | 
                   $update->set($values);
  | 
        
        
            | 
            | 
           491 | 
                   $update->where->equalTo('job_description_id_boss', $job_description_id);
  | 
        
        
            | 
            | 
           492 | 
              | 
        
        
            | 
            | 
           493 | 
                   //error_log($update->getSqlString($this->adapter->platform));
  | 
        
        
            | 
            | 
           494 | 
              | 
        
        
            | 
            | 
           495 | 
                   return $this->executeUpdate($update);
  | 
        
        
            | 
            | 
           496 | 
               }
  | 
        
        
            | 
            | 
           497 | 
              | 
        
        
            | 
            | 
           498 | 
              | 
        
        
            | 
            | 
           499 | 
           }
  |