Пример #1
0
 public function editMessageAction()
 {
     //Edit Message
     $messageId = $this->_getParam('messageid');
     $this->view->message_id = $messageId;
     $model1 = new Application_Model_Message();
     $model = $model1->find($messageId);
     if (false === $model) {
         $this->_flashMessenger->addMessage(array('error' => 'Invalid request! Please try again.'));
         $this->_helper->_redirector->gotoUrl($this->view->seoUrl('admin/log/message'));
     }
     $options['categoryId'] = $model->getCategoryId();
     $options['severityId'] = $model->getSeverityId();
     $options['typeId'] = $model->getTypeId();
     $options['userMessage'] = $model->getUserMessage();
     $options['sysMessage'] = $model->getSysMessage();
     $request = $this->getRequest();
     $form = new Application_Form_Message();
     $form->populate($options);
     $options = $request->getPost();
     if ($request->isPost()) {
         if ($options['user_message'] == $model->getUserMessage()) {
             $form->getElement('userMessage')->removeValidator("Db_NoRecordExists");
         }
         if ($form->isValid($options)) {
             $model->setOptions($options);
             $model->save();
             $this->_flashMessenger->addMessage(array('success' => 'Message has been updated successfully!'));
             $this->_helper->_redirector->gotoUrl($this->view->seoUrl('/admin/log/edit-message/messageid/' . $messageId));
         } else {
             $this->_flashMessenger->addMessage(array('error' => 'Unable to save the data. Please provide valid inputs and try again.'));
             $form->reset();
             $form->populate($options);
         }
     }
     $this->view->form = $form;
 }
 /**
  * Read / Compose a new message (via ajax)
  */
 public function newAction()
 {
     $current_user = Zend_Auth::getInstance()->getIdentity();
     $request = $this->getRequest();
     $to_user = $request->getParam('to', false);
     $offset = $request->getParam('offset', false);
     $Profiles = new Application_Model_Profiles();
     $ProfilesMeta = new Application_Model_ProfilesMeta();
     $Connections = new Application_Model_Connections();
     $Messages = new Application_Model_Messages();
     $Notifications = new Application_Model_Notifications();
     $message_form = new Application_Form_Message();
     $this->view->message_form = $message_form;
     $user = $Profiles->getProfile($to_user);
     $json_ret = array('errors' => '', 'html' => '', 'offset' => '');
     if (!$user || !isset($user->id) || $user->type != 'user') {
         $json_ret['errors'] = $this->view->translate('This user does not exist');
         // exit
         $this->getHelper('json')->sendJson($json_ret);
     }
     $users_meta = $ProfilesMeta->getMetaValues($user->id);
     // check private message privacy
     if ($current_user->role != 'admin' && $current_user->role != 'reviewer' && isset($users_meta['contact_privacy']) && $users_meta['contact_privacy'] == 'f' && !$Connections->areFriends($current_user->id, $user->id)) {
         $json_ret['errors'] = $this->view->translate('Private profile (friends only)');
         // exit
         $this->getHelper('json')->sendJson($json_ret);
     }
     $this->view->to_screen_name = $user->screen_name;
     if ($request->isPost() && $message_form->isValid($_POST)) {
         $content = $message_form->getValue('content');
         $result = $Messages->sendMessage($user->id, $content);
         if (!$result) {
             $json_ret['errors'] = $this->view->translate('Server-side error');
             // exit
             $this->getHelper('json')->sendJson($json_ret);
         }
         // mark as read
         $Messages->markAsRead($user->id);
     }
     // get new messages
     $messages = $Messages->getMessages($user->id, $offset);
     // clear email notifications since you are looking at them right now
     $Notifications->clearEmailNotifications(8);
     if (!empty($messages)) {
         // send last visible message
         $last = end($messages);
         $json_ret['offset'] = $last['message_id'];
         foreach ($messages as $message) {
             $this->view->message = $message;
             $json_ret['html'] .= $this->view->render('/partial/message.phtml');
         }
     }
     $this->getHelper('json')->sendJson($json_ret);
 }