Permalink
Browse files

Fixed comments not refreshing if user is not authenticated

  • Loading branch information...
1 parent 56cf098 commit 54dcf291ab172ec93b45197231a676f56d187a2d sasuuri committed Oct 20, 2010
Showing with 19 additions and 17 deletions.
  1. +10 −11 application/controllers/AjaxController.php
  2. +2 −3 application/models/Comments.php
  3. +7 −3 www/js/comments.js
View
21 application/controllers/AjaxController.php
@@ -464,17 +464,16 @@ public function getcommentsAction() {
$auth = Zend_Auth::getInstance();
- if ($auth->hasIdentity()) {
- $type = $this->params['type'];
- $id = $this->params['id'];
-
- $comments = new Oibs_Controller_Plugin_Comments($type, $id);
- $newComments = array();
- $newComments = $comments->getNewComments($auth->getIdentity()->user_id);
-
- if (count($newComments) != 0) {
- $this->view->comments = $newComments;
- }
+ $user_id = ($auth->hasIdentity()) ? $auth->getIdentity()->user_id : "0";
+ $type = $this->params['type'];
+ $id = $this->params['id'];
+
+ $comments = new Oibs_Controller_Plugin_Comments($type, $id);
+ $newComments = array();
+ $newComments = $comments->getNewComments($user_id);
+
+ if (count($newComments) != 0) {
+ $this->view->comments = $newComments;
}
}
View
5 application/models/Comments.php
@@ -176,13 +176,12 @@ public function getComments($type, $id, $id_usr, $time) {
->where('type_cmt = ?' , $type)
->order('created_cmt DESC')
;
- //Zend_Debug::dump($select->__toString());
+
if ($time != 0) {
$select->where('created_cmt >= from_unixtime('.$time.') and id_usr != '.$id_usr);
- $select->orWhere('created_cmt > from_unixtime('.$time.') and id_usr = '.$id_usr);
+ if ($id_usr != 0) $select->orWhere('created_cmt > from_unixtime('.$time.') and id_usr = '.$id_usr);
}
$result = $this->fetchAll($select);
- //Zend_Debug::dump($result->toArray()); die;
return $result->toArray();
}
View
10 www/js/comments.js
@@ -73,7 +73,8 @@ function refreshComments(timer) {
$.getJSON(jsMeta.commentUrls[0].getCommentsUrl, function(data) {
if (data != "0") {
$.each(data, function(key, value) {
- addCommentRow(value.id, value.parent, value.commentDiv);
+ var scrollToComment = !timer;
+ addCommentRow(value.id, value.parent, value.commentDiv, scrollToComment);
});
}
});
@@ -91,7 +92,8 @@ function refreshComments(timer) {
* @param div commentrow
* @return
*/
-function addCommentRow(id, parent, div) {
+function addCommentRow(id, parent, div, scrollToComment) {
+ scrollToComment = (typeof(scrollToComment) != 'undefined') ? scrollToComment : false;
target = "";
level = "";
if (parent != 0) {
@@ -110,7 +112,9 @@ function addCommentRow(id, parent, div) {
$("div#content_view_comment_"+id+"_container").removeClass("content_view_comment_container_");
$("div#content_view_comment_"+id+"_container").addClass("content_view_comment_container_" + level);
$("div#content_view_comment_"+id+"_container").effect("highlight", {}, 2000);
- $(window).scrollTop($("div#content_view_comment_"+id+"_container").offset().top);
+ if (scrollToComment) {
+ $(window).scrollTop($("div#content_view_comment_"+id+"_container").offset().top);
+ }
}
/**

0 comments on commit 54dcf29

Please sign in to comment.