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

/**
 * 蝠・ｽ刀讀懃ｴ｢
 *
 * @package     recommend
 * @author      netnee T.Ototgawa <tomokauzu.otogawa@netnee.jp>
 * @access      public
 */
class Onedepo_Logic_Recommend {

    var $item;
    var $tcast;
    var $genre;
    var $image;
    var $name;
    var $member;

    var $data;


    function getRecommendItem($media,$limit=4)
    {
        $where = array();
        $params = array();

        $log =& LogFactory::getLog();
        $log->debug("debug", "Onedepo_Logic_Recommend#getRecommendItem");

        $this->data = $this->item->getRecommendItem($media,$limit);
        return $this->data;
    }
    
    // お勧め商品取得 (ログインユーザが好むジャンル)
    function getRecommendItemForMembercd($membercd, $media, $limit=4)
    {
        $where = array();
        $params = array();

        $log =& LogFactory::getLog();
        $log->debug("debug", "Onedepo_Logic_Recommend#getRecommendItemForMembercd");
        
        //ログインユーザが好むジャンル取得
        $genre_list = $this->member->getGenrecdForMembercd($membercd);
        $this->data = $this->item->getRecommendItemForGenre($genre_list, $media, $limit);
        return $this->data;
    }


    function getCastnmForItemcd()
    {
        $where = array();
        $params = array();
        $cd = "";

        $log =& LogFactory::getLog();
        $log->debug("debug", "Onedepo_Logic_Recommend#getCastnmForItemcd");

        $itemcd = array();
        foreach ($this->data as $key => $val) 
        {
            if (!empty($val["itemcd"]))
                $itemcd[] = $val["itemcd"];
        }
        $cd = implode(",", $itemcd);

        //$log->debug($cd, "Onedepo_Logic_Recommend#getCastnmForItemcd");
        if (empty($cd)) return;

        $list = $this->tcast->getCastnmForItemcd($cd);

        $castnm = array();
        foreach ($list as $key => $val)
        {
            $castnm[$key] = implode(" ", $val);
        }
        return $castnm;
    }

    function getCastForItemcd($itemcd)
    {
        $log =& LogFactory::getLog();
        $log->debug("debug", "Onedepo_Logic_Recommend#getCastnmForItemcd");

        return $this->tcast->getCastForItemcd($itemcd);;
    }

    function getGenrenmForItemcd()
    {
        $where = array();
        $params = array();
        $cd = "";

        $log =& LogFactory::getLog();
        $log->debug("debug", "Onedepo_Logic_Recommend#getGenrenmForItemcd");

        $itemcd = array();
        foreach ($this->data as $key => $val) 
        {
            if (!empty($val["itemcd"]))
                $itemcd[] = $val["itemcd"];
        }
        $cd = implode(",", $itemcd);

        //$log->debug($cd, "Onedepo_Logic_Recommend#getGenrenmForItemcd");
        if (empty($cd)) return;

        $list = $this->genre->getGenrenmForItemcd($cd);

        $genrenm = array();
        foreach ($list as $key => $val)
        {
            $genrenm[$key] = implode(" ", $val);
        }
        return $genrenm;
    }

    function getGenreForItemcd()
    {
        $where = array();
        $params = array();
        $cd = "";

        $log =& LogFactory::getLog();
        $log->debug("debug", "Onedepo_Logic_Recommend#getGenreForItemcd");

        $itemcd = array();
        foreach ($this->data as $key => $val) 
        {
            if (!empty($val["itemcd"]))
                $itemcd[] = $val["itemcd"];
        }
        $cd = implode(",", $itemcd);

        //$log->debug($cd, "Onedepo_Logic_Recommend#getGenrenmForItemcd");
        if (empty($cd)) return;

        $list = $this->genre->getGenreForItemcd($cd);

        $genre = array();
        foreach ($list as $key => $val)
        {
            $genre[$key] = $val;
        }
        return $genre;
    }

    function getItemImageForItemcd()
    {
        $where = array();
        $params = array();
        $cd = "";

        $log =& LogFactory::getLog();
        $log->debug("debug", "Onedepo_Logic_Recommend#getImageForItemcd");

        $itemcd = array();
        foreach ($this->data as $key => $val) 
        {
            if (!empty($val["itemcd"]))
                $itemcd[] = $val["itemcd"];
        }
        $cd = implode(",", $itemcd);

        //$log->debug($cd, "Onedepo_Logic_Recommend#getImageForItemcd");
        if (empty($cd)) return;

        $list = $this->image->getItemImageForItemcd($cd);

        $imagenm = array();
        foreach ($list as $key => $val) {
            foreach ($val as $imgsize) {
                if (is_file(IMAGE_DIR ."/1/". $key . $imgsize . ".jpg"))
                    $imagenm[$key][$imgsize] = IMAGE_URI ."/". $key . $imgsize .".jpg";
            }
        }
        return $imagenm;
    }

    // お勧め予約商品取得
    function getReserveRecommendItem()
    {
        $log =& LogFactory::getLog();
        $log->debug("debug", "Onedepo_Logic_Recommend#getReserveRecommendItem");

        $this->data = $this->item->getReserveRecommendItem();
        return $this->data;
    }

    // お勧め予約商品取得 (ログインユーザが好むジャンル)
    function getReserveRecommendItemForMembercd($membercd)
    {
        $log =& LogFactory::getLog();
        $log->debug("debug", "Onedepo_Logic_Recommend#getRecommendItemForMembercd");
        
        //ログインユーザが好むジャンル取得
        $genre_list = $this->member->getGenrecdForMembercd($membercd);
        $this->data = $this->item->getReserveRecommendItemForGenre($genre_list);
        return $this->data;
    }


}
?>