Rev 649 | 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\MicrolearningTopicCapsule;use Laminas\Db\Sql\Expression;use LeadersLinked\Hydrator\ObjectPropertyHydrator;use Laminas\Db\ResultSet\HydratingResultSet;use Laminas\Paginator\Paginator;use Laminas\Paginator\Adapter\DbSelect;class MicrolearningTopicCapsuleMapper extends MapperCommon{const _TABLE = 'tbl_microlearning_topic_capsules';/**** @var MicrolearningTopicCapsuleMapper*/private static $_instance;/**** @param AdapterInterface $adapter*/private function __construct($adapter){parent::__construct($adapter);}/**** @param AdapterInterface $adapter* @return MicrolearningTopicCapsuleMapper*/public static function getInstance($adapter){if(self::$_instance == null) {self::$_instance = new MicrolearningTopicCapsuleMapper($adapter);}return self::$_instance;}/**** @param int $company_id* @param int $topic_id* @return int*/public function fetchTotalCountByCompanyIdAndTopicId($company_id, $topic_id){$select = $this->sql->select();$select->columns(['total' => new Expression('COUNT(*)')]);$select->from(self::_TABLE);$select->where->equalTo('company_id', $company_id);$select->where->equalTo('topic_id', $topic_id);$record = $this->executeFetchOneArray($select);return $record['total'];}/**** @param int $topic_id* @return int*/public function fetchTotalCountByTopicId($topic_id){$select = $this->sql->select();$select->columns(['total' => new Expression('COUNT(*)')]);$select->from(self::_TABLE);$select->where->equalTo('topic_id', $topic_id);$select->where->equalTo('status', MicrolearningTopicCapsule::STATUS_ACTIVE);$record = $this->executeFetchOneArray($select);return $record['total'];}/**** @param int $company_id* @return int*/public function fetchTotalCountAllActiveByCompanyId($company_id){$select = $this->sql->select();$select->columns(['total' => new Expression('COUNT(*)')]);$select->from(self::_TABLE);$select->where->equalTo('company_id', $company_id);$select->where->equalTo('status', MicrolearningTopicCapsule::STATUS_ACTIVE);$record = $this->executeFetchOneArray($select);return $record['total'];}/**** @param int $id* @return MicrolearningTopicCapsule*/public function fetchOne($id){$prototype = new MicrolearningTopicCapsule();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('id', $id);return $this->executeFetchOneObject($select, $prototype);}/**** @param int $topic_id* @param int $capsule_id* @return MicrolearningTopicCapsule*/public function fetchOneByTopicIdAndCapsuleId($topic_id, $capsule_id){$prototype = new MicrolearningTopicCapsule();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('topic_id', $topic_id);$select->where->equalTo('capsule_id', $capsule_id);return $this->executeFetchOneObject($select, $prototype);}/*** Deletes all topic-capsule relationships for a given topic ID.** @param int $topic_id* @return boolean*/public function deleteByTopicId($topic_id){$delete = $this->sql->delete(self::_TABLE);$delete->where->equalTo('topic_id', $topic_id);return $this->executeDelete($delete);}/*** Deletes all topic-capsule relationships for a given capsule ID.** @param int $capsule_id* @return boolean*/public function deleteAllByCapsuleId($capsule_id){$delete = $this->sql->delete(self::_TABLE);$delete->where->equalTo('capsule_id', $capsule_id);return $this->executeDelete($delete);}/*** Fetches a single topic-capsule relationship by capsule ID.* Since a capsule might theoretically be in multiple topics, this fetches the first one found.** @param int $capsule_id* @return MicrolearningTopicCapsule|null*/public function fetchOneByCapsuleId($capsule_id){$prototype = new MicrolearningTopicCapsule();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('capsule_id', $capsule_id);$select->limit(1); // Ensure only one record is fetchedreturn $this->executeFetchOneObject($select, $prototype);}/**** @param int $company_id* @param int $topic_id* @return int*/public function fetchCountByCompanyIdAndTopicId($company_id, $topic_id){$select = $this->sql->select(self::_TABLE);$select->columns(['total' => new Expression('COUNT(*)')]);$select->where->equalTo('company_id', $company_id);$select->where->equalTo('topic_id', $topic_id);$record = $this->executeFetchOneArray($select);return $record['total'];}/**** @param int $topic_id* @return MicrolearningTopicCapsule[]*/public function fetchAllByTopicId($topic_id){$prototype = new MicrolearningTopicCapsule();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('topic_id', $topic_id);$select->order('added_on DESC');return $this->executeFetchAllObject($select, $prototype);}/**** @param int $company_id* @param int $topic_id* @return MicrolearningTopicCapsule[]*/public function fetchAllByCompanyIdAndTopicId($company_id, $topic_id){$prototype = new MicrolearningTopicCapsule();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('company_id', $company_id);$select->where->equalTo('topic_id', $topic_id);$select->order('added_on DESC');return $this->executeFetchAllObject($select, $prototype);}/**** @param int $topic_id* @return MicrolearningTopicCapsule[]*/public function fetchAllActiveByTopicId($topic_id){$prototype = new MicrolearningTopicCapsule();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('topic_id', $topic_id);$select->where->equalTo('status', MicrolearningTopicCapsule::STATUS_ACTIVE);$select->order('added_on DESC');return $this->executeFetchAllObject($select, $prototype);}/**** @param int $capsule_id* @return MicrolearningTopicCapsule[]*/public function fetchAllByCapsuleId($capsule_id){$prototype = new MicrolearningTopicCapsule();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('capsule_id', $capsule_id);$select->order('added_on DESC');return $this->executeFetchAllObject($select, $prototype);}/**** @param int $topic_id* @return MicrolearningTopicCapsule[]*/public function fetchAllActiveAndPublishByTopicId($topic_id){$prototype = new MicrolearningTopicCapsule();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('topic_id', $topic_id);$select->where->equalTo('status', MicrolearningTopicCapsule::STATUS_ACTIVE);$select->where->greaterThanOrEqualTo('publish_on', new Expression('CURRENT_DATE()'));$select->order('added_on DESC');return $this->executeFetchAllObject($select, $prototype);}/**** @param MicrolearningTopicCapsule $record* @return boolean*/public function insert($record){$hydrator = new ObjectPropertyHydrator();$values = $hydrator->extract($record);$values = $this->removeEmpty($values);$insert = $this->sql->insert(self::_TABLE);$insert->values($values);$result = $this->executeInsert($insert);if($result) {$record->id = $this->lastInsertId;}return $result;}/**** @param MicrolearningTopicCapsule $record* @return boolean*/public function update($record){$hydrator = new ObjectPropertyHydrator();$values = $hydrator->extract($record);$values = $this->removeEmpty($values);$update = $this->sql->update(self::_TABLE);$update->set($values);$update->where->equalTo('id', $record->id);return $this->executeUpdate($update);}/**** @param MicrolearningTopicCapsule $record* @return boolean*/public function delete($record){$delete = $this->sql->delete(self::_TABLE);$delete->where->equalTo('id', $record->id);return $this->executeDelete($delete);}}