public function getModel() { $model = new Comment(); $model->setText($this->_data['text']); $model->setStatementId($this->_st->getId()); if ($this->_user->user_id) { $model->setUserId($this->_user->user_id); $model->setUsername($this->_user->name); } else { $model->setUserId(0); $model->setUsername($this->_data['name']); $model->setEmail($this->_data['email']); } $model->setIpAddress($this->_user->ip_address); return $model; }
/** * Test * * @return void */ public function testGetUser() { $user = UserModel::fromArray(array('lastname' => 'User test', 'firstname' => 'User test', 'email' => '*****@*****.**', 'login' => 'test', 'user_acl_role_id' => 1)); $user->setPassword('test'); $user->save(); $this->object->setUserId($user->getId()); $this->assertInstanceOf('Gc\\User\\Model', $this->object->getUser()); $user->delete(); unset($user); }
private function makeComment(CommentFO $fo, $type, $typeId) { $user = Session::get('user'); $comment = new Comment(); $comment->setContent($fo->getComment()); $comment->setType($type); $comment->setTypeId($typeId); $comment->setDate(null); $comment->setUserId($user->getId()); return $comment; }
public function executeAdd() { $comment = new Comment(); $comment->setSnippet(SnippetPeer::retrieveByPk($this->getRequestParameter('id'))); if ($this->getUser()->isAuthenticated()) { $comment->setUserId($this->getUser()->getGuardUser()->getId()); } else { $comment->setName($this->getRequestParameter('name')); $comment->setEmail($this->getRequestParameter('email')); } $comment->setRawBody($this->getRequestParameter('raw_body')); $comment->save(); $this->comment = $comment; }
public static function update($values, $user) { $comment = new Comment(); $comment->setComment(substr($values['comment'], 0, 5000)); if ($values['application_id']) { $comment->setApplicationId($values['application_id']); } if ($values['module_id']) { $comment->setMaduleId($values['module_id']); } if ($values['theme_id']) { $comment->setThemeId($values['theme_id']); } $comment->setUserId($user->getId()); $comment->save(); return $comment; }
/** * @param sfWebRequest $request * @return application/json data */ public function execute($request) { if ($request->getMethod() == \sfWebRequest::GET) { $datas = array('commit' => $request->getParameter('commit'), 'file_id' => $request->getParameter('fileId'), 'position' => $request->getParameter('position'), 'line' => $request->getParameter('line'), 'user_id' => $this->getUser()->getId()); } else { if ($request->getMethod() == \sfWebRequest::POST) { // get the propel connection $con = Propel::getConnection(); $con->beginTransaction(); try { // get the comment arguments parameter $datas = $request->getParameter('comment'); $this->forward404Unless($datas, "Comment arguments not found"); $commit = $datas['commit']; $this->forward404Unless($commit, 'Commit Hash Not Found'); $fileId = $datas['file_id']; $this->forward404Unless($fileId, 'File Id Not Found'); $file = FileQuery::create()->filterById($fileId)->findOne(); $this->forward404Unless($file, 'File Not Found'); $position = $datas['position']; $this->forward404Unless($position, 'Position Line Number Not Found'); $line = $datas['line']; $this->forward404Unless($line, 'Line Number Not Found'); $value = $datas['value']; $this->forward404Unless($value, 'Comment Value Not Found'); // new comment object $lineComment = new Comment(); $lineComment->setUserId($this->getUser()->getId())->setCommit($commit)->setBranchId($file->getBranchId())->setFileId($fileId)->setPosition($position)->setLine($line)->setType(CommentPeer::TYPE_LINE)->setValue($value)->save($con); $lineComment->getBranch()->setReviewRequest(false)->save(); $datas = array_merge($datas, array('form_visible' => false)); $con->commit(); $this->dispatcher->notify(new sfEvent($this, 'notification.comment', array('project-id' => $lineComment->getBranch()->getRepositoryId(), 'type' => 'line', 'object' => $lineComment))); } catch (Exception $e) { $con->rollBack(); throw $e; } } } // returns a json object $this->getResponse()->setContentType('application/json'); return $this->renderText(json_encode(array('html' => $this->getComponent('default', 'commentLine', $datas)))); }
<?php include_once "../configRoot.php"; require_once ROOT_NAME . "/classes/Database.php"; require_once ROOT_NAME . "/classes/Comment.php"; require_once ROOT_NAME . "/includes/checkProfile.php"; if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["comment"])) { $userId = $id; // user's id from a cookie $page = $_POST["page"]; $commentText = $_POST["comment"]; $commentText = htmlentities($commentText); $tweetId = $_POST["tweet_id"]; $db = Database::getInstance(); $conn = $db->getConnection(); $comment = new Comment($conn); $comment->setUserId($id); $comment->setText($commentText); $comment->setTweetId($tweetId); $comment->addToDatabase(); if (strpos($page, "tweet")) { header("location: ../{$page}"); } elseif (strpos($page, "user")) { header("location: ../{$page}"); } else { header("location: ../index.php"); } } else { header("location: ../index.php"); }
/** * Test #17. * The findByHash function returns an object populated with previous * values if a hash for a previous instance is given. * @depends testUpdate * @depends testHashGetInstance */ public function testHashOldInstance() { global $testTripId1, $testCommentId1, $testUserId1; global $testUserId2; // create the object and save it $object = new Comment($testTripId1, $testCommentId1); $object->setUserId($testUserId1); $object->setReferenceId('-test-reference-id-1'); $object->setCommentText('comment text'); $object->setDeleted('N'); $this->assertTrue($object->save()); $this->assertEquals(1, $this->countTestRows()); $old_hash = $object->getHash(); // change values and update the object $object->setUserId($testUserId2); $object->setReferenceId('-test-reference-id-2'); $object->setCommentText('comment text 2'); $object->setDeleted('Y'); $this->assertTrue($object->save()); $this->assertEquals(2, $this->countTestRows()); $new_hash = $object->getHash(); // read the object from the database and confirm that the old // values are returned $object = Comment::findByHash($old_hash); $this->assertNotNull($object); $this->assertEquals($testTripId1, $object->getTripId()); $this->assertEquals($testCommentId1, $object->getCommentId()); $this->assertEquals($testUserId1, $object->getUserId()); $this->assertEquals('-test-reference-id-1', $object->getReferenceId()); $this->assertEquals('comment text', $object->getCommentText()); $this->assertEquals('N', $object->getDeleted()); // read the new object from the database and confirm that the new // values are returned $object = Comment::findByHash($new_hash); $this->assertNotNull($object); $this->assertEquals($testTripId1, $object->getTripId()); $this->assertEquals($testCommentId1, $object->getCommentId()); $this->assertEquals($testUserId2, $object->getUserId()); $this->assertEquals('-test-reference-id-2', $object->getReferenceId()); $this->assertEquals('comment text 2', $object->getCommentText()); $this->assertEquals('Y', $object->getDeleted()); $this->assertEquals($new_hash, $object->getHash()); }
} $commentId = ''; if (isset($data['commentId']) && $data['commentId'] !== '') { $commentId = $data['commentId']; } else { $commentId = Comment::generateCommentId(); } if ($tripId === '' || $commentId === '') { $response = errorResponse(RESPONSE_BAD_REQUEST, 'Need tripId and commentId'); } else { if (!$auth->canPutComment($tripId, $commentId)) { $response = errorResponse(RESPONSE_UNAUTHORIZED); } else { $object = new Comment($tripId, $commentId); if (isset($data['userId'])) { $object->setUserId($data['userId']); } if (isset($data['referenceId'])) { $object->setReferenceId($data['referenceId']); } if (isset($data['commentText'])) { $object->setCommentText($data['commentText']); } if (isset($data['deleted'])) { $object->setDeleted($data['deleted']); } if ($object->save()) { $response = successResponse(); } else { // @codeCoverageIgnoreStart // cannot unit test database errors
session_start(); require_once '../resources/require.php'; // Umożliwia wyśletanie odświeżonej treści strony, po dodaniu komentarza if ($_SERVER['REQUEST_METHOD'] === 'POST') { $_GET['tweet_text'] = $_POST['tweet_text']; } // Tworzy obiekt tweet potrzebny do wyświetlania treści wpisu, który przekierował na tę stronę i dodawania do niego komentarzy $tweet = new Tweet($mysqli); $tweet->setText($_GET['tweet_text']); $tweet->loadFromDB(); // Tworzy nowy komentarz i uzupełnia treść informacji o sukcesie/błędach if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (trim($_POST['comment_text']) != '') { $comment = new Comment($mysqli); $comment->setTweetId($tweet->getId()); $comment->setUserId($_SESSION['user_id']); $comment->setText($_POST['comment_text']); $comment->setCreationDate(date("Y-m-d H:i:s")); if (!$comment->create()) { $info = 'Błąd przy dodawaniu komentarza.'; } else { $info = 'Dodano komentarz.'; } } else { $info = 'Uzupełnij treść komentarza.'; } } ?> <!DOCTYPE html> <html lang="pl-PL">
public function loadAllComments() { $tweetId = $this->id; $conn = $this->connection; $commentsArray = []; $sqlQuery = "SELECT user_id, text FROM comments WHERE tweet_id = {$tweetId} ORDER BY created_at DESC"; $result = $conn->query($sqlQuery); if ($result->num_rows > 0) { while (list($userId, $text) = $result->fetch_array(MYSQLI_NUM)) { $comment = new Comment($conn); $comment->setUserId($userId); $comment->setText($text); $commentsArray[] = $comment; } return $commentsArray; } else { return false; } }
/** * Test #11. SYNCH get an existent object. * @depends testDataWipedBeforeTest * @depends testGetExistent */ public function testSynchGet() { global $synchAuthToken; global $testTripId1; global $testCommentId1; // Create the object and set attributes $object = new Comment($testTripId1, $testCommentId1); $object->setUserId('user'); $object->setReferenceId('-reference-1'); $object->setCommentText('Comment Text'); $object->setDeleted('Y'); // Save the object and confirm a row is added to the database $this->assertTrue($object->save()); $this->assertEquals(1, $this->countTestRows()); $data = array('hash' => $object->getHash()); $result = getApi('synchComment.php', $data, $synchAuthToken); $this->assertEquals(RESPONSE_SUCCESS, $result['resultCode']); $this->assertTrue(isset($result['tripId'])); $this->assertTrue(isset($result['commentId'])); $this->assertTrue(isset($result['created'])); $this->assertTrue(isset($result['updated'])); $this->assertTrue(isset($result['userId'])); $this->assertTrue(isset($result['referenceId'])); $this->assertTrue(isset($result['commentText'])); $this->assertTrue(isset($result['deleted'])); $this->assertTrue(isset($result['hash'])); $this->assertEquals($testTripId1, $result['tripId']); $this->assertEquals($testCommentId1, $result['commentId']); $this->assertEquals($object->getCreated(), $result['created']); $this->assertEquals($object->getUpdated(), $result['updated']); $this->assertEquals('user', $result['userId']); $this->assertEquals('-reference-1', $result['referenceId']); $this->assertEquals('Comment Text', $result['commentText']); $this->assertEquals('Y', $result['deleted']); $this->assertEquals($object->getHash(), $result['hash']); }