public function find($id) { $user = parent::find($id); // Add Gravatar $gravatarSize = 80; $user->gravatar = $this->getGravatar($user->email, $gravatarSize); return $user; }
public function findAll($pagekey = null) { if (isset($pagekey)) { $all = $this->query()->where('pagekey = ?')->execute([$pagekey]); return $all; } else { parent::findAll(); } }
/** * Find and return all comments. * * @param int $pageKey is used to get specific page of comments. * * @return array */ public function findAll($pageKey = null) { if (isset($pageKey)) { $this->db->select()->from($this->getSource())->where('pagekey = ?'); $this->db->execute([$pageKey]); $this->db->setFetchModeClass(__CLASS__); return $this->db->fetchAll(); } else { parent::findAll(); } }
/** * Find and return all comments. * * @param int $pageKey is used to get specific page of comments. * * @return array */ public function findAll($key = null, $type = null) { if (isset($key) && isset($type)) { $this->db->select()->from($this->getSource())->where('commentKey = ?')->andWhere('commentType = ?'); $this->db->execute([$key, $type]); $this->db->setFetchModeClass(__CLASS__); return $this->db->fetchAll(); } else { parent::findAll(); } }
/** * Function to find all answers by question ID and sort by * specified value. * * @param integer $idQuestion. * @param string $sortBy the column to sort by. * @param string $prefix the prefix for the database. * * @return object $answer with the results. */ public function findAllAndSort($idQuestion = null, $sortBy = null, $prefix = '') { if (isset($idQuestion)) { $this->db->select($prefix . 'answer.*, coalesce(sum(score), 0) AS score')->from($this->getSource())->where('idQuestion = ?')->leftJoin('score', 'postId = ' . $prefix . 'answer.id AND ' . $prefix . 'score.postType = "answer"')->leftJoin('question', $prefix . 'question.id = idQuestion')->groupBy($prefix . 'answer.id')->orderBy($sortBy . ' DESC'); $this->db->execute([$idQuestion]); $this->db->setFetchModeClass(__CLASS__); return $this->db->fetchAll(); } else { parent::findAll(); } }
/** * Returns the comment with the specified id. * This is an "adapter" for the class in the parent, since * the CommentController class expects an array and not an object. * The model object is still populated with the values from * the database, since this is done in the parent method. * * @return comment as array */ public function find($commentId = null) { return parent::find($commentId)->getProperties(); }