| 283 | 
           www | 
           1 | 
           <?php
  | 
        
        
            | 
            | 
           2 | 
           declare(strict_types=1);
  | 
        
        
            | 
            | 
           3 | 
              | 
        
        
            | 
            | 
           4 | 
           namespace LeadersLinked\Mapper;
  | 
        
        
            | 
            | 
           5 | 
              | 
        
        
            | 
            | 
           6 | 
           use LeadersLinked\Model\MicrolearningExtendUser;
  | 
        
        
            | 
            | 
           7 | 
           use LeadersLinked\Mapper\Common\MapperCommon;
  | 
        
        
            | 
            | 
           8 | 
           use Laminas\Db\Adapter\AdapterInterface;
  | 
        
        
            | 
            | 
           9 | 
           use Laminas\Log\LoggerInterface;
  | 
        
        
            | 
            | 
           10 | 
           use LeadersLinked\Hydrator\ObjectPropertyHydrator;
  | 
        
        
            | 
            | 
           11 | 
              | 
        
        
            | 
            | 
           12 | 
              | 
        
        
            | 
            | 
           13 | 
           class MicrolearningExtendUserMapper extends MapperCommon
  | 
        
        
            | 
            | 
           14 | 
           {
  | 
        
        
            | 
            | 
           15 | 
               const _TABLE = 'tbl_microlearning_extend_user';
  | 
        
        
            | 
            | 
           16 | 
              | 
        
        
            | 
            | 
           17 | 
              | 
        
        
            | 
            | 
           18 | 
               /**
  | 
        
        
            | 
            | 
           19 | 
                *
  | 
        
        
            | 
            | 
           20 | 
                * @var MicrolearningExtendUserMapper
  | 
        
        
            | 
            | 
           21 | 
                */
  | 
        
        
            | 
            | 
           22 | 
               private static $_instance;
  | 
        
        
            | 
            | 
           23 | 
              | 
        
        
            | 
            | 
           24 | 
               /**
  | 
        
        
            | 
            | 
           25 | 
                *
  | 
        
        
            | 
            | 
           26 | 
                * @param AdapterInterface $adapter
  | 
        
        
            | 
            | 
           27 | 
                */
  | 
        
        
            | 
            | 
           28 | 
               private function __construct($adapter)
  | 
        
        
            | 
            | 
           29 | 
               {
  | 
        
        
            | 
            | 
           30 | 
                   parent::__construct($adapter);
  | 
        
        
            | 
            | 
           31 | 
               }
  | 
        
        
            | 
            | 
           32 | 
              | 
        
        
            | 
            | 
           33 | 
               /**
  | 
        
        
            | 
            | 
           34 | 
                *
  | 
        
        
            | 
            | 
           35 | 
                * @param AdapterInterface $adapter
  | 
        
        
            | 
            | 
           36 | 
                * @param LoggerInterface $logger
  | 
        
        
            | 
            | 
           37 | 
                * @param int $user_id
  | 
        
        
            | 
            | 
           38 | 
                * @return \LeadersLinked\Mapper\MicrolearningExtendUserMapper
  | 
        
        
            | 
            | 
           39 | 
                */
  | 
        
        
            | 
            | 
           40 | 
               public static function getInstance($adapter)
  | 
        
        
            | 
            | 
           41 | 
               {
  | 
        
        
            | 
            | 
           42 | 
                   if(self::$_instance == null) {
  | 
        
        
            | 
            | 
           43 | 
                       self::$_instance = new MicrolearningExtendUserMapper($adapter);
  | 
        
        
            | 
            | 
           44 | 
                   }
  | 
        
        
            | 
            | 
           45 | 
                   return self::$_instance;
  | 
        
        
            | 
            | 
           46 | 
               }
  | 
        
        
            | 
            | 
           47 | 
              | 
        
        
            | 
            | 
           48 | 
               /**
  | 
        
        
            | 
            | 
           49 | 
                *
  | 
        
        
            | 
            | 
           50 | 
                * @param int $id
  | 
        
        
            | 
            | 
           51 | 
                * @return MicrolearningExtendUser
  | 
        
        
            | 
            | 
           52 | 
                */
  | 
        
        
            | 
            | 
           53 | 
               public function fetchOne($id)
  | 
        
        
            | 
            | 
           54 | 
               {
  | 
        
        
            | 
            | 
           55 | 
                   $prototype = new MicrolearningExtendUser();
  | 
        
        
            | 
            | 
           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 | 
                * @param int $company_id
  | 
        
        
            | 
            | 
           65 | 
                * @return MicrolearningExtendUser[]
  | 
        
        
            | 
            | 
           66 | 
                */
  | 
        
        
            | 
            | 
           67 | 
               public function fetchAllByCompanyId($company_id)
  | 
        
        
            | 
            | 
           68 | 
               {
  | 
        
        
            | 
            | 
           69 | 
                   $prototype = new MicrolearningExtendUser();
  | 
        
        
            | 
            | 
           70 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           71 | 
                   $select->where->equalTo('company_id', $company_id);
  | 
        
        
            | 
            | 
           72 | 
              | 
        
        
            | 
            | 
           73 | 
                   return $this->executeFetchAllObject($select, $prototype);
  | 
        
        
            | 
            | 
           74 | 
               }
  | 
        
        
            | 
            | 
           75 | 
              | 
        
        
            | 
            | 
           76 | 
               /**
  | 
        
        
            | 
            | 
           77 | 
                *
  | 
        
        
            | 
            | 
           78 | 
                * @param int $company_id
  | 
        
        
            | 
            | 
           79 | 
                * @param int $user_id
  | 
        
        
            | 
            | 
           80 | 
                * @return MicrolearningExtendUser
  | 
        
        
            | 
            | 
           81 | 
                */
  | 
        
        
            | 
            | 
           82 | 
               public function fetchOneByCompanyIdAndUserId($company_id, $user_id)
  | 
        
        
            | 
            | 
           83 | 
               {
  | 
        
        
            | 
            | 
           84 | 
                   $prototype = new MicrolearningExtendUser();
  | 
        
        
            | 
            | 
           85 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           86 | 
                   $select->where->equalTo('company_id', $company_id);
  | 
        
        
            | 
            | 
           87 | 
                   $select->where->equalTo('user_id', $user_id);
  | 
        
        
            | 
            | 
           88 | 
              | 
        
        
            | 
            | 
           89 | 
                   return $this->executeFetchOneObject($select, $prototype);
  | 
        
        
            | 
            | 
           90 | 
               }
  | 
        
        
            | 
            | 
           91 | 
              | 
        
        
            | 
            | 
           92 | 
              | 
        
        
            | 
            | 
           93 | 
              | 
        
        
            | 
            | 
           94 | 
               /**
  | 
        
        
            | 
            | 
           95 | 
                *
  | 
        
        
            | 
            | 
           96 | 
                * @param MicrolearningExtendUser $microlearningExtendUser
  | 
        
        
            | 
            | 
           97 | 
                * @return boolean
  | 
        
        
            | 
            | 
           98 | 
                */
  | 
        
        
            | 
            | 
           99 | 
               public function insert($microlearningExtendUser)
  | 
        
        
            | 
            | 
           100 | 
               {
  | 
        
        
            | 
            | 
           101 | 
                   $hydrator = new ObjectPropertyHydrator();
  | 
        
        
            | 
            | 
           102 | 
                   $values = $hydrator->extract($microlearningExtendUser);
  | 
        
        
            | 
            | 
           103 | 
                   unset($values['added_on']);
  | 
        
        
            | 
            | 
           104 | 
                   unset($values['updated_on']);
  | 
        
        
            | 
            | 
           105 | 
              | 
        
        
            | 
            | 
           106 | 
                   $insert = $this->sql->insert(self::_TABLE);
  | 
        
        
            | 
            | 
           107 | 
                   $insert->values($values);
  | 
        
        
            | 
            | 
           108 | 
              | 
        
        
            | 
            | 
           109 | 
                   //echo $insert->getSqlString($this->adapter->platform); exit;
  | 
        
        
            | 
            | 
           110 | 
              | 
        
        
            | 
            | 
           111 | 
              | 
        
        
            | 
            | 
           112 | 
              | 
        
        
            | 
            | 
           113 | 
                   $result = $this->executeInsert($insert);
  | 
        
        
            | 
            | 
           114 | 
                   if($result) {
  | 
        
        
            | 
            | 
           115 | 
                       $microlearningExtendUser->id = $this->lastInsertId;
  | 
        
        
            | 
            | 
           116 | 
                   }
  | 
        
        
            | 
            | 
           117 | 
              | 
        
        
            | 
            | 
           118 | 
                   return $result;
  | 
        
        
            | 
            | 
           119 | 
               }
  | 
        
        
            | 
            | 
           120 | 
              | 
        
        
            | 
            | 
           121 | 
               /**
  | 
        
        
            | 
            | 
           122 | 
                *
  | 
        
        
            | 
            | 
           123 | 
                * @param MicrolearningExtendUser $microlearningExtendUser
  | 
        
        
            | 
            | 
           124 | 
                * @return boolean
  | 
        
        
            | 
            | 
           125 | 
                */
  | 
        
        
            | 
            | 
           126 | 
               public function update($microlearningExtendUser)
  | 
        
        
            | 
            | 
           127 | 
               {
  | 
        
        
            | 
            | 
           128 | 
                   $hydrator = new ObjectPropertyHydrator();
  | 
        
        
            | 
            | 
           129 | 
                   $values = $hydrator->extract($microlearningExtendUser);
  | 
        
        
            | 
            | 
           130 | 
                   unset($values['added_on']);
  | 
        
        
            | 
            | 
           131 | 
                   unset($values['updated_on']);
  | 
        
        
            | 
            | 
           132 | 
              | 
        
        
            | 
            | 
           133 | 
              | 
        
        
            | 
            | 
           134 | 
              | 
        
        
            | 
            | 
           135 | 
                   $update = $this->sql->update(self::_TABLE);
  | 
        
        
            | 
            | 
           136 | 
                   $update->set($values);
  | 
        
        
            | 
            | 
           137 | 
                   $update->where->equalTo('id', $microlearningExtendUser->id);
  | 
        
        
            | 
            | 
           138 | 
              | 
        
        
            | 
            | 
           139 | 
                   return $this->executeUpdate($update);
  | 
        
        
            | 
            | 
           140 | 
               }
  | 
        
        
            | 
            | 
           141 | 
              | 
        
        
            | 
            | 
           142 | 
               /**
  | 
        
        
            | 
            | 
           143 | 
                *
  | 
        
        
            | 
            | 
           144 | 
                * @param int $id
  | 
        
        
            | 
            | 
           145 | 
                * @return boolean
  | 
        
        
            | 
            | 
           146 | 
                */
  | 
        
        
            | 
            | 
           147 | 
               public function delete($id)
  | 
        
        
            | 
            | 
           148 | 
               {
  | 
        
        
            | 
            | 
           149 | 
                   $delete = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           150 | 
                   $delete->where->equalTo('id', $id);
  | 
        
        
            | 
            | 
           151 | 
              | 
        
        
            | 
            | 
           152 | 
                   return $this->executeDelete($delete);
  | 
        
        
            | 
            | 
           153 | 
               }
  | 
        
        
            | 
            | 
           154 | 
              | 
        
        
            | 
            | 
           155 | 
              | 
        
        
            | 
            | 
           156 | 
           }
  |