Exemplo n.º 1
0
 public function isValid($value, $context = null)
 {
     $result = true;
     $this->_value = $value;
     $whereAnd[] = $this->dbAdapter->quoteInto("ti.box_id = ? ", $this->_data['box_id']);
     if (isset($this->_data['start_dt']) && $this->_data['start_dt'] != '' && $this->_data['start_dt'] == $value) {
         $whereOr[] = $this->dbAdapter->quoteInto("(ti.start_dt < ? AND  ti.end_dt > ? )", HCMS_Utils_Date::dateLocalToIso($this->_data['start_dt']));
     }
     if (isset($this->_data['end_dt']) && $this->_data['end_dt'] != '' && $this->_data['end_dt'] == $value) {
         $whereOr[] = $this->dbAdapter->quoteInto("(ti.start_dt < ? AND  ti.end_dt > ? )", HCMS_Utils_Date::dateLocalToIso($this->_data['end_dt']));
     }
     if (isset($this->_data['id']) && $this->_data['end_dt'] != '') {
         $whereAnd[] = $this->dbAdapter->quoteInto("ti.id != ? ", $this->_data['id']);
     }
     if (isset($this->_data['end_dt']) && $this->_data['end_dt'] != '' && isset($this->_data['start_dt']) && $this->_data['start_dt'] != '') {
         $whereOr[] = $this->dbAdapter->quoteInto("(ti.start_dt >= ?  AND ", HCMS_Utils_Date::dateLocalToIso($this->_data['start_dt'])) . $this->dbAdapter->quoteInto(" ti.end_dt <= ? )", HCMS_Utils_Date::dateLocalToIso($this->_data['end_dt']));
     }
     $whereOr = implode(' OR ', $whereOr);
     $whereAnd = implode(' AND ', $whereAnd);
     $sql = "SELECT COUNT(ti.id) AS doubles\n                FROM teaser_item AS ti\n                WHERE ({$whereOr} )AND {$whereAnd}";
     //        echo "\n\n$sql\n\n"; die();
     $resultSet = $this->dbAdapter->fetchAll($sql);
     if (0 == count($resultSet)) {
         return false;
     }
     $row = $resultSet[0];
     $result = $row['doubles'] == 0;
     if (!$result) {
         $this->_error(self::PERIOD_OCCUPIED);
     }
     return $result;
 }
Exemplo n.º 2
0
 public function indexAction()
 {
     $teaserId = $this->_getParam('preview_teaser_id');
     $previewDTIso = $this->_request->getParam('preview_dt');
     if (!isset($teaserId)) {
         throw new Exception('Slider not defined');
     }
     if (!isset($previewDTIso)) {
         throw new Exception('Date/time not defined');
     }
     $teaser = new Teaser_Model_Teaser();
     if (!Teaser_Model_TeaserMapper::getInstance()->find($teaserId, $teaser)) {
         throw new Exception('Slider not found');
     }
     echo $this->view->renderTeaser2($teaser->get_box_code(), null, CURR_LANG, array('preview_teaser_id' => $teaserId, 'active' => 'yes', 'preview_dt' => HCMS_Utils_Date::dateLocalToIso($previewDTIso)));
     $this->_helper->viewRenderer->setNoRender(true);
 }
