public function testGetSetItemCountPerPage()
 {
     $this->_restorePaginatorDefaults();
     $this->assertEquals(10, $this->_paginator->getItemCountPerPage());
     $this->_paginator->setItemCountPerPage(15);
     $this->assertEquals(15, $this->_paginator->getItemCountPerPage());
     $this->_paginator->setItemCountPerPage(10);
 }
Example #2
0
 /**
  * @group ZF-4193
  */
 public function testCastsIntegerValuesToInteger()
 {
     // Current page number
     $this->_paginator->setCurrentPageNumber(3.3);
     $this->assertTrue($this->_paginator->getCurrentPageNumber() == 3);
     // Item count per page
     $this->_paginator->setItemCountPerPage(3.3);
     $this->assertTrue($this->_paginator->getItemCountPerPage() == 3);
     // Page range
     $this->_paginator->setPageRange(3.3);
     $this->assertTrue($this->_paginator->getPageRange() == 3);
 }
 /**
  * Create the page object used in View - paginator method
  * @access public
  * @return object
  */
 public function getPages()
 {
     $pages = new stdClass();
     $pageCount = $this->_paginator->count();
     $pages->pageCount = $pageCount;
     $pages->itemCountPerPage = $this->_itemCountPerPage;
     $pages->first = 1;
     $pages->current = (int) $this->_currentPage;
     $pages->last = $pageCount;
     // Previous and next
     if ($this->_currentPage - 1 > 0) {
         $pages->previous = $this->_currentPage - 1;
     }
     if ($this->_currentPage + 1 <= $pageCount) {
         $pages->next = $this->_currentPage + 1;
     }
     // Pages in range
     $pageRange = $this->_paginator->getPageRange();
     if ($pageRange > $pageCount) {
         $pageRange = $pageCount;
     }
     $delta = ceil($pageRange / 2);
     if ($this->_currentPage - $delta > $pageCount - $pageRange) {
         $lowerBound = $pageCount - $pageRange + 1;
         $upperBound = $pageCount;
     } else {
         if ($this->_currentPage - $delta < 0) {
             $delta = $this->_currentPage;
         }
         $offset = $this->_currentPage - $delta;
         $lowerBound = $offset + 1;
         $upperBound = $offset + $pageRange;
     }
     $pages->pagesInRange = $this->_paginator->getPagesInRange($lowerBound, $upperBound);
     $pages->firstPageInRange = min($pages->pagesInRange);
     $pages->lastPageInRange = max($pages->pagesInRange);
     // Item numbers
     if ($this->_currentItems == null) {
         $this->getCurrentItems();
     }
     if ($this->_currentItems !== null) {
         $pages->currentItemCount = $this->_paginator->getCurrentItemCount();
         $pages->itemCountPerPage = $this->_paginator->getItemCountPerPage();
         $pages->totalItemCount = $this->_paginator->getTotalItemCount();
         $pages->firstItemNumber = ($this->_currentPage - 1) * $this->_paginator->getItemCountPerPage() + 1;
         $pages->lastItemNumber = $pages->firstItemNumber + $pages->currentItemCount - 1;
     }
     return $pages;
 }
