Beispiel #1
0
 public function indexAction()
 {
     // BEGIN:FILTERS
     $filters = array();
     //array with variables to send to pagination (filters)
     $type = $this->getRequest()->getParam('type');
     //can be 'sent','trash' or empty (inbox)
     $this->view->type = $type;
     if (!empty($type)) {
         $filters['type'] = $type;
     }
     $searchTxt = $this->getRequest()->getParam('searchTxt');
     if (!empty($searchTxt)) {
         $filters['searchTxt'] = $searchTxt;
     }
     $this->view->search = $filters;
     // END:FILTERS
     //BEGIN:SEARCH FORM
     $formSearch = new Default_Form_MessagesSearch();
     $formSearch->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/messages-search.phtml'))));
     $this->view->formSearch = $formSearch;
     //END:SEARCH FORM
     //BEGIN:FORM ADD
     $replyId = $this->getRequest()->getParam('replyId');
     $form = new Default_Form_Messages();
     $form->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/messages.phtml'))));
     if (!empty($replyId)) {
         $model = new Default_Model_Messages();
         $model->find($replyId);
         if ($model->getIdUserTo() == Zend_Registry::get('user')->getId()) {
             $form->reply($model);
         }
     }
     $this->view->form = $form;
     if ($this->getRequest()->isPost()) {
         $post = $this->getRequest()->getPost();
         if (!empty($post['action']) && $post['action'] == 'add') {
             //if is valid save message
             if ($form->isValid($this->getRequest()->getPost())) {
                 //save message
                 $model = new Default_Model_Messages();
                 $model->setOptions($form->getValues());
                 $model->setIdUserFrom(Zend_Registry::get('user')->getId());
                 $savedId = $model->save();
                 if ($savedId) {
                     //BEGIN:SAVE ATTACHMENTS
                     if (!empty($post['galleryFiles']) && is_array($post['galleryFiles'])) {
                         foreach ($post['galleryFiles'] as $valuesGallery) {
                             $tmpFiles = new Default_Model_TempFiles();
                             if ($tmpFiles->find($valuesGallery)) {
                                 $gallery = new Default_Model_UploadedFiles();
                                 $gallery->setIdMessage($savedId);
                                 $gallery->setType($tmpFiles->getFileType());
                                 $gallery->setIdUser(Zend_Registry::get('user')->getId());
                                 $gallery->setModule('messages');
                                 $gallery->setName($tmpFiles->getFileName());
                                 $gallery->save();
                                 //copy picture and crop
                                 $tempFile = APPLICATION_PUBLIC_PATH . '/media/temps/' . $tmpFiles->getFileName();
                                 $targetFile = APPLICATION_PUBLIC_PATH . '/media/files/' . $tmpFiles->getFileName();
                                 @copy($tempFile, $targetFile);
                                 @unlink($tempFile);
                                 $tmpFiles->delete();
                             }
                         }
                     }
                     //END:SAVE ATTACHMENTS
                     $this->_flashMessenger->addMessage("<div class='success  canhide'><p>Your message was succesfully sent.</p><a href='javascript:;'></a></div>");
                 } else {
                     $this->_flashMessenger->addMessage("<div class='failure canhide'><p>Error sending message!</p><a href='javascript:;'></a></div>");
                 }
                 $this->_redirect(WEBROOT . 'messages');
             }
         }
     }
     //END:FORM	ADD
     //BEGIN:LISTING
     $model = new Default_Model_Messages();
     $select = $model->getMapper()->getDbTable()->select();
     if (!empty($type) && $type == 'sent') {
         //sent
         $select->from(array('u' => 'messages'), array('u.id', 'idUserFrom' => 'u.idUserTo', 'u.subject', 'u.created'))->where('u.idUserFrom = ?', Zend_Registry::get('user')->getId())->where('NOT u.deletedFrom')->where('NOT u.trashedFrom');
     } elseif (!empty($type) && $type == 'trash') {
         //trash
         $select->from(array('u' => 'messages'), array('u.id', 'u.idUserFrom', 'u.idUserTo', 'u.subject', 'u.created'))->where("" . "(u.idUserTo = '" . Zend_Registry::get('user')->getId() . "' AND u.trashedTo = 1 AND NOT u.deletedTo)  " . "OR " . "(u.idUserFrom = '" . Zend_Registry::get('user')->getId() . "'  AND u.trashedFrom = 1 AND NOT u.deletedFrom)");
     } else {
         //inbox
         $select->from(array('u' => 'messages'), array('u.id', 'u.idUserFrom', 'u.idUserTo', 'u.subject', 'u.created'))->where('u.idUserTo = ?', Zend_Registry::get('user')->getId())->where('NOT u.deletedTo')->where('NOT u.trashedTo');
     }
     if (!empty($searchTxt)) {
         $select->where("u.subject  LIKE ('%" . $searchTxt . "%') OR u.message  LIKE ('%" . $searchTxt . "%')");
     }
     $select->order('u.created  DESC')->setIntegrityCheck(false);
     // pagination
     $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select));
     $paginator->setItemCountPerPage(10);
     $paginator->setCurrentPageNumber($this->_getParam('page'));
     $paginator->setPageRange(5);
     Zend_Paginator::setDefaultScrollingStyle('Sliding');
     Zend_View_Helper_PaginationControl::setDefaultViewPartial(array('_pagination.phtml', $filters));
     $this->view->inboxNr = Needs_Messages::getInboxMessagesNumber();
     $this->view->sentNr = Needs_Messages::getSentMessagesNumber();
     $this->view->trashNr = Needs_Messages::getTrashMessagesNumber();
     $this->view->result = $paginator;
     $this->view->itemCountPerPage = $paginator->getItemCountPerPage();
     $this->view->totalItemCount = $paginator->getTotalItemCount();
     //END:LISTING
 }
Beispiel #2
0
 public function indexAction()
 {
     // BEGIN:FILTERS
     $filters = array();
     //array with variables to send to pagination (filters)
     $searchTxt = $this->getRequest()->getParam('searchTxt');
     if (!empty($searchTxt)) {
         $filters['searchTxt'] = $searchTxt;
     }
     $this->view->search = $filters;
     // END:FILTERS
     //BEGIN:SEARCH FORM
     $formSearch = new Default_Form_FileManagerSearch();
     $formSearch->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/file-manager-search.phtml'))));
     $this->view->formSearch = $formSearch;
     //END:SEARCH FORM
     //BEGIN:FORM ADD
     $replyId = $this->getRequest()->getParam('replyId');
     $form = new Default_Form_FileManager();
     $form->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/file-manager.phtml'))));
     $this->view->form = $form;
     $formshare = new Default_Form_ShareFile();
     if ($this->getRequest()->isPost()) {
         $post = $this->getRequest()->getPost();
         if (!empty($post['action']) && $post['action'] == 'add') {
             //if is valid save message
             if ($form->isValid($this->getRequest()->getPost())) {
                 //BEGIN:SAVE ATTACHMENTS
                 if (!empty($post['galleryFiles']) && is_array($post['galleryFiles'])) {
                     foreach ($post['galleryFiles'] as $valuesGallery) {
                         $tmpFiles = new Default_Model_TempFiles();
                         if ($tmpFiles->find($valuesGallery)) {
                             $post = $this->getRequest()->getPost();
                             $gallery = new Default_Model_FileManager();
                             $gallery->setOptions($form->getValues());
                             $gallery->setType($tmpFiles->getFileType());
                             $gallery->setSize($tmpFiles->getFileSize());
                             $gallery->setModule('sharedfiles');
                             $gallery->setName($tmpFiles->getFileName());
                             $savedId = $gallery->save();
                             if ($savedId) {
                                 $shared = new Default_Model_SharedList();
                                 $shared->setIdUser(Zend_Registry::get('user')->getId());
                                 $shared->setIdFile($savedId);
                                 $shared->save();
                             }
                             //copy picture and crop
                             $tempFile = APPLICATION_PUBLIC_PATH . '/media/temps/' . $tmpFiles->getFileName();
                             $targetFile = APPLICATION_PUBLIC_PATH . '/media/files/' . $tmpFiles->getFileName();
                             @copy($tempFile, $targetFile);
                             @unlink($tempFile);
                             $tmpFiles->delete();
                         }
                     }
                     //END:SAVE ATTACHMENTS
                     $this->_flashMessenger->addMessage("<div class='success  canhide'><p>Your file was succesfully uploaded.</p><a href='javascript:;'></a></div>");
                 } else {
                     $this->_flashMessenger->addMessage("<div class='failure canhide'><p>Error uploading file!</p><a href='javascript:;'></a></div>");
                 }
                 $this->_redirect(WEBROOT . 'file-manager');
             }
         }
         if (!empty($post['action']) && $post['action'] == 'sharefile') {
             //if is valid save shared file message
             if ($formshare->isValid($this->getRequest()->getPost())) {
                 $model = new Default_Model_Messages();
                 $model->setOptions($formshare->getValues());
                 $model->setIdUserFrom(Zend_Registry::get('user')->getId());
                 $model->save();
                 //BEGIN:SAVE ATTACHMENTS
                 $shared = new Default_Model_SharedList();
                 $shared->setOptions($formshare->getValues());
                 //echo $formshare->getValue('idUserTo');
                 //die();//aici e ok
                 $shared->setIdUser($formshare->getValue('idUserTo'));
                 //aici nu seteaza
                 $shared->save();
                 //END:SAVE ATTACHMENTS
                 $this->_flashMessenger->addMessage("<div class='success  canhide'><p>Your file was succesfully shared.</p><a href='javascript:;'></a></div>");
             } else {
                 $this->_flashMessenger->addMessage("<div class='failure canhide'><p>Error sharing file!</p><a href='javascript:;'></a></div>");
             }
             $this->_redirect(WEBROOT . 'file-manager');
         }
     }
     //END:FORM	ADD
     //BEGIN:LISTING
     $model = new Default_Model_FileManager();
     $select = $model->getMapper()->getDbTable()->select();
     //if(!empty($type) && $type == 'sent'){  //sent
     $select->from(array('sl' => 'shared_list'), array('sl.idUser', 'sl.created'))->joinLeft(array('uf' => 'uploaded_files'), 'uf.id = sl.idFile', array('uf.id', 'uf.name', 'uf.description', 'uf.type', 'uf.size'))->where('sl.idUser = ?', Zend_Registry::get('user')->getId())->where('NOT sl.deleted');
     //	}
     if (!empty($searchTxt)) {
         $select->where("uf.name LIKE ('%" . $searchTxt . "%') OR uf.description LIKE ('%" . $searchTxt . "%')");
     }
     $select->order('sl.created DESC')->setIntegrityCheck(false);
     // pagination
     $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select));
     $paginator->setItemCountPerPage(10);
     $paginator->setCurrentPageNumber($this->_getParam('page'));
     $paginator->setPageRange(5);
     Zend_Paginator::setDefaultScrollingStyle('Sliding');
     Zend_View_Helper_PaginationControl::setDefaultViewPartial(array('_pagination.phtml', $filters));
     $this->view->result = $paginator;
     $this->view->itemCountPerPage = $paginator->getItemCountPerPage();
     $this->view->totalItemCount = $paginator->getTotalItemCount();
     //END:LISTING
 }