/** * Mark comment as removed * * @param Comment $comment * * @return Comment */ public function remove($comment) { $comment->setStatus('deleted'); $this->em->flush(); $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache'); $cacheService->clearNamespace('comment'); return $comment; }
/** * Add to notification * * @return unknown_type */ public function addComment(Comment $comment) { $notification = $this->getPrototype(); // set content of the notification $content = array(); $content[Notification::COMMENT_NAME] = $comment->getCommenterName(); $content[Notification::COMMENT_EMAIL] = $comment->getCommenterEmail(); $content[Notification::COMMENT_IP] = $comment->getIp(); $content[Notification::COMMENT_SUBJECT] = $comment->getSubject(); $content[Notification::COMMENT_MESSAGE] = $comment->getMessage(); $content[Notification::COMMENT_PUBLICATION] = $comment->getPublicationId(); //serialize the content $notification->setContent(serialize($content)); $notification->setType(Notification::TYPE_COMMENT); $notification->setStatus(Notification::STATUS_PENDING); $this->getEntityManager()->persist($notification); $this->flush(); }
public function getProperty($p_key) { $this->__load(); return parent::getProperty($p_key); }
/** * Check if the comment is the same as this one * * @param Comment $p_comment * @return bool * @deprecated legacy from frontend controllers */ public function SameAs($p_comment) { return $p_comment->getId() == $this->getId(); }
/** * Method for saving a comment * * @param Comment $entity * @param array $values * * @return Comment */ public function save(Comment $entity, $values) { $values += array('recommended' => false); $em = $this->getEntityManager(); $commenterRepository = $em->getRepository('Newscoop\\Entity\\Comment\\Commenter'); $commenter = new Commenter(); $commenter = $commenterRepository->save($commenter, $values); $entity->setCommenter($commenter)->setSubject($values['subject'])->setMessage($values['message'])->setStatus($values['status'])->setIp($values['ip'])->setTimeCreated($values['time_created'])->setRecommended($values['recommended']); if (array_key_exists('source', $values)) { $entity->setSource($values['source']); } $threadLevel = 0; if (!empty($values['parent']) && 0 != $values['parent']) { $parent = $this->find($values['parent']); // set parent of the comment $entity->setParent($parent)->setLanguage($parent->getLanguage())->setForum($parent->getForum())->setThread($parent->getThread()); /** * get the maximum thread order from the current parent */ $qb = $this->createQueryBuilder('c'); $threadOrder = $qb->select('MAX(c.thread_order)')->andwhere('c.parent = :parent')->andWhere('c.thread = :thread')->andWhere('c.language = :language')->setParameter('parent', $parent)->setParameter('thread', $parent->getThread()->getId())->setParameter('language', $parent->getLanguage()->getId()); $threadOrder = $threadOrder->getQuery()->getSingleScalarResult(); // if the comment parent doesn't have children then use the parent thread order if (empty($threadOrder)) { $threadOrder = $parent->getThreadOrder(); } $threadOrder += 1; /** * update all the comment for the thread where thread order is less or equal * of the current thread_order */ $qb = $this->createQueryBuilder('c'); $qb->update()->set('c.thread_order', 'c.thread_order+1')->andwhere('c.thread_order >= :thread_order')->andWhere('c.thread = :thread')->andWhere('c.language = :language')->setParameter('language', $parent->getLanguage()->getId())->setParameter('thread', $parent->getThread()->getId())->setParameter('thread_order', $threadOrder); $qb->getQuery()->execute(); // set the thread level the thread level of the parent plus one the current level $threadLevel = $parent->getThreadLevel() + 1; } else { $languageRepository = $em->getRepository('Newscoop\\Entity\\Language'); if (is_numeric($values['language'])) { $language = $languageRepository->findOneById($values['language']); } else { $language = $languageRepository->findOneByCode($values['language']); } $articleRepository = $em->getRepository('Newscoop\\Entity\\Article'); $thread = $articleRepository->find(array('number' => $values['thread'], 'language' => $language->getId())); $query = $this->createQueryBuilder('c')->select('MAX(c.thread_order)')->where('c.thread = :thread')->andWhere('c.language = :language')->setParameter('thread', $thread->getNumber())->setParameter('language', $language->getId())->getQuery(); // increase by one of the current comment $threadOrder = $query->getSingleScalarResult() + 1; $entity->setLanguage($language)->setForum($thread->getPublication())->setThread($thread); } $entity->setThreadOrder($threadOrder)->setThreadLevel($threadLevel); $em->persist($entity); $user = $commenter->getUser(); if ($user instanceof User) { $em->getRepository('Newscoop\\Entity\\User')->setUserPoints($user); } return $entity; }