<?php
/**
 * Created by PhpStorm.
 * User: neosoft
 * Date: 22/11/14
 * Time: 11:11 AM
 */

class Agents extends CI_Model {

    /**
     *  Models default constructor.
     */
    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }

    /**
     * Function to get all agents
     * @param $strTableName
     * @param string $intAgentId
     * @return mixed
     * @access Public
     * @author Himanshu Charegaonkar
     */
    function fnGetAllAgents($strTableName, $intAgentId = "")
    {
        if ($intAgentId != "") {
            $query = $this->db->get_where($strTableName, array('id' => $intAgentId));
        } else {
            $query = $this->db->get($strTableName);
        }
        $this->db->order_by("id", "desc");
        return $query->result_array();
    }

    /**
     * Function to save the agent
     * @param unknown_type $strTableName: String - table Name
     * @param unknown_type $arrDetails: Array of details
     * @author	Himanshu Charegaonkar
     * @access	public
     */
    function fnSavePromotion($strTableName, $arrDetails)
    {
        $this->db->insert($strTableName, $arrDetails);
        return $this->db->insert_id();
    }

    /**
     * Function fnUpdatePromotion
     * Function update magazine promotion  details.
     * @param $arrResultData: Array of result set
     * @param $intId: Integer - Id
     * @param $strTableName - Table Name
     * @return mixed
     * @author	Himanshu Charegaonkar
     * @access	public
     */
    function fnUpdatePromotion($strTableName, $arrResultData, $intId)
    {
        $this->db->where('id', $intId);
        return $this->db->update($strTableName, $arrResultData);
    }

    /**
     * Function to check given value
     * @param $strTable
     * @param $strColumnValue
     * @return mixed
     * @access Public
     * @author Himanshu Charegaonkar
     */
    function fnCheckGivenLanguage($strTable, $strColumnValue)
    {
        $query = "select id
				FROM  ".$strTable. "
				WHERE LOWER(name) = '" . $strColumnValue."'";

        return $this->db->query($query)->result_array();
    }
} 