public function executeTogglePublish() { $comment_id = $this->getRequestParameter('id'); $comment = sfCommentPeer::retrieveByPk($comment_id); $this->forward404Unless($comment); // retrieve commentable object from comment $commentable_peer = $comment->getCommentableModel() . 'Peer'; $commentable_id = $comment->getCommentableId(); $commentable_object = call_user_func(array($commentable_peer, 'retrieveByPK'), $commentable_id); // toggle publish state using the behavior API if ($comment->getIsPublic()) { $commentable_object->unpublishComment($comment_id); } else { $commentable_object->publishComment($comment_id); } if ($this->getRequestParameter('from_email') == 1) { $this->comment = $comment; return sfView::SUCCESS; } if ($referer = $this->getRequest()->getReferer()) { $this->redirect($referer); } else { $this->redirect('deppCommentingAdmin/list'); } }
/** * Removes one comment from the object. * * @param BaseObject $object */ public function removeComment(BaseObject $object, $comment_id) { $c = new Criteria(); $c->add(sfCommentPeer::COMMENTABLE_ID, $object->getPrimaryKey()); $c->add(sfCommentPeer::COMMENTABLE_MODEL, get_class($object)); $c->add(sfCommentPeer::ID, $comment_id); return sfCommentPeer::doDelete($c); }
$object1->save(); $object1->addComment('One first comment.'); $object1->addComment('One second comment.'); $object_comments = $object1->getComments(); $nb_object_comments = $object1->getNbComments(); $t->ok($nb_object_comments == count($object_comments) && $nb_object_comments == 2, 'getNbComments() returns the number of comments attached to the object when it has still not been saved.'); $object1->addComment('One third comment.'); $object1->save(); $object_comments = $object1->getComments(); $nb_object_comments = $object1->getNbComments(); $t->ok($nb_object_comments == count($object_comments) && $nb_object_comments == 3, 'getNbComments() returns the number of comments attached to the object, when it has been saved also.'); $object1->clearComments(); $t->ok($object1->getNbComments() === 0, 'comments on an object can be cleared using clearComments().'); // these tests check for comments retrieval methods $t->diag('comments retrieval methods'); sfCommentPeer::doDeleteAll(); $object1 = _create_object(); $object1->save(); $object1->addComment('One first comment.'); $object1->addComment('One second comment.'); $asc_comments = $object1->getComments(array('order' => 'asc')); $desc_comments = $object1->getComments(array('order' => 'desc')); $t->ok($asc_comments[0]['Text'] == 'One first comment.' && $asc_comments[1]['Text'] == 'One second comment.' && $desc_comments[1]['Text'] == 'One first comment.' && $desc_comments[0]['Text'] == 'One second comment.', 'comments can be retrieved in a specific order.'); // test count cache, removal publish/unpublish) // default values are used (i.e. the number of public comments is cached) $t->diag('count cache'); $object2 = _create_object(); $object2->save(); $object2->addComment('My first'); $object2->addComment('My second'); $t->ok(call_user_func(array($object2, TEST_CACHE_COUNT_GETTER)) == 2 && call_user_func(array($object2, TEST_CACHE_COUNT_GETTER)) == $object2->getNbComments(), 'count cache is working properly while adding comments.');
public static function retrieveByPKs($pks, $con = null) { if ($con === null) { $con = Propel::getConnection(self::DATABASE_NAME); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(); $criteria->add(sfCommentPeer::ID, $pks, Criteria::IN); $objs = sfCommentPeer::doSelect($criteria, $con); } return $objs; }
/** * Deletes all comments for a commentable object (on delete cascade emulation) * * @param BaseObject $object */ public function preDelete(BaseObject $object) { try { $c = new Criteria(); $c->add(sfCommentPeer::COMMENTABLE_ID, $object->getPrimaryKey()); sfCommentPeer::doDelete($c); } catch (Exception $e) { throw new Exception('Unable to delete comments related to commentable object'); } }
public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = sfCommentPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setCommentableModel($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setCommentableId($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setNamespace($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setTitle($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setText($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setAuthorId($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { $this->setAuthorName($arr[$keys[7]]); } if (array_key_exists($keys[8], $arr)) { $this->setAuthorEmail($arr[$keys[8]]); } if (array_key_exists($keys[9], $arr)) { $this->setCreatedAt($arr[$keys[9]]); } }