<?php
/**
 * staticresource_model - Model for static resource search.
 *
 * @author $Author: dtong $
 * @version $Id: staticresource_model.php,v 1.1 2011/05/13 12:47:49 dtong Exp $
 * @copyright Copyright (c) 2011, Tiller Software Co., Ltd.
*/

class Staticresource_model extends CI_Model {

	function __construct() {
		parent::__construct();
	}

	function get ($course_query, $type) {
		if ( !$course_query || !osa_is_int_one($type) ) {
			return FALSE;
		}
		$restab = $this->db->dbprefix('resource');
		$unittab = $this->db->dbprefix('unit');
		$status_edit = CMS_UNIT_STATUS_EDIT;
		$statuc_publish = CMS_UNIT_STATUS_PUBLISH;
		$sql = "select c.name coursename,u2.id real_unitid,u2.title unit_title,u2.status unit_status,r.* " .
				 "from $restab r " .
				 "join $unittab u on r.type=$type and u.id=r.unitid " .
				 "join $unittab u2 on u.id=u2.groupid and (u2.status=$status_edit or u2.status=$statuc_publish) " .
				 "join ($course_query) c on u2.courseid=c.id " .
				 "order by r.unitid,r.text1";
		$query = $this->db->query($sql);
		if ( $query->num_rows() <= 0 ) {
			return FALSE;
		}
		return $query->result();
	}
}