| 1 | 
           www | 
           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\CompanyMicrolearningUserProgress;
  | 
        
        
            | 
            | 
           9 | 
           use LeadersLinked\Hydrator\ObjectPropertyHydrator;
  | 
        
        
            | 
            | 
           10 | 
           use Laminas\Db\Sql\Expression;
  | 
        
        
            | 
            | 
           11 | 
              | 
        
        
            | 
            | 
           12 | 
              | 
        
        
            | 
            | 
           13 | 
           class CompanyMicrolearningUserProgressMapper extends MapperCommon
  | 
        
        
            | 
            | 
           14 | 
           {
  | 
        
        
            | 
            | 
           15 | 
               const _TABLE = 'tbl_company_microlearning_user_progress';
  | 
        
        
            | 
            | 
           16 | 
              | 
        
        
            | 
            | 
           17 | 
               /**
  | 
        
        
            | 
            | 
           18 | 
                *
  | 
        
        
            | 
            | 
           19 | 
                * @var CompanyMicrolearningUserProgressMapper
  | 
        
        
            | 
            | 
           20 | 
                */
  | 
        
        
            | 
            | 
           21 | 
               private static $_instance;
  | 
        
        
            | 
            | 
           22 | 
              | 
        
        
            | 
            | 
           23 | 
               /**
  | 
        
        
            | 
            | 
           24 | 
                *
  | 
        
        
            | 
            | 
           25 | 
                * @param AdapterInterface $adapter
  | 
        
        
            | 
            | 
           26 | 
                */
  | 
        
        
            | 
            | 
           27 | 
               private function __construct($adapter)
  | 
        
        
            | 
            | 
           28 | 
               {
  | 
        
        
            | 
            | 
           29 | 
                   parent::__construct($adapter);
  | 
        
        
            | 
            | 
           30 | 
               }
  | 
        
        
            | 
            | 
           31 | 
              | 
        
        
            | 
            | 
           32 | 
               /**
  | 
        
        
            | 
            | 
           33 | 
                *
  | 
        
        
            | 
            | 
           34 | 
                * @param AdapterInterface $adapter
  | 
        
        
            | 
            | 
           35 | 
                * @return CompanyMicrolearningUserProgressMapper
  | 
        
        
            | 
            | 
           36 | 
                */
  | 
        
        
            | 
            | 
           37 | 
               public static function getInstance($adapter)
  | 
        
        
            | 
            | 
           38 | 
               {
  | 
        
        
            | 
            | 
           39 | 
                   if(self::$_instance == null) {
  | 
        
        
            | 
            | 
           40 | 
                       self::$_instance = new CompanyMicrolearningUserProgressMapper($adapter);
  | 
        
        
            | 
            | 
           41 | 
                   }
  | 
        
        
            | 
            | 
           42 | 
                   return self::$_instance;
  | 
        
        
            | 
            | 
           43 | 
               }
  | 
        
        
            | 
            | 
           44 | 
              | 
        
        
            | 
            | 
           45 | 
               /**
  | 
        
        
            | 
            | 
           46 | 
                *
  | 
        
        
            | 
            | 
           47 | 
                * @param int $user_id
  | 
        
        
            | 
            | 
           48 | 
                * @return CompanyMicrolearningUserProgress[]
  | 
        
        
            | 
            | 
           49 | 
                */
  | 
        
        
            | 
            | 
           50 | 
               public function fetchAllByUserId($user_id)
  | 
        
        
            | 
            | 
           51 | 
               {
  | 
        
        
            | 
            | 
           52 | 
                   $prototype = new CompanyMicrolearningUserProgress();
  | 
        
        
            | 
            | 
           53 | 
              | 
        
        
            | 
            | 
           54 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           55 | 
                   $select->where->equalTo('user_id', $user_id);
  | 
        
        
            | 
            | 
           56 | 
              | 
        
        
            | 
            | 
           57 | 
                   return $this->executeFetchAllObject($select, $prototype);
  | 
        
        
            | 
            | 
           58 | 
               }
  | 
        
        
            | 
            | 
           59 | 
              | 
        
        
            | 
            | 
           60 | 
               /**
  | 
        
        
            | 
            | 
           61 | 
                *
  | 
        
        
            | 
            | 
           62 | 
                * @return int[]
  | 
        
        
            | 
            | 
           63 | 
                */
  | 
        
        
            | 
            | 
           64 | 
               public function fetchAllDistinctUserIds()
  | 
        
        
            | 
            | 
           65 | 
               {
  | 
        
        
            | 
            | 
           66 | 
                   $user_ids = [];
  | 
        
        
            | 
            | 
           67 | 
              | 
        
        
            | 
            | 
           68 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           69 | 
                   $select->columns(['user_id' => new Expression('DISTINCT(user_id)')]);
  | 
        
        
            | 
            | 
           70 | 
              | 
        
        
            | 
            | 
           71 | 
                   $records = $this->executeFetchAllArray($select);
  | 
        
        
            | 
            | 
           72 | 
                   foreach ($records as $record)
  | 
        
        
            | 
            | 
           73 | 
                   {
  | 
        
        
            | 
            | 
           74 | 
                       array_push($user_ids, $record['user_id']);
  | 
        
        
            | 
            | 
           75 | 
                   }
  | 
        
        
            | 
            | 
           76 | 
              | 
        
        
            | 
            | 
           77 | 
                   return $user_ids;
  | 
        
        
            | 
            | 
           78 | 
              | 
        
        
            | 
            | 
           79 | 
               }
  | 
        
        
            | 
            | 
           80 | 
              | 
        
        
            | 
            | 
           81 | 
              | 
        
        
            | 
            | 
           82 | 
              | 
        
        
            | 
            | 
           83 | 
               /**
  | 
        
        
            | 
            | 
           84 | 
                *
  | 
        
        
            | 
            | 
           85 | 
                * @return CompanyMicrolearningUserProgress[]
  | 
        
        
            | 
            | 
           86 | 
                */
  | 
        
        
            | 
            | 
           87 | 
               public function fetchAllTopics()
  | 
        
        
            | 
            | 
           88 | 
               {
  | 
        
        
            | 
            | 
           89 | 
                   $prototype = new CompanyMicrolearningUserProgress();
  | 
        
        
            | 
            | 
           90 | 
              | 
        
        
            | 
            | 
           91 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           92 | 
                   $select->where->equalTo('type', CompanyMicrolearningUserProgress::TYPE_TOPIC);
  | 
        
        
            | 
            | 
           93 | 
              | 
        
        
            | 
            | 
           94 | 
                   //echo $select->getSqlString($this->adapter->platform); exit;
  | 
        
        
            | 
            | 
           95 | 
              | 
        
        
            | 
            | 
           96 | 
                   return $this->executeFetchAllObject($select, $prototype);
  | 
        
        
            | 
            | 
           97 | 
               }
  | 
        
        
            | 
            | 
           98 | 
              | 
        
        
            | 
            | 
           99 | 
              | 
        
        
            | 
            | 
           100 | 
               /**
  | 
        
        
            | 
            | 
           101 | 
                *
  | 
        
        
            | 
            | 
           102 | 
                * @return CompanyMicrolearningUserProgress[]
  | 
        
        
            | 
            | 
           103 | 
                */
  | 
        
        
            | 
            | 
           104 | 
               public function fetchAllCapsules()
  | 
        
        
            | 
            | 
           105 | 
               {
  | 
        
        
            | 
            | 
           106 | 
                   $prototype = new CompanyMicrolearningUserProgress();
  | 
        
        
            | 
            | 
           107 | 
              | 
        
        
            | 
            | 
           108 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           109 | 
                   $select->where->equalTo('type', CompanyMicrolearningUserProgress::TYPE_CAPSULE);
  | 
        
        
            | 
            | 
           110 | 
              | 
        
        
            | 
            | 
           111 | 
                   return $this->executeFetchAllObject($select, $prototype);
  | 
        
        
            | 
            | 
           112 | 
               }
  | 
        
        
            | 
            | 
           113 | 
              | 
        
        
            | 
            | 
           114 | 
              | 
        
        
            | 
            | 
           115 | 
               /**
  | 
        
        
            | 
            | 
           116 | 
                *
  | 
        
        
            | 
            | 
           117 | 
                * @param int $user_id
  | 
        
        
            | 
            | 
           118 | 
                * @param int $slide_id
  | 
        
        
            | 
            | 
           119 | 
                * @return CompanyMicrolearningUserProgress
  | 
        
        
            | 
            | 
           120 | 
                */
  | 
        
        
            | 
            | 
           121 | 
               public function fetchOneByUserIdAndSlideId($user_id, $slide_id)
  | 
        
        
            | 
            | 
           122 | 
               {
  | 
        
        
            | 
            | 
           123 | 
                   $prototype = new CompanyMicrolearningUserProgress();
  | 
        
        
            | 
            | 
           124 | 
              | 
        
        
            | 
            | 
           125 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           126 | 
                   $select->where->equalTo('user_id', $user_id);
  | 
        
        
            | 
            | 
           127 | 
                   $select->where->equalTo('slide_id', $slide_id);
  | 
        
        
            | 
            | 
           128 | 
                   $select->where->equalTo('type', CompanyMicrolearningUserProgress::TYPE_SLIDE);
  | 
        
        
            | 
            | 
           129 | 
              | 
        
        
            | 
            | 
           130 | 
                   $select->limit(1);
  | 
        
        
            | 
            | 
           131 | 
              | 
        
        
            | 
            | 
           132 | 
                   return $this->executeFetchOneObject($select, $prototype);
  | 
        
        
            | 
            | 
           133 | 
               }
  | 
        
        
            | 
            | 
           134 | 
              | 
        
        
            | 
            | 
           135 | 
               /**
  | 
        
        
            | 
            | 
           136 | 
                *
  | 
        
        
            | 
            | 
           137 | 
                * @param int $user_id
  | 
        
        
            | 
            | 
           138 | 
                * @param int $capsule_id
  | 
        
        
            | 
            | 
           139 | 
                * @return CompanyMicrolearningUserProgress
  | 
        
        
            | 
            | 
           140 | 
                */
  | 
        
        
            | 
            | 
           141 | 
               public function fetchOneByUseridAndCapsuleId($user_id, $capsule_id)
  | 
        
        
            | 
            | 
           142 | 
               {
  | 
        
        
            | 
            | 
           143 | 
                   $prototype = new CompanyMicrolearningUserProgress();
  | 
        
        
            | 
            | 
           144 | 
              | 
        
        
            | 
            | 
           145 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           146 | 
                   $select->where->equalTo('user_id', $user_id);
  | 
        
        
            | 
            | 
           147 | 
                   $select->where->equalTo('capsule_id', $capsule_id);
  | 
        
        
            | 
            | 
           148 | 
                   $select->where->equalTo('type', CompanyMicrolearningUserProgress::TYPE_CAPSULE);
  | 
        
        
            | 
            | 
           149 | 
                   $select->limit(1);
  | 
        
        
            | 
            | 
           150 | 
              | 
        
        
            | 
            | 
           151 | 
                   return $this->executeFetchOneObject($select, $prototype);
  | 
        
        
            | 
            | 
           152 | 
               }
  | 
        
        
            | 
            | 
           153 | 
              | 
        
        
            | 
            | 
           154 | 
               /**
  | 
        
        
            | 
            | 
           155 | 
                *
  | 
        
        
            | 
            | 
           156 | 
                * @param int $user_id
  | 
        
        
            | 
            | 
           157 | 
                * @param int $topic_id
  | 
        
        
            | 
            | 
           158 | 
                * @return CompanyMicrolearningUserProgress
  | 
        
        
            | 
            | 
           159 | 
                */
  | 
        
        
            | 
            | 
           160 | 
               public function fetchOneByUserIdAndTopicId($user_id, $topic_id)
  | 
        
        
            | 
            | 
           161 | 
               {
  | 
        
        
            | 
            | 
           162 | 
                   $prototype = new CompanyMicrolearningUserProgress();
  | 
        
        
            | 
            | 
           163 | 
              | 
        
        
            | 
            | 
           164 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           165 | 
                   $select->where->equalTo('user_id', $user_id);
  | 
        
        
            | 
            | 
           166 | 
                   $select->where->equalTo('topic_id', $topic_id);
  | 
        
        
            | 
            | 
           167 | 
                   $select->where->equalTo('type', CompanyMicrolearningUserProgress::TYPE_TOPIC);
  | 
        
        
            | 
            | 
           168 | 
                   $select->limit(1);
  | 
        
        
            | 
            | 
           169 | 
              | 
        
        
            | 
            | 
           170 | 
                   return $this->executeFetchOneObject($select, $prototype);
  | 
        
        
            | 
            | 
           171 | 
               }
  | 
        
        
            | 
            | 
           172 | 
              | 
        
        
            | 
            | 
           173 | 
              | 
        
        
            | 
            | 
           174 | 
               /**
  | 
        
        
            | 
            | 
           175 | 
                *
  | 
        
        
            | 
            | 
           176 | 
                * @param int $user_id
  | 
        
        
            | 
            | 
           177 | 
                * @param int $capsule_id
  | 
        
        
            | 
            | 
           178 | 
                * @return int
  | 
        
        
            | 
            | 
           179 | 
                */
  | 
        
        
            | 
            | 
           180 | 
               public function fetchCountAllSlideViewedByUserIdAndCapsuleId($user_id, $capsule_id)
  | 
        
        
            | 
            | 
           181 | 
               {
  | 
        
        
            | 
            | 
           182 | 
              | 
        
        
            | 
            | 
           183 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           184 | 
                   $select->columns(['total' => new Expression('COUNT(*)')]);
  | 
        
        
            | 
            | 
           185 | 
                   $select->where->equalTo('user_id', $user_id);
  | 
        
        
            | 
            | 
           186 | 
                   $select->where->equalTo('capsule_id', $capsule_id);
  | 
        
        
            | 
            | 
           187 | 
                   $select->where->equalTo('type', CompanyMicrolearningUserProgress::TYPE_SLIDE);
  | 
        
        
            | 
            | 
           188 | 
                   $select->limit(1);
  | 
        
        
            | 
            | 
           189 | 
              | 
        
        
            | 
            | 
           190 | 
                   $record = $this->executeFetchOneArray($select);
  | 
        
        
            | 
            | 
           191 | 
                   return $record['total'];
  | 
        
        
            | 
            | 
           192 | 
               }
  | 
        
        
            | 
            | 
           193 | 
              | 
        
        
            | 
            | 
           194 | 
               /**
  | 
        
        
            | 
            | 
           195 | 
                *
  | 
        
        
            | 
            | 
           196 | 
                * @param int $user_id
  | 
        
        
            | 
            | 
           197 | 
                * @param int $topic_id
  | 
        
        
            | 
            | 
           198 | 
                * @param int $capsule_id
  | 
        
        
            | 
            | 
           199 | 
                * @return int
  | 
        
        
            | 
            | 
           200 | 
                */
  | 
        
        
            | 
            | 
           201 | 
               public function fetchCountAllSlideCompletedByUserIdAndTopicIdAndCapsuleId($user_id, $topic_id, $capsule_id)
  | 
        
        
            | 
            | 
           202 | 
               {
  | 
        
        
            | 
            | 
           203 | 
              | 
        
        
            | 
            | 
           204 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           205 | 
                   $select->columns(['total' => new Expression('COUNT(*)')]);
  | 
        
        
            | 
            | 
           206 | 
                   $select->where->equalTo('user_id', $user_id);
  | 
        
        
            | 
            | 
           207 | 
                   $select->where->equalTo('topic_id', $topic_id);
  | 
        
        
            | 
            | 
           208 | 
                   $select->where->equalTo('capsule_id', $capsule_id);
  | 
        
        
            | 
            | 
           209 | 
                   $select->where->equalTo('type', CompanyMicrolearningUserProgress::TYPE_SLIDE);
  | 
        
        
            | 
            | 
           210 | 
                   $select->where->equalTo('completed', 1);
  | 
        
        
            | 
            | 
           211 | 
                   $select->limit(1);
  | 
        
        
            | 
            | 
           212 | 
              | 
        
        
            | 
            | 
           213 | 
                   $record = $this->executeFetchOneArray($select);
  | 
        
        
            | 
            | 
           214 | 
                   return $record['total'];
  | 
        
        
            | 
            | 
           215 | 
               }
  | 
        
        
            | 
            | 
           216 | 
              | 
        
        
            | 
            | 
           217 | 
              | 
        
        
            | 
            | 
           218 | 
               /**
  | 
        
        
            | 
            | 
           219 | 
                *
  | 
        
        
            | 
            | 
           220 | 
                * @param int $user_id
  | 
        
        
            | 
            | 
           221 | 
                * @param int $capsule_id
  | 
        
        
            | 
            | 
           222 | 
                * @return int
  | 
        
        
            | 
            | 
           223 | 
                */
  | 
        
        
            | 
            | 
           224 | 
               public function fetchCountAllSlideCompletedByUserIdAndCapsuleId($user_id, $capsule_id)
  | 
        
        
            | 
            | 
           225 | 
               {
  | 
        
        
            | 
            | 
           226 | 
              | 
        
        
            | 
            | 
           227 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           228 | 
                   $select->columns(['total' => new Expression('COUNT(*)')]);
  | 
        
        
            | 
            | 
           229 | 
                   $select->where->equalTo('user_id', $user_id);
  | 
        
        
            | 
            | 
           230 | 
                   $select->where->equalTo('capsule_id', $capsule_id);
  | 
        
        
            | 
            | 
           231 | 
                   $select->where->equalTo('type', CompanyMicrolearningUserProgress::TYPE_SLIDE);
  | 
        
        
            | 
            | 
           232 | 
                   $select->where->equalTo('completed', 1);
  | 
        
        
            | 
            | 
           233 | 
                   $select->limit(1);
  | 
        
        
            | 
            | 
           234 | 
              | 
        
        
            | 
            | 
           235 | 
                   //echo $select->getSqlString($this->adapter->platform);
  | 
        
        
            | 
            | 
           236 | 
              | 
        
        
            | 
            | 
           237 | 
                   $record = $this->executeFetchOneArray($select);
  | 
        
        
            | 
            | 
           238 | 
                   return $record['total'];
  | 
        
        
            | 
            | 
           239 | 
               }
  | 
        
        
            | 
            | 
           240 | 
              | 
        
        
            | 
            | 
           241 | 
               /**
  | 
        
        
            | 
            | 
           242 | 
                *
  | 
        
        
            | 
            | 
           243 | 
                * @param int $user_id
  | 
        
        
            | 
            | 
           244 | 
                * @param int $capsule_id
  | 
        
        
            | 
            | 
           245 | 
                * @return int
  | 
        
        
            | 
            | 
           246 | 
                */
  | 
        
        
            | 
            | 
           247 | 
               public function fetchCountAllSlideCompletedByUserIdAndTopicId($user_id, $topic_id)
  | 
        
        
            | 
            | 
           248 | 
               {
  | 
        
        
            | 
            | 
           249 | 
              | 
        
        
            | 
            | 
           250 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           251 | 
                   $select->columns(['total' => new Expression('COUNT(*)')]);
  | 
        
        
            | 
            | 
           252 | 
                   $select->where->equalTo('user_id', $user_id);
  | 
        
        
            | 
            | 
           253 | 
                   $select->where->equalTo('topic_id', $topic_id);
  | 
        
        
            | 
            | 
           254 | 
                   $select->where->equalTo('type', CompanyMicrolearningUserProgress::TYPE_SLIDE);
  | 
        
        
            | 
            | 
           255 | 
                   $select->where->equalTo('completed', 1);
  | 
        
        
            | 
            | 
           256 | 
                   $select->limit(1);
  | 
        
        
            | 
            | 
           257 | 
              | 
        
        
            | 
            | 
           258 | 
                   echo $select->getSqlString($this->adapter->platform) . PHP_EOL;
  | 
        
        
            | 
            | 
           259 | 
              | 
        
        
            | 
            | 
           260 | 
                   $record = $this->executeFetchOneArray($select);
  | 
        
        
            | 
            | 
           261 | 
                   return $record['total'];
  | 
        
        
            | 
            | 
           262 | 
               }
  | 
        
        
            | 
            | 
           263 | 
              | 
        
        
            | 
            | 
           264 | 
               /**
  | 
        
        
            | 
            | 
           265 | 
                *
  | 
        
        
            | 
            | 
           266 | 
                * @param int $company_id
  | 
        
        
            | 
            | 
           267 | 
                * @param int $user_id
  | 
        
        
            | 
            | 
           268 | 
                * @return int
  | 
        
        
            | 
            | 
           269 | 
                */
  | 
        
        
            | 
            | 
           270 | 
               public function fetchCountAllSlideCompletedByCompanyIdAndUserId($company_id, $user_id)
  | 
        
        
            | 
            | 
           271 | 
               {
  | 
        
        
            | 
            | 
           272 | 
              | 
        
        
            | 
            | 
           273 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           274 | 
                   $select->columns(['total' => new Expression('COUNT(*)')]);
  | 
        
        
            | 
            | 
           275 | 
                   $select->where->equalTo('company_id', $company_id);
  | 
        
        
            | 
            | 
           276 | 
                   $select->where->equalTo('user_id', $user_id);
  | 
        
        
            | 
            | 
           277 | 
                   $select->where->equalTo('type', CompanyMicrolearningUserProgress::TYPE_SLIDE);
  | 
        
        
            | 
            | 
           278 | 
                   $select->where->equalTo('completed', 1);
  | 
        
        
            | 
            | 
           279 | 
                   $select->limit(1);
  | 
        
        
            | 
            | 
           280 | 
              | 
        
        
            | 
            | 
           281 | 
                   $record = $this->executeFetchOneArray($select);
  | 
        
        
            | 
            | 
           282 | 
                   return $record['total'];
  | 
        
        
            | 
            | 
           283 | 
               }
  | 
        
        
            | 
            | 
           284 | 
              | 
        
        
            | 
            | 
           285 | 
              | 
        
        
            | 
            | 
           286 | 
               /**
  | 
        
        
            | 
            | 
           287 | 
                *
  | 
        
        
            | 
            | 
           288 | 
                * @param int $user_id
  | 
        
        
            | 
            | 
           289 | 
                * @param int $topic_id
  | 
        
        
            | 
            | 
           290 | 
                * @return int
  | 
        
        
            | 
            | 
           291 | 
                */
  | 
        
        
            | 
            | 
           292 | 
               public function fetchCountAllSlideViewedByUserIdAndTopicId($user_id, $topic_id)
  | 
        
        
            | 
            | 
           293 | 
               {
  | 
        
        
            | 
            | 
           294 | 
              | 
        
        
            | 
            | 
           295 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           296 | 
                   $select->columns(['total' => new Expression('COUNT(*)')]);
  | 
        
        
            | 
            | 
           297 | 
                   $select->where->equalTo('user_id', $user_id);
  | 
        
        
            | 
            | 
           298 | 
                   $select->where->equalTo('topic_id', $topic_id);
  | 
        
        
            | 
            | 
           299 | 
                   $select->where->equalTo('type', CompanyMicrolearningUserProgress::TYPE_SLIDE);
  | 
        
        
            | 
            | 
           300 | 
                   $select->limit(1);
  | 
        
        
            | 
            | 
           301 | 
              | 
        
        
            | 
            | 
           302 | 
                   $record = $this->executeFetchOneArray($select);
  | 
        
        
            | 
            | 
           303 | 
                   return $record['total'];
  | 
        
        
            | 
            | 
           304 | 
               }
  | 
        
        
            | 
            | 
           305 | 
              | 
        
        
            | 
            | 
           306 | 
               /**
  | 
        
        
            | 
            | 
           307 | 
                *
  | 
        
        
            | 
            | 
           308 | 
                * @param CompanyMicrolearningUserProgress $userProgress
  | 
        
        
            | 
            | 
           309 | 
                * return boolean
  | 
        
        
            | 
            | 
           310 | 
                */
  | 
        
        
            | 
            | 
           311 | 
               public function insert($userProgress)
  | 
        
        
            | 
            | 
           312 | 
               {
  | 
        
        
            | 
            | 
           313 | 
                   $hydrator = new ObjectPropertyHydrator();
  | 
        
        
            | 
            | 
           314 | 
                   $values = $hydrator->extract($userProgress);
  | 
        
        
            | 
            | 
           315 | 
                   $values = $this->removeEmpty($values);
  | 
        
        
            | 
            | 
           316 | 
              | 
        
        
            | 
            | 
           317 | 
                   $insert = $this->sql->insert(self::_TABLE);
  | 
        
        
            | 
            | 
           318 | 
                   $insert->values($values);
  | 
        
        
            | 
            | 
           319 | 
              | 
        
        
            | 
            | 
           320 | 
                   //echo $insert->getSqlString($this->adapter->platform); exit;
  | 
        
        
            | 
            | 
           321 | 
              | 
        
        
            | 
            | 
           322 | 
                   $result = $this->executeInsert($insert);
  | 
        
        
            | 
            | 
           323 | 
                   if($result) {
  | 
        
        
            | 
            | 
           324 | 
                       $userProgress->id = $this->lastInsertId;
  | 
        
        
            | 
            | 
           325 | 
                   }
  | 
        
        
            | 
            | 
           326 | 
                   return $result;
  | 
        
        
            | 
            | 
           327 | 
               }
  | 
        
        
            | 
            | 
           328 | 
              | 
        
        
            | 
            | 
           329 | 
              | 
        
        
            | 
            | 
           330 | 
               /**
  | 
        
        
            | 
            | 
           331 | 
                *
  | 
        
        
            | 
            | 
           332 | 
                * @param CompanyMicrolearningUserProgress $userProgress
  | 
        
        
            | 
            | 
           333 | 
                * return boolean
  | 
        
        
            | 
            | 
           334 | 
                */
  | 
        
        
            | 
            | 
           335 | 
               public function update($userProgress)
  | 
        
        
            | 
            | 
           336 | 
               {
  | 
        
        
            | 
            | 
           337 | 
                   $hydrator = new ObjectPropertyHydrator();
  | 
        
        
            | 
            | 
           338 | 
                   $values = $hydrator->extract($userProgress);
  | 
        
        
            | 
            | 
           339 | 
                   $values = $this->removeEmpty($values);
  | 
        
        
            | 
            | 
           340 | 
              | 
        
        
            | 
            | 
           341 | 
              | 
        
        
            | 
            | 
           342 | 
                   $update = $this->sql->update(self::_TABLE);
  | 
        
        
            | 
            | 
           343 | 
                   $update->set($values);
  | 
        
        
            | 
            | 
           344 | 
                   $update->where->equalTo('id', $userProgress->id);
  | 
        
        
            | 
            | 
           345 | 
              | 
        
        
            | 
            | 
           346 | 
                   //echo $update->getSqlString($this->adapter->platform) . PHP_EOL;
  | 
        
        
            | 
            | 
           347 | 
              | 
        
        
            | 
            | 
           348 | 
                   return $this->executeUpdate($update);
  | 
        
        
            | 
            | 
           349 | 
               }
  | 
        
        
            | 
            | 
           350 | 
              | 
        
        
            | 
            | 
           351 | 
              | 
        
        
            | 
            | 
           352 | 
               /**
  | 
        
        
            | 
            | 
           353 | 
                *
  | 
        
        
            | 
            | 
           354 | 
                * @param int $userId
  | 
        
        
            | 
            | 
           355 | 
                * @return int
  | 
        
        
            | 
            | 
           356 | 
                */
  | 
        
        
            | 
            | 
           357 | 
               public function getCountCapsulesCompletedByUserId($userId)
  | 
        
        
            | 
            | 
           358 | 
               {
  | 
        
        
            | 
            | 
           359 | 
                   $select = $this->sql->select(self::_TABLE);
  | 
        
        
            | 
            | 
           360 | 
                   $select->columns(['total' => new Expression('COUNT(*)')] );
  | 
        
        
            | 
            | 
           361 | 
                   $select->where->equalTo('type', CompanyMicrolearningUserProgress::TYPE_CAPSULE);
  | 
        
        
            | 
            | 
           362 | 
                   $select->where->equalTo('user_id', $userId);
  | 
        
        
            | 
            | 
           363 | 
                   $select->where->equalTo('completed', 1);
  | 
        
        
            | 
            | 
           364 | 
              | 
        
        
            | 
            | 
           365 | 
                   $record = $this->executeFetchOneArray($select);
  | 
        
        
            | 
            | 
           366 | 
              | 
        
        
            | 
            | 
           367 | 
                   return $record['total'];
  | 
        
        
            | 
            | 
           368 | 
              | 
        
        
            | 
            | 
           369 | 
               }
  | 
        
        
            | 
            | 
           370 | 
              | 
        
        
            | 
            | 
           371 | 
              | 
        
        
            | 
            | 
           372 | 
              | 
        
        
            | 
            | 
           373 | 
           }
  |