summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/comment/controllers/comments.php2
-rw-r--r--modules/comment/helpers/comment.php21
-rw-r--r--modules/comment/helpers/comment_installer.php2
-rw-r--r--modules/comment/tests/Comment_Helper_Test.php15
-rw-r--r--modules/comment/views/comment.html.php6
5 files changed, 15 insertions, 31 deletions
diff --git a/modules/comment/controllers/comments.php b/modules/comment/controllers/comments.php
index 773eb25a..434aa36f 100644
--- a/modules/comment/controllers/comments.php
+++ b/modules/comment/controllers/comments.php
@@ -45,7 +45,7 @@ class Comments_Controller extends REST_Controller {
$comment->author = $this->input->post('author');
$comment->email = $this->input->post('email');
$comment->text = $this->input->post('text');
- $comment->datetime = time();
+ $comment->created = time();
$comment->item_id = $this->input->post('item_id');
$comment->save();
diff --git a/modules/comment/helpers/comment.php b/modules/comment/helpers/comment.php
index 2a742b70..7695cadb 100644
--- a/modules/comment/helpers/comment.php
+++ b/modules/comment/helpers/comment.php
@@ -36,20 +36,15 @@ class comment_Core {
* @param string $email author's email
* @param string $text comment body
* @param integer $item_id id of parent item
- * @param integer $datetime optional comment date and time in Unix format
* @return Comment_Model
*/
- static function create($author, $email, $text, $item_id, $datetime=NULL) {
- if (is_null($datetime)) {
- $datetime = time();
- }
-
+ static function create($author, $email, $text, $item_id) {
$comment = ORM::factory("comment");
$comment->author = $author;
$comment->email = $email;
$comment->text = $text;
- $comment->datetime = $datetime;
$comment->item_id = $item_id;
+ $comment->created = time();
$comment->save();
module::event("comment_created", $comment);
@@ -111,7 +106,7 @@ class comment_Core {
// @todo Set proper Content-Type in a central place (REST_Controller::dispatch?).
static function get_comments($item_id) {
$comments = ORM::factory('comment')->where('item_id', $item_id)
- ->orderby('datetime', 'asc')
+ ->orderby('created', 'asc')
->find_all();
if (!$comments->count()) {
@@ -151,7 +146,7 @@ class comment_Core {
public static function get_atom_entry($comment) {
$feed = new Gallery_Atom_Entry();
- $feed->updated($comment->datetime)
+ $feed->updated($comment->created)
->title(sprintf(_("Comment #%d"), $comment->id))
->content($comment->text)
->author()
@@ -169,7 +164,7 @@ class comment_Core {
* @todo Put proper user ID into author URI.
*/
public static function get_atom_feed($comments) {
- $latest_comment = $comments[0]->datetime;
+ $latest_comment = $comments[0]->created;
$item_id = $comments[0]->item_id;
/* Set up feed header. */
@@ -183,7 +178,7 @@ class comment_Core {
foreach ($comments as $id => $comment) {
$feed->entry()
->id(url::abs_site("comments/$comment->id"))
- ->updated($comment->datetime)
+ ->updated($comment->created)
->title(sprintf(_("Comment #%d"), $comments->count() - $id))
->content($comment->text)
->author()
@@ -213,8 +208,8 @@ class comment_Core {
$elapsed_days = round($time_difference / comment::SECONDS_IN_A_DAY);
$elapsed_months = round($time_difference / comment::SECONDS_IN_A_MONTH);
$elapsed_years = round($time_difference / comment::SECONDS_IN_A_YEAR);
- $seconds_since_midnight = $date_info_now['hours'] * comment::SECONDS_IN_AN_HOUR
- + $date_info_now['minutes'] * comment::SECONDS_IN_A_MINUTE + $date_info_now['seconds'];
+ $seconds_since_midnight = $date_info_now['hours'] * comment::SECONDS_IN_AN_HOUR +
+ $date_info_now['minutes'] * comment::SECONDS_IN_A_MINUTE + $date_info_now['seconds'];
/* Construct message depending on how much time passed. */
if ($elapsed_years > 0) {
diff --git a/modules/comment/helpers/comment_installer.php b/modules/comment/helpers/comment_installer.php
index 8310c6e1..be8b2a14 100644
--- a/modules/comment/helpers/comment_installer.php
+++ b/modules/comment/helpers/comment_installer.php
@@ -28,7 +28,7 @@ class comment_installer {
`author` varchar(255) default NULL,
`email` varchar(255) default NULL,
`text` text,
- `datetime` int(9) NOT NULL,
+ `created` int(9) NOT NULL,
`item_id` int(9) NOT NULL,
PRIMARY KEY (`id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
diff --git a/modules/comment/tests/Comment_Helper_Test.php b/modules/comment/tests/Comment_Helper_Test.php
index 74f784b2..a4dbb88a 100644
--- a/modules/comment/tests/Comment_Helper_Test.php
+++ b/modules/comment/tests/Comment_Helper_Test.php
@@ -26,22 +26,11 @@ class Comment_Helper_Test extends Unit_Test_Case {
$this->assert_equal($rand, $comment->email);
$this->assert_equal($rand, $comment->text);
$this->assert_equal($rand, $comment->item_id);
- $this->assert_equal($rand, $comment->datetime);
- }
-
- public function create_comment_using_current_time_test() {
- $rand = rand();
- $comment = comment::create($rand, $rand, $rand, $rand);
-
- $this->assert_equal($rand, $comment->author);
- $this->assert_equal($rand, $comment->email);
- $this->assert_equal($rand, $comment->text);
- $this->assert_equal($rand, $comment->item_id);
- $this->assert_true($comment->datetime > time() - 10 && $comment->datetime <= time());
+ $this->assert_true(!empty($comment->created));
}
public function format_elapsed_time_test() {
- /* This test could be improved by using random numbers and specifically testing corner cases. */
+ // This test could be improved by using random numbers and specifically testing corner cases.
$now = time();
$yesterday = $now - comment::SECONDS_IN_A_DAY;
diff --git a/modules/comment/views/comment.html.php b/modules/comment/views/comment.html.php
index 2b306404..4cd1663c 100644
--- a/modules/comment/views/comment.html.php
+++ b/modules/comment/views/comment.html.php
@@ -2,10 +2,10 @@
<li id="gComment-<?= $comment->id; ?>">
<p>
<a href="#" class="gAuthor"><?= $comment->author ?></a>
- <?= comment::format_elapsed_time($comment->datetime) ?>,
- <span class="gUnderstate"><?= strftime('%c', $comment->datetime) ?></span>
+ <?= comment::format_elapsed_time($comment->created) ?>,
+ <span class="gUnderstate"><?= strftime('%c', $comment->created) ?></span>
</p>
<div>
- <?= $comment->text ?>
+ <?= $comment->text ?>
</div>
</li>