Example #4
0
 /**
  * Create the grid data structure
  * 
  * @return object
  */
 protected function _createGridData(Zend_Controller_Request_Abstract $request)
 {
     // Instantiate Zend_Paginator with the required data source adaptor
     if (!$this->_paginator instanceof Zend_Paginator) {
         $this->_paginator = new Zend_Paginator($this->_adapter);
         $this->_paginator->setDefaultItemCountPerPage($request->getParam('rows', $this->_defaultItemCountPerPage));
     }
     // Filter items by supplied search criteria
     if ($request->getParam('_search') == 'true') {
         $filter = $this->_getFilterParams($request);
         $this->_paginator->getAdapter()->filter($filter['field'], $filter['value'], $filter['expression'], $filter['options']);
     }
     // Sort items by the supplied column field
     if ($request->getParam('sidx')) {
         $this->_paginator->getAdapter()->sort($request->getParam('sidx'), $request->getParam('sord', 'asc'));
     }
     // Pass the current page number to paginator
     $this->_paginator->setCurrentPageNumber($request->getParam('page', 1));
     // Fetch a row of items from the adapter
     $rows = $this->_paginator->getCurrentItems();
     $grid = new stdClass();
     $grid->page = $this->_paginator->getCurrentPageNumber();
     $grid->total = $this->_paginator->getItemCountPerPage();
     $grid->records = $this->_paginator->getTotalItemCount();
     $grid->rows = array();
     foreach ($rows as $k => $row) {
         if (isset($row['id'])) {
             $grid->rows[$k]['id'] = $row['id'];
         }
         $grid->rows[$k]['cell'] = array();
         foreach ($this->_columns as $column) {
             array_push($grid->rows[$k]['cell'], $column->cellValue($row));
         }
     }
     return $grid;
 }
 public function indexAction()
 {
     $auth = Zend_Auth::getInstance();
     $authAccount = $auth->getStorage()->read();
     $params = array();
     $conditions = array();
     if ($this->getRequest()->getParam('nameSearch')) {
         $params['nameSearch'] = $this->getRequest()->getParam('nameSearch');
     }
     if ($this->getRequest()->getParam('idGroupSearch')) {
         $params['idGroupSearch'] = $this->getRequest()->getParam('idGroupSearch');
     }
     if ($this->getRequest()->getParam('fromDate')) {
         $params['fromDate'] = date("Y-m-d", strtotime($this->getRequest()->getParam('fromDate')));
     }
     if ($this->getRequest()->getParam('toDate')) {
         $params['toDate'] = date("Y-m-d", strtotime($this->getRequest()->getParam('toDate')));
     }
     //BEGIN:SELECT EXPENSES
     $conditions['pagination'] = true;
     $expenses = new Default_Model_RecurrentExpenses();
     $select = $expenses->getMapper()->getDbTable()->select()->from(array('p' => 'recurrent_expenses'), array('p.id', 'p.name', 'p.price', 'p.date', 'p.created', 'p.deleted'))->where('p.type=?', 0)->where('NOT p.deleted')->where('idMember=?', Zend_Registry::get('user')->getId());
     if (!empty($params['nameSearch'])) {
         $select->where('p.name LIKE ?', '%' . $params['nameSearch'] . '%');
     }
     if (!empty($params['idGroupSearch'])) {
         $select->where('p.idGroup = ?', $params['idGroupSearch']);
     }
     if (!empty($params['fromDate'])) {
         $select->where('p.date >= ?', $params['fromDate']);
     }
     if (!empty($params['toDate'])) {
         $select->where('p.date <= ?', $params['toDate']);
     }
     $select->joinLeft(array('uf' => 'uploaded_files'), 'p.`id` = uf.`idMessage`', array('ufiles' => 'uf.id', 'recurrent' => 'uf.idUser'))->setIntegrityCheck(false);
     $select->order(array('date DESC'));
     $resultExpense = Needs_Tools::showRecurrentExpensesDashboardbyDate(!empty($params['fromDate']) ? $params['fromDate'] : date('Y-m-01'), !empty($params['toDate']) ? $params['toDate'] : date('Y-m-d'));
     $this->view->resultExpense = $resultExpense;
     //END:SELECT PROJECTS
     $form = new Default_Form_RecurrentExpenses();
     $form->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/recurrent-expenses/add-expense.phtml'))));
     $this->view->form = $form;
     if ($this->getRequest()->isPost() && $this->getRequest()->getParam('control') == 'addExpense') {
         if ($form->isValid($this->getRequest()->getPost())) {
             $post = $this->getRequest()->getPost();
             $model = new Default_Model_RecurrentExpenses();
             $model->setOptions($form->getValues());
             $model->setDate(date("Y-m-d", strtotime($post["date"])));
             $model->setType('0');
             $idGroup = $this->getRequest()->getParam('idGroup');
             $model->setIdGroup($idGroup);
             if ($expenseId = $model->save()) {
                 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->setIdMessage($expenseId);
                             $gallery->setIdUser(1);
                             $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
                 }
                 $idGroup = $this->getRequest()->getParam('idGroup');
                 $modelGroup = new Default_Model_ProductGroups();
                 $modelGroup->setIdProduct($expenseId);
                 $modelGroup->setIdGroup($idGroup);
                 $modelGroup->setRepeated(1);
                 $modelGroup->save();
                 //mesaj de succes
                 $this->_flashMessenger->addMessage("<div class='success  canhide'><p>Recurrent expense was added successfully<a href='javascript:;'></a><p></div>");
             } else {
                 //mesaj de eroare
                 $this->_flashMessenger->addMessage("<div class='failure canhide'><p>Recurrent expense was not added<a href='javascript:;'></a><p></div>");
             }
             //redirect
             $this->_redirect(WEBROOT . 'recurrent-expenses');
         }
     }
     $formsearch = new Default_Form_RecurrentExpenseSearch();
     $formsearch->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/recurrent-expenses/expense-search.phtml'))));
     $this->view->formsearch = $formsearch;
     $this->view->search = $params;
     // pagination
     $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select));
     $paginator->setItemCountPerPage(15);
     $paginator->setCurrentPageNumber($this->_getParam('page'));
     $paginator->setPageRange(5);
     Zend_Paginator::setDefaultScrollingStyle('Sliding');
     Zend_View_Helper_PaginationControl::setDefaultViewPartial(array('_pagination.phtml', $params));
     $this->view->result = $paginator;
     $this->view->itemCountPerPage = $paginator->getItemCountPerPage();
     $this->view->totalItemCount = $paginator->getTotalItemCount();
 }
