Changeset 15064
- Timestamp:
- 01/29/09 14:07:38 (4 years ago)
- Files:
-
- plugins/sfSocialPlugin/trunk/README (modified) (2 diffs)
- plugins/sfSocialPlugin/trunk/config/schema.yml (modified) (1 diff)
- plugins/sfSocialPlugin/trunk/data/fixtures/03_messages.yml (modified) (1 diff)
- plugins/sfSocialPlugin/trunk/lib/filter/sfSocialMessageRcptFormFilter.class.php (added)
- plugins/sfSocialPlugin/trunk/lib/filter/sfSocialMessageSentFormFilter.class.php (deleted)
- plugins/sfSocialPlugin/trunk/lib/form/sfSocialMessageForm.class.php (modified) (2 diffs)
- plugins/sfSocialPlugin/trunk/lib/form/sfSocialMessageRcptForm.class.php (added)
- plugins/sfSocialPlugin/trunk/lib/form/sfSocialMessageSentForm.class.php (deleted)
- plugins/sfSocialPlugin/trunk/lib/model/sfSocialEventInvitePeer.php (modified) (1 diff)
- plugins/sfSocialPlugin/trunk/lib/model/sfSocialMessage.php (modified) (3 diffs)
- plugins/sfSocialPlugin/trunk/lib/model/sfSocialMessagePeer.php (modified) (1 diff)
- plugins/sfSocialPlugin/trunk/lib/model/sfSocialMessageRcpt.php (added)
- plugins/sfSocialPlugin/trunk/lib/model/sfSocialMessageRcptPeer.php (added)
- plugins/sfSocialPlugin/trunk/lib/model/sfSocialMessageSent.php (deleted)
- plugins/sfSocialPlugin/trunk/lib/model/sfSocialMessageSentPeer.php (deleted)
- plugins/sfSocialPlugin/trunk/modules/sfSocialMessage/lib/BasesfSocialMessageActions.class.php (modified) (8 diffs)
- plugins/sfSocialPlugin/trunk/modules/sfSocialMessage/templates/composeSuccess.php (modified) (1 diff)
- plugins/sfSocialPlugin/trunk/modules/sfSocialMessage/templates/listSuccess.php (modified) (2 diffs)
- plugins/sfSocialPlugin/trunk/modules/sfSocialMessage/templates/readSuccess.php (modified) (1 diff)
- plugins/sfSocialPlugin/trunk/modules/sfSocialMessage/templates/sentSuccess.php (modified) (1 diff)
- plugins/sfSocialPlugin/trunk/modules/sfSocialMessage/templates/sentlistSuccess.php (modified) (2 diffs)
- plugins/sfSocialPlugin/trunk/modules/sfSocialMessage/templates/sentreadSuccess.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfSocialPlugin/trunk/README
r14577 r15064 31 31 Enable modules in you application settings 32 32 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 37 38 38 39 ## Roadmap … … 43 44 The project aims to implement: 44 45 45 * Contactsystem (aka friends system): search for other users, request46 * **Contact** system (aka friends system): search for other users, request 46 47 contact, accept/deny contact request, see list of your contacts, 47 48 categorize contacts in groups, see contacts of other users, 48 49 see contact shared with other users, see "degrees of separation" 49 50 50 * Messagesystem: send a message, read received messages, reply to a51 * **Message** system: send a message, read received messages, reply to a 51 52 message. 52 53 53 * Groupsystem: create a group, invite users to join, manage groups.54 * **Group** system: create a group, invite users to join, manage groups. 54 55 55 * Eventsystem: create an event, invite users to partecipate, confirm56 * **Event** system: create an event, invite users to partecipate, confirm 56 57 partecipation (yes/no/maybe) 57 58 58 * Commentsystem: write commments, reply to comments. For groups, events59 * **Comment** system: write commments, reply to comments. For groups, events 59 60 and maybe for something else. 60 61 61 * Notificationsystem: a glue for all other systems. Notify your contacts62 * **Notification** system: a glue for all other systems. Notify your contacts 62 63 when you do an action (add a contact, create an event, etc.) plugins/sfSocialPlugin/trunk/config/schema.yml
r14756 r15064 92 92 id: ~ 93 93 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 }95 94 subject: { type: varchar, size: 255, required: true } 96 text: { type: longvarchar, required: true } 97 read: { type: boolean, default: false } 95 text: { type: longvarchar } 98 96 created_at: ~ 99 97 100 sf_social_message_ sent:101 _attributes: { phpName: sfSocialMessage Sent }98 sf_social_message_rcpt: 99 _attributes: { phpName: sfSocialMessageRcpt } 102 100 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 } 104 102 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 1 1 sfSocialMessage: 2 maxmike:2 from_max: 3 3 user_from: max 4 user_to: mike5 4 subject: lorem ipsum 6 5 text: dolor sit amet, consectetur adipiscing elit. Sed accumsan laoreet sapien. Maecenas et nisl et mi imperdiet auctor. 7 dannyanna:6 from_danny: 8 7 user_from: danny 9 user_to: anna10 8 subject: hello pal 11 9 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: 14 11 user_from: mario 15 user_to: max16 12 subject: how do you do? 17 13 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? 18 18 19 sfSocialMessage Sent:20 max mike:21 user_from:max19 sfSocialMessageRcpt: 20 max_to_mike: 21 msg_id: from_max 22 22 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 27 25 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 32 32 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 4 4 * sfSocialMessage form. 5 5 * 6 * @package ##PROJECT_NAME##6 * @package sfSocialPlugin 7 7 * @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> 10 9 */ 11 10 class sfSocialMessageForm extends BasesfSocialMessageForm … … 14 13 { 15 14 // hide unuseful fields 16 unset($this['created_at'] , $this['read']);15 unset($this['created_at']); 17 16 18 17 // 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'); 20 20 $this->widgetSchema['user_from'] = new sfWidgetFormInputHidden(); 21 21 $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'))); 23 31 } 24 32 } plugins/sfSocialPlugin/trunk/lib/model/sfSocialEventInvitePeer.php
r14756 r15064 23 23 $pager->setPeerMethod('doSelectJoinAllExceptsfGuardUserRelatedByUserFrom'); 24 24 #$pager->setPeerMethod('doSelectJoinAll'); 25 #$pager->setPeerMethod('doSelectJoinAllExceptinvited'); 25 26 $pager->setPage($page); 26 27 $pager->init(); plugins/sfSocialPlugin/trunk/lib/model/sfSocialMessage.php
r14717 r15064 5 5 6 6 /** 7 * check if message is belonging to user7 * check if user is in message's recipients 8 8 * @param sfGuardUser $user 9 9 * @return boolean … … 11 11 public function checkUserTo($user) 12 12 { 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(); 14 32 } 15 33 16 34 /** 17 35 * mark message as read 36 * @param sfGuardUser $user 18 37 */ 19 public function read( )38 public function read($user) 20 39 { 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; 23 66 } 24 67 … … 34 77 } 35 78 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 36 94 } plugins/sfSocialPlugin/trunk/lib/model/sfSocialMessagePeer.php
r14717 r15064 3 3 class sfSocialMessagePeer extends BasesfSocialMessagePeer 4 4 { 5 6 /**7 * get messages received by user8 * @param sfGuardUser $user9 * @param integer $page current page10 * @param integer $n max per page11 * @return sfPropelPager12 */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 user28 * @param sfGuardUser $user29 * @param integer $page current page30 * @param integer $n max per page31 * @return sfPropelPager32 */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 user48 * @param sfGuardUser $user49 * @return integer50 */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 59 5 } plugins/sfSocialPlugin/trunk/modules/sfSocialMessage/lib/BasesfSocialMessageActions.class.php
r14717 r15064 11 11 { 12 12 13 public function preExecute() 14 { 15 $this->user = $this->getUser()->getGuardUser(); 16 } 17 13 18 /** 14 19 * List of received messages … … 17 22 public function executeList(sfWebRequest $request) 18 23 { 19 $ page = $request->getParameter('page');20 $this->pager = sfSocialMessagePeer::getUserMessages($this->getUser()->getGuardUser(), $page);21 $this->unread = sfSocialMessage Peer::countUnreadMessages($this->getUser()->getGuardUser());24 $this->pager = sfSocialMessageRcptPeer::getUserMessages($this->user, 25 $request->getParameter('page')); 26 $this->unread = sfSocialMessageRcptPeer::countUnreadMessages($this->user); 22 27 } 23 28 … … 28 33 public function executeSentlist(sfWebRequest $request) 29 34 { 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')); 32 37 } 33 38 … … 38 43 public function executeRead(sfWebRequest $request) 39 44 { 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')); 43 46 $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), 45 49 'unauthorized'); 46 $this->message->read( );50 $this->message->read($this->user); 47 51 } 48 52 … … 53 57 public function executeSentread(sfWebRequest $request) 54 58 { 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')); 58 60 $this->forward404Unless($this->message, 'message not found'); 59 $this->forward404Unless($this->message->checkUserFrom($this-> getUser()->getGuardUser()),61 $this->forward404Unless($this->message->checkUserFrom($this->user), 60 62 'unauthorized'); 63 $this->rcpts = $this->message->getsfSocialMessageRcpts(); 61 64 } 62 65 … … 74 77 $message = sfSocialMessagePeer::retrieveByPK($reply_to); 75 78 $this->forward404Unless($message, 'message not found'); 76 $this->forward404Unless($message->checkUserTo($this-> getUser()->getGuardUser()),79 $this->forward404Unless($message->checkUserTo($this->user), 77 80 'unauthorized'); 78 $this->form->setDefault(' user_to', $message->getsfGuardUserRelatedByUserFrom()->getId());81 $this->form->setDefault('to', $message->getsfGuardUser()->getId()); 79 82 $this->form->setDefault('subject', $message->getReplySubject()); 80 83 } … … 83 86 $values = $request->getParameter('sf_social_message'); 84 87 $sent = $this->form->bindAndSave($values); 88 $msg = $this->form->getObject(); 89 $msg->send($values['to']); 85 90 $this->forwardIf($sent, 'sfSocialMessage', 'sent'); 86 91 } … … 94 99 { 95 100 $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']); 99 103 } 100 104 plugins/sfSocialPlugin/trunk/modules/sfSocialMessage/templates/composeSuccess.php
r14577 r15064 4 4 <tr> 5 5 <td colspan="2"> 6 <input type="submit" />6 <input type="submit" value="<?php echo __('send') ?>" /> 7 7 </td> 8 8 </tr> 9 9 </table> 10 10 </form> 11 <?php echo link_to(__('cancel'), '@sf_social_message_list') ?> plugins/sfSocialPlugin/trunk/modules/sfSocialMessage/templates/listSuccess.php
r14717 r15064 7 7 <?php endif ?> 8 8 <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' ?>"> 11 12 <?php echo $message->getCreatedAt() ?> 12 13 * <?php echo link_to($message->getSubject(), '@sf_social_message_read?id=' . $message->getId()) ?> 13 - <?php echo __('from') ?> <u><?php echo $message->getsfGuardUser RelatedByUserFrom()->getUsername() ?></u> <!-- TODO user link -->14 - <?php echo __('from') ?> <u><?php echo $message->getsfGuardUser()->getUsername() ?></u> <!-- TODO user link --> 14 15 </li> 15 16 <?php endforeach ?> … … 21 22 <?php endif ?> 22 23 <?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->getsfGuardUser RelatedByUserFrom()->getUsername() ?></u></h2> <!-- TODO user link -->1 <h2><?php echo __('Message from') ?> <u><?php echo $message->getsfGuardUser()->getUsername() ?></u></h2> <!-- TODO user link --> 2 2 <h3><?php echo __('Date') ?>: <?php echo $message->getCreatedAt() ?></h3> 3 3 <h3><?php echo __('Subject') ?>: <?php echo $message->getSubject() ?></h3> 4 < div id="message_body">4 <blockquote> 5 5 <?php echo $message->getText() ?> 6 </ div>6 </blockquote> 7 7 <hr /> 8 8 <?php echo link_to(__('Reply'), '@sf_social_message_new?reply_to=' . $message->getId()) ?> | plugins/sfSocialPlugin/trunk/modules/sfSocialMessage/templates/sentSuccess.php
r14577 r15064 1 1 <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 4 4 <h2><?php echo __('Messages sent') ?></h2> 5 5 <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"> 8 9 <?php echo $message->getCreatedAt() ?> 9 10 * <?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 -->11 11 </li> 12 12 <?php endforeach ?> … … 18 18 <?php endif ?> 19 19 <?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> 2 7 <h3><?php echo __('Date') ?>: <?php echo $message->getCreatedAt() ?></h3> 3 8 <h3><?php echo __('Subject') ?>: <?php echo $message->getSubject() ?></h3> 4 < div id="message_body">9 <blockquote> 5 10 <?php echo $message->getText() ?> 6 </ div>11 </blockquote> 7 12 <hr /> 8 13 <?php echo link_to(__('Back to list'), '@sf_social_message_sentlist') ?>