Rev 3032 | Rev 3141 | 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\Model\Topic;use LeadersLinked\Hydrator\ObjectPropertyHydrator;use Laminas\Paginator\Paginator;use Laminas\Db\ResultSet\HydratingResultSet;use Laminas\Paginator\Adapter\DbSelect;use LeadersLinked\Mapper\TopicMapper;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* @return Feed*/public function fetchOneNonDeleted($id){$select = $this->sql->select(self::_TABLE);$select->where->equalTo('id', $id);$select->where->equalTo('type', Feed::TYPE_MYT_QUESTION);$select->where->notEqualTo('status', Feed::STATUS_DELETED);$prototype = new Feed();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);}/**** @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);}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;}public function fetchFiveForoJoinTopic($group_id,$topic_type){$prototype = new Feed();$select = $this->sql->select();$select->from(['f' => self::_TABLE]);$select->join(['t' => TopicMapper::_TABLE], 't.id = f.topic_id ', []);$select->where->equalTo('f.high_performance_group_id', $group_id);$select->where->equalTo('f.status', Feed::STATUS_PUBLISHED);$select->where->equalTo('f.type', Feed::TYPE_HPTG);$select->where->equalTo('t.type', $topic_type);$select->where->equalTo('t.status', Topic::STATUS_ACTIVE);$select->order('added_on DESC');$hydrator = new ObjectPropertyHydrator();$resultset = new HydratingResultSet($hydrator, $prototype);$adapter = new DbSelect($select, $this->sql, $resultset);$paginator = new Paginator($adapter);$paginator->setItemCountPerPage(5);$paginator->setCurrentPageNumber(1);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);$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);//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 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);}/**** @return Feed*/public function fetchAllByMytQuestion(){$prototype = new Feed();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('type', Feed::TYPE_MYT_QUESTION);$select->where->notEqualTo('status', Feed::STATUS_DELETED);$select->order('added_on DESC');return $this->executeFetchAllObject($select, $prototype);}/**** @return Feed*/public function fetchAllByMytAnswer($related_feed){$prototype = new Feed();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('related_feed', $related_feed);$select->where->equalTo('type', Feed::TYPE_MYT_ANSWER);$select->where->notEqualTo('status', Feed::STATUS_DELETED);$select->order('title');return $this->executeFetchAllObject($select, $prototype);}/**** @return Feed*/public function fetchAllByTopicId($topic_id){$prototype = new Feed();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('topic_id', $topic_id);$select->order('title');return $this->executeFetchAllObject($select, $prototype);}/**** @return Feed*/public function fetchAllByMytAnswerComented(){$prototype = new Feed();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('type', Feed::TYPE_MYT_ANSWER);$select->where->notEqualTo('status', Feed::STATUS_DELETED);$select->order('title');return $this->executeFetchAllObject($select, $prototype);}/**** @return Feed*/public function fetchAllByDevelop(){$prototype = new Feed();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('type', Feed::TYPE_DC);$select->where->notEqualTo('status', Feed::STATUS_DELETED);$select->order('added_on DESC');return $this->executeFetchAllObject($select, $prototype);}/**** @return Feed*/public function fetchAllByDevelopAndCategoryId($id){$prototype = new Feed();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('type', Feed::TYPE_DC);$select->where->equalTo('topic_id', $id);$select->where->notEqualTo('status', Feed::STATUS_DELETED);$select->order('added_on DESC');return $this->executeFetchAllObject($select, $prototype);}/**** @return Feed*/public function fetchAllByDevelopInternContent(){$prototype = new Feed();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('type', Feed::TYPE_DC);//$select->where->equalTo('link_media', 'cesa');$select->where->isNotNull('file_type');$select->where->notEqualTo('status', Feed::STATUS_DELETED);$select->order('title');//echo $insert->getSqlString($this->adapter->platform); exit;return $this->executeFetchAllObject($select, $prototype);}/**** @return Feed*/public function fetchAllByDevelopExternContent(){$prototype = new Feed();$select = $this->sql->select(self::_TABLE);$select->where->equalTo('type', Feed::TYPE_DC);$select->where->notEqualTo('status', Feed::STATUS_DELETED);$select->where->notEqualTo('link_media', 'cesa');$select->order('title');return $this->executeFetchAllObject($select, $prototype);}}