<?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     [[package名]]
 * @author      H.Watanabe <hiroshi.watanabe@netnee.jp>
 * @access      public
 */
class Admin_Itemmanage_Stock_List
{
    /**
     * [[機能説明]]
     *
     * @access  public
     */
    
    var $title;
    var $pagename;
    var $div;
    
    /**
     * Pager設定
     */
    var $Pager_perPage;
    var $Pager_delta;
    var $Pager_append;
    var $Pager_clearIfVoid;
    var $Pager_linkClass;
    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;
    
    //components
    var $lg_stock;
    var $db_maker;
    var $db_label;
    var $db_cast;
    var $actionChain;
    
    //post
    var $maker_capi;
    var $makercd;
    var $labelcd;
    var $stock;
    var $src_title;
    
    var $count;
    var $pagedata;
    
    var $nowpages;
    var $totalpages;
    var $links;
    var $from;
    var $results;
    
    function execute()
    {
        $log =& LogFactory::getLog();
        $log->debug("Admin_Itemmanage_Stock_Searchが実行されました", "Admin_Itemmanage_Stock_Search#execute");

        $errorList =& $this->actionChain->getCurErrorList();
        
        if( $this->makercd == 0 ) {
            $errorList->add('nomaker', 'メーカーを選択してください');
            return 'error';
        }
        
        $div = (empty($this->div)) ? 2 : 1;
        if (!is_numeric($this->from)) {
            $this->from = 1;
        }
        $from = ($this->from-1)*$this->Pager_perPage;
        
        $div = (empty($this->div)) ? 2 : 1;
        
        $this->results = $this->lg_stock->searchStock(
                                            $this->Pager_perPage, 
                                            $from, 
                                            $this->makercd, 
                                            $this->labelcd, 
                                            $this->stock, 
                                            $this->src_title, 
                                            $div);
        
        // pager設定
        $pager_ini = array(
            '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($pager_ini);
        $this->pagedata = $pager->getPageData();
        $this->nowpages = $pager->getCurrentPageID();
        $this->totalpages = $pager->numPages();
        $this->links = $pager->getLinks();
        
        $this->count = $this->results["recordcount"];
        unset($this->results["recordcount"]);
        
        return 'success';
    }
    
    // pagerのLink取得
    function getLink()
    {
        return $this->links['all'];
    }
    
    // キャスト名取得
    function getCastnm($param)
    {
        $cast = $this->db_cast->getCastnmForItemcd($param['itemcd']);
        return $cast;
    }
}
?>
