<?php
/*
+--------------------------------------------------------------------------
|   TanyaCMS - Question and Answer Sofware
|   -----------------------------------------------------------------------
|   by fbschool dev team
|   (c) 2011 - 2012 FBSCHOOL
|   http://www.fbschool.com/tanyacms
|   -----------------------------------------------------------------------
|   This is NOT a freeware, use is subject to license terms
|   Support: 13455n@gmail.com
+--------------------------------------------------------------------------
*/


if (!defined('IN_TANYACMS'))
{
	die;
}

class work_class extends ASK_MODEL
{

	/**
	 * Add Work Experience
	 */
	function add_work_experience($uid, $start_year, $end_year, $company_name, $job_id)
	{
		$insert_arr['uid'] = intval($uid);
		$insert_arr['start_year'] = intval($start_year);
		$insert_arr['end_year'] = intval($end_year);
		$insert_arr['company_name'] = htmlspecialchars($company_name);
		$insert_arr['job_id'] = intval($job_id);
		$insert_arr['add_time'] = time();
		
		//Insert obtain the user ID
		return $this->insert('work_experience', $insert_arr);
	}

	/**
	  * Get Job Information
	  */
	function get_jobs_list()
	{
		if ($rs = $this->fetch_all('jobs', null, 'id ASC'))
		{
			$job_list = array();
			
			foreach ($rs as $key => $val)
			{
				$job_list[$val['id']] = $val['job_name'];
			}
			
			return $job_list;
		}
		else
		{
			return false;
		}
	}

	/**
	  * Based on the job ID to get position information
	  */
	function get_jobs_by_id($id)
	{
		return $this->fetch_row('jobs', 'id = ' . intval($id));
	}

	/**
	  * By user ID access to Education
	  * 
	  * @param $uid
	  * 
	  * @return array
	  */
	function get_work_experience_list($uid)
	{
		return $this->fetch_all('work_experience', "uid = " . intval($uid), ' start_year DESC');
	}

	/**
	  * By user ID access to Education
	  * 
	  * @param $uid
	  * 
	  * @return array
	  */
	function get_education_experience_row($education_id, $uid)
	{
		return $this->fetch_row('work_experience', 'education_id = ' . intval($education_id) . ' AND uid = ' . intval($uid));
	}

	/**
	 * Updating school experience
	 * 
	 * @param  $update_arr
	 * @param  $education_id
	 * @param  $uid
	 */
	function update_education_experience($update_arr, $education_id, $uid)
	{
		return $this->update('work_experience', $update_arr, 'education_id = ' . intval($education_id) . ' AND uid = ' . intval($uid));
	}

	/**
	  * Delete school experience
	  * 
	  * @param  $education_id
	  * @param  $uid
	  */
	function del_work_experience($work_id, $uid)
	{
		return $this->delete('work_experience', 'uid = ' . intval($uid) . ' AND work_id = ' . intval($work_id));
	}

	/**
	  * Through user ID Get Work experience
	  * 
	  * @param $uid
	  * 
	  * @return array
	  */
	function get_work_experience_row($work_id, $uid)
	{
		return $this->fetch_row('work_experience', 'work_id = ' . intval($work_id) . ' AND uid =' . intval($uid));
	}

	/**
	 * Updating school experience
	 * 
	 * @param  $update_arr
	 * @param  $education_id
	 * @param  $uid
	 */
	function update_work_experience($update_arr, $work_id, $uid)
	{
		$uid = intval($uid);
		$work_id = intval($work_id);
		
		if ((! $uid) || (! $work_id))
		{
			return false;
		}
		
		return $this->update('work_experience', $update_arr, "uid = {$uid} AND work_id = {$work_id}");
	}

	function remove_job($job_id)
	{
		return $this->delete('jobs', 'id = ' . intval($job_id));
	}

	function add_job($job_name)
	{
		return $this->insert('jobs', array(
			'job_name' => htmlspecialchars($job_name)
		));
	}
	
	function update_job($id, $data)
	{
		return $this->update('jobs', $data, 'id = ' . intval($id));
	}
}