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

/**
 * キャスト関連
 *
 * @package     Onedepo.Logic.Castview
 * @author      netnee <mail@example.com>
 * @access      public
 */
class Onedepo_Logic_Castview
{
    var $cast;
    var $name;
    var $pref;
    var $item;
    
    var $cd;
    var $resultcastdata;
    var $hasimagetcastdata;
    
    var $initial = array(
                        // あ ～
                        "a" => array("あ"), "i" => array("い"), "u" => array("う"), "e" => array("え"), "o" => array("お")
                        // か ～
                        , "ka" => array("か","が"), "ki" => array("き","ぎ"), "ku" => array("く","ぐ"), "ke" => array("け","げ"), "ko" => array("こ","ご")
                        // さ ～
                        , "sa" => array("さ","ざ"), "si" => array("し","じ"), "su" => array("す","ず"), "se" => array("せ","ぜ"), "so" => array("そ","ぞ")
                        // た ～
                        , "ta" => array("た","だ"), "ti" => array("ち","ぢ"), "tu" => array("つ","づ"), "te" => array("て","で"), "to" => array("と","ど")
                        // な ～
                        , "na" => array("な"), "ni" => array("に"), "nu" => array("ぬ"), "ne" => array("ね"), "no" => array("の")
                        // は ～
                        , "ha" => array("は","ば","ぱ"), "hi" => array("ひ","び","ぴ"), "hu" => array("ふ","ぶ","ぷ"), "he" => array("へ","べ","ぺ"), "ho" => array("ほ","ぼ","ぽ")
                        // ま ～
                        , "ma" => array("ま"), "mi" => array("み"), "mu" => array("む"), "me" => array("め"), "mo" => array("も")
                        // や ～
                        , "ya" => array("や"), "yu" => array("ゆ"), "yo" => array("よ")
                        // ら ～
                        , "ra" => array("ら"), "ri" => array("り"), "ru" => array("る"), "re" => array("れ"), "ro" => array("ろ")
                        // わ ～
                        , "wa" => array("わ")/*, "wo" => array(""), "nn" => array("")*/
                        // その他
                        , "oth" => array("その他")
                         );
    
    
    /**
    * キャストデータ取得
    * 
    */
    function getCastDetailData()
    {
        $log =& LogFactory::getLog();
        $log->debug("debug", "Onedepo_Logic_Castview#getCastDetailData");
        
        $this->resultcastdata = $this->cast->selectKey($this->cd);
        
        // キャスト区分名取得
        if (!empty($this->resultcastdata["castdiv"])){
             $tmpdata = $this->name->selectKey(6, $this->resultcastdata["castdiv"]);   // 名称区分：６
             
             $this->resultcastdata["castdivnm"] = $tmpdata["name"];
        }
        
        // 出身県名取得
        if (!empty($this->resultcastdata["birthplacecd"])){
             $tmpdata = $this->pref->selectKey($this->resultcastdata["birthplacecd"]);
             
             $this->resultcastdata["birthplacenm"] = $tmpdata["prefnm"];
        }
        
        return $this->resultcastdata;
    }

    /**
    * キャスト出演作品データ取得
    * 
    */
    function getCastApprItem($displmt)
    {
        $log =& LogFactory::getLog();
        $log->debug("debug", "Onedepo_Logic_Castview#getCastApprItem");
        
        
        $where = array("castitem.castcd = ?");
        $param = array($this->cd);
        
        $appritem = $this->cast->getItemcdForCast($where, $param);
        
        if (empty($appritem)){
            return "";
        }
        
        $whr = " basic.itemcd in ( ";
        $cnt = 0;
        foreach( $appritem as $val ){
            if ($cnt++ == 0){
                $whr .= " ? ";
            } else {
                $whr .= " , ? ";
            }
        }
        $whr .= " ) ";
        
        $where = array(array($whr));
        $param = $appritem;
        $sort = "salestartdate DESC";
        
        $itemlist = $this->item->getNewitemList($displmt, 0, $where, $param, $sort);
        unset($itemlist["recordcount"]);
        unset($itemlist["recordcount2"]);
        
        return $itemlist;
    }


    /**
    * おすすめキャスト取得
    * 
    */
    function selectRecommendCast($div=1, $shopdiv=null)
    {
        $log =& LogFactory::getLog();
        $log->debug("debug", "Onedepo_Logic_Castview#selectRecommendCast");
        
        return $this->cast->selectAllRecommend($div, $shopdiv);
    }


    /**
    * 検索語によるキャスト取得
    * 
    */
    function searchCastByWord($srcword, $shopdiv=null)
    {
        $log =& LogFactory::getLog();
        $log->debug("debug", "Onedepo_Logic_Castview#searchCastByWord");
        
        if(!empty($srcword)){
            $this->resultcastdata = $this->cast->selectSearch($srcword, 1, NULL, $shopdiv);
        }
    }


    /**
    * かなによるキャスト取得
    * 
    */
    function searchCastByKana($kana, $shopdiv=null)
    {
        $log =& LogFactory::getLog();
        $log->debug("debug", "Onedepo_Logic_Castview#searchCastByKana");
        
        // ”かな”以外の検索
        if ($kana == "oth"){
            $this->resultcastdata = $this->cast->viewSelectNonKana(1,$shopdiv);
            $log->debug("Search type : Other", "Onedepo_Logic_Castview#searchCastByKana");
            return "";
        }
        
        // ”かな”による検索
        $kanadata = array();
        foreach($this->initial as $key => $val){
            if ($key == $kana){
                foreach($val as $i){
                    $kanadata[] = $i;
                }
                break;
            }
        }
        
        if (!empty($kanadata)){
            $this->resultcastdata = $this->cast->selectKana(1, $kanadata, $shopdiv);
            $log->debug("Search type : Kana", "Onedepo_Logic_Castview#searchCastByKana");
        }
    }


    /**
    * 画像登録有りキャスト取得
    * 
    */
    function selectImageCast()
    {
        $log =& LogFactory::getLog();
        $log->debug("debug", "Onedepo_Logic_Castview#selectImageCast");
        
        if (empty($this->resultcastdata)){
            return "";
        }
        
        $castcd = array();
        foreach ($this->resultcastdata as $key => $val){
                if (!empty($val["castcd"]))
                $castcd[] = $val["castcd"];
        }
        
        $paramccd = implode(",", $castcd);
        
        return $this->cast->viewSelectImageSHasCast($paramccd);
    }


    /**
    *画像登録なしキャスト取得
    * 
    */
    function selectNonImageCast()
    {
        $log =& LogFactory::getLog();
        $log->debug("debug", "Onedepo_Logic_Castview#selectNonImageCast");
        
        if (empty($this->resultcastdata)){
            return "";
        }
        $castcd = array();
        foreach ($this->resultcastdata as $key => $val){
                if (!empty($val["castcd"]))
                $castcd[] = $val["castcd"];
        }
        
        $paramccd = implode(",", $castcd);
        
        return $this->cast->viewSelectNonImageSCast($paramccd);
    }

}
?>