/** * Get an array of audio for post * * @param Zend_Db_Adapter_Abstract $db * @param array $options * @return array Default_Model_DbTable_BlogPostAudio */ public static function GetAudio_Array($db, $options = array()) { // initialize the options $defaults = array('post_id' => array()); foreach ($defaults as $k => $v) { $options[$k] = array_key_exists($k, $options) ? $options[$k] : $v; } $select = $db->select(); $select->from(array('au' => 'blog_posts_audio'), array('au.*')); // filter results on specified post ids (if any) if (count($options['post_id']) > 0) { $select->where('au.post_id in (?)', $options['post_id']); } $select->order('au.ranking'); $strSelect = $select->__toString(); // fetch post data from database $data = $db->fetchAll($select); // turn data into array of BlogPostAudio objects $audio = parent::BuildMultiple_Array($db, __CLASS__, $data); return $audio; }
/** * 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; }
/** * Get an array of comments for post * * @param Zend_Db_Adapter_Abstract $db * @param array $options * @return array Default_Model_DbTable_BlogPostComment */ public static function GetComments_Array($db, $options = array()) { // initialize the options $defaults = array('user_id' => array(), 'post_id' => array(), 'reply_id' => array(), 'comment_id' => array()); foreach ($defaults as $k => $v) { $options[$k] = array_key_exists($k, $options) ? $options[$k] : $v; } $select = $db->select(); $select->from(array('c' => 'blog_posts_comments'), array('c.*')); // filter results on specified user ids (if any) if (count($options['user_id']) > 0) { $select->where('c.user_id in (?)', $options['user_id']); } // filter results on specified post ids (if any) if (count($options['post_id']) > 0) { $select->where('c.post_id in (?)', $options['post_id']); } // filter results on specified reply ids (if any) if (count($options['reply_id']) > 0) { $select->where('c.reply_id in (?)', $options['reply_id']); } // filter results on specified id ids (if any) if (count($options['comment_id']) > 0) { $select->where('c.id in (?)', $options['comment_id']); } $select->order('c.id'); $strSelect = $select->__toString(); // fetch post data from database $data = $db->fetchAll($select); // turn data into array of BlogPostComment objects $comments = parent::BuildMultiple_Array($db, __CLASS__, $data); return $comments; }
/** * 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; }
/** * Get an array of tags to posts * * @param Zend_Db_Adapter_Abstract $db * @param array $options * @return array */ public static function GetTags_Array($db, $options = array()) { // initialize the options $defaults = array('post_id' => array()); foreach ($defaults as $k => $v) { $options[$k] = array_key_exists($k, $options) ? $options[$k] : $v; } $select = $db->select(); $select->from(array('t' => 'blog_posts_tags'), 't.*'); // filter results on specified post ids (if any) if (count($options['post_id']) > 0) { $select->where('t.post_id in (?)', $options['post_id']); } // fetch post data from database $data = $db->fetchAll($select); // turn data into array of DatabaseObject_BlogPostLocation objects $tags = parent::BuildMultiple_Array($db, __CLASS__, $data); return $tags; }
/** * 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; }
/** * Set value * * @param string $name * @param string $value * @return void */ public function __set($name, $value) { switch ($name) { case 'password': $value = md5($value); break; case 'user_type': if (!array_key_exists($value, self::$userTypes)) { // $value = 'member'; $value = 'commentator'; } break; } return parent::__set($name, $value); }