Share Pastebin
Guest
Public paste!

yingyes

By: a guest | Apr 4th, 2008 | Syntax: None | Size: 4.79 KB | Hits: 144 | Expires: Never
Copy text to clipboard
  1. <?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3.  * CodeIgniter
  4.  *
  5.  * An open source application development framework for PHP 4.3.2 or newer
  6.  *
  7.  * @package             CodeIgniter
  8.  * @author              ExpressionEngine Dev Team
  9.  * @copyright   Copyright (c) 2006, EllisLab, Inc.
  10.  * @license             http://codeigniter.com/user_guide/license.html
  11.  * @link                http://codeigniter.com
  12.  * @since               Version 1.0
  13.  * @filesource
  14.  */
  15.  
  16. // ------------------------------------------------------------------------
  17.  
  18. /**
  19.  * CodeIgniter User Authentication Model
  20.  *
  21.  * This Model provides CodeIgniter with a simple
  22.  * and flexible user authnetication
  23.  *
  24.  * @package             CodeIgniter
  25.  * @subpackage  Model
  26.  * @category    Model
  27.  * @author              Mathew Davies
  28.  * @link               
  29.  */
  30.  
  31. class Template_Model extends Model
  32. {
  33.         var $query_count=0;
  34.         function __construct()
  35.         {
  36.                 parent::Model();
  37.         }
  38.         function clear_count()
  39.         {
  40.                 $this->query_count=0;
  41.         }
  42.         function get_count()
  43.         {
  44.                 return $this->query_count;
  45.         }
  46.         function get($table)
  47.         {
  48.                 return $this->db->get($table);
  49.         }
  50.         function get_where($table,$array)
  51.         {
  52.                 return $this->db->get_where($table,$array);
  53.         }
  54.         function select($array='*')
  55.         {
  56.                 if(is_array($array))
  57.                 {      
  58.                         $string=implode(',',$array);
  59.                 }
  60.                 else
  61.                 {
  62.                         $string=$array;
  63.                 }
  64.                 $this->db->select($string);
  65.         }
  66.         function set($data, $name = '' )
  67.         {
  68.                 if ( empty($name) && is_array($data) )
  69.                 {
  70.                         $this->db->set($data);
  71.                 }
  72.                 else
  73.                 {
  74.                         $this->db->set($name, $data);
  75.                 }
  76.                
  77.         }
  78.  
  79.         function insert ($table)
  80.         {
  81.                 $this->db->insert($table);
  82.                
  83.                 if ( $this->db->affected_rows() > 0 )
  84.                 {
  85.                         return true;
  86.                 }
  87.                 return false;
  88.         }
  89.         function get_page_by_template_id_and_url($template_id,$url)
  90.         {
  91.                 if(!empty($template_id))
  92.                 {      
  93.                         $this->query_count++;
  94.                         return $this->db->query("select * from `pages` where `template`='".$template_id."' and `url`='".$url."' order by `orderby` ASC");
  95.                 }
  96.                 return false;
  97.         }
  98.         function get_pages_by_template_id($template_id)
  99.         {
  100.                 if(!empty($template_id))
  101.                 {      
  102.                         $this->query_count++;
  103.                         return $this->db->query("select * from `pages` where `template`='".$template_id."' order by `orderby` ASC");
  104.                 }
  105.                 return false;
  106.         }
  107.  
  108.         function get_admin_layout_by_template_id($template_id)
  109.         {
  110.                 if(!empty($template_id))
  111.                 {      
  112.                         $this->query_count++;
  113.                         return $this->db->query("select * from `admin_layout` where `template`='".$template_id."'");
  114.                 }
  115.                 return false;
  116.         }
  117.  
  118.         function get_admin_pages_by_template_id($template_id)
  119.         {
  120.                 if(!empty($template_id))
  121.                 {      
  122.                         $this->query_count++;
  123.                         return $this->db->query("select * from `admin_pages` where `template`='".$template_id."'");
  124.                 }
  125.                 return false;
  126.         }
  127.  
  128.         function get_layout_by_template_id($template_id)
  129.         {
  130.                 if(!empty($template_id))
  131.                 {      
  132.                         $this->query_count++;
  133.                         return $this->db->query("select * from `layout` where `template`='".$template_id."'");
  134.                 }
  135.                 return false;
  136.         }
  137.  
  138.         function get_sections_by_template_id($template_id)
  139.         {
  140.                 if(!empty($template_id))
  141.                 {      
  142.                         $this->query_count++;
  143.                         return $this->db->query("select * from `sections` where `template`='".$template_id."'");
  144.                 }
  145.                 return false;
  146.         }
  147.         function get_theme_css($template_id)
  148.         {
  149.                 if(!empty($template_id))
  150.                 {      
  151.                         $this->query_count++;
  152.                         return $this->db->query("select * from `css` where `template`='".$template_id."'");
  153.                 }
  154.                 return false;
  155.         }
  156.         function get_theme_js($template_id)
  157.         {
  158.                 if(!empty($template_id))
  159.                 {      
  160.                         $this->query_count++;
  161.                         return $this->db->query("select * from `js` where `template`='".$template_id."'");
  162.                 }
  163.                 return false;
  164.         }
  165.         function get_asset_dirs_by_template_id($template_id)
  166.         {
  167.                 if(!empty($template_id))
  168.                 {      
  169.                         $this->query_count++;
  170.                         return $this->db->query("select * from `templates` where `id`='".$template_id."'");
  171.                 }
  172.                 return false;
  173.         }
  174.  
  175.         function left_join_by_template_id($t_id)
  176.         {
  177.                 if(!empty($name))
  178.                 {
  179.                         $this->query_count++;
  180.                                 $q=$this->db->query("SELECT templates.name, templates.images_dir, templates.swf_dir, templates.pdf_dir,
  181.                                                                         layout.name,layout.url
  182.                                                                         FROM templates
  183.                                                                         LEFT JOIN layout
  184.                                                                         ON templates.id=layout.template_id
  185.                                                                         WHERE templates.id='".$t_id."'");
  186.                         return $q->row()->id;
  187.                 }
  188.                 return false;
  189.         }
  190.         function get_config_item_value($item_name)
  191.         {
  192.                 if(!empty($item_name))
  193.                 {
  194.                         $this->query_count++;
  195.                         $this->db->select('value');
  196.                         $q=$this->db->get_where('site_config',array('name'=>$item_name));
  197.                         //$q=$this->db->query("select `value` from `site_config` where `name`='".$item_name."'");
  198.                         return $q->row()->value;
  199.                 }
  200.                 return false;
  201.         }
  202.         function get_template_id_by_name($name)
  203.         {
  204.                 if(!empty($name))
  205.                 {
  206.                         $this->query_count++;
  207.                         $q=$this->db->query("select `id` from `templates` where `name`='".$name."'");
  208.                         return ($q->num_rows()!=0)?$q->row()->id:false;
  209.                 }
  210.                 return false;
  211.         }
  212.  
  213.        
  214. }
  215. ?>