array('title')); protected $_statuses = array( 'active' => 'Active', 'upcoming' => 'Not Active', 'expired' => 'Expired', '' => 'All', ); public function getStatuses() { return $this->_statuses; } protected function _filter(Zend_Db_Select $select) { if (!$this->hasFilter()) { return $this; } parent::_filter($select); if (!empty($this->_filter['status'])) { switch ($this->_filter['status']) { case 'active': $select->where('`startDate` <= CURRENT_DATE()'); $select->where('`hasNoExpirationDate` = "y" OR `endDate` >= CURRENT_DATE()'); break; case 'upcoming': $select->where('`startDate` > CURRENT_DATE()'); break; case 'expired': $select->where('`hasNoExpirationDate` = "n"'); $select->where('`endDate` < CURRENT_DATE()'); break; } } if (array_key_exists('query', $this->_filter)) { $this->_select->joinLeft( $this->_getPair($this->_tableAlias . '2ProductCategory', 'p2pc'), '`p2pc`.`promoId` = `Promo`.`id`', [] ); $this->_select->joinLeft( $this->_getPair('ProductCategory', 'pc'), '`pc`.`id` = `p2pc`.`categoryId`', [] ); $this->_select->group('Promo.id'); } return $this; } /** * Return data for code * * @param string $code * @return array|bool */ public function getDataByCode($code) { if ($promoData = $this->_getTable()->searchBy(array('code' => $code))) { $this->_addRelatedProductCategories($promoData); } return $promoData; } public function generateCode($iterations = self::CODE_GENERATION_ITERATIONS) { $codeValidator = new Qs_Validate_Unique(new Qs_Db_Table('Promo'), 'code', $this->getData('id')); $expirationWhere = '(`hasNoExpirationDate` = "y") OR (`hasNoExpirationDate` = "n" AND `endDate` < CURRENT_DATE())'; $codeValidator->setWhere($expirationWhere); $iterations = (int) $iterations; $iterations = ($iterations > 0) ? $iterations : static::CODE_GENERATION_ITERATIONS; $code = ''; $unique = false; while ($unique == false && $iterations > 0) { $code = strtoupper(substr(md5(rand().microtime(true).rand()), 0, static::DEFAULT_CODE_LENGTH)); $code = strtoupper($code); if ($codeValidator->isValid($code)) { $unique = true; } else { $code = ''; } $iterations--; } return $code; } public function getObjectInfo() { $data = parent::getObjectInfo(); $data['itemTitle'] = strip_tags($this->_renderDescription($data)); return $data; } protected function _renderDescription(array $data) { $text = ''; if (empty($data)) { return $text; } if ($data['type'] == App_ECommerce_Promo_Admin_View::PROMO_TYPE_PERCENT) { require_once 'lib/Smarty/app_plugins/modifier.money.php'; $text .= smarty_modifier_money($data['value'], 2, true) . '% '; } else { $text .= '$' . number_format($data['value'], 2, '.', ',') . ' '; } $text .= 'off '; if ('y' == $data['isRelated'] && $data['relatedCategories']) { $cateories = explode(self::CATEGORY_SEPARATOR, $data['relatedCategories']); $cateoriesList = '