[Isocial-svn] SF.net SVN: isocial: [50] app
Status: Pre-Alpha
Brought to you by:
aguidrevitch
From: <di...@us...> - 2008-03-09 13:53:18
|
Revision: 50 http://isocial.svn.sourceforge.net/isocial/?rev=50&view=rev Author: dim0s77 Date: 2008-03-09 06:53:21 -0700 (Sun, 09 Mar 2008) Log Message: ----------- added reading message after his opening by recipient Modified Paths: -------------- app/controllers/message_controller.php app/views/message/_rows.tpl Modified: app/controllers/message_controller.php =================================================================== --- app/controllers/message_controller.php 2008-03-09 13:06:23 UTC (rev 49) +++ app/controllers/message_controller.php 2008-03-09 13:53:21 UTC (rev 50) @@ -9,45 +9,30 @@ } function inbox () { - $this->inbox_messages = $this->_getInboxMessages(); + $this->inbox_messages = $this->_getBoxMessages('inbox_message'); $this->message_threads = $this->Message->count('thread_id', array('distinct' => 'thread_id', 'conditions' => "sender_id = " . $this->current_user->getId())); } - - function _getInboxMessages () { - $messages = $this->current_user->inbox_message->load(); - $inbox_messages = array(); - if(!empty($messages)) { - foreach ($messages as $message_loop_key => $message) { - if (isset($inbox_messages[$message->thread_id])) { - if ($inbox_messages[$message->thread_id]->id < $message->id) { - $inbox_messages[$message->thread_id] = $message; - } - } else { - $inbox_messages[$message->thread_id] = $message; - } - } - } - return $inbox_messages; + + function outbox () { + $this->outbox_messages = $this->_getBoxMessages('outbox_message'); + $this->message_threads = $this->Message->count('thread_id', array('distinct' => 'thread_id', + 'conditions' => "recipient_id = " . $this->current_user->getId())); } - function outbox () { - $messages = $this->current_user->outbox_message->load(); - $outbox_messages = array(); + function _getBoxMessages ($box_message) { + $messages = $this->current_user->$box_message->load(); + $box_messages = array(); if(!empty($messages)) { foreach ($messages as $message_loop_key => $message) { - if (isset($outbox_messages[$message->thread_id])) { - if ($outbox_messages[$message->thread_id]->id < $message->id) { - $outbox_messages[$message->thread_id] = $message; - } - } else { - $outbox_messages[$message->thread_id] = $message; + if (!isset($inbox_messages[$message->thread_id])) { + $box_messages[$message->thread_id] = $message; } } } - $this->outbox_messages = $outbox_messages; + return $box_messages; } - + function send () { if (!empty($this->params['message']) && !empty($this->params['message']['recipient']) && @@ -57,10 +42,9 @@ $message = $this->current_user->outbox_message->build(); $message->setAttributes($this->params['message']); $message->recipient->assign($recipient); - if (empty($message->subject)) { - $message->subject = $this->t('(no subject)'); - } - + if (empty($message->subject)) { + $message->subject = $this->t('(no subject)'); + } if ($message->save()) { if (!$message->thread_id) { $message->thread_id = $message->getId(); @@ -96,7 +80,7 @@ 'include' => array('sender', 'recipient'))); return $this->render(array('partial' =>'thread', 'locals' => array('interlocutor' => $interlocutor, - 'messages' => $messages))); + 'messages' => $messages))); } } } @@ -113,9 +97,18 @@ if ($thread->sender_id == $user_id || $thread->recipient_id == $user_id ) { $recipient_id = $thread->sender_id == $user_id ? $thread->recipient_id : $thread->sender_id; $this->interlocutor = $this->User->findFirst(array( 'id' => $recipient_id)); - $this->messages = $this->Message->find('all', array('conditions' => array('thread_id' => $thread->getId()), - 'order' => 'created_at', - 'include' => array('sender', 'recipient'))); + $messages = $this->Message->find('all', array('conditions' => array('thread_id' => $thread->getId()), + 'order' => 'created_at', + 'include' => array('sender', 'recipient'))); + if(!empty($messages)) { + foreach ($messages as $message_loop_key => $message) { + if ($message->recipient_id == $this->current_user->getId()) { + $message->is_read = 1; + $message->save(); + } + } + } + $this->messages = $messages; return; } } Modified: app/views/message/_rows.tpl =================================================================== --- app/views/message/_rows.tpl 2008-03-09 13:06:23 UTC (rev 49) +++ app/views/message/_rows.tpl 2008-03-09 13:53:21 UTC (rev 50) @@ -7,9 +7,9 @@ <? if ($target == 'sender') { echo '<a href="">'; if (!$message->is_read) { - echo '<img src="/images/email.png" alt="_{New message}" class="">'; + echo '<img src="/images/email.png" alt="' . $text_helper->translate("New message", array()) . '">'; } else { - echo '<img src="/images/email_open.png" alt="_{Message is readed}" class="">'; + echo '<img src="/images/email_open.png" alt="' . $text_helper->translate("Message is read", array()) . '">'; } echo '</a>'; } else { @@ -20,7 +20,7 @@ <td class="checkbox"><input onclick="oncheck(this, {?message.is_read}{message.is_read}{else}0{end})" type="checkbox" class="check{?message.is_read}read{else}unread{end}" id="{message.id}" name="check_messages[]" value="{message.id}"></td> <td class="profile_photo"><a href=""><img src="/images/nophoto_men_sm.gif" alt="" class=""></a></td> <td class="info"> - <span class="name"><a href="">{sender.name?}</a></span> + <span class="name"><a href=""><? if ($target == 'recipient') { ?>_{To}: <? } ?>{sender.name?}</a></span> <span class="datetime">{message.created_at?}</span> </td> <td class="msg"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |