/** * @return array */ public static function loadAll() { $dbWrapper = new DatabaseWrapper(); $connection = $dbWrapper->getConnection(); $query = "SELECT * FROM temos;"; $temos = []; foreach ($connection->query($query) as $row) { $tema = new Tema($connection); $tema->setId($row['id']); $tema->setDate($row['subject_date']); $tema->setName($row['name']); $query = 'SELECT * FROM comments INNER JOIN temos ON comments.subjectId = ' . $row['id'] . " AND temos.id = " . $row['id'] . ";"; $comments = []; foreach ($connection->query($query) as $i) { $comment = new Comment($connection); $comment->setId($i['id']); $comment->setsubjectId($i['subjectId']); $comment->setText($i['text']); $comment->setDate($i['date']); $comment->setAuthor($i['author']); $comments[] = $comment; } foreach ($comments as $comment) { $tema->setComments($comment); } $temos[] = $tema; } return $temos; }
/** * Test * * @return void */ public function testDeleteWithWrongValues() { $configuration = Registry::get('Application')->getConfig(); if ($configuration['db']['driver'] == 'pdo_mysql') { $this->markTestSkipped('Mysql does not thrown exception.'); } $this->setExpectedException('Gc\\Exception'); $this->object->setId('undefined'); $this->assertFalse($this->object->delete()); }
public function testPut() { $comment = new Comment(); $comment->setId(50); $comment->setContent('Très bien'); $comment->setPostDate('2012-12-21 00:00:00'); $comment->setIdUser(1); $comment->setIdAnnouncement(10); $commentMapper = new CommentMapper(); $commentMapper->setId(50); $commentMapper->updateComment($comment); $this->assertEquals($comment, $commentMapper->selectComment()); }
public function findCommentById($id) { $stmt = $this->dtb->prepare('SELECT * FROM comments WHERE postID = :pid'); $stmt->bindValue(':pid', $pid, PDO::PARAM_INT); $stmt->execute(); $data = array(); $um = new PdoUserManager(); $pm = new PdoPostManager(); $d = $stmt->fetch(PDO::FETCH_OBJ); $c = new Comment(); $c->setId($d->id); $c->setBody($d->body); //$c->setPost($pm->findPostById($d->postID)); $c->setUser($um->findUserById($d->userID)); $c->setPublicationDate($d->publicationDate); $data[] = $c; $stmt->closeCursor(); return $data; }
public function recherche($marecherche) { $requete = $this->_db->prepare('select c.comment_id , c.comment , c.note , a.nom , u.first_name , u.name from commentaire c inner join utilisateur u on u.id=c.profile_id inner join article a on a.id=c.article_id where a.nom like "%":search"%";'); $requete->execute(array(':search' => $marecherche)); $results = $requete->fetchAll(); $tabresult = array(); if (empty($results)) { /** Si pas de resultat alors faux */ return false; } else { /** Sinon parcours et stocke dans un tableau les commentaires */ foreach ($results as $result) { $moncommentaire = new Comment(); $moncommentaire->setId($result['comment_id'])->setPid($result['first_name'] . " " . $result['name'])->setComment($result['comment'])->setNote($result['note'])->setArticleid($result['nom']); array_push($tabresult, $moncommentaire); // Push l'objet $article dans le tableau $tabobject } } return $tabresult; }
/** * @param array $data * @return Media */ public function getMedia($data = array()) { $media = new Media(); $media->setId($data["id"])->setLink($data["link"])->setCaptionText(isset($data["caption"]) && isset($data["caption"]["text"]) ? $data["caption"]["text"] : ""); if ($data["type"] == "image") { $media->setType(Media::TYPE_IMAGE); $media->setSource($data["images"]["standard_resolution"]["url"]); } elseif ($data["type"] == "video") { $media->setType(Media::TYPE_VIDEO); $media->setSource($data["videos"]["standard_resolution"]["url"]); } $media->setUser($this->getUserInfo($data["user"])); if (intval($data["comments"]["count"]) > 0) { foreach ($data["comments"]["data"] as $comment) { $createdAt = new \DateTime(); $createdAt->setTimestamp(intval($comment["created_time"])); $commentObj = new Comment(); $commentObj->setId($comment["id"])->setCreatedAt($createdAt)->setText($comment["text"]); $media->addComment($commentObj); } } return $media; }
/** * This function queries all the comments and returns them in an * autocomplete * array if needed. * * @access public * @author k * @param boolean $parameters['forAutocompletion'] * Do we prepare the array * for the autocompletion mechanism? * @param integer $parameters['idParent'] * the ID of the page the * list of page news we want * @return int[] <code>NULL</code>, if there are no order person available * or * the query is erroneous or the array with keys */ public static function getListOfTypeComment($parameters) { $structuredKeys = array(); $keys = array(); $values = array(); foreach (Comment::$rawComments as $id => $array) { if (isset($parameters['idParent']) && $array['idPost'] === $parameters['idParent']) { $object = new Comment(); $object->setId($id); $object->setCompleteComment(); $keys[] = $id; $title = $id; $structuredKeys[$id] = array('id' => $id, 'object' => $object, 'title' => $title); $values[] = $title; } } if (isset($parameters['forAutocompletion']) && $parameters['forAutocompletion']) { $a[] = $values; $a[] = $keys; return $a; } else { return $structuredKeys; } }
/** * Creates and returns a submission comment object from a row * @param $row array * @return Comment object */ function &_returnCommentFromRow($row, $childLevels = 0) { $userDao =& DAORegistry::getDAO('UserDAO'); $comment = new Comment(); $comment->setId($row['comment_id']); $comment->setSubmissionId($row['submission_id']); $comment->setUser($userDao->getUser($row['user_id']), true); $comment->setPosterIP($row['poster_ip']); $comment->setPosterName($row['poster_name']); $comment->setPosterEmail($row['poster_email']); $comment->setTitle($row['title']); $comment->setBody($row['body']); $comment->setDatePosted($this->datetimeFromDB($row['date_posted'])); $comment->setDateModified($this->datetimeFromDB($row['date_modified'])); $comment->setParentCommentId($row['parent_comment_id']); $comment->setChildCommentCount($row['num_children']); if (!HookRegistry::call('CommentDAO::_returnCommentFromRow', array(&$comment, &$row, &$childLevels))) { if ($childLevels > 0) { $comment->setChildren($this->getCommentsByParentId($row['comment_id'], $childLevels - 1)); } else { if ($childLevels == SUBMISSION_COMMENT_RECURSE_ALL) { $comment->setChildren($this->getCommentsByParentId($row['comment_id'], SUBMISSION_COMMENT_RECURSE_ALL)); } } } return $comment; }
public function getComment($selectResult) { $comment = new Comment(); while ($list = mysqli_fetch_assoc($selectResult)) { $comment->setId($list['com_comment_id']); $comment->setText($list['com_text']); $comment->setRatingId($list['com_rating_id']); $comment->setCreatedBy($list['com_created_by']); $comment->setEntryId($list['com_entry_id']); } //end while return $comment; }
public function loadComments($survey, $arrayComments){ /* TODO START */ /* TODO END */ $comments = array(); for($i=0; $i < count($arrayComments) ; $i++ ){ $comment = new Comment($arrayComments[$i]['id_survey'],$arrayComments[$i]['message'],$arrayComments[$i]['owner']); $comment->setId($arrayComments[$i]['ID']); $comment->setDate($arrayComments[$i]['date']); $comments[] = $comment; } return $comments; }