Exemplo n.º 3
0
 /**
  * Find all items
  * @param array $criteria
  * @param array $orderBy
  * @param array $paging
  * @return array 
  */
 public function fetchAll($criteria = array(), $orderBy = array(), &$paging = null)
 {
     /* @var $select Zend_Db_Select*/
     $select = $this->_dbTable->select();
     $select->setIntegrityCheck(false)->from(array('i' => 'teaser_item'), array('i.*'));
     if (isset($criteria['lang'])) {
         $this->_makeTranslationJoin($criteria['lang'], $select, 'teaser_item', 'i', 'id', self::$_translatedFields);
     }
     if (isset($criteria['search_filter'])) {
         $select->where('i.title LIKE  ?', '%' . $criteria['search_filter'] . '%');
     }
     if (isset($criteria['title'])) {
         $select->where(' i.title LIKE ? ', '%' . $criteria['title'] . '%');
     }
     if (isset($criteria['start_dt'])) {
         $select->where(' i.start_dt >= ? ', HCMS_Utils_Date::dateLocalToIso($criteria['start_dt']));
     }
     if (isset($criteria['end_dt'])) {
         $select->where('i.end_dt <= ? ', HCMS_Utils_Date::dateLocalToIso($criteria['end_dt']));
     }
     if (isset($criteria['fallback'])) {
         $select->where('i.fallback = ? ', $criteria['fallback']);
     }
     if (isset($criteria['box_id'])) {
         $select->where('i.box_id = ? ', $criteria['box_id']);
     }
     if (isset($criteria['code'])) {
         $select->where('tb.code = ? ', $criteria['code']);
     }
     if (isset($criteria['active']) && $criteria['active'] == 'yes') {
         $select->where('i.end_dt > NOW()');
         $select->where('i.start_dt <= NOW()');
     }
     if (isset($criteria['box_code'])) {
         $select->where('i.box_code = ? ', $criteria['box_code']);
     }
     if (is_array($orderBy) && count($orderBy) > 0) {
         $select->order($orderBy);
     } else {
         $select->order(array('i.order_num ASC'));
     }
     //        echo $select->__toString();die();
     // init paginator
     if ($paging != null) {
         $resultSet = $this->_getPagingRows($paging, $select);
     } else {
         $resultSet = $this->_dbTable->fetchAll($select);
     }
     $items = array();
     if (0 == count($resultSet)) {
         return $items;
     }
     foreach ($resultSet as $row) {
         $item = new Teaser_Model_Item();
         $this->_rowToEntity($row->toArray(), $item);
         $items[] = $item;
     }
     return $items;
 }
 public function itemEditAction()
 {
     $data = $this->getRequest()->getPost('data');
     $id = $this->_getParam('id');
     $cloneId = $this->_getParam('clone_id');
     $langFilter = $this->_getParam('langFilter');
     $defaultTeaserId = $this->_getParam('teaser_id');
     //check if cancel button is pressed
     if ($this->_formHelper->isCancel()) {
         //cancel form
         return $this->_formHelper->returnCancel($this->view->url(array('action' => 'index')), $this->translate('Action canceled'));
     }
     //create form object
     $form = new Teaser_Form_TeaserItem($data);
     //postback - save?
     if ($this->_formHelper->isSave()) {
         //check if valid
         if ($form->isValid()) {
             $values = $form->getValues();
             //create entity object from submitted values, and save
             $item = new Teaser_Model_Item($values);
             $item->set_start_dt(HCMS_Utils_Date::dateLocalToIso($item->get_start_dt()));
             if (isset($data["end_dt"]) && $data["end_dt"] != "") {
                 $item->set_end_dt(HCMS_Utils_Date::dateLocalToIso($item->get_end_dt()));
             }
             Teaser_Model_ItemMapper::getInstance()->save($item, $langFilter != '' ? $langFilter : null);
             //save done, return success
             return $this->_formHelper->returnSuccess($this->view->url(array('action' => 'index')), $this->translate('Item saved.'));
         } else {
             //we have errors - return json or continue
             $this->_formHelper->returnError($form->getMessages());
         }
     } elseif (!$this->_formHelper->getRequest()->isPost()) {
         if (!isset($id) && isset($cloneId)) {
             $id = $cloneId;
         }
         //edit action
         if (isset($id) && $id > 0) {
             $item = new Teaser_Model_Item();
             if (!Teaser_Model_ItemMapper::getInstance()->find($id, $item, $langFilter != '' ? $langFilter : null)) {
                 throw new Exception("Item not found");
             }
             Teaser_Model_ItemMapper::getInstance()->populateTeaserIds($item);
             //fetch data
             $data = $item->toArray();
             $data['start_dt'] = HCMS_Utils_Date::dateIsoToLocal($item->get_start_dt(), "HH:mm");
             $data['end_dt'] = HCMS_Utils_Date::dateIsoToLocal($item->get_end_dt(), "HH:mm");
             $data['teaser_ids'] = $item->get_teaser_ids();
             if (isset($cloneId)) {
                 unset($data['id']);
                 $data['title'] = 'Clone ' . $data['title'];
             }
             //populate form with data
             $form->setData($data);
         }
         if (null != $this->_getParam('box_code')) {
             $data['box_code'] = $this->_getParam('box_code');
         }
     }
     $languages = Application_Model_TranslateMapper::getInstance()->getLanguages();
     $this->view->languages = $languages;
     if (!isset($data['teaser_ids'])) {
         $data['teaser_ids'] = array();
     }
     $this->view->data = $data;
     //teasers with the same box
     $this->view->availableTeasers = Teaser_Model_TeaserMapper::getInstance()->fetchAll(array('box_code' => $data['box_code']));
     $this->view->defaultTeaserId = $defaultTeaserId;
 }
