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


require_once 'Pager.php';

class Admin_Portalmanage_Recommend_List
{
	// ページ情報
	var $pagename;
	var $title;

	// DB
	var $recommend;
	var $data;
	var $cnt;
	var $data2;
	
	// 表示パラメータ
	var $sort;          // ソートキー
	var $pageID;        // ページ番号
	var $srcword;       // 検索
	var $srcdispnum;    // 表示件数

	// 表示件数
	var $srcdispnumlist;// 表示件数リスト

	// リストのページング
	var $pagedata;    // Pagerデータ
	var $links;       // Pagerリンク

	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;
	
	function getPager()
	{
        // Pager設定
        $pageparams = array(
        'totalItems'    => $this->cnt,
        'perPage'       => $this->Pager_perPage,       // １ページの行数
        'delta'         => $this->Pager_delta,       // 表示ページから、前後に表示するページ数
        'append'        => $this->Pager_append,
        'currentPage'   => $this->pageID,
        '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,
        'extraVars' => array('sort' => $this->sort, 'srcword' => $this->srcword,'srcdispnum' => $this->srcdispnum),
        );

        // Pager出力
        $pager = & Pager::factory($pageparams);
        $this->pagedata = $pager->getPageData();
        $link =	$pager->getLinks();
        return $link["all"];
	}
	
    function execute()
    {
        // 一覧表示件数
        if (!empty($this->srcdispnum)) $this->Pager_perPage = $this->srcdispnum;

        $this->srcdispnumlist = array();
        $this->srcdispnumlist[] = 10;
        $this->srcdispnumlist[] = 20;
        $this->srcdispnumlist[] = 50;
        $this->srcdispnumlist[] = 100;
        
        // 並び替え
        $sorttype = array(
        //"maker"        => "makernm ",
        //"-maker"       => "makernm DESC ",
        "title"        => "itemnmkana ",
        "-title"       => "itemnmkana DESC ",
        //"label"        => "labelnm ",
        //"-label"       => "labelnm DESC ",
        "startdate"    => "startdate ",
        "-startdate"   => "startdate DESC ",
        "closedate"    => "closedate ",
        "-closedate"   => "closedate DESC ",
        "priority"   => "priority ",
        "-priority"  => "priority DESC ",
        );
        if (empty($sorttype[$this->sort]))
        $this->sort = "title";


        $sort = $sorttype[$this->sort];
    
        $where = array();
        $where[0][0] = "delflg = false";
        if($this -> srcword){
            $where[0][1] = "itemnm LIKE '%" . $this -> srcword ."%'";
        }
        
        $this->data = $this->recommend->getRecommendList(
                                $this->Pager_perPage,
                                $this->Pager_perPage*($this->pageID-1),
                                $where,
                                array(),
                                $sort);
        $this->cnt = array_pop($this->data);

        $log =& LogFactory::getLog();
        $log->debug("Admin_Portalmanage_Recommend_Listが実行されました", "Admin_Portalmanage_Recommend_List#execute");
        return 'success';
    }
    /**
     * ページリンク取得
     *
     * @return object ページリンク
     */
    function getLink()
    {
    	return $this->links;
    }
    
    /**
     * リスト復帰用の検索条件保持URLパラメータ出力
     * 
     * @return object
     */
     function getExtraParam()
     {
         return 'fromaction=admin_portalmanage_recommend_list'.
                '&sort='.$this->sort.
                '&pageID='.$this->pageID.
                '&srcword='.$this->srcword.
                '&srcdispnum='.$this->srcdispnum;
     }
}
?>