Rev 427 | Rev 1855 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
<?phpdeclare(strict_types=1);namespace LeadersLinked\Mapper;use Laminas\Db\Adapter\AdapterInterface;use Laminas\Db\Sql\Expression;use Laminas\Log\LoggerInterface;use LeadersLinked\Mapper\Common\MapperCommon;use LeadersLinked\Model\Feed;use LeadersLinked\Hydrator\ObjectPropertyHydrator;class FeedMapper extends MapperCommon{const _TABLE = 'tbl_feeds';/**** @var FeedMapper*/private static $_instance;/**** @param AdapterInterface $adapter*/private function __construct($adapter){parent::__construct($adapter);}/**** @param AdapterInterface $adapter* @return \LeadersLinked\Mapper\FeedMapper*/public static function getInstance($adapter){if(self::$_instance == null) {self::$_instance = new FeedMapper($adapter);}return self::$_instance;}/*public function fetchCountSharesByFeedId(int $shared_feed_id){$select = $this->sql->select(self::_TABLE);$select->columns(['total' => new Expression('COUNT(*)') ]);$select->where->equalTo('shared_feed_id', $shared_feed_id);$record = $this->executeFetchOneArray($select);return $record['total'];}*//**** @param int $id* @return Feed*/public function fetchOne($id){$select = $this->sql->select(self::_TABLE);$select->where->equalTo('id', $id);$prototype = new Feed();return $this->executeFetchOneObject($select, $prototype);}/**** @param int $feed_uuid* @return Feed*/public function fetchOneByUuid($uuid){$select = $this->sql->select(self::_TABLE);$select->where->equalTo('uuid', $uuid);$prototype = new Feed();return $this->executeFetchOneObject($select, $prototype);}/**** @return Feed[]*/public function fetchAllTypeVideo(){$select = $this->sql->select(self::_TABLE);$select->where->equalTo('file_type', Feed::FILE_TYPE_VIDEO);//echo $select->getSqlString($this->adapter->platform);$prototype = new Feed();return $this->executeFetchAllObject($select, $prototype);}/**** @param int $shared_feed_id* @return int*/public function fetchCountSharedByFeedId($shared_feed_id){$select = $this->sql->select(self::_TABLE);$select->columns(['total' => new Expression('COUNT(*)') ]);$select->where->equalTo('shared_feed_id', $shared_feed_id);$record = $this->executeFetchOneArray($select);return $record['total'];}/**** @param Feed $feed* @return boolean*/public function update($feed){$hydrator = new ObjectPropertyHydrator();$values = $hydrator->extract($feed);$values = $this->removeEmpty($values);$update = $this->sql->update(self::_TABLE);$update->set($values);$update->where->equalTo('id', $feed->id);return $this->executeUpdate($update);}/**** @param Feed $feed* @return boolean*/public function insert($feed){$hydrator = new ObjectPropertyHydrator();$values = $hydrator->extract($feed);$values = $this->removeEmpty($values);$insert = $this->sql->insert(self::_TABLE);$insert->values($values);$response = $this->executeInsert($insert);if($response) {$feed->id = $this->lastInsertId;}return $values;}/**** @param int $id* @return int*/public function fetchTotalComments($id){$select = $this->sql->select(self::_TABLE);$select->columns(['total_comments']);$select->where->equalTo('id', $id);$record = $this->executeFetchOneArray($select);return $record['total_comments'];}/**** @param int $feed_id* @return boolean*//*public function incTotalComments($id){$update = $this->sql->update(self::_TABLE);$update->set(['total_comments' => new Expression('total_comments + 1')]);$update->where->equalTo('id', $id);return $this->executeUpdate($update);}*//**** @param int $feed_id* @return boolean*/public function incTotalShared($id){$update = $this->sql->update(self::_TABLE);$update->set(['total_shared' => new Expression('total_shared + 1')]);$update->where->equalTo('id', $id);return $this->executeUpdate($update);}/**** @param int $id* @return int*/public function fetchTotalShared($id){$select = $this->sql->select(self::_TABLE);$select->columns(['total_shared']);$select->where->equalTo('id', $id);$record = $this->executeFetchOneArray($select);return $record['total_shared'];}/**** @param int $feed_id* @return boolean*/public function delete($feed_id){$update = $this->sql->update(self::_TABLE);$update->set(['status' => Feed::STATUS_DELETED]);$update->where->equalTo('id', $feed_id);return $this->executeUpdate($update);}}