Created
October 27, 2011 19:30
-
-
Save mikedfunk/1320594 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); | |
/** | |
* Authors Model | |
* | |
* All model methods related to authors. | |
* | |
* @license Commercial | |
* @author Mike Funk | |
* @link http://xulonpress.com | |
* @email webmaster@xulonpress.com | |
* | |
* @file | |
* @version 1.0 | |
* @date 04/02/2011 | |
* | |
* Copyright (c) 2011 | |
*/ | |
// -------------------------------------------------------------------------- | |
/** | |
* Authors_model class. | |
* | |
* @extends CI_Model | |
*/ | |
class Authors_model extends CI_Model { | |
// -------------------------------------------------------------------------- | |
/** | |
* ci | |
* | |
* Codeigniter super object | |
* | |
* @var mixed | |
* @access private | |
*/ | |
private $ci; | |
// -------------------------------------------------------------------------- | |
/** | |
* Construct | |
* | |
* Getting started. | |
* | |
* @access public | |
*/ | |
public function __construct() | |
{ | |
parent::__construct(); | |
$this->ci =& get_instance(); | |
// $this->ci->load->library('db_cache_tools'); | |
$this->db->cache_on(); | |
} | |
// -------------------------------------------------------------------------- | |
/** | |
* get_author function. | |
* | |
* Return author by id. | |
* | |
* @access public | |
* @param string $author_id (default: '') | |
* @param bool $cache (default: TRUE) | |
* @return object | |
*/ | |
public function get_author($author_id = '', $cache = TRUE) | |
{ | |
if (!$cache) {$this->db->cache_off();} | |
if ($author_id != '' && $author_id !== FALSE) | |
{ | |
$this->db->where('ci_authors.id', $author_id); | |
} | |
$return = $this->db->get('ci_authors'); | |
if (!$cache) {$this->db->cache_on();} | |
return $return; | |
} | |
// -------------------------------------------------------------------------- | |
/** | |
* get_authors_by_account_id function. | |
* | |
* Return authors by account id. | |
* | |
* @access public | |
* @param string $author_id (default: FALSE) | |
* @param bool $cache (default: TRUE) | |
* @return object | |
*/ | |
public function get_authors_by_account_id($account_id = FALSE, $cache = TRUE) | |
{ | |
if (!$cache) {$this->db->cache_off();} | |
if ($account_id != FALSE) | |
{ | |
$this->db->where('ci_authors.account_id', $account_id); | |
} | |
$return = $this->db->get('ci_authors'); | |
if (!$cache) {$this->db->cache_on();} | |
return $return; | |
} | |
// -------------------------------------------------------------------------- | |
/** | |
* get_authors_table function. | |
* | |
* Returns all authors. | |
* | |
* @access public | |
* @param string $limit (default: '') | |
* @param string $offset (default: '') | |
* @param string $sort_by (default: '') | |
* @param string $sort_dir (default: 'asc') | |
* @param string $filter (default: '') | |
* @param string $account_id (default: '') | |
* @return object | |
*/ | |
public function get_authors_table($limit='', $offset='', $sort_by = '', $sort_dir = 'asc', $filter = '', $account_id = '') | |
{ | |
$this->db->select(' | |
ci_authors.id | |
,ci_authors.pen_name | |
,ci_authors.prefix | |
,ci_authors.first_name | |
,ci_authors.middle_name | |
,ci_authors.last_name | |
,ci_authors.suffix | |
,ci_authors.account_id | |
,ci_accounts.email_address | |
'); | |
// filter | |
if ($filter != '') | |
{ | |
$where = "(`ci_authors`.`prefix` LIKE '%".$filter."%' | |
OR `ci_authors`.`first_name` LIKE '%".$filter."%' | |
OR `ci_authors`.`middle_name` LIKE '%".$filter."%' | |
OR `ci_authors`.`last_name` LIKE '%".$filter."%' | |
OR `ci_authors`.`suffix` LIKE '%".$filter."%' | |
OR `ci_accounts`.`email_address` LIKE '%".$filter."%')"; | |
$this->db->where($where); | |
} | |
if ($account_id != '' && $account_id !== FALSE) | |
{ | |
$this->db->where('account_id', $account_id); | |
} | |
$this->db->join('ci_accounts','ci_accounts.id = ci_authors.account_id', 'left'); | |
if ($sort_by != '') | |
{ | |
$this->db->order_by($sort_by, $sort_dir); | |
} | |
else | |
{ | |
$this->db->order_by('ci_authors.last_name', 'asc'); | |
} | |
return $this->db->get('ci_authors', $limit, $offset); | |
} | |
// -------------------------------------------------------------------------- | |
/** | |
* edit_author function. | |
* | |
* Edit author by post, delete caches. | |
* | |
* @access public | |
* @param array $post | |
* @return bool | |
*/ | |
public function edit_author($post) | |
{ | |
$this->db->where('id', $post['id']); | |
$return = $this->db->update('ci_authors', $post); | |
$this->db->cache_delete('authors', 'list_authors'); | |
$this->db->cache_delete('authors', 'edit_author'); | |
return $return; | |
} | |
// -------------------------------------------------------------------------- | |
/** | |
* add_author function. | |
* | |
* Add author by post, delete caches. | |
* | |
* @access public | |
* @param mixed $post | |
* @return bool | |
*/ | |
public function add_author($post) | |
{ | |
$return = $this->db->insert('ci_authors', $post); | |
$this->db->cache_delete('authors', 'list_authors'); | |
$this->db->cache_delete('authors', 'edit_author'); | |
return $return; | |
// return $this->db-insert_id(); | |
} | |
// -------------------------------------------------------------------------- | |
/** | |
* delete_author function. | |
* | |
* Delete author by id, delete caches. | |
* | |
* @access public | |
* @param int $id | |
* @return bool | |
*/ | |
public function delete_author($id) | |
{ | |
$this->db->where('id', $id); | |
$this->db->cache_delete('authors', 'list_authors'); | |
$this->db->cache_delete('authors', 'edit_author'); | |
return $this->db->delete('ci_authors'); | |
} | |
} | |
/* End of file authors_model.php */ | |
/* Location: ./booktrack/application/models/authors_model.php */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment