You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.2 KiB

7 years ago
7 years ago
  1. <?php
  2. /**
  3. * 배너 라이브러리
  4. */
  5. class Banner {
  6. protected $CI;
  7. protected $banners = NULL;
  8. function __construct()
  9. {
  10. $this->CI =& get_instance();
  11. }
  12. /**
  13. * 특정 Key를 가진 배너를 하나만 가져온다.
  14. * @param string $bng_key
  15. */
  16. function one( $bng_key ="")
  17. {
  18. if(empty($bng_key)) return array();
  19. $banner_list = $this->lists($bng_key);
  20. if(isset($banner_list[0]) && is_array($banner_list[0]) && $banner_list[0])
  21. return $banner_list[0];
  22. else
  23. return array();
  24. }
  25. /**
  26. * 특정 Key를 가진 배너의 목록을 모두 가져온다.
  27. * @param string $bng_key
  28. * @return array
  29. */
  30. function lists( $bng_key="" )
  31. {
  32. if( empty($bng_key) ) return array();
  33. if( empty($this->banners))
  34. {
  35. $this->CI->db->where('ban_status', 'Y');
  36. $this->CI->db->group_start();
  37. $this->CI->db->or_group_start();
  38. $this->CI->db->where('ban_timer_use', 'N');
  39. $this->CI->db->group_end();
  40. $this->CI->db->or_group_start();
  41. $this->CI->db->where('ban_timer_use','Y');
  42. $this->CI->db->where('ban_timer_start <=', date('Y-m-d H:i:s'));
  43. $this->CI->db->where('ban_timer_end >=', date('Y-m-d H:i:s'));
  44. $this->CI->db->group_end();
  45. $this->CI->db->group_end();
  46. $this->CI->db->order_by('ban_sort ASC');
  47. $result = $this->CI->db->get("banner");
  48. $this->banners = $result->result_array();
  49. }
  50. $return = array();
  51. foreach($this->banners as &$banner)
  52. {
  53. if($banner['bng_key'] == $bng_key)
  54. {
  55. $banner['tag'] = "";
  56. $banner['tag'] .= ( $banner['ban_link_use'] && $banner['ban_link_url'] ) ? " href=\"{$banner['ban_link_url']}\"" : '';
  57. $banner['tag'] .= ( $banner['ban_link_use'] && $banner['ban_link_url'] && $banner['ban_link_type'] == 'Y' ) ? ' target="_blank"' :'';
  58. $return[] = $banner;
  59. }
  60. }
  61. return $return;
  62. }
  63. }