Created
November 19, 2015 10:16
-
-
Save linushstge/db6fc9890a884388708f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
class Media_model extends CI_Model | |
{ | |
private $table = 'media'; | |
private $store = []; | |
function __construct() | |
{ | |
parent::__construct(); | |
if(!empty($this->store)) { | |
return; | |
} | |
$this->db->order_by('date', 'desc'); | |
$media = $this->db->get($this->table)->result_array(); | |
foreach($media as $file) { | |
$this->store[$file['id']] = $file; | |
} | |
} | |
public function all() | |
{ | |
return $this->store; | |
} | |
public function limit($max = 25, $start = 1) | |
{ | |
$this->db->limit($max, $start); | |
$this->db->order_by('date', 'desc'); | |
return $this->db->get($this->table)->result_array(); | |
} | |
public function byId($mediaId) | |
{ | |
if(!$mediaId) { | |
return; | |
} | |
return $this->store[$mediaId]; | |
} | |
public function count() | |
{ | |
$q = $this->db->get($this->table); | |
return $q->num_rows(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment