public function getTrashMessagesNumber() { $model = new Default_Model_Messages(); $select = $model->getMapper()->getDbTable()->select()->from(array('u' => 'messages'), array('id' => 'COUNT(u.id)'))->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)")->order('u.created DESC')->setIntegrityCheck(false); $model->fetchRow($select); return $model->getId(); }
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 }
public function indexAction() { // BEGIN:FILTERS $filters = array(); //array with variables to send to pagination (filters) // END:FILTERS //BEGIN:LISTING MESSAGES $model = new Default_Model_Messages(); $select = $model->getMapper()->getDbTable()->select(); $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'); $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->result = $paginator; $this->view->itemCountPerPage = $paginator->getItemCountPerPage(); $this->view->totalItemCount = $paginator->getTotalItemCount(); //END:LISTING MESSAGES //BEGIN:LISTING LATEST EXPENSES / INCOME $model = new Default_Model_Expenses(); $select = $model->getMapper()->getDbTable()->select(); $select->from(array('u' => 'expenses'), array('u.id', 'u.name', 'u.price', 'u.date', 'u.type'))->where('u.idMember = ?', Zend_Registry::get('user')->getId())->where('NOT u.deleted'); $select->order('u.date DESC'); // pagination $paginatorLatest = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select)); $paginatorLatest->setItemCountPerPage(10); $paginatorLatest->setCurrentPageNumber($this->_getParam('page')); $paginatorLatest->setPageRange(5); Zend_Paginator::setDefaultScrollingStyle('Sliding'); Zend_View_Helper_PaginationControl::setDefaultViewPartial(array('_pagination.phtml', $filters)); $this->view->resultLatest = $paginatorLatest; $this->view->itemCountPerPageLatest = $paginatorLatest->getItemCountPerPage(); $this->view->totalItemCountLatest = $paginatorLatest->getTotalItemCount(); //END:LISTING LATEST EXPENSES / INCOME //START: Expenses PIE $groups = new Default_Model_Groups(); $select = $groups->getMapper()->getDbTable()->select()->from(array('g' => 'groups'), array('g.id', 'g.name', 'g.color', 'g.created', 'g.deleted'))->joinLeft(array('pg' => 'product_groups'), 'g.id = pg.idGroup', array())->joinLeft(array('p' => 'expenses'), 'p.id = pg.idProduct', array('price' => 'SUM(p.price)'))->where('NOT g.deleted')->where('p.type=?', 0)->where('p.date>=?', date('Y-m-01'))->group('g.id')->setIntegrityCheck(false); $resultPieExpenses = $groups->fetchAll($select); $this->view->resultPieExpenses = $resultPieExpenses; //END: Expenses PIE //START: Income PIE $groups2 = new Default_Model_Groups(); $select2 = $groups2->getMapper()->getDbTable()->select()->from(array('g' => 'groups'), array('g.id', 'g.name', 'g.color', 'g.created', 'g.deleted'))->joinLeft(array('pg' => 'product_groups'), 'g.id = pg.idGroup', array())->joinLeft(array('p' => 'expenses'), 'p.id = pg.idProduct', array('price' => 'SUM(p.price)'))->where('NOT g.deleted')->where('p.type=?', 1)->where('p.date>=?', date('Y-m-01'))->group('g.id')->setIntegrityCheck(false); $resultPieIncome = $groups2->fetchAll($select2); $this->view->resultPieIncome = $resultPieIncome; //END: Income PIE $date = date('Y-m-d'); $thisWeekStartDate = Needs_Tools::getWeekDaysByDate($date, $type = 'start'); $thisWeekEndDay = Needs_Tools::getWeekDaysByDate($date, $type = 'end'); $this->view->dateFrom = $thisWeekStartDate; $this->view->dateTo = $thisWeekEndDay; // $resultInfo= Needs_Tools::showProjectedDashboard($thisWeekStartDate,$thisWeekEndDay); // if ($resultInfo){ // $this->view->foodCost=$resultInfo["foodCost"]; // $this->view->laborCost=$resultInfo["laborCost"]; // $this->view->idShop=$resultInfo["idShop"]; // }else{ // $this->view->foodCost=''; // $this->view->laborCost=''; // $this->view->idShop=''; // } $resultIncomeExpense = Needs_Tools::showIncomeExpensesDashboard(date('Y'), date('m')); if ($resultIncomeExpense) { $value = array(); foreach ($resultIncomeExpense as $values) { $value[] = $values->getPrice(); } $this->view->incomeAmount = isset($value[1]) ? $value[1] : 0; $this->view->expensesAmount = isset($value[0]) ? $value[0] : 0; } else { $this->view->incomeAmount = 0; $this->view->expensesAmount = 0; } $date = date('Y-m-d'); $day = date('d', strtotime($date)); $feb = date('L', strtotime($date)) ? 29 : 28; //an bisect $days = array(0, 31, $feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31); //nr zile pe luna //$month=array(1,2,3,4,5,6,7,8,9,10,11,12); $newdate = strtotime('-' . $days[date('n', strtotime($date))] . ' days', strtotime($date)); $resultIncomeExpenseLastMonth = Needs_Tools::showIncomeExpensesDashboard(date('Y', $newdate), date('m', $newdate)); if ($resultIncomeExpenseLastMonth) { $value = array(); foreach ($resultIncomeExpenseLastMonth as $values) { $value[] = $values->getPrice(); } $this->view->incomeAmountLastMonth = isset($value[1]) ? $value[1] : 0; $this->view->expensesAmountLastMonth = isset($value[0]) ? $value[0] : 0; } else { $this->view->incomeAmountLastMonth = 0; $this->view->expensesAmountLastMonth = 0; } $this->view->newdate = $newdate; //$this->view->form = $form; }