<?php
/**
 * @copyright ONE/DEPO Project
 * @license   PHP License 3.01 <http://www.php.net/license/3_01.txt>
 */


/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * [[機能説明]]
 *
 * @package     [[package名]]
 * @author      Tominaga hitosi <mail@example.com>
 * @access      public
 */
class Admin_Usermanage_Itemrequest_Requestlist
{
    /**
     * [[機能説明]]
     *
     * @access  public
     */

    var $c_request;
    var $session;
    var $request_array;

    //検索条件用変数
    var $requestno;
    var $itemname;
    var $limit;
    var $condition;
    var $div;
    var $membercd;
    var $username;
    var $sort;
    var $conditions;

    var $title;
    var $pagename;

	function getRequestlist()
	{
	    return $this->request_array;
	}
	
	function setRequest()
	{
        //商品タイトルとユーザー名は、値が入力されていれば前後に%をくっつける
        $data = $this -> conditions;
        $conditionsort = $this -> sort;
        if($data[1] != "") $data[1] = "%" . $data[1] . "%";
        if($data[6] != "") $data[6] = "%" . $data[6] . "%";

        if($conditionsort == "") $conditionsort = "requestno";

	    $requests = $this->c_request->selectAll($data, $conditionsort);
        $count = 1;
	    //商品名、ユーザ名をコードから取得して新たに配列を組みなおす
	    foreach($requests as $request){
            //各種値の事前処理
            switch($request['requestcondition']) {
                case 1:
                    $condition = "可";
                    break;
                case 2:
                    $condition = "良い";
                    break;
                case 3:
                    $condition = "非常に良い";
                    break;
                case 4:
                    $condition = "ほぼ新品";
                    break;
                case 5:
                    $condition = "新品";
                    break;
            }
            ($request['requestdiv'] == 1) ? $div = "探す" : $div = "買う";
            $username = $request['lastnm'] . $request['firstnm'];

            $this -> request_array[] = array('no' => $count,
                                              'requestno' => $request['requestno'],
                                              'itemname' => $request['itemnm'],
                                              'limit' => $request['closedate'],
                                              'price' => $request['requestprice'],
                                              'condition' => $condition,
                                              'div' => $div,
                                              'membercd' => $request['requestmembercd'],
                                              'username' => $username);
	        $count += 1;
	    }
	}
	
	function setSearchcondition()
	{
        if(isset($_POST['dispatch_admin_usermanage_itemrequest_requestlist'])) {
            if($_POST['dispatch_admin_usermanage_itemrequest_requestlist'] == "検索") {
                $this -> conditions = array($this -> requestno,
                                            $this -> itemname,
                                            $this -> limit,
                                            $this -> condition,
                                            $this -> div,
                                            $this -> membercd,
                                            $this -> username);
                $this -> session -> setParameter('requestConditions', $this -> conditions);
		    }
        }
	}

    function checkCondition()
    {
        $this -> conditions = $this -> session -> getParameter('requestConditions');
        if($this -> conditions == null){
            $this -> conditions = array(null, null, null, "1", "3", null, null);
            $this -> session -> setParameter('requestConditions', $this -> conditions);
        }
    }

    function execute()
    {
        $log =& LogFactory::getLog();
        $log->debug("Admin_Usermanage_Itemrequest_Requestlistが実行されました", "Admin_Usermanage_Itemrequest_Requestlist#execute");
        $this -> checkCondition();
        $this -> setSearchcondition();
        $this -> setRequest();
        return 'success';
    }
}
?>