Page
[ class tree: Page ] [ index: Page ] [ all elements ]

Source for file LC_Page_FrontParts_Bloc_News.php

Documentation is available at LC_Page_FrontParts_Bloc_News.php

  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.lockon.co.jp/
  8.  *
  9.  * This program is free software; you can redistribute it and/or
  10.  * modify it under the terms of the GNU General Public License
  11.  * as published by the Free Software Foundation; either version 2
  12.  * of the License, or (at your option) any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  22.  */
  23.  
  24. // {{{ requires
  25. require_once CLASS_REALDIR 'pages/frontparts/bloc/LC_Page_FrontParts_Bloc.php';
  26.  
  27. /**
  28.  * 新着情報 のページクラス.
  29.  *
  30.  * @package Page
  31.  * @author LOCKON CO.,LTD.
  32.  * @version $Id: LC_Page_FrontParts_Bloc_News.php 21126 2011-08-04 11:48:01Z nanasess $
  33.  */
  34.  
  35.     // }}}
  36.     // {{{ functions
  37.  
  38.     /**
  39.      * Page を初期化する.
  40.      *
  41.      * @return void 
  42.      */
  43.     function init({
  44.         parent::init();
  45.     }
  46.  
  47.     /**
  48.      * Page のプロセス.
  49.      *
  50.      * @return void 
  51.      */
  52.     function process({
  53.         $this->action();
  54.         $this->sendResponse();
  55.     }
  56.  
  57.     /**
  58.      * Page のアクション.
  59.      *
  60.      * @return void 
  61.      */
  62.     function action({
  63.  
  64.         $objFormParam new SC_FormParam_Ex();
  65.         switch($this->getMode()){
  66.             case "getList":
  67.                 $this->lfInitNewsParam($objFormParam);
  68.                 $objFormParam->setParam($_POST);
  69.                 $objFormParam->convParam();
  70.                 $this->arrErr $objFormParam->checkError(false);
  71.                 if(empty($this->arrErr)){
  72.                     $json $this->lfGetNewsForJson($objFormParam);
  73.                     echo $json;
  74.                     exit;
  75.                 else {
  76.                     echo $this->lfGetErrors($this->arrErr);
  77.                     exit;
  78.                 }
  79.                 break;
  80.             case "getDetail":
  81.                 $this->lfInitNewsParam($objFormParam);
  82.                 $objFormParam->setParam($_GET);
  83.                 $objFormParam->convParam();
  84.                 $this->arrErr $objFormParam->checkError(false);
  85.                 if(empty($this->arrErr)){
  86.                      $json $this->lfGetNewsDetailForJson($objFormParam);
  87.                      echo $json;
  88.                      exit;
  89.                 else {
  90.                     echo $this->lfGetErrors($this->arrErr);
  91.                     exit;
  92.                 }
  93.                 break;
  94.             default:
  95.                 $this->newsCount $this->lfGetNewsCount();
  96.                 $this->arrNews $this->lfGetNews();
  97.                 break;
  98.         }
  99.     }
  100.  
  101.     /**
  102.      * デストラクタ.
  103.      *
  104.      * @return void 
  105.      */
  106.     function destroy({
  107.         parent::destroy();
  108.     }
  109.  
  110.    /**
  111.      * 新着情報パラメーター初期化
  112.      *
  113.      * @param array $objFormParam フォームパラメータークラス
  114.      * @return void 
  115.      */
  116.     function lfInitNewsParam(&$objFormParam{
  117.         $objFormParam->addParam("現在ページ""pageno"INT_LEN'n'array("NUM_CHECK""MAX_LENGTH_CHECK")""false);
  118.         $objFormParam->addParam("表示件数""disp_number"INT_LEN'n'array("NUM_CHECK""MAX_LENGTH_CHECK")""false);
  119.         $objFormParam->addParam("新着ID""news_id"INT_LEN'n'array("NUM_CHECK""MAX_LENGTH_CHECK")""false);
  120.     }
  121.  
  122.     /**
  123.      * 新着情報を取得する.
  124.      *
  125.      * @return array $arrNewsList 新着情報の配列を返す
  126.      */
  127.     function lfGetNews(){
  128.         $objQuery SC_Query_Ex::getSingletonInstance();
  129.         $sql '';
  130.         $sql .= " SELECT ";
  131.         $sql .= "   *, ";
  132.         $sql .= "   cast(news_date as date) as news_date_disp ";
  133.         $sql .= " FROM ";
  134.         $sql .= "   dtb_news ";
  135.         $sql .= " WHERE ";
  136.         $sql .= "   del_flg = '0' ";
  137.         $sql .= " ORDER BY ";
  138.         $sql .= "   rank DESC ";
  139.  
  140.         $arrNewsList $objQuery->getAll($sql);
  141.         return $arrNewsList;
  142.     }
  143.  
  144.     /**
  145.      * 新着情報をJSON形式で取得する
  146.      * (ページと表示件数を指定)
  147.      *
  148.      * @param array $objFormParam フォームパラメータークラス
  149.      * @return String $json 新着情報のJSONを返す
  150.      */
  151.     function lfGetNewsForJson(&$objFormParam){
  152.  
  153.         $objQuery SC_Query_Ex::getSingletonInstance();
  154.         $arrData $objFormParam->getHashArray();
  155.         
  156.         $dispNumber $arrData['disp_number'];
  157.         $pageNo $arrData['pageno'];
  158.         if(!empty($dispNumber&& !empty($pageNo)){
  159.              $objQuery->setLimitOffset($dispNumber(($pageNo 1$dispNumber));
  160.         }
  161.  
  162.         $objQuery->setOrder("rank DESC ");
  163.         $arrNewsList $objQuery->select(" * , cast(news_date as date) as news_date_disp "," dtb_news "," del_flg = '0' ");
  164.  
  165.         //新着情報の最大ページ数をセット
  166.         $newsCount $this->lfGetNewsCount();
  167.         $arrNewsList["news_page_count"ceil($newsCount 3);
  168.  
  169.         $json =  SC_Utils_Ex::jsonEncode($arrNewsList);    //JSON形式
  170.  
  171.         return $json;
  172.     }
  173.  
  174.     /**
  175.      * 新着情報1件分をJSON形式で取得する
  176.      * (news_idを指定)
  177.      *
  178.      * @param array $objFormParam フォームパラメータークラス
  179.      * @return String $json 新着情報1件分のJSONを返す
  180.      */
  181.     function lfGetNewsDetailForJson(&$objFormParam){
  182.  
  183.         $objQuery SC_Query_Ex::getSingletonInstance();
  184.         $arrData $objFormParam->getHashArray();
  185.         $newsId $arrData['news_id'];
  186.         $arrNewsList $objQuery->select(" * , cast(news_date as date) as news_date_disp "," dtb_news "," del_flg = '0' AND news_id = ? "array($newsId));
  187.  
  188.         $json =  SC_Utils_Ex::jsonEncode($arrNewsList);    //JSON形式
  189.  
  190.         return $json;
  191.     }
  192.     
  193.     /**
  194.      * 新着情報の件数を取得する
  195.      *
  196.      * @return Integer $count 新着情報の件数を返す
  197.      */
  198.     function lfGetNewsCount(){
  199.  
  200.         $count 0;
  201.         
  202.         $objQuery SC_Query_Ex::getSingletonInstance();
  203.         $count $objQuery->count("dtb_news""del_flg = '0'");
  204.  
  205.         return $count;
  206.     }
  207.  
  208.     /**
  209.      * エラーメッセージを整形し, JSON 形式で返す.
  210.      *
  211.      * @param array $arrErr エラーメッセージの配列
  212.      * @return string JSON 形式のエラーメッセージ
  213.      */
  214.     function lfGetErrors($arrErr{
  215.         $messages '';
  216.         foreach ($arrErr as $val{
  217.             $messages .= $val "\n";
  218.         }
  219.         return SC_Utils_Ex::jsonEncode(array('error' => $messages));
  220.     }
  221. }
  222. ?>

Documentation generated on Fri, 24 Feb 2012 14:02:01 +0900 by Seasoft