Guest User

Untitled

a guest
Apr 25th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. <?php
  2. static public function getUserLinks($user = NULL, $options = NULL)
  3. {
  4. $status = OPEN;
  5.  
  6. if(isset($options['status']))
  7. $status = $options['status'];
  8. if(isset($options['section']))
  9. $section = $options['section'];
  10.  
  11. if(isset($user))
  12. {
  13. if (!isset(User_Current::getUser()->id))
  14. return new PEAR_Error('Неверно задан параметр $user');
  15. $userid = User_Current::getUser()->id;
  16. }
  17. elseif (is_numeric($user))
  18. $userid = $user;
  19. else
  20. {
  21. if (!($user instanceof User2))
  22. return new PEAR_Error('Неверно задан параметр $user');
  23. $userid = $user->id;
  24. }
  25.  
  26. // Имя файла кэша
  27. $cache_name = (isset($status)) ? "status_{$status}" : "status_all";
  28. $cache_name .= (isset($section)) ? "_section_{$section}" : "_section_all";
  29. $cache_name .= "_user_{$userid}";
  30.  
  31. $links_data = Cache::get($cache_name, 'links', 'links/');
  32. if(!is_array($links_data))
  33. {
  34. switch(true)
  35. {
  36. $where = " WHERE `id` = ? AND ";
  37. case(isset($status, $section)) :
  38. $where .= "`status` = ? AND `id_link_category` = ?";
  39. break;
  40. case(isset($status)) :
  41. $where .= "`status` = ?";
  42. break;
  43. case(isset($section)) :
  44. $where .= "`id_link_category` = ?";
  45. break;
  46. default : $where =" WHERE `id` = ?";
  47. }
  48. $result = DB_Connect::query("SELECT SQL_CALC_FOUND_ROWS `id_link` FROM `links` {$where} ORDER BY `next_id`", $userid,$options);
  49.  
  50. $links_data = array();
  51. while(list($id) = $result->fetchRow())
  52. array_push(&$links_data, new Link($id));
  53.  
  54. if(!empty($links_data))
  55. Cache::save($links_data, $cache_name, 'links', 'links/', 24 * 3600);
  56. }
  57.  
  58. return $links_data;
  59. }
  60. ?>
Add Comment
Please, Sign In to add comment