Index: branches/version-2_12-dev/data/class/pages/admin/contents/LC_Page_Admin_Contents.php
===================================================================
--- branches/version-2_12-dev/data/class/pages/admin/contents/LC_Page_Admin_Contents.php	(revision 22567)
+++ branches/version-2_12-dev/data/class/pages/admin/contents/LC_Page_Admin_Contents.php	(revision 22581)
@@ -82,80 +82,85 @@
     {
 
-        $objDb = new SC_Helper_DB_Ex();
+        $objNews = new SC_Helper_News_Ex();
+
         $objFormParam = new SC_FormParam_Ex();
         $this->lfInitParam($objFormParam);
         $objFormParam->setParam($_POST);
         $objFormParam->convParam();
+
         $news_id = $objFormParam->getValue('news_id');
 
         //---- 新規登録/編集登録
         switch ($this->getMode()) {
-            case 'regist':
-                $arrPost = $objFormParam->getHashArray();
+            case 'edit':
                 $this->arrErr = $this->lfCheckError($objFormParam);
-                if (SC_Utils_Ex::isBlank($this->arrErr)) {
-                    // ニュースIDの値がPOSTされて来た場合は既存データの編集とみなし、
-                    // 更新メソッドを呼び出す。
-                    // ニュースIDが存在しない場合は新規登録を行う。
-                    $arrPost['link_method'] = $this->checkLinkMethod($arrPost['link_method']);
-                    $arrPost['news_date'] = $this->getRegistDate($arrPost);
-                    $member_id = $_SESSION['member_id'];
-                    if (strlen($news_id) > 0 && is_numeric($news_id)) {
-                        $this->lfNewsUpdate($arrPost,$member_id);
-                    } else {
-                        $this->lfNewsInsert($arrPost,$member_id);
+                if (!SC_Utils_Ex::isBlank($this->arrErr['news_id'])) {
+                    trigger_error('', E_USER_ERROR);
+                    return;
+                }
+
+                if (count($this->arrErr) <= 0) {
+                    // POST値の引き継ぎ
+                    $arrParam = $objFormParam->getHashArray();
+                    // 登録実行
+                    $res_news_id = $this->doRegist($news_id, $arrParam, $objNews);
+                    if ($res_news_id !== FALSE) {
+                        // 完了メッセージ
+                        $news_id = $res_news_id;
+                        $this->tpl_onload = "alert('登録が完了しました。');";
                     }
-                    $news_id = '';
-                    $this->tpl_onload = "window.alert('編集が完了しました');";
-                } else {
-                    $this->arrForm = $arrPost;
                 }
-                break;
-            case 'search':
-                if (is_numeric($news_id)) {
-                    list($this->arrForm) = $this->getNews($news_id);
-                    list($this->arrForm['year'],$this->arrForm['month'],$this->arrForm['day']) = $this->splitNewsDate($this->arrForm['cast_news_date']);
-                    $this->edit_mode = 'on';
-                }
-                break;
+                // POSTデータを引き継ぐ
+                $this->tpl_news_id = $news_id;
+                break;
+
+            case 'pre_edit':
+                $news = $objNews->get($news_id);
+                list($news['year'],$news['month'],$news['day']) = $this->splitNewsDate($news['cast_news_date']);
+                $objFormParam->setParam($news);
+
+                // POSTデータを引き継ぐ
+                $this->tpl_news_id = $news_id;
+                break;
+
             case 'delete':
             //----　データ削除
-                if (is_numeric($news_id)) {
-                    $pre_rank = $this->getRankByNewsId($news_id);
-                    $this->computeRankForDelete($news_id,$pre_rank);
-
-                    SC_Response_Ex::reload();             //自分にリダイレクト（再読込による誤動作防止）
-                }
-                break;
-            case 'move':
+                $objNews->delete($news_id);
+                //自分にリダイレクト（再読込による誤動作防止）
+                SC_Response_Ex::reload();
+                break;
+
             //----　表示順位移動
-                if (strlen($news_id) > 0 && is_numeric($news_id) == true) {
-                    $term = $objFormParam->getValue('term');
-                    if ($term == 'up') {
-                        $objDb->sfRankUp('dtb_news', 'news_id', $news_id);
-                    } else if ($term == 'down') {
-                        $objDb->sfRankDown('dtb_news', 'news_id', $news_id);
-                    }
-
-                    $this->objDisplay->reload();
-                }
-                break;
+            case 'up':
+                $objNews->rankUp($news_id);
+
+                // リロード
+                SC_Response_Ex::reload();
+                break;
+
+            case 'down':
+                $objNews->rankDown($news_id);
+
+                // リロード
+                SC_Response_Ex::reload();
+                break;
+
             case 'moveRankSet':
             //----　指定表示順位移動
                 $input_pos = $this->getPostRank($news_id);
                 if (SC_Utils_Ex::sfIsInt($input_pos)) {
-                    $objDb->sfMoveRank('dtb_news', 'news_id', $news_id, $input_pos);
+                    $objNews->moveRank($news_id, $input_pos);
                 }
-                $this->objDisplay->reload();
-                break;
+                SC_Response_Ex::reload();
+                break;
+
             default:
                 break;
         }
 
-        $this->arrNews = $this->getNews();
-        $this->tpl_news_id = $news_id;
+        $this->arrNews = $objNews->getList();
         $this->line_max = count($this->arrNews);
-        $this->max_rank = $this->getRankMax();
-
+
+        $this->arrForm = $objFormParam->getFormParamList();
     }
 
@@ -197,52 +202,22 @@
         $objFormParam->addParam('本文', 'news_comment', LTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK'));
         $objFormParam->addParam('別ウィンドウで開く', 'link_method', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
-        $objFormParam->addParam('ランク移動', 'term', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
-    }
-
-    /**
-     * 新着記事のデータの登録を行う
-     * @param Array $arrPost POSTデータの配列
-     * @param Integer $member_id 登録した管理者のID
-     */
-    function lfNewsInsert($arrPost,$member_id)
-    {
-        $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance();
-
-        // rankの最大+1を取得する
-        $rank_max = $this->getRankMax();
-        $rank_max = $rank_max + 1;
-
-        $table = 'dtb_news';
-        $sqlval = array();
-        $news_id = $objQuery->nextVal('dtb_news_news_id');
+    }
+
+    /**
+     * 登録処理を実行.
+     * 
+     * @param integer $news_id
+     * @param array $sqlval
+     * @param object $objNews
+     * @return multiple
+     */
+    function doRegist($news_id, $sqlval, SC_Helper_News_Ex $objNews)
+    {
         $sqlval['news_id'] = $news_id;
-        $sqlval['news_date'] = $arrPost['news_date'];
-        $sqlval['news_title'] = $arrPost['news_title'];
-        $sqlval['creator_id'] = $member_id;
-        $sqlval['news_url'] = $arrPost['news_url'];
-        $sqlval['link_method'] = $arrPost['link_method'];
-        $sqlval['news_comment'] = $arrPost['news_comment'];
-        $sqlval['rank'] = $rank_max;
-        $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
-        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
-        $objQuery->insert($table, $sqlval);
-    }
-
-    function lfNewsUpdate($arrPost,$member_id)
-    {
-        $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance();
-
-        $table = 'dtb_news';
-        $sqlval = array();
-        $sqlval['news_date'] = $arrPost['news_date'];
-        $sqlval['news_title'] = $arrPost['news_title'];
-        $sqlval['creator_id'] = $member_id;
-        $sqlval['news_url'] = $arrPost['news_url'];
-        $sqlval['news_comment'] = $arrPost['news_comment'];
-        $sqlval['link_method'] = $arrPost['link_method'];
-        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
-        $where = 'news_id = ?';
-        $arrValIn = array($arrPost['news_id']);
-        $objQuery->update($table, $sqlval, $where, $arrValIn);
+        $sqlval['creator_id'] = $_SESSION['member_id'];
+        $sqlval['link_method'] = $this->checkLinkMethod($sqlval['link_method']);
+        $sqlval['news_date'] = $this->getRegistDate($sqlval);
+        unset($sqlval['year'], $sqlval['month'], $sqlval['day']);
+        return $objNews->save($sqlval);
     }
 
@@ -272,50 +247,4 @@
 
     /**
-     * ニュース記事を取得する。
-     * @param Integer news_id ニュースID
-     */
-    function getNews($news_id = '')
-    {
-        $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance();
-        $col = '*, cast(news_date as date) as cast_news_date';
-        $table = 'dtb_news';
-        $order = 'rank DESC';
-        if (strlen($news_id) == 0) {
-            $where = 'del_flg = 0';
-            $arrWhereVal = array();
-        } else {
-            $where = 'del_flg = 0 AND news_id = ?';
-            $arrWhereVal = array($news_id);
-        }
-        $objQuery->setOrder($order);
-        return $objQuery->select($col, $table, $where, $arrWhereVal);
-    }
-
-    /**
-     * 指定されたニュースのランクの値を取得する。
-     * @param Integer $news_id
-     */
-    function getRankByNewsId($news_id)
-    {
-        $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance();
-        $col = 'rank';
-        $table = 'dtb_news';
-        $where = 'del_flg = 0 AND news_id = ?';
-        $arrWhereVal = array($news_id);
-        list($rank) = $objQuery->select($col, $table, $where, $arrWhereVal);
-        return $rank['rank'];
-    }
-
-    /**
-     * 削除する新着情報以降のrankを1つ繰り上げる。
-     * @param Integer $news_id
-     * @param Integer $rank
-     */
-    function computeRankForDelete($news_id,$rank)
-    {
-        SC_Helper_DB_Ex::sfDeleteRankRecord('dtb_news', 'news_id', $news_id);
-    }
-
-    /**
      * ニュースの日付の値をフロントでの表示形式に合わせるために分割
      * @param String $news_date
@@ -324,18 +253,4 @@
     {
         return explode('-', $news_date);
-    }
-
-    /**
-     * ランクの最大値の値を返す。
-     * @return Intger $max ランクの最大値の値
-     */
-    function getRankMax()
-    {
-        $objQuery =& SC_Query_Ex::getSingletonInstance();
-        $col = 'MAX(rank) as max';
-        $table = 'dtb_news';
-        $where = 'del_flg = 0';
-        list($result) = $objQuery->select($col, $table, $where);
-        return $result['max'];
     }
 
