public function renderComment(Comment $comm, $template) { $vars = array('id' => $comm->getId(), 'username' => $comm->getUsername(), 'text' => $comm->getText(), 'date' => date('j.m.Y H:i', $comm->getDate()), 'ip' => $comm->getIpAddress()); $user = FrontController::getUser(); $config = FrontController::$config; if (in_array($this->_user->user_group, $config['moder_groups']) || in_array($this->_user->user_id, $config['moders']) || ($user->user_id == $comm->getUserId() && $comm->getUserId() || $user->ip_address == $comm->getIpAddress() && $comm->getDate() > time() - $config['owner_comment_del_time'])) { $blocks['perm_del'] = true; } return $this->render($template, $vars, $blocks); }
public function onNewComment(FrontController $sender, Comment $comment, Statement $st) { $users = $st->getSubscribers(); if ($users) { require_once ST_DIR . '/Classes/Mailer.php'; $mailer = new Mailer(); $vars = array('text' => strip_tags($comment->getText()), 'st_link' => FrontController::getURLByRoute('view', array('id' => $st->getId()), true), 'title' => $st->getTitle(), 'comment_user' => $comment->getUsername()); foreach ($users as $user) { if ($user->user_id == $comment->getUserId() || $user->email == $comment->getEmail()) { continue; } $vars['username'] = $user->name; $vars['unSubscribeLink'] = $this->_getSubscribeLink($user->email, $user->user_id, $st->getId()); $mailer->sendMail('SubscribeNewComment', $user->email, $vars); } } $user = FrontController::getUser(); if (!$user->user_id) { $guest = clone $user; $guest->email = $comment->getEmail(); $guest->name = $comment->getUsername(); $this->_subscribe($st, $guest); } else { $this->_subscribe($st, $user); } }
/** * Ссылка на удаление комментария * * @param Comment $comment */ function link_to_comment_delete($comment, $title = null) { $user = sfContext::getInstance()->getUser(); if ($user->isAuthenticated() && $user->getGuardUser()->getId() == $comment->getUserId() && $comment->hasDeletable()) { return jq_link_to_remote($title ? $title : 'Удалить', array('method' => 'post', 'url' => url_for('comment_delete', $comment), 'success' => 'jQuery("#comment-' . $comment->id . '").remove();', 'confirm' => 'Вы точно хотите удалить свой комментарий?')); } }
public function canPutComment($tripId = '', $commentId = '') { $user = $this->getUser(); if ($user) { $access = $user->getAccess(); if ($access === LEVEL_ADMIN) { // administrator can put all comments return true; } if ($access === LEVEL_VISITOR || $access === LEVEL_CONTRIB) { // visitor and contributor can put their own comments, or // new comments (comments that don't have any user ID) if ($tripId && $commentId) { $object = new Comment($tripId, $commentId); $objectId = $object->getUserId(); return $objectId === '' || $objectId === $user->getUserId(); } } } return false; }
$requestObject->commentPhotoType = null; } if (empty($requestObject->commentText) === true) { throw new InvalidArgumentException("Comment Text cannot be empty", 408); } // perform the actual put or post if ($method === "PUT") { $comment = Comment::getCommentByCommentId($pdo, $commentId); if ($comment === null) { throw new RuntimeException("Comment does not exist", 404); } if ($_SESSION["user"] !== "S" && $_SESSION["user"]->getUserId() !== $comment->getUserId()) { throw new RuntimeException("You may only edit your own comments", 403); } // trailId, userId, browser, createDate, ipAddress, commentPhoto, commentPhotoType, commentText $comment = new Comment($commentId, $comment->getTrailId(), $comment->getUserId(), $comment->getBrowser(), $comment->getCreateDate(), $comment->getIpAddress(), $requestObject->commentPhoto, $requestObject->commentPhotoType, $requestObject->commentText); $comment->update($pdo); $reply->message = "Comment updated OK"; } elseif ($method === "POST") { $comment = new Comment(null, $requestObject->trailId, $_SESSION["user"]->getUserId(), $browser, new DateTime(), $ipAddress, $requestObject->commentPhoto, $requestObject->commentPhotoType, $requestObject->commentText); $comment->insert($pdo); $reply->message = "Comment created OK"; } } elseif ($method === "DELETE") { verifyXsrf(); $comment = Comment::getCommentByCommentId($pdo, $commentId); if ($comment === null) { throw new RuntimeException("Comment does not exist", 404); } $comment->delete($pdo); $reply->message = "Comment deleted OK";
/** * test #14. * Overriding automatic attributes using a future date. Because * a future date is used, the record can no longer be changed after * it was saved. * @depends testSaveEmptyObject * @depends testSetAttributes * @depends testUpdate * @depends testOverrideAutomaticAttributesNewRecord */ public function testOverrideAutomaticAttributesFutureDate() { global $testTripId1, $testCommentId1, $testUserId1; global $testUserId2; // Create the object, which automatically gets the current date $object = new Comment($testTripId1, $testCommentId1); $object->setUserId($testUserId1); $object->setReferenceId('-test-reference-id-1'); $object->setCommentText('comment text'); $object->setDeleted('Y'); $this->assertTrue($object->save()); $this->assertEquals(1, $this->countTestRows()); $originalCreated = $object->getCreated(); $originalUpdated = $object->getUpdated(); $originalHash = $object->getHash(); // Change the object with different values, using a guaranteed // future date for the Created and Updated fields. Note that // the mySQL timestamp values allow for dates up to January 19, // 2038. Select as the future date for this test January 18, 2038 // values after first save are unchanged $object->setCreated('2038-01-18 10:10:10.000000'); $object->setUpdated('2038-01-18 10:10:11.000000'); $object->setUserId($testUserId2); $object->setReferenceId('-test-reference-id-2'); $object->setCommentText('comment text 2'); $object->setDeleted('N'); $object->setHash('future date hash'); // Check the values before saving $this->assertEquals($testTripId1, $object->getTripId()); $this->assertEquals($testCommentId1, $object->getCommentId()); $this->assertEquals('2038-01-18 10:10:10.000000', $object->getCreated()); $this->assertEquals('2038-01-18 10:10:11.000000', $object->getUpdated()); $this->assertEquals($testUserId2, $object->getUserId()); $this->assertEquals('-test-reference-id-2', $object->getReferenceId()); $this->assertEquals('comment text 2', $object->getCommentText()); $this->assertEquals('N', $object->getDeleted()); $this->assertEquals('future date hash', $object->getHash()); // update the record, this adds a row in the database $this->assertTrue($object->save()); $this->assertEquals(2, $this->countTestRows()); // after the update, the information has been saved $this->assertEquals($testTripId1, $object->getTripId()); $this->assertEquals($testCommentId1, $object->getCommentId()); $this->assertEquals('2038-01-18 10:10:10.000000', $object->getCreated()); $this->assertEquals('2038-01-18 10:10:11.000000', $object->getUpdated()); $this->assertEquals($testUserId2, $object->getUserId()); $this->assertEquals('-test-reference-id-2', $object->getReferenceId()); $this->assertEquals('comment text 2', $object->getCommentText()); $this->assertEquals('N', $object->getDeleted()); $this->assertEquals('future date hash', $object->getHash()); // Try to update the record. This will add a row in the database $object->setReferenceId('-test-reference-id-1'); $object->setUserId($testUserId1); $object->setCommentText('comment text 3'); $object->setDeleted('Y'); $this->assertTrue($object->save()); $this->assertEquals(3, $this->countTestRows()); // but the new information is not saved. The previously saved // information cannot be overwritten without manually setting the // updated field. $this->assertEquals($testTripId1, $object->getTripId()); $this->assertEquals($testCommentId1, $object->getCommentId()); $this->assertEquals('2038-01-18 10:10:10.000000', $object->getCreated()); $this->assertEquals('2038-01-18 10:10:11.000000', $object->getUpdated()); $this->assertEquals($testUserId2, $object->getUserId()); $this->assertEquals('-test-reference-id-2', $object->getReferenceId()); $this->assertEquals('comment text 2', $object->getCommentText()); $this->assertEquals('N', $object->getDeleted()); // Note: this will FAIL in the current implementation! //$this->assertEquals('future date hash', $object->getHash()); }
/** * test inserting a comment and and grabbing it by user Id */ public function testGetValidCommentByUserId() { // get the count of rows in the database $numRows = $this->getConnection()->getRowCount("comment"); // create a new comment and insert to mySQL $comment = new Comment(null, $this->trail->getTrailId(), $this->user->getUserId(), $this->VALID_BROWSER, $this->VALID_CREATEDATE, $this->VALID_IPADDRESS, $this->VALID_COMMENTPHOTO, $this->VALID_COMMENTPHOTOTYPE, $this->VALID_COMMENTTEXT); $comment->insert($this->getPDO()); //grab the data from mySQL and make sure it matches expectations $pdoComments = Comment::getCommentByUserId($this->getPDO(), $comment->getUserId()); $this->assertSame($numRows + 1, $this->getConnection()->getRowCount("comment")); foreach ($pdoComments as $pdoComment) { $this->assertSame($pdoComment->getBrowser(), $this->VALID_BROWSER); $this->assertEquals($pdoComment->getCreateDate(), $this->VALID_CREATEDATE); $this->assertSame($pdoComment->getIpAddress(), $this->VALID_IPADDRESS); $this->assertSame($pdoComment->getCommentPhoto(), $this->VALID_COMMENTPHOTO); $this->assertSame($pdoComment->getCommentPhotoType(), $this->VALID_COMMENTPHOTOTYPE); $this->assertSame($pdoComment->getCommentText(), $this->VALID_COMMENTTEXT); } }
/** * Filter the query by a related Comment object * * @param Comment $comment the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return sfGuardUserQuery The current query, for fluid interface */ public function filterByCommentRelatedByUserId($comment, $comparison = null) { if ($comment instanceof Comment) { return $this->addUsingAlias(sfGuardUserPeer::ID, $comment->getUserId(), $comparison); } elseif ($comment instanceof PropelCollection) { return $this->useCommentRelatedByUserIdQuery()->filterByPrimaryKeys($comment->getPrimaryKeys())->endUse(); } else { throw new PropelException('filterByCommentRelatedByUserId() only accepts arguments of type Comment or PropelCollection'); } }
public function __construct(Comment $comment, array $users) { $this->comment = $comment; $this->user = $users[$comment->getUserId()]; }
/** * Test #13. SYNCH request write new object. */ public function testSynchPut() { global $synchAuthToken; global $testTripId1, $testCommentId1; $this->assertEquals(0, $this->countTestRows()); $data = array('tripId' => $testTripId1, 'commentId' => $testCommentId1, 'created' => '2015-10-01', 'updated' => '2015-10-02', 'userId' => 'user', 'referenceId' => '-reference-1', 'commentText' => 'Comment Text', 'deleted' => 'Y', 'hash' => 'forced hash'); $result = putApi('synchComment.php', $data, $synchAuthToken); $this->assertEquals(RESPONSE_SUCCESS, $result['resultCode']); $this->assertEquals(1, $this->countTestRows()); $object = new Comment($testTripId1, $testCommentId1); $this->assertEquals('2015-10-01 00:00:00.000000', $object->getCreated()); $this->assertEquals('2015-10-02 00:00:00.000000', $object->getUpdated()); $this->assertEquals('user', $object->getUserId()); $this->assertEquals('-reference-1', $object->getReferenceId()); $this->assertEquals('Comment Text', $object->getCommentText()); $this->assertEquals("Y", $object->getDeleted()); $this->assertEquals('forced hash', $object->getHash()); }