Rev 6521 | AutorÃa | Comparar con el anterior | Ultima modificación | Ver Log |
<?phpdeclare(strict_types=1);namespace LeadersLinked\Mapper;use LeadersLinked\Model\ContentReaction;use LeadersLinked\Mapper\Common\MapperCommon;use Laminas\Db\Adapter\AdapterInterface;use Laminas\Log\LoggerInterface;use Laminas\Db\Sql\Expression;use LeadersLinked\Hydrator\ObjectPropertyHydrator;class ContentReactionMapper extends MapperCommon{const _TABLE = 'tbl_content_reactions';/**** @var ContentReactionMapper*/private static $_instance;/**** @param AdapterInterface $adapter*/private function __construct($adapter){parent::__construct($adapter);}/**** @param AdapterInterface $adapter* @return \LeadersLinked\Mapper\ContentReactionMapper*/public static function getInstance($adapter){if(self::$_instance == null) {self::$_instance = new ContentReactionMapper($adapter);}return self::$_instance;}/**** @param int $feed_id* @return array*/public function fetchCountByFeedId($feed_id){$select = $this->sql->select(self::_TABLE);$select->columns(['total' => new Expression('COUNT(*)'), 'reaction']);$select->where->equalTo('feed_id', $feed_id);$select->where->equalTo('relational', ContentReaction::RELATIONAL_FEED);$select->group('reaction');return $this->executeFetchAllArray($select);}/**** @param int $my_coach_question_id* @return array*/public function fetchCountByMyCoachQuestionId($my_coach_question_id){$selectIn = $this->sql->select(MyCoachAnswerMapper::_TABLE);$selectIn->columns(['id']);$selectIn->where->equalTo('question_id', $my_coach_question_id);$select = $this->sql->select(self::_TABLE);$select->columns(['total' => new Expression('COUNT(*)'), 'reaction']);$select->where->in('my_coach_answer_id', $selectIn);$select->where->equalTo('relational', ContentReaction::RELATIONAL_MY_COACH);//$select->group('reaction');$record = $this->executeFetchOneArray($select);return $record['total'];}/**** @param int $my_coach_answer_id* @return array*/public function fetchCountByMyCoachAnswerId($my_coach_answer_id){$select = $this->sql->select(self::_TABLE);$select->columns(['total' => new Expression('COUNT(*)'), 'reaction']);$select->where->equalTo('my_coach_answer_id', $my_coach_answer_id);$select->where->equalTo('relational', ContentReaction::RELATIONAL_MY_COACH);$record = $this->executeFetchOneArray($select);return $record['total'];}/*public function fetchCountByMyCoachAnswerId($my_coach_answer_id){$select = $this->sql->select(self::_TABLE);$select->columns(['total' => new Expression('COUNT(*)'), 'reaction']);$select->where->equalTo('my_coach_answer_id', $my_coach_answer_id);$select->where->equalTo('relational', ContentReaction::RELATIONAL_MY_COACH);$select->group('reaction');return $this->executeFetchAllArray($select);}*//**** @param int $knowledge_area_id* @return array*/public function fetchCountByKnowledgeAreaId($knowledge_area_id){$select = $this->sql->select(self::_TABLE);$select->columns(['total' => new Expression('COUNT(*)'), 'reaction']);$select->where->equalTo('knowledge_area_id', $knowledge_area_id);$select->where->equalTo('relational', ContentReaction::RELATIONAL_KNOWLEDGE_AREA);$select->group('reaction');return $this->executeFetchAllArray($select);}/**** @param int $post_id* @return array*/public function fetchCountByPostId($post_id){$select = $this->sql->select(self::_TABLE);$select->columns(['total' => new Expression('COUNT(*)'), 'reaction']);$select->where->equalTo('post_id', $post_id);$select->where->equalTo('relational', ContentReaction::RELATIONAL_POST);$select->group('reaction');return $this->executeFetchAllArray($select);}/**** @param int $feed_id* @param int $user_id* @return ContentReaction*/public function fetchOneByFeedIdAndUserId($feed_id, $user_id){$select = $this->sql->select(self::_TABLE);$select->where->equalTo('feed_id', $feed_id);$select->where->equalTo('user_id', $user_id);$select->where->equalTo('relational', ContentReaction::RELATIONAL_FEED);$prototype = new ContentReaction();return $this->executeFetchOneObject($select, $prototype);}/**** @param int $post_id* @param int $user_id* @return ContentReaction*/public function fetchOneByPostIdAndUserId($post_id, $user_id){$select = $this->sql->select(self::_TABLE);$select->where->equalTo('post_id', $post_id);$select->where->equalTo('user_id', $user_id);$select->where->equalTo('relational', ContentReaction::RELATIONAL_POST);$prototype = new ContentReaction();return $this->executeFetchOneObject($select, $prototype);}/**** @param int $my_coach_answer_id* @param int $user_id* @return ContentReaction*/public function fetchOneByMyCoachAnswerIdAndUserId($my_coach_answer_id, $user_id){$select = $this->sql->select(self::_TABLE);$select->where->equalTo('my_coach_answer_id', $my_coach_answer_id);$select->where->equalTo('user_id', $user_id);$select->where->equalTo('relational', ContentReaction::RELATIONAL_MY_COACH);$prototype = new ContentReaction();return $this->executeFetchOneObject($select, $prototype);}/**** @param int $knowledge_area_id* @param int $user_id* @return ContentReaction*/public function fetchOneByKnowledgeAreaIdAndUserId($knowledge_area_id, $user_id){$select = $this->sql->select(self::_TABLE);$select->where->equalTo('knowledge_area_id', $knowledge_area_id);$select->where->equalTo('user_id', $user_id);$select->where->equalTo('relational', ContentReaction::RELATIONAL_KNOWLEDGE_AREA);$prototype = new ContentReaction();return $this->executeFetchOneObject($select, $prototype);}/**** @param int $feed_id* @param int $user_id* @return boolean*/public function deleteByFeedIdAndUserId($feed_id, $user_id){$delete = $this->sql->delete(self::_TABLE);$delete->where->equalTo('feed_id', $feed_id);$delete->where->equalTo('user_id', $user_id);$delete->where->equalTo('relational', ContentReaction::RELATIONAL_FEED);return $this->executeDelete($delete);}/**** @param int $knowledge_area_id* @param int $user_id* @return boolean*/public function deleteByKnowledgeAreaIdAndUserId($knowledge_area_id, $user_id){$delete = $this->sql->delete(self::_TABLE);$delete->where->equalTo('knowledge_area_id', $knowledge_area_id);$delete->where->equalTo('user_id', $user_id);$delete->where->equalTo('relational', ContentReaction::RELATIONAL_KNOWLEDGE_AREA);return $this->executeDelete($delete);}/**** @param int $my_coach_answer_id* @param int $user_id* @return boolean*/public function deleteByByMyCoachAnswerId($my_coach_answer_id, $user_id){$delete = $this->sql->delete(self::_TABLE);$delete->where->equalTo('my_coach_answer_id', $my_coach_answer_id);$delete->where->equalTo('user_id', $user_id);$delete->where->equalTo('relational', ContentReaction::RELATIONAL_MY_COACH);return $this->executeDelete($delete);}/**** @param int $post_id* @param int $user_id* @return boolean*/public function deleteByPostIdAndUserId($post_id, $user_id){$delete = $this->sql->delete(self::_TABLE);$delete->where->equalTo('post_id', $post_id);$delete->where->equalTo('user_id', $user_id);$delete->where->equalTo('relational', ContentReaction::RELATIONAL_POST);return $this->executeDelete($delete);}/**** @param ContentReaction $contentReaction* @return boolean*/public function insert($contentReaction){$hydrator = new ObjectPropertyHydrator();$values = $hydrator->extract($contentReaction);$values = $this->removeEmpty($values);$insert = $this->sql->insert(self::_TABLE);$insert->values($values);$response = $this->executeInsert($insert);if($response) {$contentReaction->id = $this->getLastInsertId();}return $response;}/**** @param ContentReaction $contentReaction* @return boolean*/public function update($contentReaction){$hydrator = new ObjectPropertyHydrator();$values = $hydrator->extract($contentReaction);$values = $this->removeEmpty($values);$update = $this->sql->update(self::_TABLE);$update->set($values);$update->where->equalTo('id', $contentReaction->id);return $this->executeUpdate($update);}}