<?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 'Net/UserAgent/Mobile.php';

/**
 * 携帯向けポータル
 *
 * @package     Mobile.Portal
 * @author      netnee
 * @access      public
 */
class Mobile_Portal
{
    var $recommend;
    var $session;
    var $auth;
    var $news;
    var $view;
    var $c_preorder;

    var $recommenddata;
    var $newitemlist;

    var $parameters = array(
                         "etc" => array(
                              "type" => "all",
                              "stock" => "all",
                              "saledate" => "all",
                          ),
                         "salestartdate_start" => "", // 発売日前xx日
                         "salestartdate_end" => ""  // 発売日後xx日
                      );


    var $tag;

    var $shoplist;
    var $attentionshops;

    var $exec_s;
    var $exec_e;

    /**
     * ポータルページ表示
     *
     * @access  public
     */
    function execute()
    {
        $log =& LogFactory::getLog();
        $func_name = "Mobile_Portal#execute";
        $log->debug("実行されました", $func_name);

        $mobile = &Net_UserAgent_Mobile::isMobile();
        if (!$mobile) {
            return 'notmobile';
        }


        // ショップ一覧
        $this->getExectime();
        $this->shoplist = $this->view->getGenreHasImage("S");
        $this->getExectime(false, "shoplist");

        // 注目
        $this->getExectime();
        $this->attentionshops = $this->view->getGenreHasImage("M");
        $this->getExectime(false, "attentionshops");

        // おすすめ商品
        $this->getExectime();
        $this->recommenddata = $this->recommend->getRecommendItem(NULL, 8);
        $this->getExectime(false, "recommenddata");
        //--
        // 新着
        /*
        $this->getExectime();
        $this->newitemlist = $this->getNewList(
                             array("etc"=>
                                   array("stock"=>"stk")),
                             8
                         );
        $this->getExectime(false, "newitemlist");
        */
        //--

        $log->debug("終了しました", $func_name);
        
        return 'success';
    }
    function getExectime($start=true, $func="") {
        $log =& LogFactory::getLog();
        $func_name = "General_Portal#getExectime " .$func;
        if ($start) {
            $this->exec_s=microtime(true);
        } else {
            $this->exec_e=microtime(true)-$this->exec_s;
            $log->debug("exectime".$this->exec_e, $func_name);
        }
    }

    function checkAuth()
    {
        return $this->auth->checkAuth();
    }

    function getOneDepoInfo(){
        return $this->news->selectRelease();
    }

    /**
     * 「新着情報」表示用
     *
     * @access  public
     */
    function getNewList($params=array(), $limit=8){
        $parameters = array_merge($this->parameters, $params);

        $res = $this->view->getNewListPortal($limit,
                                             0,
                                             $parameters
                                             );

        return $res;
    }
    function getCartCd($params) {
        if (empty($params["sellingprice"])) {
            $params["sellingprice"] = 0;
        }
        return $this->view->getCd($params["itemcd"],$params["sellingprice"]);
    }

    function getItemTagList($params)
    {
        $this->getExectime();
        $t = $this->tag->getItemTag($params["itemcd"]);
        $this->getExectime(false, "tag");
        return $t;
    }
    
    // 文字列 str を文字数 lmt 以下に丸める
    function strTrimWidth($params){
        return mb_strimwidth($params["str"], 0, $params["lmt"], " …", "UTF-8");
    }

}
?>
