[Isocial-svn] SF.net SVN: isocial: [60] app
Status: Pre-Alpha
Brought to you by:
aguidrevitch
From: <agu...@us...> - 2008-03-11 18:57:08
|
Revision: 60 http://isocial.svn.sourceforge.net/isocial/?rev=60&view=rev Author: aguidrevitch Date: 2008-03-11 11:57:11 -0700 (Tue, 11 Mar 2008) Log Message: ----------- number of unread messages is displayed instantly on page load (was ajax update only) Modified Paths: -------------- app/application_controller.php app/controllers/message_controller.php app/models/message.php app/views/shared/loggedin/pageheader.tpl Modified: app/application_controller.php =================================================================== --- app/application_controller.php 2008-03-10 16:47:44 UTC (rev 59) +++ app/application_controller.php 2008-03-11 18:57:11 UTC (rev 60) @@ -19,7 +19,7 @@ var $_errors = array(); - var $models = array('User'); + var $app_models = array('User', 'Message'); var $app_helpers = array('AutoComplete', 'City'); var $current_user; @@ -173,66 +173,9 @@ return "=?utf-8?B?" . base64_encode($value) . "?="; } - - function auto_complete_for_city () { - if (empty($this->params['city'])) { - $this->renderNothing(); - } else { - $query = $this->params['city']; - - $entries = $this->City->find('all', - array('conditions' => - array( - 'first_id IS NOT NULL AND name LIKE ?', $query . '%' - ), - 'include' => 'country', - 'limit' => 10 - ) - ); - - $limit = empty($entries) ? 10 : 10 - count($entries); - if ($limit) { - $aquery = utf8_to_ascii($query); - if ($aquery != $query) { - $asciied = $this->City->find('all', - array('conditions' => - array( - 'first_id IS NOT NULL AND name LIKE ?', $aquery . '%' - ), - 'include' => 'country', - 'limit' => $limit - ) - ); - } - } - - if (empty($entries) && empty($asciied)) { - $entries = array(); - } else if (empty($entries)) { - $entries = $asciied; - } else if (empty($asciied)) { - $entries = $entries; - } else { - $entries = array_merge($entries, $asciied); - } - $this->renderText( $this->city_helper->auto_complete_result($entries, $query) ); - } + function unread_messages_count () { + return $this->current_user ? $this->Message->unread_messages_count($this->current_user->getId()) : 0; } - - function _auto_complete_result ($items, $field, $phrase = '') { - // converting to an array - $entries = array(); - foreach ($items as $item) { - $entry = array(); - foreach ($item->getColumns() as $column => $details) { - $entry[$column] = $item->get($column); - } - $entries[] = $entry; - } - - return $this->javascript_macros_helper->auto_complete_result($entries, $field, $phrase); - } - } ?> Modified: app/controllers/message_controller.php =================================================================== --- app/controllers/message_controller.php 2008-03-10 16:47:44 UTC (rev 59) +++ app/controllers/message_controller.php 2008-03-11 18:57:11 UTC (rev 60) @@ -113,11 +113,7 @@ } function inbox_count () { - if ($this->current_user) { - $count = $this->Message->count('id', array('conditions' => array("recipient_id = ? AND is_read = 0", $this->current_user->getId()))); - return $this->renderText($count); - } - return $this->renderNothing(); + return $this->renderText( $this->unread_messages_count() ); } function mark_unread () { Modified: app/models/message.php =================================================================== --- app/models/message.php 2008-03-10 16:47:44 UTC (rev 59) +++ app/models/message.php 2008-03-11 18:57:11 UTC (rev 60) @@ -5,6 +5,9 @@ var $belongs_to = array('sender' => array('class_name' => 'User', 'primary_key_name' => 'sender_id'), 'recipient' => array('class_name' => 'User', 'primary_key_name' => 'recipient_id')); + function unread_messages_count ( $recipient_id ) { + return $this->count('id', array('conditions' => array("recipient_id = ? AND is_read = 0", $recipient_id))); + } } ?> Modified: app/views/shared/loggedin/pageheader.tpl =================================================================== --- app/views/shared/loggedin/pageheader.tpl 2008-03-10 16:47:44 UTC (rev 59) +++ app/views/shared/loggedin/pageheader.tpl 2008-03-11 18:57:11 UTC (rev 60) @@ -1,7 +1,7 @@ <ul id="headermenuleft"> <li><a class="globallink" href="/profile/">_{Profile}</a> <a href="/profile/basic">_{edit}</a></li> <li><a class="globallink" href="/friend/">_{Friends}</a></li> - <li><a class="globallink" href="/message/">_{Messages} (<span id="messages_count">0</span>)</a></li> + <li><a class="globallink" href="/message/">_{Messages} (<span id="messages_count"><?= $controller->unread_messages_count() ?></span>)</a></li> </ul> <ul id="headermenuright"> <li><a href="/user/logout">_{Logout}</a></li> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |