PageRenderTime 263ms CodeModel.GetById 121ms app.highlight 3ms RepoModel.GetById 137ms app.codeStats 0ms

/halogy/application/modules/files/models/files_model.php

https://bitbucket.org/haloweb/halogy-1.0/
PHP | 104 lines | 67 code | 16 blank | 21 comment | 6 complexity | c03fdea1aa4da00654d03db7b9ea3daf 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 Files_model extends Model {
 20	
 21	function Files_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_files($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('(fileRef LIKE "%'.$this->db->escape_like_str($query).'%")');
 42				
 43		$this->db->order_by('fileRef', 'asc');
 44		
 45		$query = $this->db->get('files', $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_folders($folderID = '')
 58	{
 59		// default where
 60		$this->db->where(array('siteID' => $this->siteID, 'deleted' => 0));
 61		$this->db->order_by('folderOrder');
 62		
 63		// get based on folder ID
 64		if ($folderID)
 65		{
 66			$query = $this->db->get_where('file_folders', array('folderID' => $folderID), 1);
 67			
 68			if ($query->num_rows())
 69			{
 70				return $query->row_array();
 71			}
 72			else
 73			{
 74				return false;
 75			}	
 76		}
 77		// or just get all of em
 78		else
 79		{
 80			// template type
 81			$query = $this->db->get('file_folders');
 82			
 83			if ($query->num_rows())
 84			{
 85				return $query->result_array();
 86			}
 87			else
 88			{
 89				return false;
 90			}
 91		}
 92	}	
 93
 94	function update_children($folderID)
 95	{
 96		// update page draft
 97		$this->db->set('folderID', 0);
 98		$this->db->where('siteID', $this->siteID);
 99		$this->db->where('folderID', $folderID);
100		$this->db->update('files');
101
102		return TRUE;
103	}
104}