/src/components/com_coupon/models/coupon.php
PHP | 171 lines | 102 code | 21 blank | 48 comment | 14 complexity | 9cea379e6651abe66d38c52ae79b3a0c MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
- <?php
- /**
- * @version $Id: archive.php 19343 2010-11-03 18:12:02Z ian $
- * @package Joomla
- * @subpackage Content
- * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
- * @license GNU/GPL, see LICENSE.php
- * Joomla! is free software. This version may have been modified pursuant to the
- * GNU General Public License, and as distributed it includes or is derivative
- * of works licensed under the GNU General Public License or other free or open
- * source software licenses. See COPYRIGHT.php for copyright notices and
- * details.
- */
-
- // Check to ensure this file is included in Joomla!
- defined('_JEXEC') or die( 'Restricted access' );
-
- jimport('joomla.application.component.model');
-
- /**
- * Content Component Archive Model
- *
- * @package Joomla
- * @subpackage Content
- * @since 1.5
- */
- class CouponModelCoupon extends JModel
- {
- /**
- * Article list array
- *
- * @var array
- */
- var $_data = array();
-
- /**
- * Article total
- *
- * @var integer
- */
- var $_total = array();
-
- /**
- * Method to get the archived article list
- *
- * @access public
- * @return array
- */
- function getData()
- {
- global $mainframe;
- // Lets load the content if it doesn't already exist
- if (empty($this->_data))
- {
- $query = $this->_buildQuery();
- $this->_data = $this->_getList($query);
- }
-
- return $this->_data;
- }
-
- /**
- * Method to get the total number of content items for the frontpage
- *
- * @access public
- * @return integer
- */
- function getTotal()
- {
- // Lets load the content if it doesn't already exist
- if (empty($this->_total))
- {
- $query = $this->_buildQuery();
- $this->_total = $this->_getListCount($query);
- }
-
- return $this->_total;
- }
-
- // JModel override to add alternating value for $odd
- function &_getList( $query, $limitstart=0, $limit=0 )
- {
- $result =& parent::_getList($query, $limitstart, $limit);
- if ($result == null) {
- $result = array();
- }
-
- $odd = 1;
- foreach ($result as $k => $row) {
- $result[$k]->odd = $odd;
- $odd = 1 - $odd;
- }
-
- return $result;
- }
-
- function _buildQuery()
- {
- global $mainframe;
- $db =& JFactory::getDBO();
- $params = &$mainframe->getParams();
- $session = JFactory::getSession();
- $catid = $db->getEscaped(JRequest::getInt("coupon_cat", 0));
- if ($catid == 0) {
- $catid = $this->getGroupCatFromCookie();
-
- if ($catid == null || !CouponHelperCoupon::isCouponCatEnable($catid)) {
- jimport("site.constants");
- $catid = JSiteConstants::LOCATE_CAT_DANANG;
- }
- }
- $industryid = JRequest::getInt('industryid', 0);
- // Get the WHERE and ORDER BY clauses for the query
- $where = 'HAVING (cat_id = ' . $catid . ' or cat_id = 0) AND deal.status = 1 ';
- if($industryid != 0) {
- $where = $where.'AND industry_id = '.$industryid;
- }
- $orderby = " ORDER BY deal.priority desc ";
- $query = 'SELECT DISTINCT deal.*, DATE_FORMAT(MIN(satisfy_time), "%e %m %Y %H %i %s") AS satisfy_time,DATE_FORMAT(dead_line, "%e %m %Y %H %i %s") AS dead_line, dead_line - now() < 0 as time_out, SUM(deal_option.counter) AS counter, deal.min_order AS min_order, SUM(deal_option.max_order) AS max_order, deal_option.deal_id' .
- ', CASE WHEN CHAR_LENGTH(deal.alias) THEN CONCAT_WS(":", deal.id, deal.alias) ELSE deal.id END as slug' .
- ' FROM pm_deal deal LEFT JOIN pm_deal_option deal_option ON deal.id = deal_option.deal_id
- GROUP BY deal_option.deal_id '.
- $where.
- $orderby;
- return $query;
- }
-
- function getOptionsOfDeal($dealId) {
- $query = $this->_buildOptionsOfDealQuery($dealId);
- $result =& parent::_getList($query);
- return $result;
- }
-
- function _buildOptionsOfDealQuery($dealId) {
- global $mainframe;
- $params = &$mainframe->getParams();
-
- $industryid = JRequest::getInt('industryid', 0);
- // Get the WHERE and ORDER BY clauses for the query
- $where = ' WHERE deal_id='.$dealId;
- if($industryid != 0) {
- $where = $where.'AND industry_id = '.$industryid;
- }
- $orderby = " ORDER BY ordering ";
- $limit = "";
- $query = 'SELECT * FROM #__deal_option '.
- $where.
- $orderby.
- $limit;
- return $query;
- }
-
- function getGroupCatFromCookie() {
- $result = null;
- jimport('joomla.utilities.utility');
- $hash = JUtility::getHash('JCOUPON_CATEGORY_ID');
-
- if ($str = JRequest::getString($hash, '', 'cookie', JREQUEST_ALLOWRAW | JREQUEST_NOTRIM))
- {
- jimport('joomla.utilities.simplecrypt');
-
- //Create the encryption key, apply extra hardening using the user agent string
- $key = JUtility::getHash('JCOUPON_CATEGORY_ID');
-
- $crypt = new JSimpleCrypt($key);
- $result = $crypt->decrypt($str);
- }
-
- return $result;
- }
- }