PageRenderTime 32ms CodeModel.GetById 12ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/halogy/application/modules/images/models/images_model.php

https://bitbucket.org/haloweb/halogy-1.0/
PHP | 153 lines | 105 code | 26 blank | 22 comment | 9 complexity | a35fb81a64dee6ecbb6c5fb0b307c93c MD5 | raw file
  1<?php
  2/**
  3 * Halogy
  4 *
  5 * A user friendly, modular content management system for PHP 5.0
  6 * Built on CodeIgniter - http://codeigniter.com
  7 *
  8 * @package		Halogy
  9 * @author		Haloweb Ltd.
 10 * @copyright	Copyright (c) 2008-2011, Haloweb Ltd.
 11 * @license		http://halogy.com/license
 12 * @link		http://halogy.com/
 13 * @since		Version 1.0
 14 * @filesource
 15 */
 16
 17// ------------------------------------------------------------------------
 18
 19class Images_model extends Model {
 20	
 21	function Images_model()
 22	{
 23		parent::Model();
 24		
 25		// get siteID, if available
 26		if (defined('SITEID'))
 27		{
 28			$this->siteID = SITEID;
 29		}
 30	}
 31	
 32	function search_images($query, $limit = '')
 33	{
 34		if (!$query)
 35		{
 36			return FALSE;
 37		}	
 38		
 39		$this->db->where(array('siteID' => $this->siteID, 'deleted' => 0));
 40		
 41		$this->db->where('(imageRef LIKE "%'.$this->db->escape_like_str($query).'%" OR imageName LIKE "%'.$this->db->escape_like_str($query).'%")');
 42				
 43		$this->db->order_by('imageRef', 'asc');
 44		
 45		$query = $this->db->get('images', $limit);
 46		
 47		if ($query->num_rows())
 48		{
 49			return $query->result_array();
 50		}
 51		else
 52		{
 53			return false;
 54		}
 55	}
 56	
 57	function get_images_by_folder_ref($ref, $limit = '')
 58	{
 59		$this->db->where(array('images.siteID' => $this->siteID, 'images.deleted' => 0));		
 60		
 61		$this->db->where('folderSafe', $ref);
 62		
 63		$this->db->select('images.*, folderName, folderSafe');
 64		$this->db->join('image_folders', 'image_folders.folderID = images.folderID');
 65		
 66		$this->db->order_by('imageRef', 'asc');
 67		
 68		$query = $this->db->get('images', $limit);
 69		
 70		if ($query->num_rows())
 71		{
 72			return $query->result_array();
 73		}
 74		else
 75		{
 76			return false;
 77		}
 78	}
 79
 80	function get_folders($folderID = '')
 81	{
 82		// default where
 83		$this->db->where(array('siteID' => $this->siteID, 'deleted' => 0));
 84		$this->db->order_by('folderOrder');
 85		
 86		// get based on folder ID
 87		if ($folderID)
 88		{
 89			$query = $this->db->get_where('image_folders', array('folderID' => $folderID), 1);
 90			
 91			if ($query->num_rows())
 92			{
 93				return $query->row_array();
 94			}
 95			else
 96			{
 97				return FALSE;
 98			}	
 99		}
100		// or just get all of em
101		else
102		{
103			$query = $this->db->get('image_folders');
104			
105			if ($query->num_rows())
106			{
107				return $query->result_array();
108			}
109			else
110			{
111				return FALSE;
112			}
113		}
114	}	
115
116	function lookup_user($userID, $display = FALSE)
117	{
118		// default wheres
119		$this->db->where('userID', $userID);
120
121		// grab
122		$query = $this->db->get('users', 1);
123
124		if ($query->num_rows())
125		{
126			$row = $query->row_array();
127			
128			if ($display !== FALSE)
129			{
130				return ($row['displayName']) ? $row['displayName'] : $row['firstName'].' '.$row['lastName'];
131			}
132			else
133			{
134				return $row;
135			}
136		}
137		else
138		{
139			return FALSE;
140		}		
141	}
142
143	function update_children($folderID)
144	{
145		// update page draft
146		$this->db->set('folderID', 0);
147		$this->db->where('siteID', $this->siteID);
148		$this->db->where('folderID', $folderID);
149		$this->db->update('images');
150
151		return TRUE;
152	}
153}