Example #6
0
 public function indexAction()
 {
     $auth = Zend_Auth::getInstance();
     $authAccount = $auth->getStorage()->read();
     $params = array();
     $conditions = array();
     if ($this->getRequest()->getParam('nameSearch')) {
         $params['nameSearch'] = $this->getRequest()->getParam('nameSearch');
     }
     //BEGIN:SELECT GROUPS
     $conditions['pagination'] = true;
     $groups = new Default_Model_Groups();
     $select = $groups->getMapper()->getDbTable()->select()->from(array('g' => 'groups'), array('g.id', 'g.name', 'g.created', 'g.deleted'))->joinLeft(array('pg' => 'product_groups'), 'g.id = pg.idGroup', array('productsNr' => 'COUNT(pg.id)'))->where('NOT g.deleted');
     if (!empty($params['nameSearch'])) {
         $select->where('name LIKE ?', '%' . $params['nameSearch'] . '%');
     }
     $select->group('g.id');
     $select->setIntegrityCheck(false);
     $select->order(array('name ASC'));
     //END:SELECT GROUPS
     $form = new Default_Form_Groups();
     $form->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/groups/add-group.phtml'))));
     $this->view->form = $form;
     $this->view->color = "#fff";
     //$this->view->search=$params;
     if ($this->getRequest()->getParam('idGroup')) {
         $id = $this->getRequest()->getParam('idGroup');
         $model = new Default_Model_Groups();
         if ($model->find($id)) {
             $form = new Default_Form_Groups();
             $form->edit($model);
             $form->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/groups/edit-group.phtml'))));
             $this->view->form = $form;
             $this->view->color = $model->getColor();
             $this->view->idGroup = $model->getId();
             if ($this->getRequest()->isPost()) {
                 if ($this->getRequest()->getPost('submit')) {
                     if ($form->isValid($this->getRequest()->getPost())) {
                         $model->setOptions($form->getValues());
                         if ($groupId = $model->save()) {
                             //mesaj de succes
                             $this->_flashMessenger->addMessage("<div class='success  canhide'><p>Group was modified successfully<a href='javascript:;'></a></p></div>");
                         } else {
                             $this->_flashMessenger->addMessage("<div class='failure canhide'><p>Group was not modified<a href='javascript:;'></a></p></div>");
                         }
                         $this->_redirect(WEBROOT . 'groups');
                     }
                 }
             }
         }
     } elseif ($this->getRequest()->isPost()) {
         // && $this->getRequest()->getParam('action') == 'add'
         if ($form->isValid($this->getRequest()->getPost())) {
             $post = $this->getRequest()->getPost();
             $model = new Default_Model_Groups();
             $model->setOptions($form->getValues());
             if ($groupId = $model->save()) {
                 //mesaj de succes
                 $this->_flashMessenger->addMessage("<div class='success  canhide'><p>Group was added successfully<a href='javascript:;'></a><p></div>");
             } else {
                 //mesaj de eroare
                 $this->_flashMessenger->addMessage("<div class='failure canhide'><p>Group was not added<a href='javascript:;'></a><p></div>");
             }
             //redirect
             $this->_redirect(WEBROOT . 'groups');
         }
     }
     $formsearch = new Default_Form_GroupSearch();
     $formsearch->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/groups/group-search.phtml'))));
     $this->view->formsearch = $formsearch;
     $this->view->search = $params;
     // pagination
     $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select));
     $paginator->setItemCountPerPage(20);
     $paginator->setCurrentPageNumber($this->_getParam('page'));
     $paginator->setPageRange(5);
     Zend_Paginator::setDefaultScrollingStyle('Sliding');
     Zend_View_Helper_PaginationControl::setDefaultViewPartial(array('_pagination.phtml', array()));
     $this->view->result = $paginator;
     $this->view->itemCountPerPage = $paginator->getItemCountPerPage();
     $this->view->totalItemCount = $paginator->getTotalItemCount();
 }
