<?php
/**
 * CourseMediaDat Entity
 * $Id: CourseMediaDat.inc,v 1.1 2020/2/27 14:40:01 Exp $
 * @author zb
 * @package jp.compass.entity
 * @access public
 */
class CourseMediaDat extends CompassDynamicData
{
	var $course_id;
	var $parent_category_id;
	var $sub_category_id;
	var $title;
	var $comment;
	var $tags;
	var $front_image;
	var $media;
	var $size;
	var $teacher;
	var $teacher_profile;
	var $is_free;
	var $price;
	var $view_count;
	var $delete_flg;
	
	//用户是否已经购买本视频
	var $haveBuy;

	/**
	 * 构造实现。course_media_dat创建实例。
	 * 
	 * @access public
	 * @param mixed course_media_dat
	 */
	function constructor($record)
	{
		parent::constructor($record);

		$this->course_id   	= $record["course_id"];
		$this->title       	= $record["title"];
		$this->comment      = $record["comment"];
		$this->tags        	= $record["tags"];
		$this->front_image 	= $record["front_image"];
		$this->media       	= $record["media"];
		$this->size        	= $record["size"];
		$this->teacher     	= $record["teacher"];
		$this->teacher_profile     = $record["teacher_profile"];
		$this->is_free     	= $record["is_free"];
		$this->price       	= $record["price"];
		$this->view_count  	= $record["view_count"];
		$this->delete_flg  	= $record["delete_flg"];
	}

	/**
	 * 根据条件,获取数据列表。
	 * 条件与DBManager的doSelect相同。
	 * @access public
	 * @static
	 * @param array 检索条件
	 * @return array Entity的队列
	 */
	public static function getList($w_param = null, $orderkey = null, $direction = "ASC", $offset = null, $limit = null)
	{
		if ($w_param == null) {
			$w_param = array();
			$w_param["delete_flg"] = "false";
		}

		return CompassDBHandler::getList("CourseMediaDat", "course_media_dat", $w_param, $orderkey, $direction, $offset, $limit);
	}

	/**
	 * 根据条件，获取数据列表的件数。
	 * 条件与DBManager的doSelect相同。
	 * @access public
	 * @static
	 * @param array 检索条件
	 * @return array Entity的队列
	 */
	public static function getListCount($w_param = null)
	{
		if ($w_param == null) {
			$w_param = array();
			$w_param["delete_flg"] = "false";
		}
		$db = CompassDBManager::getInstance();
		$result = $db->doSelect("course_media_dat", $w_param, null, null, null, null, "count(*) as count");

		return $result[0]["count"];
	}

	/**
	 * 获得此类指定ID的实例。
	 */
	public static function getById($id)
	{
		// delete_flg
		$param = array();
		$param["delete_flg"] = false;

		return CompassDBHandler::getById("CourseMediaDat", "course_media_dat", $id, $param);
	}

	// -- 这里开始Dynamic ---
	/**
	 * 将此实例写入DB。
	 * DynamicData共用的保存方法。
	 * @access public
	 * @return int 写入实例的ID
	 */
	public function save()
	{
		$v_param = array();

		ParamUtil::copyObj2Array($v_param, $this, "course_id");
		ParamUtil::copyObj2Array($v_param, $this, "parent_category_id");
		ParamUtil::copyObj2Array($v_param, $this, "sub_category_id");
		ParamUtil::copyObj2Array($v_param, $this, "title");
		ParamUtil::copyObj2Array($v_param, $this, "comment");
		ParamUtil::copyObj2Array($v_param, $this, "tags");
		ParamUtil::copyObj2Array($v_param, $this, "front_image");
		ParamUtil::copyObj2Array($v_param, $this, "media");
		ParamUtil::copyObj2Array($v_param, $this, "size");
		ParamUtil::copyObj2ArrayNullField($v_param, $this, "teacher");
		ParamUtil::copyObj2ArrayNullField($v_param, $this, "teacher_profile");
		ParamUtil::copyObj2Array($v_param, $this, "is_free");
		ParamUtil::copyObj2Array($v_param, $this, "price");
		ParamUtil::copyObj2Array($v_param, $this, "view_count");
		ParamUtil::copyObj2Array($v_param, $this, "delete_flg");

		// 保存
		parent::_save("course_media_dat", $v_param);
	}
}