Beispiel #1
0
 public function inviteAction()
 {
     if (!$this->_helper->requireUser()->isValid()) {
         return;
     }
     if (!$this->_helper->requireSubject('event')->isValid()) {
         return;
     }
     // @todo auth
     // Prepare data
     $viewer = Engine_Api::_()->user()->getViewer();
     $this->view->event = $event = Engine_Api::_()->core()->getSubject();
     $this->view->friends = $friends = $viewer->membership()->getMembers();
     // Prepare form
     $this->view->form = $form = new Ynevent_Form_Invite();
     $count = 0;
     foreach ($friends as $friend) {
         if ($event->membership()->isMember($friend, null)) {
             continue;
         }
         $form->users->addMultiOption($friend->getIdentity(), $friend->getTitle());
         $count++;
     }
     $this->view->count = $count;
     // Not posting
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if (!$form->isValid($this->getRequest()->getPost())) {
         return;
     }
     $values = $form->getValues();
     // Process
     $table = $event->getTable();
     $db = $table->getAdapter();
     $db->beginTransaction();
     try {
         $usersIds = $form->getValue('users');
         if ($form->getElement('message')) {
             $message = $form->getElement('message')->getValue();
         }
         $notifyApi = Engine_Api::_()->getDbtable('notifications', 'activity');
         foreach ($friends as $friend) {
             if (!in_array($friend->getIdentity(), $usersIds)) {
                 continue;
             }
             $event->membership()->addMember($friend)->setResourceApproved($friend);
             if (isset($message) && !empty($message)) {
                 $notifyApi->addNotification($friend, $viewer, $event, 'ynevent_invite_message', array('message' => $message));
             } else {
                 $notifyApi->addNotification($friend, $viewer, $event, 'ynevent_invite');
             }
         }
         $db->commit();
     } catch (Exception $e) {
         $db->rollBack();
         throw $e;
     }
     return $this->_forward('success', 'utility', 'core', array('messages' => array(Zend_Registry::get('Zend_Translate')->_('Members invited')), 'layout' => 'default-simple', 'parentRefresh' => true));
 }
Beispiel #2
0
 public function inviteAction()
 {
     if (!$this->_helper->requireUser()->isValid()) {
         return;
     }
     if (!$this->_helper->requireSubject('event')->isValid()) {
         return;
     }
     // @todo auth
     // Prepare data
     $viewer = Engine_Api::_()->user()->getViewer();
     $this->view->event = $event = Engine_Api::_()->core()->getSubject();
     // Prepare friends
     $friendsTable = Engine_Api::_()->getDbtable('membership', 'user');
     $friendsIds = $friendsTable->select()->from($friendsTable, 'user_id')->where('resource_id = ?', $viewer->getIdentity())->where('active = ?', true)->limit(100)->query()->fetchAll(Zend_Db::FETCH_COLUMN);
     if (!empty($friendsIds)) {
         // 			$friends = Engine_Api::_()->getItemTable('user')->find($friendsIds);
         $friendTbl = Engine_Api::_()->getItemTable('user');
         $select = $friendTbl->select()->where('user_id IN (?)', $friendsIds)->order('displayname');
         $friends = $friendTbl->fetchAll($select);
     } else {
         $friends = array();
     }
     $this->view->friends = $friends;
     // Prepare form
     $this->view->form = $form = new Ynevent_Form_Invite();
     $count = 0;
     foreach ($friends as $friend) {
         if ($event->membership()->isMember($friend, null)) {
             continue;
         }
         $form->users->addMultiOption($friend->getIdentity(), $friend->getTitle());
         $count++;
     }
     $this->view->count = $count;
     // Not posting
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if (!$form->isValid($this->getRequest()->getPost())) {
         return;
     }
     $values = $form->getValues();
     // Process
     $table = $event->getTable();
     $db = $table->getAdapter();
     $db->beginTransaction();
     try {
         $usersIds = $form->getValue('users');
         $notifyApi = Engine_Api::_()->getDbtable('notifications', 'activity');
         if ($form->getElement('message')) {
             $message = $form->getElement('message')->getValue();
         }
         foreach ($friends as $friend) {
             if (!in_array($friend->getIdentity(), $usersIds)) {
                 continue;
             }
             $event->membership()->addMember($friend)->setResourceApproved($friend);
             if (isset($message) && !empty($message)) {
                 $notifyApi->addNotification($friend, $viewer, $event, 'ynevent_invite_message', array('message' => $message));
             } else {
                 $notifyApi->addNotification($friend, $viewer, $event, 'ynevent_invite');
             }
         }
         $db->commit();
     } catch (Exception $e) {
         $db->rollBack();
         throw $e;
     }
     //Invite people via email
     $recipients = $values['recipients'];
     $message = $values['message'];
     if (isset($message) && !empty($message)) {
         $sent = $this->InviteViaEmail($recipients, $message, $event, "ynevent_invite_message");
     } else {
         $sent = $this->InviteViaEmail($recipients, $message, $event, "ynevent_invite");
     }
     $session = new Zend_Session_Namespace('mobile');
     if ($session->mobile) {
         $callbackUrl = $this->view->url(array('id' => $event->getIdentity()), 'event_profile', true);
         $this->_forward('success', 'utility', 'core', array('smoothboxClose' => true, 'parentRedirect' => $callbackUrl, 'messages' => array(Zend_Registry::get('Zend_Translate')->_('Members invited'))));
     } else {
         return $this->_forward('success', 'utility', 'core', array('messages' => array(Zend_Registry::get('Zend_Translate')->_('Members invited')), 'layout' => 'default-simple', 'parentRefresh' => true));
     }
 }