Rev 6481 | 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\MyCoachAnswer;use LeadersLinked\Hydrator\ObjectPropertyHydrator;use Laminas\Db\Sql\Expression;class MyCoachAnswerMapper extends MapperCommon{const _TABLE = 'tbl_my_coach_answers';/**** @var MyCoachAnswerMapper*/private static $_instance;/**** @param AdapterInterface $adapter*/private function __construct($adapter){parent::__construct($adapter);}/**** @param AdapterInterface $adapter* @return MyCoachAnswerMapper*/public static function getInstance($adapter){if(self::$_instance == null) {self::$_instance = new MyCoachAnswerMapper($adapter);}return self::$_instance;}/**** @param int $id* @return MyCoachAnswer*/public function fetchOne($id){$select = $this->sql->select(self::_TABLE);$select->where->equalTo('id', $id);$prototype = new MyCoachAnswer();return $this->executeFetchOneObject($select, $prototype);}/**** @param string $uuid* @return MyCoachAnswer*/public function fetchOneByUuid($uuid){$select = $this->sql->select(self::_TABLE);$select->where->equalTo('uuid', $uuid);$prototype = new MyCoachAnswer();return $this->executeFetchOneObject($select, $prototype);}/**** @param int $question_id* @return MyCoachAnswer[]*/public function fetchAllByQuestionId($question_id){$select = $this->sql->select(self::_TABLE);$select->where->equalTo('question_id', $question_id);$prototype = new MyCoachAnswer();return $this->executeFetchAllObject($select, $prototype);}/**** @param int $question_id* @return MyCoachAnswer*/public function fetchOneLastAnswerByQuestionId($question_id){$select = $this->sql->select(self::_TABLE);$select->where->equalTo('question_id', $question_id);$select->order('added_on DESC');$prototype = new MyCoachAnswer();return $this->executeFetchOneObject($select, $prototype);}/**** @param int $my_coach_question_id* @return int*/public function fetchCountByMyCoachQuestionId($my_coach_question_id){$select = $this->sql->select(self::_TABLE);$select->columns(['total' => new Expression('COUNT(*)')]);$select->where->equalTo('question_id', $my_coach_question_id);$record = $this->executeFetchOneArray($select);return $record['total'];}/**** @param int $question_id* @return boolean*/public function deleteAllByQuestionId($question_id ){$delete = $this->sql->delete(self::_TABLE);$delete->where->equalTo('question_id', $question_id);return $this->executeDelete($delete);}/**** @param MyCoachAnswer $record* @return boolean*/public function delete($record){$delete = $this->sql->delete(self::_TABLE);$delete->where->equalTo('id', $record->id);return $this->executeDelete($delete);}/**** @param MyCoachAnswer $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 MyCoachAnswer $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);}}