Development

Changeset 15064

You must first sign up to be able to contribute.

Changeset 15064

Show
Ignore:
Timestamp:
01/29/09 14:07:38 (4 years ago)
Author:
garak
Message:

refactored sfSocialMessage module

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfSocialPlugin/trunk/README

    r14577 r15064  
    3131Enable modules in you application settings 
    3232 
    33     [php] 
    34     // apps/frontend/config/settings.yml 
    35     // XXX list is not complete. Customize on your needs 
    36     enabled_modules: [default, sfGuardAuth, sfSocialContact, sfSocialMessage] 
     33    [yml] 
     34    # apps/frontend/config/settings.yml 
     35    enabled_modules: [default, sfGuardAuth, sfSocialContact, sfSocialMessage, sfSocialEvent] 
     36    # this list is not complete: customize on your needs 
     37 
    3738 
    3839## Roadmap 
     
    4344The project aims to implement: 
    4445 
    45   * Contact system (aka friends system): search for other users, request 
     46  * **Contact** system (aka friends system): search for other users, request 
    4647    contact, accept/deny contact request, see list of your contacts, 
    4748    categorize contacts in groups, see contacts of other users, 
    4849    see contact shared with other users, see "degrees of separation" 
    4950 
    50   * Message system: send a message, read received messages, reply to a 
     51  * **Message** system: send a message, read received messages, reply to a 
    5152    message. 
    5253 
    53   * Group system: create a group, invite users to join, manage groups. 
     54  * **Group** system: create a group, invite users to join, manage groups. 
    5455 
    55   * Event system: create an event, invite users to partecipate, confirm 
     56  * **Event** system: create an event, invite users to partecipate, confirm 
    5657    partecipation (yes/no/maybe) 
    5758 
    58   * Comment system: write commments, reply to comments. For groups, events 
     59  * **Comment** system: write commments, reply to comments. For groups, events 
    5960    and maybe for something else. 
    6061 
    61   * Notification system: a glue for all other systems. Notify your contacts 
     62  * **Notification** system: a glue for all other systems. Notify your contacts 
    6263    when you do an action (add a contact, create an event, etc.) 
  • plugins/sfSocialPlugin/trunk/config/schema.yml

    r14756 r15064  
    9292    id: ~ 
    9393    user_from: { type: integer, required: true, foreignTable: sf_guard_user, foreignReference: id, onDelete: cascade, onUpdate: cascade } 
    94     user_to: { type: integer, required: true, foreignTable: sf_guard_user, foreignReference: id, onDelete: cascade, onUpdate: cascade } 
    9594    subject: { type: varchar, size: 255, required: true } 
    96     text: { type: longvarchar, required: true } 
    97     read: { type: boolean, default: false } 
     95    text: { type: longvarchar } 
    9896    created_at: ~ 
    9997 
    100   sf_social_message_sent: 
    101     _attributes:    { phpName: sfSocialMessageSent } 
     98  sf_social_message_rcpt: 
     99    _attributes:    { phpName: sfSocialMessageRcpt } 
    102100    id: ~ 
    103     user_from: { type: integer, required: true, foreignTable: sf_guard_user, foreignReference: id, onDelete: cascade, onUpdate: cascade } 
     101    msg_id: { type: integer, required: true, foreignTable: sf_social_message, foreignReference: id, onDelete: cascade, onUpdate: cascade } 
    104102    user_to: { type: integer, required: true, foreignTable: sf_guard_user, foreignReference: id, onDelete: cascade, onUpdate: cascade } 
    105     subject: { type: varchar, size: 255 } 
    106     text: { type: longvarchar } 
    107     created_at: ~ 
     103    read: { type: boolean, default: false } 
  • plugins/sfSocialPlugin/trunk/data/fixtures/03_messages.yml

    r14577 r15064  
    11sfSocialMessage: 
    2   maxmike
     2  from_max
    33    user_from: max 
    4     user_to: mike 
    54    subject: lorem ipsum 
    65    text: dolor sit amet, consectetur adipiscing elit. Sed accumsan laoreet sapien. Maecenas et nisl et mi imperdiet auctor. 
    7   dannyanna
     6  from_danny
    87    user_from: danny 
    9     user_to: anna 
    108    subject: hello pal 
    119    text: Duis aliquam, diam consequat varius condimentum, nulla tortor tincidunt enim, sed faucibus pede ipsum a tortor. Curabitur posuere metus ac nisl. Sed porta feugiat ipsum. 
    12     read: true 
    13   mariomax: 
     10  from_mario: 
    1411    user_from: mario 
    15     user_to: max 
    1612    subject: how do you do? 
    1713    text: are you happy? I'm fine. Hooga appa loopa. Eeny, meeny, miny, moe 
     14  from_luigi: 
     15    user_from: luigi 
     16    subject: a message 
     17    text: a text for a message. Clever, uhu? 
    1818 
    19 sfSocialMessageSent: 
    20   maxmike: 
    21     user_from: max 
     19sfSocialMessageRcpt: 
     20  max_to_mike: 
     21    msg_id: from_max 
    2222    user_to: mike 
    23     subject: lorem ipsum 
    24     text: dolor sit amet, consectetur adipiscing elit. Sed accumsan laoreet sapien. Maecenas et nisl et mi imperdiet auctor. 
    25   dannyanna: 
    26     user_from: danny 
     23  max_to_anna: 
     24    msg_id: from_max 
    2725    user_to: anna 
    28     subject: hello pal 
    29     text: Duis aliquam, diam consequat varius condimentum, nulla tortor tincidunt enim, sed faucibus pede ipsum a tortor. Curabitur posuere metus ac nisl. Sed porta feugiat ipsum. 
    30   mariomax: 
    31     user_from: mario 
     26  danny_to_mike: 
     27    msg_id: from_danny 
     28    user_to: mike 
     29    read: true 
     30  mario_to_max: 
     31    msg_id: from_mario 
    3232    user_to: max 
    33     subject: how do you do? 
    34     text: are you happy? I'm fine. Hooga appa loopa. Eeny, meeny, miny, moe 
     33  luigi_to_max: 
     34    msg_id: from_luigi 
     35    user_to: max 
     36    read: true 
  • plugins/sfSocialPlugin/trunk/lib/form/sfSocialMessageForm.class.php

    r14756 r15064  
    44 * sfSocialMessage form. 
    55 * 
    6  * @package    ##PROJECT_NAME## 
     6 * @package    sfSocialPlugin 
    77 * @subpackage form 
    8  * @author     ##AUTHOR_NAME## 
    9  * @version    SVN: $Id: sfPropelFormTemplate.php 10377 2008-07-21 07:10:32Z dwhittle $ 
     8 * @author     Massimiliano Arione <garakkio@gmail.com> 
    109 */ 
    1110class sfSocialMessageForm extends BasesfSocialMessageForm 
     
    1413  { 
    1514    // hide unuseful fields 
    16     unset($this['created_at'], $this['read']); 
     15    unset($this['created_at']); 
    1716 
    1817    // hide user_id, binding it to current user's id 
    19     $uid = sfContext::getInstance()->getUser()->getAttribute('user_id', '', 'sfGuardSecurityUser'); 
     18    $uid = sfContext::getInstance()->getUser()->getAttribute('user_id', '', 
     19                                                             'sfGuardSecurityUser'); 
    2020    $this->widgetSchema['user_from'] = new sfWidgetFormInputHidden(); 
    2121    $this->setDefault('user_from', $uid); 
    22     $this->setValidator('user_from', new sfValidatorChoice(array('choices' => array($uid)))); 
     22    $this->setValidator('user_from', 
     23                        new sfValidatorChoice(array('choices' => array($uid)))); 
     24 
     25    // add recipients field 
     26    $this->widgetSchema['to'] = new sfWidgetFormPropelChoiceMany(array('model' => 'sfGuardUser', 
     27                                                                       'add_empty' => false)); 
     28    $this->setValidator('to', 
     29                        new sfValidatorPropelChoiceMany(array('model' => 'sfGuardUser', 
     30                                                              'column' => 'id'))); 
    2331  } 
    2432} 
  • plugins/sfSocialPlugin/trunk/lib/model/sfSocialEventInvitePeer.php

    r14756 r15064  
    2323    $pager->setPeerMethod('doSelectJoinAllExceptsfGuardUserRelatedByUserFrom'); 
    2424    #$pager->setPeerMethod('doSelectJoinAll'); 
     25    #$pager->setPeerMethod('doSelectJoinAllExceptinvited'); 
    2526    $pager->setPage($page); 
    2627    $pager->init(); 
  • plugins/sfSocialPlugin/trunk/lib/model/sfSocialMessage.php

    r14717 r15064  
    55 
    66  /** 
    7    * check if message is belonging to user 
     7   * check if user is in message's recipients 
    88   * @param  sfGuardUser $user 
    99   * @return boolean 
     
    1111  public function checkUserTo($user) 
    1212  { 
    13     return $this->getUserTo() == $user->getId(); 
     13    $rcpts = $this->getsfSocialMessageRcpts(); 
     14    foreach ($rcpts as $rcpt) 
     15    { 
     16      if ($rcpt->getUserTo() == $user->getId()) 
     17      { 
     18        return true; 
     19      } 
     20    } 
     21    return false; 
     22  } 
     23 
     24  /** 
     25   * check if user is message's sender 
     26   * @param  sfGuardUser $user 
     27   * @return boolean 
     28   */ 
     29  public function checkUserFrom($user) 
     30  { 
     31    return $this->getUserFrom() == $user->getId(); 
    1432  } 
    1533 
    1634  /** 
    1735   * mark message as read 
     36   * @param  sfGuardUser $user 
    1837   */ 
    19   public function read(
     38  public function read($user
    2039  { 
    21     $this->setRead(true); 
    22     $this->save(); 
     40    $rcpts = $this->getsfSocialMessageRcpts(); 
     41    foreach ($rcpts as $rcpt) 
     42    { 
     43      if ($rcpt->getUserTo() == $user->getId()) 
     44      { 
     45        $rcpt->setRead(true); 
     46        $rcpt->save(); 
     47      } 
     48    } 
     49  } 
     50 
     51  /** 
     52   * get message recipients' user names 
     53   * @return boolean 
     54   */ 
     55  public function getRcptUsers() 
     56  { 
     57    $rcpts = $this->getsfSocialMessageRcpts(); 
     58    foreach ($rcpts as $rcpt) 
     59    { 
     60      if ($rcpt->getUserTo() == $user->getId()) 
     61      { 
     62        return true; 
     63      } 
     64    } 
     65    return false; 
    2366  } 
    2467 
     
    3477  } 
    3578 
     79  /** 
     80   * save rcpt objects for message 
     81   * @param array $rcpts 
     82   */ 
     83  public function send($rcpts) 
     84  { 
     85    foreach ($rcpts as $user_to) 
     86    { 
     87      $rcpt = new sfSocialMessageRcpt; 
     88      $rcpt->setsfSocialMessage($this); 
     89      $rcpt->setUserTo($user_to); 
     90      $rcpt->save(); 
     91    } 
     92  } 
     93 
    3694} 
  • plugins/sfSocialPlugin/trunk/lib/model/sfSocialMessagePeer.php

    r14717 r15064  
    33class sfSocialMessagePeer extends BasesfSocialMessagePeer 
    44{ 
    5  
    6   /** 
    7    * get messages received by user 
    8    * @param  sfGuardUser   $user 
    9    * @param  integer       $page  current page 
    10    * @param  integer       $n     max per page 
    11    * @return sfPropelPager 
    12    */ 
    13   public static function getUserMessages(sfGuardUser $user, $page = 1, $n = 10) 
    14   { 
    15     $c = new Criteria(); 
    16     $c->add(self::USER_TO, $user->getId()); 
    17     $c->addDescendingOrderByColumn(self::CREATED_AT); 
    18     $pager = new sfPropelPager('sfSocialMessage', $n); 
    19     $pager->setCriteria($c); 
    20     $pager->setPeerMethod('doSelectJoinsfGuardUserRelatedByUserTo'); 
    21     $pager->setPage($page); 
    22     $pager->init(); 
    23     return $pager; 
    24   } 
    25  
    26   /** 
    27    * get messages sent by user 
    28    * @param  sfGuardUser   $user 
    29    * @param  integer       $page  current page 
    30    * @param  integer       $n     max per page 
    31    * @return sfPropelPager 
    32    */ 
    33   public static function getUserSentMessages(sfGuardUser $user, $page = 1, $n = 10) 
    34   { 
    35     $c = new Criteria(); 
    36     $c->add(self::USER_FROM, $user->getId()); 
    37     $c->addDescendingOrderByColumn(self::CREATED_AT); 
    38     $pager = new sfPropelPager('sfSocialMessage', $n); 
    39     $pager->setCriteria($c); 
    40     $pager->setPeerMethod('doSelectJoinsfGuardUserRelatedByUserFrom'); 
    41     $pager->setPage($page); 
    42     $pager->init(); 
    43     return $pager; 
    44   } 
    45  
    46   /** 
    47    * get number of unread messages of user 
    48    * @param  sfGuardUser   $user 
    49    * @return integer 
    50    */ 
    51   public static function countUnreadMessages(sfGuardUser $user) 
    52   { 
    53     $c = new Criteria(); 
    54     $c->add(self::USER_TO, $user->getId()); 
    55     $c->add(self::READ, false); 
    56     return self::doCount($c); 
    57   } 
    58  
    595} 
  • plugins/sfSocialPlugin/trunk/modules/sfSocialMessage/lib/BasesfSocialMessageActions.class.php

    r14717 r15064  
    1111{ 
    1212 
     13  public function preExecute() 
     14  { 
     15    $this->user = $this->getUser()->getGuardUser(); 
     16  } 
     17 
    1318 /** 
    1419  * List of received messages 
     
    1722  public function executeList(sfWebRequest $request) 
    1823  { 
    19     $page = $request->getParameter('page'); 
    20     $this->pager = sfSocialMessagePeer::getUserMessages($this->getUser()->getGuardUser(), $page); 
    21     $this->unread = sfSocialMessagePeer::countUnreadMessages($this->getUser()->getGuardUser()); 
     24    $this->pager = sfSocialMessageRcptPeer::getUserMessages($this->user, 
     25                                                            $request->getParameter('page')); 
     26    $this->unread = sfSocialMessageRcptPeer::countUnreadMessages($this->user); 
    2227  } 
    2328 
     
    2833  public function executeSentlist(sfWebRequest $request) 
    2934  { 
    30     $page = $request->getParameter('page'); 
    31     $this->pager = sfSocialMessagePeer::getUserSentMessages($this->getUser()->getGuardUser(), $page); 
     35    $this->pager = sfSocialMessageRcptPeer::getUserSentMessages($this->user, 
     36                                                                $request->getParameter('page')); 
    3237  } 
    3338 
     
    3843  public function executeRead(sfWebRequest $request) 
    3944  { 
    40     $id = $request->getParameter('id'); 
    41     $this->forward404Unless($id, 'id not passed'); 
    42     $this->message = sfSocialMessagePeer::retrieveByPK($id); 
     45    $this->message = sfSocialMessagePeer::retrieveByPK($request->getParameter('id')); 
    4346    $this->forward404Unless($this->message, 'message not found'); 
    44     $this->forward404Unless($this->message->checkUserTo($this->getUser()->getGuardUser()), 
     47    $this->rcpts = $this->message->getsfSocialMessageRcpts(); 
     48    $this->forward404Unless($this->message->checkUserTo($this->user), 
    4549                            'unauthorized'); 
    46     $this->message->read(); 
     50    $this->message->read($this->user); 
    4751  } 
    4852 
     
    5357  public function executeSentread(sfWebRequest $request) 
    5458  { 
    55     $id = $request->getParameter('id'); 
    56     $this->forward404Unless($id, 'id not passed'); 
    57     $this->message = sfSocialMessageSentPeer::retrieveByPK($id); 
     59    $this->message = sfSocialMessagePeer::retrieveByPK($request->getParameter('id')); 
    5860    $this->forward404Unless($this->message, 'message not found'); 
    59     $this->forward404Unless($this->message->checkUserFrom($this->getUser()->getGuardUser()), 
     61    $this->forward404Unless($this->message->checkUserFrom($this->user), 
    6062                            'unauthorized'); 
     63    $this->rcpts = $this->message->getsfSocialMessageRcpts(); 
    6164  } 
    6265 
     
    7477      $message = sfSocialMessagePeer::retrieveByPK($reply_to); 
    7578      $this->forward404Unless($message, 'message not found'); 
    76       $this->forward404Unless($message->checkUserTo($this->getUser()->getGuardUser()), 
     79      $this->forward404Unless($message->checkUserTo($this->user), 
    7780                              'unauthorized'); 
    78       $this->form->setDefault('user_to', $message->getsfGuardUserRelatedByUserFrom()->getId()); 
     81      $this->form->setDefault('to', $message->getsfGuardUser()->getId()); 
    7982      $this->form->setDefault('subject', $message->getReplySubject()); 
    8083    } 
     
    8386      $values = $request->getParameter('sf_social_message'); 
    8487      $sent = $this->form->bindAndSave($values); 
     88      $msg = $this->form->getObject(); 
     89      $msg->send($values['to']); 
    8590      $this->forwardIf($sent, 'sfSocialMessage', 'sent'); 
    8691    } 
     
    9499  { 
    95100    $values = $request->getParameter('sf_social_message', array()); 
    96     $this->forward404Unless($values['user_to'], 'user not found'); 
    97     $to = sfGuardUserPeer::retrieveByPK($values['user_to']); 
    98     $this->to = $to->getUsername(); 
     101    $this->forward404Unless($values['to'], 'users not found'); 
     102    $this->to = sfGuardUserPeer::retrieveByPKs($values['to']); 
    99103  } 
    100104 
  • plugins/sfSocialPlugin/trunk/modules/sfSocialMessage/templates/composeSuccess.php

    r14577 r15064  
    44    <tr> 
    55      <td colspan="2"> 
    6         <input type="submit" /> 
     6        <input type="submit" value="<?php echo __('send') ?>" /> 
    77      </td> 
    88    </tr> 
    99  </table> 
    1010</form> 
     11<?php echo link_to(__('cancel'), '@sf_social_message_list') ?> 
  • plugins/sfSocialPlugin/trunk/modules/sfSocialMessage/templates/listSuccess.php

    r14717 r15064  
    77<?php endif ?> 
    88<ul> 
    9 <?php foreach ($pager->getResults() as $message): ?> 
    10   <li class="<?php echo $message->getRead() ? 'read' : 'unread' ?>"> 
     9<?php foreach ($pager->getResults() as $rcpt): ?> 
     10<?php $message = $rcpt->getSfSocialMessage() ?> 
     11  <li class="<?php echo $rcpt->getRead() ? 'read' : 'unread' ?>"> 
    1112    <?php echo $message->getCreatedAt() ?> 
    1213    * <?php echo link_to($message->getSubject(), '@sf_social_message_read?id=' . $message->getId()) ?> 
    13     - <?php echo __('from') ?> <u><?php echo $message->getsfGuardUserRelatedByUserFrom()->getUsername() ?></u> <!-- TODO user link --> 
     14    - <?php echo __('from') ?> <u><?php echo $message->getsfGuardUser()->getUsername() ?></u> <!-- TODO user link --> 
    1415  </li> 
    1516<?php endforeach ?> 
     
    2122<?php endif ?> 
    2223<?php endif ?> 
     24<?php echo link_to(__('Sent messages'), '@sf_social_message_sentlist') ?> | 
     25<?php echo link_to(__('Compose a new message'), '@sf_social_message_new') ?> 
  • plugins/sfSocialPlugin/trunk/modules/sfSocialMessage/templates/readSuccess.php

    r14577 r15064  
    1 <h2><?php echo __('Message from') ?> <u><?php echo $message->getsfGuardUserRelatedByUserFrom()->getUsername() ?></u></h2> <!-- TODO user link --> 
     1<h2><?php echo __('Message from') ?> <u><?php echo $message->getsfGuardUser()->getUsername() ?></u></h2> <!-- TODO user link --> 
    22<h3><?php echo __('Date') ?>: <?php echo $message->getCreatedAt() ?></h3> 
    33<h3><?php echo __('Subject') ?>: <?php echo $message->getSubject() ?></h3> 
    4 <div id="message_body"
     4<blockquote
    55  <?php echo $message->getText() ?> 
    6 </div
     6</blockquote
    77<hr /> 
    88<?php echo link_to(__('Reply'), '@sf_social_message_new?reply_to=' . $message->getId()) ?> | 
  • plugins/sfSocialPlugin/trunk/modules/sfSocialMessage/templates/sentSuccess.php

    r14577 r15064  
    11<h2>OK</h2> 
    2 <?php echo __('Message successfully sent to') ?> <?php echo $to ?> 
     2<?php echo __('Message successfully sent to') ?>: 
     3<ul> 
     4<?php foreach ($to as $user): ?> 
     5  <li><?php echo $user->getUsername() ?></li> 
     6<?php endforeach ?> 
     7</ul> 
     8<?php echo link_to(__('Back to list'), '@sf_social_message_list') ?> 
  • plugins/sfSocialPlugin/trunk/modules/sfSocialMessage/templates/sentlistSuccess.php

    r14577 r15064  
    44<h2><?php echo __('Messages sent') ?></h2> 
    55<ul> 
    6 <?php foreach ($pager->getResults() as $message): ?> 
    7   <li class="<?php echo $message->getRead() ? 'read' : 'unread' ?>"> 
     6<?php foreach ($pager->getResults() as $rcpt): ?> 
     7<?php $message = $rcpt->getSfSocialMessage() ?> 
     8  <li class="read"> 
    89    <?php echo $message->getCreatedAt() ?> 
    910    * <?php echo link_to($message->getSubject(), '@sf_social_message_sentread?id=' . $message->getId()) ?> 
    10     - <?php echo __('to') ?> <u><?php echo $message->getsfGuardUserRelatedByUserTo()->getUsername() ?></u> <!-- TODO user link --> 
    1111  </li> 
    1212<?php endforeach ?> 
     
    1818<?php endif ?> 
    1919<?php endif ?> 
     20<?php echo link_to(__('Received messages'), '@sf_social_message_list') ?> 
  • plugins/sfSocialPlugin/trunk/modules/sfSocialMessage/templates/sentreadSuccess.php

    r14577 r15064  
    1 <h2><?php echo __('Message to') ?> <?php echo $message->getsfGuardUserRelatedByUserTo()->getUsername() ?></h2> 
     1<h2> 
     2  <?php echo __('Message sent from you to') ?>: 
     3  <?php foreach ($rcpts as $rcpt): ?> 
     4  <u><?php echo $rcpt->getsfGuardUser()->getUsername() ?></u> <!-- TODO user link --> 
     5  <?php endforeach ?> 
     6</h2> 
    27<h3><?php echo __('Date') ?>: <?php echo $message->getCreatedAt() ?></h3> 
    38<h3><?php echo __('Subject') ?>: <?php echo $message->getSubject() ?></h3> 
    4 <div id="message_body"
     9<blockquote
    510  <?php echo $message->getText() ?> 
    6 </div
     11</blockquote
    712<hr /> 
    813<?php echo link_to(__('Back to list'), '@sf_social_message_sentlist') ?>