Exemplo n.º 5
0
 /**
  * Find all items
  * 
  * @param array $criteria
  * @param array $orderBy
  * @param array $paging
  * @return array 
  */
 public function fetchWithItems($criteria = array(), $orderBy = array(), &$paging = null)
 {
     /* @var $select Zend_Db_Select*/
     $select = $this->_dbTable->select();
     $select->setIntegrityCheck(false)->from(array('t' => 'teaser'), array('teaser_id' => 't.id', 'teaser_name' => 't.name', 'teaser_box_code' => 't.box_code', 'teaser_content' => 't.content', 'teaser_all_menu_items' => 'all_menu_items'))->joinLeft(array('thi' => 'teaser_has_items'), 'thi.teaser_id = t.id', array('order_num' => 'thi.order_num'))->joinLeft(array('i' => 'teaser_item'), 'thi.item_id = i.id', array('i.*'));
     if (isset($criteria['lang'])) {
         $this->_makeTranslationJoin($criteria['lang'], $select, 'teaser_item', 'i', 'id', Teaser_Model_ItemMapper::$_translatedFields);
     }
     if (isset($criteria['search_filter'])) {
         $select->where('i.title LIKE  ?', '%' . $criteria['search_filter'] . '%');
     }
     if (isset($criteria['title'])) {
         $select->where('i.title LIKE ? ', '%' . $criteria['title'] . '%');
     }
     if (isset($criteria['name'])) {
         $select->where('t.name LIKE ? ', '%' . $criteria['name'] . '%');
     }
     if (isset($criteria['preview_teaser_id'])) {
         $select->where('t.id = ? ', $criteria['preview_teaser_id']);
     }
     if (isset($criteria['start_dt'])) {
         $select->where('i.start_dt >= ? ', HCMS_Utils_Date::dateLocalToIso($criteria['start_dt']));
     }
     if (isset($criteria['end_dt'])) {
         $select->where('i.end_dt <= ? ', HCMS_Utils_Date::dateLocalToIso($criteria['end_dt']));
     }
     if (isset($criteria['fallback'])) {
         $select->where('i.fallback = ? ', $criteria['fallback']);
     }
     if (isset($criteria['box_code'])) {
         $select->where('t.box_code = ? ', $criteria['box_code']);
     }
     if (isset($criteria['menu_item_id'])) {
         $select->joinLeft(array('tmi' => 'teaser_menu_item'), 'tmi.teaser_id = t.id', array());
         $select->where("(t.all_menu_items = 'yes' OR tmi.menu_item_id = ?)", $criteria['menu_item_id']);
     }
     if (isset($criteria['active']) && $criteria['active'] == 'yes') {
         $momentStr = isset($criteria['preview_dt']) ? "'" . $criteria['preview_dt'] . "'" : 'NOW()';
         $select->where('i.fallback = \'yes\' OR (i.end_dt > ' . $momentStr . ' AND i.start_dt <= ' . $momentStr . ')');
         $select->where('i.start_dt <= ' . $momentStr);
     }
     if (is_array($orderBy) && count($orderBy) > 0) {
         $select->order($orderBy);
     } else {
         $select->order(array('t.id', 'thi.order_num'));
     }
     //echo $select->__toString();die();
     // init paginator
     if ($paging != null) {
         $resultSet = $this->_getPagingRows($paging, $select);
     } else {
         $resultSet = $this->_dbTable->fetchAll($select);
     }
     $teasers = array();
     if (0 == count($resultSet)) {
         return $teasers;
     }
     $itemMapper = Teaser_Model_ItemMapper::getInstance();
     $currTeaserId = -1;
     $teaser = null;
     $items = array();
     foreach ($resultSet as $row) {
         //new teaser
         if ($row->teaser_id != $currTeaserId) {
             if (isset($teaser)) {
                 $teaser->set_items($items);
             }
             //reset items
             $items = array();
             $currTeaserId = $row->teaser_id;
             $teaser = new Teaser_Model_Teaser();
             $this->_rowToEntity(array('id' => $row->teaser_id, 'name' => $row->teaser_name, 'box_code' => $row->teaser_box_code, 'content' => $row->teaser_content, 'all_menu_items' => $row->teaser_all_menu_items), $teaser);
             $teasers[] = $teaser;
         }
         //items
         if ($row->id) {
             //check if item exists
             $item = new Teaser_Model_Item();
             $itemArr = $row->toArray();
             $itemMapper->_rowToEntity($itemArr, $item);
             $items[] = $item;
         }
     }
     if (isset($teaser) && count($items)) {
         $teaser->set_items($items);
     }
     return $teasers;
 }
 /**
  * Export action
  */
 public function exportAction()
 {
     $langFilter = $this->_request->getParam('langFilter');
     $searchFilter = $this->_request->getParam('searchFilter');
     $fromFilter = $this->_request->getParam('fromFilter');
     $toFilter = $this->_request->getParam('toFilter');
     //contact types
     $header = array('status' => $this->translate('Status'), 'first_name' => $this->translate('First Name'), 'last_name' => $this->translate('Last Name'), 'gender' => $this->translate('Gender'), 'email' => $this->translate('Email'), 'lang' => $this->translate('Language'), 'subscribed_dt' => $this->translate('Subscribed'), 'unsubscribed_dt' => $this->translate('Unsubscribed'));
     $criteria = array('application_id' => $this->_applicationId, 'data_type' => 'array');
     $criteria = array('application_id' => $this->_applicationId);
     if (null != $this->_getParam('langFilter')) {
         $criteria['lang'] = $this->_getParam('langFilter');
     }
     if (null != $this->_getParam('statusFilter')) {
         $criteria['status'] = $this->_getParam('statusFilter');
     }
     if (null != $this->_getParam('genderFilter')) {
         $criteria['gender'] = $this->_getParam('genderFilter');
     }
     if (null != $this->_getParam('subscribed_from_dt')) {
         $criteria['subscribed_from'] = HCMS_Utils_Date::dateLocalToIso($this->_getParam('subscribed_from_dt'));
     }
     if (null != $this->_getParam('subscribed_to_dt')) {
         $criteria['subscribed_to'] = HCMS_Utils_Date::dateLocalToIso($this->_getParam('subscribed_to_dt'));
     }
     if (null != $this->_getParam('unsubscribed_from_dt')) {
         $criteria['unsubscribed_from'] = HCMS_Utils_Date::dateLocalToIso($this->_getParam('unsubscribed_from_dt'));
     }
     if (null != $this->_getParam('unsubscribed_to_dt')) {
         $criteria['unsubscribed_to'] = HCMS_Utils_Date::dateLocalToIso($this->_getParam('unsubscribed_to_dt'));
     }
     if (isset($orderFilter) && !empty($orderFilter)) {
         $orderBy = array($orderFilter);
     } else {
         $orderBy = array('s.subscribed_dt DESC', 's.unsubscribed_dt DESC', 's.id DESC');
     }
     //read data to export
     $records = Contact_Model_SubscriptionMapper::getInstance()->fetchAll($criteria, $orderBy);
     /* @var $record Contact_Model_Subscription */
     foreach ($records as $record) {
         $recordArr = $record->toArray();
         $recordArr['gender'] = isset($recordArr['gender']) ? $this->view->translate($recordArr['gender']) : '';
         $records_trans[] = $recordArr;
     }
     //get exported object
     $objPHPExcel = Contact_Model_SubscriptionMapper::getInstance()->exportToExcel($this->_applicationId, $header, $records_trans, $this);
     if ($objPHPExcel != null) {
         while (ob_get_level() > 0) {
             ob_end_clean();
         }
         //disable layout
         $this->_helper->layout->disableLayout();
         $this->_helper->viewRenderer->setNoRender(true);
         // rename sheet
         $objPHPExcel->getActiveSheet()->setTitle($this->translate($this->_application->get_name()));
         $fileName = $this->_application->get_name() . "-newsletter-subscriptions" . "-" . Zend_Date::now()->toString('d-MMM-Y') . ".xls";
         // redirect output to client browser
         header('Content-Type: application/vnd.ms-excel');
         header('Content-Disposition: attachment;filename="' . $fileName . '"');
         header('Cache-Control: max-age=0');
         //create excel writer
         $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
         // output to browser
         $objWriter->save('php://output');
         exit;
     } else {
         $this->getHelper('flashMessenger')->addMessage(array("err" => $this->translate("Error occurred while exporting!")));
         $this->_redirect($this->view->url(array('action' => 'index')));
     }
 }