Rev 43 | AutorÃa | Comparar con el anterior | Ultima modificación | Ver Log |
<?phpdeclare(strict_types=1);namespace LeadersLinked\Mapper;use LeadersLinked\Mapper\Common\MapperCommon;use Laminas\Db\Adapter\AdapterInterface;use LeadersLinked\Model\CompanyMicrolearningUserProgress;use LeadersLinked\Hydrator\ObjectPropertyHydrator;use Laminas\Db\Sql\Expression;class CompanyMicrolearningUserProgressMapper extends MapperCommon{const _TABLE = 'tbl_company_microlearning_user_progress';/**** @var CompanyMicrolearningUserProgressMapper*/private static $_instance;/**** @param AdapterInterface $adapter*/private function __construct($adapter){parent::__construct($adapter);}/**** @param AdapterInterface $adapter* @return CompanyMicrolearningUserProgressMapper*/public static function getInstance($adapter){if(self::$_instance == null) {self::$_instance = new CompanyMicrolearningUserProgressMapper($adapter);}return self::$_instance;}/**** @param int $user_id* @return CompanyMicrolearningUserProgress[]*/public function fetchAllByUserId($user_id){$prototype = new CompanyMicrolearningUserProgress();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('user_id', $user_id);return $this->executeFetchAllObject($select, $prototype);}/**** @return int[]*/public function fetchAllDistinctUserIds(){$user_ids = [];$select = $this->sql->select(self::_TABLE);$select->columns(['user_id' => new Expression('DISTINCT(user_id)')]);$records = $this->executeFetchAllArray($select);foreach ($records as $record){array_push($user_ids, $record['user_id']);}return $user_ids;}/**** @return CompanyMicrolearningUserProgress[]*/public function fetchAllTopics(){$prototype = new CompanyMicrolearningUserProgress();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('type', CompanyMicrolearningUserProgress::TYPE_TOPIC);//echo $select->getSqlString($this->adapter->platform); exit;return $this->executeFetchAllObject($select, $prototype);}/**** @return CompanyMicrolearningUserProgress[]*/public function fetchAllCapsules(){$prototype = new CompanyMicrolearningUserProgress();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('type', CompanyMicrolearningUserProgress::TYPE_CAPSULE);return $this->executeFetchAllObject($select, $prototype);}/**** @param int $user_id* @param int $slide_id* @return CompanyMicrolearningUserProgress*/public function fetchOneByUserIdAndSlideId($user_id, $slide_id){$prototype = new CompanyMicrolearningUserProgress();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('user_id', $user_id);$select->where->equalTo('slide_id', $slide_id);$select->where->equalTo('type', CompanyMicrolearningUserProgress::TYPE_SLIDE);$select->limit(1);return $this->executeFetchOneObject($select, $prototype);}/**** @param int $user_id* @param int $capsule_id* @return CompanyMicrolearningUserProgress*/public function fetchOneByUseridAndCapsuleId($user_id, $capsule_id){$prototype = new CompanyMicrolearningUserProgress();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('user_id', $user_id);$select->where->equalTo('capsule_id', $capsule_id);$select->where->equalTo('type', CompanyMicrolearningUserProgress::TYPE_CAPSULE);$select->limit(1);//echo $select->getSqlString($this->adapter->platform);return $this->executeFetchOneObject($select, $prototype);}/**** @param int $user_id* @param int $topic_id* @return CompanyMicrolearningUserProgress*/public function fetchOneByUserIdAndTopicId($user_id, $topic_id){$prototype = new CompanyMicrolearningUserProgress();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('user_id', $user_id);$select->where->equalTo('topic_id', $topic_id);$select->where->equalTo('type', CompanyMicrolearningUserProgress::TYPE_TOPIC);$select->limit(1);return $this->executeFetchOneObject($select, $prototype);}/**** @param int $user_id* @param int $capsule_id* @return int*/public function fetchCountAllSlideViewedByUserIdAndCapsuleId($user_id, $capsule_id){$select = $this->sql->select(self::_TABLE);$select->columns(['total' => new Expression('COUNT(*)')]);$select->where->equalTo('user_id', $user_id);$select->where->equalTo('capsule_id', $capsule_id);$select->where->equalTo('type', CompanyMicrolearningUserProgress::TYPE_SLIDE);$select->limit(1);$record = $this->executeFetchOneArray($select);return $record['total'];}/**** @param int $user_id* @param int $topic_id* @param int $capsule_id* @return int*/public function fetchCountAllSlideCompletedByUserIdAndTopicIdAndCapsuleId($user_id, $topic_id, $capsule_id){$select = $this->sql->select(self::_TABLE);$select->columns(['total' => new Expression('COUNT(*)')]);$select->where->equalTo('user_id', $user_id);$select->where->equalTo('topic_id', $topic_id);$select->where->equalTo('capsule_id', $capsule_id);$select->where->equalTo('type', CompanyMicrolearningUserProgress::TYPE_SLIDE);$select->where->equalTo('completed', 1);$select->limit(1);$record = $this->executeFetchOneArray($select);return $record['total'];}/**** @param int $user_id* @param int $capsule_id* @return int*/public function fetchCountAllSlideCompletedByUserIdAndCapsuleId($user_id, $capsule_id){$select = $this->sql->select(self::_TABLE);$select->columns(['total' => new Expression('COUNT(*)')]);$select->where->equalTo('user_id', $user_id);$select->where->equalTo('capsule_id', $capsule_id);$select->where->equalTo('type', CompanyMicrolearningUserProgress::TYPE_SLIDE);$select->where->equalTo('completed', 1);$select->limit(1);//echo $select->getSqlString($this->adapter->platform);$record = $this->executeFetchOneArray($select);return $record['total'];}/**** @param int $user_id* @param int $capsule_id* @return int*/public function fetchCountAllSlideCompletedByUserIdAndTopicId($user_id, $topic_id){$select = $this->sql->select(self::_TABLE);$select->columns(['total' => new Expression('COUNT(*)')]);$select->where->equalTo('user_id', $user_id);$select->where->equalTo('topic_id', $topic_id);$select->where->equalTo('type', CompanyMicrolearningUserProgress::TYPE_SLIDE);$select->where->equalTo('completed', 1);$select->limit(1);echo $select->getSqlString($this->adapter->platform) . PHP_EOL;$record = $this->executeFetchOneArray($select);return $record['total'];}/**** @param int $company_id* @param int $user_id* @return int*/public function fetchCountAllSlideCompletedByCompanyIdAndUserId($company_id, $user_id){$select = $this->sql->select(self::_TABLE);$select->columns(['total' => new Expression('COUNT(*)')]);$select->where->equalTo('company_id', $company_id);$select->where->equalTo('user_id', $user_id);$select->where->equalTo('type', CompanyMicrolearningUserProgress::TYPE_SLIDE);$select->where->equalTo('completed', 1);$select->limit(1);$record = $this->executeFetchOneArray($select);return $record['total'];}/**** @param int $user_id* @param int $topic_id* @return int*/public function fetchCountAllSlideViewedByUserIdAndTopicId($user_id, $topic_id){$select = $this->sql->select(self::_TABLE);$select->columns(['total' => new Expression('COUNT(*)')]);$select->where->equalTo('user_id', $user_id);$select->where->equalTo('topic_id', $topic_id);$select->where->equalTo('type', CompanyMicrolearningUserProgress::TYPE_SLIDE);$select->limit(1);$record = $this->executeFetchOneArray($select);return $record['total'];}/**** @param CompanyMicrolearningUserProgress $userProgress* return boolean*/public function insert($userProgress){$hydrator = new ObjectPropertyHydrator();$values = $hydrator->extract($userProgress);$values = $this->removeEmpty($values);$values['added_on'] = $userProgress->added_on;$values['updated_on'] = $userProgress->updated_on;$insert = $this->sql->insert(self::_TABLE);$insert->values($values);//echo $insert->getSqlString($this->adapter->platform); exit;$result = $this->executeInsert($insert);if($result) {$userProgress->id = $this->lastInsertId;}return $result;}/**** @param CompanyMicrolearningUserProgress $userProgress* return boolean*/public function update($userProgress){$hydrator = new ObjectPropertyHydrator();$values = $hydrator->extract($userProgress);$values = $this->removeEmpty($values);$values['added_on'] = $userProgress->added_on;$values['updated_on'] = $userProgress->updated_on;$update = $this->sql->update(self::_TABLE);$update->set($values);$update->where->equalTo('id', $userProgress->id);//echo $update->getSqlString($this->adapter->platform) . PHP_EOL;return $this->executeUpdate($update);}/**** @param int $userId* @return int*/public function getCountCapsulesCompletedByUserId($userId){$select = $this->sql->select(self::_TABLE);$select->columns(['total' => new Expression('COUNT(*)')] );$select->where->equalTo('type', CompanyMicrolearningUserProgress::TYPE_CAPSULE);$select->where->equalTo('user_id', $userId);$select->where->equalTo('completed', 1);$record = $this->executeFetchOneArray($select);return $record['total'];}}