Exemple #1
0
 /**
  * Get Select object (Zend_Db_Select) for filtering table records
  *
  * @param Zend_Db_Select $select
  * @param array $filter         
  *
  * @return Zend_Db_Select
  */
 public static function GetSelectForFilter($select, $filter)
 {
     $joinTable = '';
     //-----------------------------------
     // создадим фильтр по разрешению/запрету (актуальности) блогов
     // Построим выражения SELECT
     foreach ($filter as $field => $filterParams) {
         $joinTable = $filterParams['joinTable'];
         $aliasTable = Default_Model_DatabaseObject::getAliasForTable($select, $joinTable);
         $filterParams = $filterParams['filterParams'];
         switch ($joinTable) {
             case 'blog_posts_profile':
                 if (!$aliasTable) {
                     $select->joinInner(array('p_profile' => $joinTable), 'p_profile.post_id = p.id', array())->where('p_profile.profile_key = ?', $field);
                 }
                 foreach ($filterParams as $filterParam) {
                     if (is_array($filterParam)) {
                         $andLogic = (bool) $filterParam['andLogic'];
                         if ($andLogic) {
                             $select->where('p_profile.profile_value ' . $filterParam['compare'] . ' ?', $filterParam['value']);
                         } else {
                             $select->orWhere('p_profile.profile_value ' . $filterParam['compare'] . ' ?', $filterParam['value']);
                         }
                     }
                 }
                 break;
             case 'blog_posts_images':
                 if (!$aliasTable) {
                     $select->joinInner(array('img' => $joinTable), 'img.post_id = p.id', array());
                 }
                 foreach ($filterParams as $filterParam) {
                     if (is_array($filterParam)) {
                         $andLogic = (bool) $filterParam['andLogic'];
                         if ($andLogic) {
                             $select->where('img.' . $field . ' ' . $filterParam['compare'] . ' ?', $filterParam['value']);
                         } else {
                             $select->orWhere('img.' . $field . ' ' . $filterParam['compare'] . ' ?', $filterParam['value']);
                         }
                     }
                 }
                 break;
             case 'blog_posts_audio':
                 if (!$aliasTable) {
                     $select->joinInner(array('au' => $joinTable), 'au.post_id = p.id', array());
                 }
                 foreach ($filterParams as $filterParam) {
                     if (is_array($filterParam)) {
                         $andLogic = (bool) $filterParam['andLogic'];
                         if ($andLogic) {
                             $select->where('au.' . $field . ' ' . $filterParam['compare'] . ' ?', $filterParam['value']);
                         } else {
                             $select->orWhere('au.' . $field . ' ' . $filterParam['compare'] . ' ?', $filterParam['value']);
                         }
                     }
                 }
                 break;
             case 'blog_posts_video':
                 if (!$aliasTable) {
                     $select->joinInner(array('v' => $joinTable), 'v.post_id = p.id', array());
                 }
                 foreach ($filterParams as $filterParam) {
                     if (is_array($filterParam)) {
                         $andLogic = (bool) $filterParam['andLogic'];
                         if ($andLogic) {
                             $select->where('v.' . $field . ' ' . $filterParam['compare'] . ' ?', $filterParam['value']);
                         } else {
                             $select->orWhere('v.' . $field . ' ' . $filterParam['compare'] . ' ?', $filterParam['value']);
                         }
                     }
                 }
                 break;
             case 'blog_posts_lacations':
                 if (!$aliasTable) {
                     $select->joinInner(array('l' => $joinTable), 'l.post_id = p.id', array());
                 }
                 foreach ($filterParams as $filterParam) {
                     if (is_array($filterParam)) {
                         $andLogic = (bool) $filterParam['andLogic'];
                         if ($andLogic) {
                             $select->where('l.' . $field . ' ' . $filterParam['compare'] . ' ?', $filterParam['value']);
                         } else {
                             $select->orWhere('l.' . $field . ' ' . $filterParam['compare'] . ' ?', $filterParam['value']);
                         }
                     }
                 }
                 break;
             case 'blog_posts_tags':
                 if (!$aliasTable) {
                     $select->joinInner(array('t' => $joinTable), 't.post_id = p.id', array());
                 }
                 foreach ($filterParams as $filterParam) {
                     if (is_array($filterParam)) {
                         $andLogic = (bool) $filterParam['andLogic'];
                         if ($andLogic) {
                             $select->where('t.' . $field . ' ' . $filterParam['compare'] . ' ?', $filterParam['value']);
                         } else {
                             $select->orWhere('t.' . $field . ' ' . $filterParam['compare'] . ' ?', $filterParam['value']);
                         }
                     }
                 }
                 break;
             case 'blog_posts_comments':
                 if (!$aliasTable) {
                     $select->joinInner(array('c' => $joinTable), 'c.post_id = p.id', array());
                 }
                 foreach ($filterParams as $filterParam) {
                     if (is_array($filterParam)) {
                         $andLogic = (bool) $filterParam['andLogic'];
                         if ($andLogic) {
                             $select->where('c.' . $field . ' ' . $filterParam['compare'] . ' ?', $filterParam['value']);
                         } else {
                             $select->orWhere('c.' . $field . ' ' . $filterParam['compare'] . ' ?', $filterParam['value']);
                         }
                     }
                 }
                 break;
             case 'users':
                 if (!$aliasTable) {
                     $select->joinInner(array('u' => $joinTable), 'u.id = p.user_id', array());
                 }
                 foreach ($filterParams as $filterParam) {
                     if (is_array($filterParam)) {
                         $andLogic = (bool) $filterParam['andLogic'];
                         if ($andLogic) {
                             $select->where('u.' . $field . ' ' . $filterParam['compare'] . ' ?', $filterParam['value']);
                         } else {
                             $select->orWhere('u.' . $field . ' ' . $filterParam['compare'] . ' ?', $filterParam['value']);
                         }
                     }
                 }
                 break;
             case 'users_profile':
                 if (!$aliasTable) {
                     $select->joinInner(array('u_profile' => $joinTable), 'u_profile.user_id = p.user_id', array())->where('u_profile.profile_key = ?', $field);
                 }
                 foreach ($filterParams as $filterParam) {
                     if (is_array($filterParam)) {
                         $andLogic = (bool) $filterParam['andLogic'];
                         if ($andLogic) {
                             $select->where('u_profile.value ' . $filterParam['compare'] . ' ?', $filterParam['value']);
                         } else {
                             $select->orWhere('u_profile.value ' . $filterParam['compare'] . ' ?', $filterParam['value']);
                         }
                     }
                 }
                 break;
             default:
                 foreach ($filterParams as $filterParam) {
                     if (is_array($filterParam)) {
                         $andLogic = (bool) $filterParam['andLogic'];
                         if ($andLogic) {
                             $select->where('p.' . $field . ' ' . $filterParam['compare'] . ' ?', $filterParam['value']);
                         } else {
                             $select->orWhere('p.' . $field . ' ' . $filterParam['compare'] . ' ?', $filterParam['value']);
                         }
                     }
                 }
                 break;
         }
     }
     return $select;
 }
