Rev 283 | 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\Model\Topic;use LeadersLinked\Hydrator\ObjectPropertyHydrator;use Laminas\Paginator\Paginator;use Laminas\Db\ResultSet\HydratingResultSet;use Laminas\Paginator\Adapter\DbSelect;use LeadersLinked\Mapper\TopicMapper;use LeadersLinked\Model\FastSurvey;use LeadersLinked\Library\Storage;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){$prototype = new Feed();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('id', $id);$select->where->notEqualTo('status', Feed::STATUS_DELETED);//$select->getSqlString($this->adapter->platform);return $this->executeFetchOneObject($select, $prototype);}/**** @param int $id* @param int $network_id* @return Feed*/public function fetchOneByIdAndNetworkId($id, $network_id){$prototype = new Feed();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('id', $id);$select->where->equalTo('network_id', $network_id);$select->where->notEqualTo('status', Feed::STATUS_DELETED);//$select->getSqlString($this->adapter->platform);return $this->executeFetchOneObject($select, $prototype);}/**** @param int $id* @return Feed*/public function fetchOneAnyStatus($id){$prototype = new Feed();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('id', $id);return $this->executeFetchOneObject($select, $prototype);}/**** @param int $feed_uuid* @return Feed*/public function fetchOneByUuid($uuid){$prototype = new Feed();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('uuid', $uuid);$select->where->notEqualTo('status', Feed::STATUS_DELETED);//$select->getSqlString($this->adapter->platform);return $this->executeFetchOneObject($select, $prototype);}/**** @param int $feed_uuid* @return Feed*/public function fetchOneByUuidAndNetworkId($uuid, $network_id){$prototype = new Feed();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('uuid', $uuid);$select->where->notEqualTo('status', Feed::STATUS_DELETED);//$select->getSqlString($this->adapter->platform);return $this->executeFetchOneObject($select, $prototype);}/**** @param string $feed_uuid* @return Feed*/public function fetchOneByUuidAnyStatus($uuid){$prototype = new Feed();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('uuid', $uuid);return $this->executeFetchOneObject($select, $prototype);}/**** @param string $feed_uuid* @param int $network_id* @return Feed*/public function fetchOneByUuidAndNetworkIdAnyStatus($uuid, $network_id){$prototype = new Feed();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('uuid', $uuid);$select->where->equalTo('network_id', $network_id);return $this->executeFetchOneObject($select, $prototype);}/**** @return Feed[]*/public function fetchAllTypeVideo(){$select = $this->sql->select(self::_TABLE);$select->where->equalTo('file_type', Storage::FILE_TYPE_VIDEO);//echo $select->getSqlString($this->adapter->platform);$prototype = new Feed();return $this->executeFetchAllObject($select, $prototype);}public function fetchAllTypeCalendar($highPerformanceTeamsGroups_id){$select = $this->sql->select(self::_TABLE);$select->where->equalTo('file_type', Feed::FILE_TYPE_MEETING);$select->where->equalTo('high_performance_group_id',$highPerformanceTeamsGroups_id);//echo $select->getSqlString($this->adapter->platform);$prototype = new Feed();return $this->executeFetchAllObject($select, $prototype);}/*public function fetchAllDataTableForo($search, $page = 1, $records_per_page = 10, $order_field= 'added_on', $order_direction = 'DESC', $topic_id){$prototype = new Feed();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('topic_id', $topic_id);$select->where->equalTo('status', Feed::STATUS_PUBLISHED);if($search) {$select->where->like('title', '%' . $search . '%');}$select->order($order_field . ' ' . $order_direction);$hydrator = new ObjectPropertyHydrator();$resultset = new HydratingResultSet($hydrator, $prototype);$adapter = new DbSelect($select, $this->sql, $resultset);$paginator = new Paginator($adapter);$paginator->setItemCountPerPage($records_per_page);$paginator->setCurrentPageNumber($page);return $paginator;}*//**** @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);if(empty($values['publish_on'])) {$values['publish_on'] = new Expression('CURRENT_DATE()');}$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);if(empty($values['publish_on'])) {$values['publish_on'] = new Expression('CURRENT_DATE()');}$insert = $this->sql->insert(self::_TABLE);$insert->values($values);//echo $insert->getSqlString($this->adapter->platform); exit;$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 FastSurvey $fastSurvey* @return boolean*/public function deleteByFastSurvey($fastSurvey){$delete = $this->sql->delete(self::_TABLE);$delete->where->equalTo('fast_survey_id', $fastSurvey->id);return $this->executeDelete($delete);}/**** @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);}/**** @param int $feed_id* @return boolean*/public function incTotalExternalShared($id){$update = $this->sql->update(self::_TABLE);$update->set(['total_external_shared' => new Expression('total_external_shared + 1')]);$update->where->equalTo('id', $id);return $this->executeUpdate($update);}/**** @param int $id* @return int*/public function fetchTotalExternalShared($id){$select = $this->sql->select(self::_TABLE);$select->columns(['total_external_shared']);$select->where->equalTo('id', $id);$record = $this->executeFetchOneArray($select);return $record['total_external_shared'];}/**** @return Feed[]*/public function fetchAll(){$select = $this->sql->select(self::_TABLE);$prototype = new Feed();return $this->executeFetchAllObject($select, $prototype);}}