Example #7
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
 }
 /** The lister function of all guardian articles
  * @access public
  */
 public function indexAction()
 {
     $page = $this->getParam('page');
     $key = md5('pas' . self::QUERY);
     if (!$this->getCache()->test($key)) {
         $guardian = self::GUARDIANAPI_URL . 'search?q=' . urlencode(self::QUERY) . '&page-size=50&order-by=newest&format=' . self::FORMAT . '&show-fields=all&show-tags=all&show-factboxes=all&show-references=all&api-key=' . $this->_apikey;
         $this->_curl->setUri($guardian);
         $this->_curl->getRequest();
         $articles = $this->_curl->getJson();
         $this->getCache()->save($articles);
     } else {
         $articles = $this->getCache()->load($key);
     }
     $results = array();
     foreach ($articles->response->results as $article) {
         if (isset($article->fields->thumbnail)) {
             $image = $article->fields->thumbnail;
         } else {
             $image = null;
         }
         if (isset($article->fields->standfirst)) {
             $stand = $article->fields->standfirst;
         } else {
             $stand = null;
         }
         $tags = array();
         foreach ($article->tags as $k => $v) {
             $tags[$k] = $v;
         }
         if (isset($article->fields->byline)) {
             $byline = $article->fields->byline;
         } else {
             $byline = null;
         }
         $results[] = array('id' => $article->id, 'headline' => $article->fields->headline, 'byline' => $byline, 'image' => $image, 'pubDate' => $article->webPublicationDate, 'content' => $article->fields->body, 'trailtext' => $article->fields->trailText, 'publication' => $article->fields->publication, 'sectionName' => $article->sectionName, 'linkText' => $article->webTitle, 'standfirst' => $stand, 'section' => $article->sectionName, 'url' => $article->webUrl, 'shortUrl' => $article->fields->shortUrl, 'publication' => $article->fields->publication, 'tags' => $tags);
     }
     $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Array($results));
     Zend_Paginator::setCache($this->getCache());
     if (isset($page) && $page != "") {
         $paginator->setCurrentPageNumber((int) $page);
     }
     $paginator->setItemCountPerPage(20)->setPageRange(10);
     if (in_array($this->_helper->contextSwitch()->getCurrentContext(), array('xml', 'json', 'rss', 'atom'))) {
         $paginated = array();
         foreach ($paginator as $k => $v) {
             $paginated[$k] = $v;
         }
         $data = array('pageNumber' => $paginator->getCurrentPageNumber(), 'total' => number_format($paginator->getTotalItemCount(), 0), 'itemsReturned' => $paginator->getCurrentItemCount(), 'totalPages' => number_format($paginator->getTotalItemCount() / $paginator->getItemCountPerPage(), 0));
         $this->view->data = $data;
         $this->view->guardianStories = array('guardianStory' => $paginated);
     } else {
         $this->view->data = $paginator;
     }
 }
Example #9
0
 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;
 }
