Вход Регистрация
Файл: adultscript-2.0.3-pro/files/admin/modules/channel/models/network.php
Строк: 139
<?php
class VModel_Admin_network extends VModel
{
    public function 
__construct()
    {
        
parent::__construct();
    }
    
    public function 
add($network)
    {
        
$this->db->query("
            INSERT INTO #__channel_networks
            SET user_id = "
.(int) $network['user_id'].",
                name = '"
.$this->db->escape($network['name'])."',
                slug = '"
.$this->db->escape($network['slug'])."',
                description = '"
.$this->db->escape($network['description'])."',
                add_time = "
.time()
        );
        
        if (
$this->db->affected_rows()) {
            return 
$this->db->get_last_insert_id('#__channel_networks');
        }
        
        return 
false;
    }
    
    public function 
update($network_id$network)
    {
        
$this->db->query("UPDATE #__channel_networks
                          SET user_id = "
.$network['user_id'].",
                              name = '"
.$this->db->escape($network['name'])."',
                              slug = '"
.$this->db->escape($network['slug'])."',
                              description = '"
.$this->db->escape($network['description'])."',
                              total_channels = "
.$network['total_channels'].",
                              total_videos = "
.$network['total_videos'].",
                              update_time = "
.time()."
                          WHERE network_id = "
.$network_id."
                          LIMIT 1"
);
        
        return 
true;
    }
    
    public function 
get($network_id$fields = array())
    {
        
$fields = ($fields) ? $fields : array(
            
'n.network_id''n.user_id''n.name''n.slug''n.description',
            
'n.total_channels''n.total_videos''u.username'
        
);

        
$this->db->query("SELECT ".implode(', '$fields)."
                          FROM #__channel_networks AS n
                          LEFT JOIN #__user AS u ON (u.user_id = n.user_id)
                          WHERE network_id = "
.$network_id."
                          LIMIT 1"
);

        if (
$this->db->affected_rows()) {
            return 
$this->db->fetch_assoc();
        }

        return 
false;
    }
    

    public function 
exists($column$value$network_id 0)
    {
          
$value    = (ctype_digit($value) or is_int($value)) ? (int) $value "'".$this->db->escape($value)."'";
    
          
$this->db->query("
              SELECT network_id
              FROM #__channel_networks
              WHERE "
.$column." = ".$value."
              AND network_id != "
.(int) $network_id."
              LIMIT 1"
          
);
          
          if (
$this->db->affected_rows()) {
              return 
$this->db->fetch_field('network_id');
          }
          
          return 
false;
      }
      
      public function 
delete($network_id)
      {
          
$comp    = (is_array($network_id))
              ? 
"IN (".implode(','$network_id).")"
              
"= ".$network_id;
          
          
$this->db->query("DELETE FROM #__channel_networks WHERE network_id ".$comp);
          
          return 
$this->db->affected_rows();
      }
    
    public function 
count($params)
    {
        
$where    = ($params['where']) ? 'WHERE '.$params['where'] : '';
        
$this->db->query("
            SELECT COUNT(*) AS total_networks
            FROM #__channel_networks AS n"
.$where
        
);
        
        return 
$this->db->fetch_field('total_networks');
    }
    
    public function 
networks($fields = array(), $params = array(), $limit 0)
    {
        
$fields = ($fields) ? $fields : array(
            
'n.network_id',
            
'n.name',
            
'n.slug',
            
'n.total_channels',
            
'n.total_videos',
            
'n.add_time',
            
'u.username'
        
);
        
        
$where    = (isset($params['where']) && $params['where']) ? 'WHERE '.$params['where'] : '';
        
        if (!isset(
$params['sort'])) {
            
$params['sort']     = 'n.network_id';
        }
        
        if (!isset(
$params['order'])) {
            
$params['order']    = 'ASC';
        }
        
        
$limit    = ($limit !== 0) ? " LIMIT ".$limit '';
        
        
$this->db->query("
            SELECT "
.implode(', '$fields)."
            FROM #__channel_networks AS n
            LEFT JOIN #__user AS u ON (u.user_id = n.user_id)"
.$where."
            ORDER BY "
.$params['sort'].' '.$params['order'].$limit
        
);
        
        return (
$this->db->affected_rows()) 
            ? 
$this->db->fetch_rows()
            : array();
    }
}
Онлайн: 0
Реклама