示例#1
0
 /**
  * Add the WHERE clause that keeps offline items from appearing in the results
  * @param Garp_Model_Db $model
  * @param Zend_Db_Select $select
  * @return Void
  */
 public function addWhereClause(&$model, Zend_Db_Select &$select)
 {
     $statusColumn = $model->getAdapter()->quoteIdentifier(self::STATUS_COLUMN);
     $publishedColumn = $model->getAdapter()->quoteIdentifier(self::PUBLISHED_COLUMN);
     if ($this->_modelAlias) {
         $modelAlias = $this->_modelAlias;
         $modelAlias = $model->getAdapter()->quoteIdentifier($modelAlias);
         $statusColumn = "{$modelAlias}.{$statusColumn}";
         $publishedColumn = "{$modelAlias}.{$publishedColumn}";
     }
     // Add online_status check
     $select->where($statusColumn . ' = ?', self::ONLINE);
     // Add published check
     if ($this->_config['draft_only']) {
         return;
     }
     $ini = Zend_Registry::get('config');
     $timezone = !empty($ini->resources->db->params->timezone) ? $ini->resources->db->params->timezone : null;
     $timecalc = '';
     if ($timezone == 'GMT' || $timezone == 'UTC') {
         $dstStart = strtotime('Last Sunday of March');
         $dstEnd = strtotime('Last Sunday of October');
         $now = time();
         $daylightSavingsTime = $now > $dstStart && $now < $dstEnd;
         $timecalc = '+ INTERVAL';
         if ($daylightSavingsTime) {
             $timecalc .= ' 2 HOUR';
         } else {
             $timecalc .= ' 1 HOUR';
         }
     }
     $select->where($publishedColumn . ' IS NULL OR ' . $publishedColumn . ' <= NOW() ' . $timecalc);
 }
示例#2
0
 /**
  * Set WHERE clause that checks for slug existence.
  * @param Zend_Db_Select $select
  * @param String $slugField
  * @param String $slug
  * @param Garp_Model_Db $model
  * @param String $lang
  * @return Void
  */
 protected function _setWhereClause(Zend_Db_Select &$select, $slugField, $slug, Garp_Model_Db $model, $lang = null)
 {
     $slugField = $model->getAdapter()->quoteIdentifier($slugField);
     $select->reset(Zend_Db_Select::WHERE)->where($slugField . ' = ?', $slug);
     if ($lang) {
         $select->where(Garp_Model_Behavior_Translatable::LANG_COLUMN . ' = ?', $lang);
     }
 }
示例#3
0
 /**
  * A real hacky solution to enable admins to search for translated content in the CMS
  *
  * @param Garp_Model_Db $model
  * @param Zend_Db_Select $select
  * @param string $likeValue
  * @return string A search clause
  */
 protected function _joinCmsSearchQuery(Garp_Model_Db $model, Zend_Db_Select &$select, $likeValue)
 {
     $languages = Garp_I18n::getLocales();
     $default_language = array(Garp_I18n::getDefaultLocale());
     $langColumn = self::LANG_COLUMN;
     // Exclude default language, since that's already joined in the joint view
     $languages = array_diff($languages, $default_language);
     $adapter = $model->getAdapter();
     $where = array();
     foreach ($languages as $language) {
         $i18nModel = $this->getI18nModel($model);
         $i18nAlias = $model->getName() . '_i18n_' . $language;
         $onClause = $i18nModel->refMapToOnClause(get_class($model), $i18nAlias, $model->getJointView());
         // join i18n model
         $select->joinLeft(array($i18nAlias => $i18nModel->getName()), "{$onClause} AND {$i18nAlias}.{$langColumn} = '{$language}'", array());
         // add WHERE clauses that search in the i18n model
         $translatedFields = $this->_translatableFields;
         foreach ($translatedFields as $i18nField) {
             $where[] = "{$i18nAlias}.{$i18nField} LIKE " . $adapter->quote($likeValue);
         }
     }
     return implode(' OR ', $where);
 }