Example #10
0
 /**
  * List products according given parameters.
  * This list is only for display purpose. No actions except Excel export.
  *
  * @return void
  */
 public function listAction()
 {
     $img = $this->_getParam('img');
     if (!empty($img)) {
         $this->downloadAction();
         exit;
     }
     $this->view->params['actions'] = $this->_request->getPathInfo();
     /* List products */
     $oProducts = new ProductsCollection($this->view->params);
     $products = $oProducts->getList();
     $searchCount = count($products);
     /* Params */
     $subCategoryId = 0;
     $blockParams = $oProducts->getBlockParams();
     $categorieId = $oProducts->getCatId();
     $productId = $oProducts->getProdId();
     $url = $this->view->absolute_web_root . $this->getRequest()->getPathInfo();
     Cible_View_Helper_LastVisited::saveThis($url);
     if (!$productId) {
         if (!$categorieId) {
             $categorieId = $blockParams[1];
         }
         //        Zend_Registry::set('bg-body-id', $categorieId);
         $subCategoryId = $oProducts->getSubCatId();
         if ($subCategoryId) {
             $oSubCat = new SubCategoriesObject();
             $subCat = $oSubCat->populate($subCategoryId, Zend_Registry::get('languageID'));
             $this->view->subCatName = $subCat['SCI_Name'];
         }
         $searchWords = isset($this->view->params['keywords']) && $this->view->params['keywords'] != $this->view->getCibleText('form_search_catalog_keywords_label') ? $this->view->params['keywords'] : '';
         /* Search form */
         //        $searchForm = new FormSearchCatalogue(
         //            array(
         //                'categorieId'   => $categorieId,
         //                'subCategoryId' => $subCategoryId,
         //                'keywords'      => $searchWords)
         //            );
         //
         //        $this->view->assign('searchForm', $searchForm);
         $oCategory = new CatalogCategoriesObject();
         $category = $oCategory->populate($categorieId, $this->_registry->languageID);
         $this->_registry->set('category', $category);
         $lastSearch = array();
         if (!empty($subCategoryId)) {
             $lastSearch['sousCatId'] = $subCategoryId;
         }
         if (!empty($searchWords)) {
             $lastSearch['keywords'] = $searchWords;
         }
         $this->view->assign('searchUrl', $lastSearch);
         $page = 1;
         $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Array($products));
         $paginator->setItemCountPerPage($oProducts->getLimit());
         if (isset($this->view->params['productId'])) {
             $productId = $this->view->params['productId'];
             $this->view->assign('productId', $productId);
             foreach ($products as $product) {
                 if ($product['P_ID'] != $productId) {
                     $page++;
                 } else {
                     break;
                 }
             }
         }
         $filter = $oProducts->getFilter();
         $paramPage = $this->_request->getParam('page');
         $page = isset($paramPage) ? $this->_request->getParam('page') : ceil($page / $paginator->getItemCountPerPage());
         $paginator->setCurrentPageNumber($page);
         $this->view->assign('categoryId', $categorieId);
         $this->view->assign('params', $oProducts->getBlockParams());
         $this->view->assign('paginator', $paginator);
         $this->view->assign('keywords', $searchWords);
         $this->view->assign('searchCount', $searchCount);
         $this->view->assign('filter', $filter);
         if (isset($category['CCI_ValUrl'])) {
             echo $this->_registry->set('selectedCatalogPage', $category['CCI_ValUrl']);
         }
     } else {
         $this->_registry->set('category', $this->_registry->get('catId_'));
         $this->_registry->set('productCase', '1');
         $url = $this->view->absolute_web_root . $this->getRequest()->getPathInfo();
         Cible_View_Helper_LastVisited::saveThis($url);
         $this->_registry->set('selectedCatalogPage', $products['CCI_ValUrl']);
         $this->view->assign('productDetails', $products);
         $this->renderScript('index/detail-product.phtml');
     }
 }
 public function membersAction()
 {
     $page = $this->_getParam('page');
     if (!$this->_cache->test('members')) {
         $query = 'getMps';
         $output = '&output=xml';
         $key = '&key=' . self::TWFYAPIKEY;
         $twfy = self::TWFYURL . $query . $output . $key;
         $data = Zend_Json::fromXml($this->get($twfy), true);
         $data = json_decode($data);
         $this->_cache->save($data);
     } else {
         $data = $this->_cache->load('members');
     }
     $data2 = array();
     foreach ($data->twfy->match as $a) {
         if (in_array($a->constituency, $this->_remove)) {
             unset($a->name);
             unset($a->person_id);
             unset($a->party);
             unset($a->constituency);
         }
         if (isset($a->name)) {
             $data2[] = array('name' => $a->name, 'person_id' => $a->person_id, 'constituency' => $a->constituency, 'party' => $a->party);
         }
     }
     $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Array($data2));
     if (isset($page) && $page != "") {
         $paginator->setCurrentPageNumber((int) $page);
     }
     $paginator->setItemCountPerPage(40)->setPageRange(10);
     if (in_array($this->_helper->contextSwitch()->getCurrentContext(), array('xml', 'json'))) {
         $data = array('pageNumber' => $paginator->getCurrentPageNumber(), 'total' => number_format($paginator->getTotalItemCount(), 0), 'itemsReturned' => $paginator->getCurrentItemCount(), 'totalPages' => number_format($paginator->getTotalItemCount() / $paginator->getItemCountPerPage(), 0));
         $this->view->data = $data;
         $members = array();
         foreach ($paginator as $k => $v) {
             $members[] = array();
             $members[$k] = $v;
         }
         $this->view->members = $members;
     } else {
         $this->view->data = $paginator;
     }
 }
Example #12
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
 }