Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- static public function getUserLinks($user = NULL, $options = NULL)
- {
- $status = OPEN;
- if(isset($options['status']))
- $status = $options['status'];
- if(isset($options['section']))
- $section = $options['section'];
- if($user == NULL)
- {
- if (!isset(User_Current::getUser()->id))
- return new PEAR_Error('Неверно задан параметр $user');
- $userid = User_Current::getUser()->id;
- }
- elseif (is_numeric($user))
- $userid = $user;
- else
- {
- if (!($user instanceof User2))
- return new PEAR_Error('Неверно задан параметр $user');
- $userid = $userid->id;
- }
- // Имя файла кэша
- $cache_name = (isset($status)) ? "status_{$status}" : "status_all";
- $cache_name .= (isset($section)) ? "_section_{$section}" : "_section_all";
- $cache_name .= "_user_{$userid}";
- $links_data = Cache::get($cache_name, 'links', 'links/');
- if(!is_array($links_data))
- {
- switch(true)
- {
- $where = " WHERE `id` = ? AND ";
- case(isset($status, $section)) :
- $where .= "`status` = ? AND `id_link_category` = ?";
- break;
- case(isset($status)) :
- $where .= "`status` = ?";
- break;
- case(isset($section)) :
- $where .= "`id_link_category` = ?";
- break;
- default : $where =" WHERE `id` = ?";
- }
- $result = DB_Connect::query("SELECT SQL_CALC_FOUND_ROWS `id_link` FROM `links` {$where} ORDER BY `next_id`", $userid,$options);
- $links_data = array();
- while(list($id) = $result->fetchRow())
- array_push(&$links_data, new Link($id));
- if(!empty($links_data))
- Cache::save($links_data, $cache_name, 'links', 'links/', 24 * 3600);
- }
- return $links_data;
- }
- ?>
- ?>
Add Comment
Please, Sign In to add comment