Exemple #2
0
 /**
  * Get Select object (Zend_Db_Select) for filtering table records
  *
  * @param Zend_Db_Select $select
  * @param array $filter         
  *
  * @return Zend_Db_Select
  */
 public static function GetSelectForFilter($select, $filter)
 {
     $joinTable = '';
     //-----------------------------------
     // создадим фильтр по разрешению/запрету (актуальности) блогов
     // Построим выражения SELECT
     foreach ($filter as $field => $filterParams) {
         $joinTable = $filterParams['joinTable'];
         $aliasTable = Default_Model_DatabaseObject::getAliasForTable($select, $joinTable);
         $filterParams = $filterParams['filterParams'];
         foreach ($filterParams as $filterParam) {
             if (is_array($filterParam)) {
                 $andLogic = (bool) $filterParam['andLogic'];
                 if ($andLogic) {
                     $select->where('l.' . $field . ' ' . $filterParam['compare'] . ' ?', $filterParam['value']);
                 } else {
                     $select->orWhere('l.' . $field . ' ' . $filterParam['compare'] . ' ?', $filterParam['value']);
                 }
             }
         }
     }
     return $select;
 }
Exemple #3
0
 /**
  * Get Select object (Zend_Db_Select) for filtering table records
  *
  * @param Zend_Db_Select $select        
  * @param array $filter                 
  *
  * @return Zend_Db_Select
  */
 public static function GetSelectForFilter($select, $filter)
 {
     $joinTable = '';
     //-----------------------------------
     // создадим фильтр по разрешению/запрету (актуальности) блогов
     // Построим выражения SELECT
     foreach ($filter as $field => $filterParams) {
         $joinTable = $filterParams['joinTable'];
         $aliasTable = Default_Model_DatabaseObject::getAliasForTable($select, $joinTable);
         $filterParams = $filterParams['filterParams'];
         switch ($joinTable) {
             case 'blog_info_profile':
                 if (!$aliasTable) {
                     $select->joinInner(array('i_profile' => $joinTable), 'i_profile.info_id = i.id', array())->where('i_profile.profile_key = ?', $field);
                 }
                 foreach ($filterParams as $filterParam) {
                     if (is_array($filterParam)) {
                         $andLogic = (bool) $filterParam['andLogic'];
                         if ($andLogic) {
                             $select->where('i_profile.profile_value ' . $filterParam['compare'] . ' ?', $filterParam['value']);
                         } else {
                             $select->orWhere('i_profile.profile_value ' . $filterParam['compare'] . ' ?', $filterParam['value']);
                         }
                     }
                 }
                 break;
             default:
                 foreach ($filterParams as $filterParam) {
                     if (is_array($filterParam)) {
                         $andLogic = (bool) $filterParam['andLogic'];
                         if ($andLogic) {
                             $select->where('i.' . $field . ' ' . $filterParam['compare'] . ' ?', $filterParam['value']);
                         } else {
                             $select->orWhere('i.' . $field . ' ' . $filterParam['compare'] . ' ?', $filterParam['value']);
                         }
                     }
                 }
                 break;
         }
     }
     return $select;
 }