<?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: */

require_once 'Pager.php';

/**
 * [[機能説明]]
 *
 * @package     Admin.Itemmanage.Preitem.List
 * @author      H.Watanabe <hiroshi.watanabe@netnee.jp>
 * @access      public
 */
class Admin_Itemmanage_Preitem_List
{
    // components
    var $actionChain;
    var $tmaker;
    var $view;
    var $m_name;
    var $results;
    var $castnm;
    var $media_list;
    var $tname;
    var $genreview;
    var $genre_search;
    var $db_preitem;
    
    
    var $title;
    var $pagename;

    // param
/*
    var $jancode;
    var $hinban;
    var $itemtitle;
    var $release_date_start;
    var $release_date_end;
    var $publish_date_start;
    var $publish_date_end;
    var $maker_capital;
    var $maker_name;
    var $media;
    var $cast;
    var $situation;
    var $photo_situation;
    var $publish_situation;
    var $genre_select;
 */
    var $itemnm;
    var $ganre_select;
    var $download;
    var $sellercd;
    //-- param 
    
    var $q;
    var $sort;
    
    var $cont;
    var $pagedata;    // Pagerデータ
    var $links;       // Pagerリンク
    var $from;
    
    var $Pager_perPage;
    var $Pager_delta;
    var $Pager_append;
    var $Pager_clearIfVoid;
    var $Pager_urlVar;
    var $Pager_useSessions;
    var $Pager_closeSession;
    var $Pager_mode;
    var $Pager_prevImg;
    var $Pager_nextImg;
    var $Pager_altPage;
    var $Pager_altPrev;
    var $Pager_altNext;
    var $Pager_altFirst;
    var $Pager_altLast;
    var $Pager_firstPagePre;
    var $Pager_firstPageText;
    var $Pager_firstPagePost;
    var $Pager_lastPagePre;
    var $Pager_lastPageText;
    var $Pager_lastPagePost;
    var $Pager_separator;
    var $Pager_spacesBeforeSeparator;
    var $Pager_spacesAfterSeparator;
    
    
    
    var $test;

    var $resultmax;
    

    function execute()
    {
        $log =& LogFactory::getLog();
        $log->debug("Admin_Itemmanage_Search_Resultが実行されました", "Admin_Itemmanage_Search_Result#execute");

        $errorList =& $this->actionChain->getCurErrorList();

        $to = $this->Pager_perPage;

        //ジャンルの配列チェックと数値チェック
        if (is_array($this->genre_select)) {
            foreach($this->genre_select as $val) if(!is_numeric($val)) $this->genre_select = array();
        } else if (!is_numeric($this->genre_select) || empty($this->genre_select)) {
            $this->genre_select = array();
        } else {
            $this->genre_select = array($this->genre_select);
        }
        
        //$this->results = $this->view->getSearchResults($to, $this->genre_select, $this->resultmax);

        $this->results = $this->db_preitem->getSearchResults($this->itemnm, $this->sellercd, $this->genre_select, $this->download, $this->sort, $this->from, $to);
        if (!$this->results) {
            $errorList->add(1, "指定された条件では ".$this->view->overcount."件該当します。検索結果が多すぎるので、 ".$this->resultmax."件以内になるように条件を指定してください");
            return 'input';
        }
        //print_r($this->results);
        //$this->cont = count($this->results);
        //$this->castnm = $this->view->getCastnmForItemcd();
        
        
        // Pager設定
        $pageparams = array(
            //'itemData'      => $this->results,
            'totalItems'    => $this->results["recordcount"],
            'perPage'       => $this->Pager_perPage,       // １ページの行数
            'delta'         => $this->Pager_delta,       // 表示ページから、前後に表示するページ数
            'append'        => $this->Pager_append,
            'clearIfVoid'   => $this->Pager_clearIfVoid,
            'urlVar'        => $this->Pager_urlVar,
            'useSessions'   => $this->Pager_useSessions,
            'closeSession'  => $this->Pager_closeSession,
            'mode'          => $this->Pager_mode,
            'prevImg'       => $this->Pager_prevImg,
            'nextImg'       => $this->Pager_nextImg,
            'altPage'       => $this->Pager_altPage,
            'altPrev'       => $this->Pager_altPrev,
            'altNext'       => $this->Pager_altNext,
            'altFirst'      => $this->Pager_altFirst,
            'altLast'       => $this->Pager_altLast,
            'firstPagePre'  => $this->Pager_firstPagePre,
            'firstPageText' => $this->Pager_firstPageText,
            'firstPagePost' => $this->Pager_firstPagePost,
            'lastPagePre'   => $this->Pager_lastPagePre,
            'lastPageText'  => $this->Pager_lastPageText,
            'lastPagePost'  => $this->Pager_lastPagePost,
            'separator'     => $this->Pager_separator, 
            'spacesBeforeSeparator' => $this->Pager_spacesBeforeSeparator,
            'spacesAfterSeparator'  => $this->Pager_spacesAfterSeparator
            );
        
        // Pager出力
        $pager = & Pager::factory($pageparams);
        $this->pagedata = $pager->getPageData();
        $this->links = $pager->getLinks();
        $this->cont = $this->results["recordcount"];
        unset($this->results["recordcount"]);
        return 'success';
    }
    
    /**
     * ページリンク取得
     * 
     * @return object ページリンク
     */
    function getLink()
    {
        return $this->links;
    }

    function getSearchQuery()
    {
        $this->q = "&itemnm=".               urlencode($this->itemnm) .
                   "&sellercd=".             urlencode($this->sellercd) .
                   "&download=".               urlencode($this->download);

        if (is_array($this->genre_select)) {
            foreach($this->genre_select as $val) {
                if(is_numeric($val)) $this->q .= "&genre_select[]=". $val;
            }
        } else {
            $this->q .= "&genre_select[]=". $this->genre_select;
        }


        return $this->q;
    }

    function getCastname($params)
    {
        return $this->castnm[$params["itemcd"]];
    }
    

    function getMediaList() {
        $this->media_list = $this->tname->selectDivAll(4);
        return $this->media_list;
    }

    function getMakername($params) {
        $m = $this->tmaker->viewselectKey(1,$params["makercd"]);
        return $m["makernm"];
    }

    function getStockcount($params) {
        $d = $this->view->getStockcount($params["itemcd"],$params["structcd"]);
        return $d;
    }

    function getGenreSearch() {
        $this->genre_search = $this->genreview->selectAll(NULL);
        foreach ($this->genre_search as $key => $val) {
            if (!empty($val["parentcd"])) {
                $this->genre_search[$key]["checked"] = "";
                if (in_array($val["genrecd"], $this->genre_select)) {
                    $this->genre_search[$key]["checked"] = "checked";
	            }
            } else {
                unset($this->genre_search[$key]);
            }
        }
        return $this->genre_search;
    }

}
?>
