OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / s / blog / include / db / s_blogDb.php
1 <?php
2 /**
3  * DBクラス
4  *
5  * PHP versions 5
6  *
7  * LICENSE: This source file is licensed under the terms of the GNU General Public License.
8  *
9  * @package    Magic3 Framework
10  * @author     平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
11  * @copyright  Copyright 2006-2012 Magic3 Project.
12  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
13  * @version    SVN: $Id: s_blogDb.php 4575 2012-01-09 02:13:07Z fishbone $
14  * @link       http://www.magic3.org
15  */
16 require_once($gEnvManager->getDbPath() . '/baseDb.php');
17
18 class s_blogDb extends BaseDb
19 {
20         /**
21          * ブログ定義値を取得をすべて取得
22          *
23          * @param array  $rows                  レコード
24          * @return bool                                 1行以上取得 = true, 取得なし= false
25          */
26         function getAllConfig(&$rows)
27         {
28                 $queryStr  = 'SELECT * FROM blog_config ';
29                 $queryStr .=   'ORDER BY bg_index';
30                 $retValue = $this->selectRecords($queryStr, array(), $rows);
31                 return $retValue;
32         }
33         /**
34          * ブログ定義値を取得
35          *
36          * @param string $key           キーとなる項目値
37          * @return string $value        値
38          */
39         function getConfig($key)
40         {
41                 $retValue = '';
42                 $queryStr = 'SELECT bg_value FROM blog_config ';
43                 $queryStr .=  'WHERE bg_id  = ?';
44                 $ret = $this->selectRecord($queryStr, array($key), $row);
45                 if ($ret) $retValue = $row['bg_value'];
46                 return $retValue;
47         }
48         /**
49          * ブログ定義値を更新
50          *
51          * @param string $key           キーとなる項目値
52          * @param string $value         値
53          * @return                                      true = 正常、false=異常
54          */
55         function updateConfig($key, $value)
56         {
57                 // データの確認
58                 $queryStr = 'SELECT bg_value FROM blog_config ';
59                 $queryStr .=  'WHERE bg_id  = ?';
60                 $ret = $this->isRecordExists($queryStr, array($key));
61                 if ($ret){
62                         $queryStr = "UPDATE blog_config SET bg_value = ? WHERE bg_id = ?";
63                         return $this->execStatement($queryStr, array($value, $key));
64                 } else {
65                         $queryStr = "INSERT INTO blog_config (bg_id, bg_value) VALUES (?, ?)";
66                         return $this->execStatement($queryStr, array($key, $value));
67                 }
68         }
69         /**
70          * エントリー項目一覧を取得(管理用)
71          *
72          * @param int           $limit                          取得する項目数
73          * @param int           $page                           取得するページ(1~)
74          * @param timestamp     $startDt                        期間(開始日)
75          * @param timestamp     $endDt                          期間(終了日)
76          * @param array         $category                       カテゴリーID
77          * @param string        $keyword                        検索キーワード
78          * @param string        $langId                         言語
79          * @param function      $callback                       コールバック関数
80          * @param string        $blogId                         ブログID(未指定の場合はnull)
81          * @return                      なし
82          */
83         function searchEntryItems($limit, $page, $startDt, $endDt, $category, $keyword, $langId, $callback, $blogId = null)
84         {
85                 $offset = $limit * ($page -1);
86                 if ($offset < 0) $offset = 0;
87                 
88                 $params = array();
89                 if (count($category) == 0){             // カテゴリー指定なしのとき
90                         $queryStr = 'SELECT * FROM blog_entry LEFT JOIN _login_user ON be_regist_user_id = lu_id AND lu_deleted = false ';
91                         $queryStr .=  'WHERE be_language_id = ? '; $params[] = $langId;
92                         $queryStr .=    'AND be_deleted = false ';              // 削除されていない
93                 } else {
94                         $queryStr = 'SELECT distinct(be_serial) FROM blog_entry RIGHT JOIN blog_entry_with_category ON be_serial = bw_entry_serial ';
95                         $queryStr .=  'WHERE be_language_id = ? '; $params[] = $langId;
96                         $queryStr .=    'AND be_deleted = false ';              // 削除されていない
97                         
98                         // 記事カテゴリー
99                         $queryStr .=    'AND bw_category_id in (' . implode(",", $category) . ') ';
100                 }
101                 // 商品名、商品コード、説明を検索
102                 if (!empty($keyword)){
103                         // 「'"\」文字をエスケープ
104                         $keyword = addslashes($keyword);
105                         
106                         $queryStr .=    'AND (be_name LIKE \'%' . $keyword . '%\' ';
107                         $queryStr .=    'OR be_html LIKE \'%' . $keyword . '%\' ';
108                         $queryStr .=    'OR be_html_ext LIKE \'%' . $keyword . '%\' ';
109                         $queryStr .=    'OR be_description LIKE \'%' . $keyword . '%\') ';
110                 }
111                 
112                 // 日付範囲
113                 if (!empty($startDt)){
114                         $queryStr .=    'AND ? <= be_regist_dt ';
115                         $params[] = $startDt;
116                 }
117                 if (!empty($endDt)){
118                         $queryStr .=    'AND be_regist_dt < ? ';
119                         $params[] = $endDt;
120                 }
121                 // ブログID
122                 if (isset($blogId)){
123                         $queryStr .=    'AND be_blog_id = ? ';
124                         $params[] = $blogId;
125                 }
126                 
127                 if (count($category) == 0){
128                         $queryStr .=  'ORDER BY be_regist_dt desc limit ' . $limit . ' offset ' . $offset;
129                         $this->selectLoop($queryStr, $params, $callback, null);
130                 } else {
131                         // シリアル番号を取得
132                         $serialArray = array();
133                         $ret = $this->selectRecords($queryStr, $params, $serialRows);
134                         if ($ret){
135                                 for ($i = 0; $i < count($serialRows); $i++){
136                                         $serialArray[] = $serialRows[$i]['be_serial'];
137                                 }
138                         }
139                         $serialStr = implode(',', $serialArray);
140                         if (empty($serialStr)) $serialStr = '0';        // 0レコードのときはダミー値を設定
141                 
142                         $queryStr = 'SELECT * FROM blog_entry LEFT JOIN _login_user ON be_regist_user_id = lu_id AND lu_deleted = false ';
143                         $queryStr .=  'WHERE be_serial in (' . $serialStr . ') ';
144                         $queryStr .=  'ORDER BY be_regist_dt desc limit ' . $limit . ' offset ' . $offset;
145                         $this->selectLoop($queryStr, array(), $callback, null);
146                 }
147         }
148         /**
149          * エントリー項目数を取得(管理用)
150          *
151          * @param timestamp     $startDt                        期間(開始日)
152          * @param timestamp     $endDt                          期間(終了日)
153          * @param array         $category                       カテゴリーID
154          * @param string        $keyword                        検索キーワード
155          * @param string        $langId                         言語
156          * @param string        $blogId                         ブログID(未指定の場合はnull)
157          * @return int                                                  項目数
158          */
159         function getEntryItemCount($startDt, $endDt, $category, $keyword, $langId, $blogId = null)
160         {
161                 $params = array();
162                 if (count($category) == 0){             // カテゴリー指定なしのとき
163                         $queryStr = 'SELECT * FROM blog_entry LEFT JOIN _login_user ON be_regist_user_id = lu_id AND lu_deleted = false ';
164                         $queryStr .=  'WHERE be_language_id = ? '; $params[] = $langId;
165                         $queryStr .=    'AND be_deleted = false ';              // 削除されていない
166                 } else {
167                         $queryStr = 'SELECT distinct(be_serial) FROM blog_entry RIGHT JOIN blog_entry_with_category ON be_serial = bw_entry_serial ';
168                         $queryStr .=  'WHERE be_language_id = ? '; $params[] = $langId;
169                         $queryStr .=    'AND be_deleted = false ';              // 削除されていない
170                         
171                         // 記事カテゴリー
172                         $queryStr .=    'AND bw_category_id in (' . implode(",", $category) . ') ';
173                 }
174                 // 商品名、商品コード、説明を検索
175                 if (!empty($keyword)){
176                         // 「'"\」文字をエスケープ
177                         $keyword = addslashes($keyword);
178                         
179                         $queryStr .=    'AND (be_name LIKE \'%' . $keyword . '%\' ';
180                         $queryStr .=    'OR be_html LIKE \'%' . $keyword . '%\' ';
181                         $queryStr .=    'OR be_html_ext LIKE \'%' . $keyword . '%\' ';
182                         $queryStr .=    'OR be_description LIKE \'%' . $keyword . '%\') ';
183                 }
184                 
185                 // 日付範囲
186                 if (!empty($startDt)){
187                         $queryStr .=    'AND ? <= be_regist_dt ';
188                         $params[] = $startDt;
189                 }
190                 if (!empty($endDt)){
191                         $queryStr .=    'AND be_regist_dt < ? ';
192                         $params[] = $endDt;
193                 }
194                 // ブログID
195                 if (isset($blogId)){
196                         $queryStr .=    'AND be_blog_id = ? ';
197                         $params[] = $blogId;
198                 }
199                 
200                 if (count($category) == 0){
201                         return $this->selectRecordCount($queryStr, $params);
202                 } else {
203                         // シリアル番号を取得
204                         $serialArray = array();
205                         $ret = $this->selectRecords($queryStr, $params, $serialRows);
206                         if ($ret){
207                                 for ($i = 0; $i < count($serialRows); $i++){
208                                         $serialArray[] = $serialRows[$i]['be_serial'];
209                                 }
210                         }
211                         $serialStr = implode(',', $serialArray);
212                         if (empty($serialStr)) $serialStr = '0';                // 0レコードのときはダミー値を設定
213
214                         $queryStr = 'SELECT * FROM blog_entry LEFT JOIN _login_user ON be_regist_user_id = lu_id AND lu_deleted = false ';
215                         $queryStr .=  'WHERE be_serial in (' . $serialStr . ') ';
216                         return $this->selectRecordCount($queryStr, array());
217                 }
218         }
219         /**
220          * エントリー項目を検索(表示用)
221          *
222          * @param int           $limit                          取得する項目数
223          * @param int           $page                           取得するページ(1~)
224          * @param timestamp $now                                現在日時(現在日時より未来の投稿日時の記事は取得しない)
225          * @param array         $keywords                       検索キーワード
226          * @param string        $langId                         言語
227          * @param function      $callback                       コールバック関数
228          * @return                      なし
229          */
230         function searchEntryItemsByKeyword($limit, $page, $now, $keywords, $langId, $callback)
231         {
232                 $offset = $limit * ($page -1);
233                 if ($offset < 0) $offset = 0;
234                 $initDt = $this->gEnv->getInitValueOfTimestamp();               // 日時初期化値
235                 $params = array();
236                 
237                 //$queryStr = 'SELECT * FROM blog_entry ';
238                 $queryStr  = 'SELECT * FROM blog_entry LEFT JOIN blog_id ON be_blog_id = bl_id AND bl_deleted = false ';
239                 $queryStr .=   'WHERE be_language_id = ? ';     $params[] = $langId;
240                 $queryStr .=     'AND be_deleted = false ';             // 削除されていない
241                 $queryStr .=     'AND be_regist_dt <= ? ';      $params[] = $now;       // 投稿日時が現在日時よりも過去のものを取得
242
243                 // タイトルと記事を検索
244                 if (!empty($keywords)){
245                         for ($i = 0; $i < count($keywords); $i++){
246                                 $keyword = addslashes($keywords[$i]);// 「'"\」文字をエスケープ
247                                 $queryStr .=    'AND (be_name LIKE \'%' . $keyword . '%\' ';
248                                 $queryStr .=    'OR be_html LIKE \'%' . $keyword . '%\' ';
249                                 $queryStr .=    'OR be_html_ext LIKE \'%' . $keyword . '%\' ';
250                                 $queryStr .=    'OR be_description LIKE \'%' . $keyword . '%\') ';
251                         }
252                 }
253                 
254                 // 公開期間を指定
255                 $queryStr .=    'AND (be_active_start_dt = ? OR (be_active_start_dt != ? AND be_active_start_dt <= ?)) ';
256                 $queryStr .=    'AND (be_active_end_dt = ? OR (be_active_end_dt != ? AND be_active_end_dt > ?)) ';
257                 $params[] = $initDt;
258                 $params[] = $initDt;
259                 $params[] = $now;
260                 $params[] = $initDt;
261                 $params[] = $initDt;
262                 $params[] = $now;
263                 
264                 $queryStr .=  'ORDER BY be_regist_dt desc limit ' . $limit . ' offset ' . $offset;
265                 $this->selectLoop($queryStr, $params, $callback);
266         }
267         /**
268          * 検索条件のエントリー項目数を取得(表示用)
269          *
270          * @param timestamp $now                                現在日時(現在日時より未来の投稿日時の記事は取得しない)
271          * @param array         $keywords                       検索キーワード
272          * @param string        $langId                         言語
273          * @return int                                                  項目数
274          */
275         function searchEntryItemsCountByKeyword($now, $keywords, $langId)
276         {
277                 $initDt = $this->gEnv->getInitValueOfTimestamp();               // 日時初期化値
278                 $params = array();
279                 
280                 $queryStr = 'SELECT * FROM blog_entry ';
281                 $queryStr .=  'WHERE be_language_id = ? ';      $params[] = $langId;
282                 $queryStr .=    'AND be_deleted = false ';              // 削除されていない
283                 $queryStr .=    'AND be_regist_dt <= ? ';       $params[] = $now;       // 投稿日時が現在日時よりも過去のものを取得
284
285                 // タイトルと記事を検索
286                 if (!empty($keywords)){
287                         for ($i = 0; $i < count($keywords); $i++){
288                                 $keyword = addslashes($keywords[$i]);// 「'"\」文字をエスケープ
289                                 $queryStr .=    'AND (be_name LIKE \'%' . $keyword . '%\' ';
290                                 $queryStr .=    'OR be_html LIKE \'%' . $keyword . '%\' ';
291                                 $queryStr .=    'OR be_html_ext LIKE \'%' . $keyword . '%\' ';
292                                 $queryStr .=    'OR be_description LIKE \'%' . $keyword . '%\') ';
293                         }
294                 }
295                 
296                 // 公開期間を指定
297                 $queryStr .=    'AND (be_active_start_dt = ? OR (be_active_start_dt != ? AND be_active_start_dt <= ?)) ';
298                 $queryStr .=    'AND (be_active_end_dt = ? OR (be_active_end_dt != ? AND be_active_end_dt > ?)) ';
299                 $params[] = $initDt;
300                 $params[] = $initDt;
301                 $params[] = $now;
302                 $params[] = $initDt;
303                 $params[] = $initDt;
304                 $params[] = $now;
305                 return $this->selectRecordCount($queryStr, $params);
306         }
307         /**
308          * エントリー項目の新規追加
309          *
310          * @param string  $id                   エントリーID
311          * @param string  $langId               言語ID
312          * @param string  $name                 コンテンツ名
313          * @param string  $html                 HTML
314          * @param string  $html2                HTML(続き)
315          * @param int     $status               エントリー状態(0=未設定、1=編集中、2=公開、3=非公開)
316          * @param array   $category             カテゴリーID
317          * @param string  $blogId               ブログID
318          * @param int     $regUserId    投稿者ユーザID
319          * @param timestamp $regDt              投稿日時
320          * @param timestamp     $startDt        期間(開始日)
321          * @param timestamp     $endDt          期間(終了日)
322          * @param int     $newSerial    新規シリアル番号
323          * @param bool    $showComment  コメントを表示するかどうか
324          * @param bool $receiveComment  コメントを受け付けるかどうか
325          * @return bool                                 true = 成功、false = 失敗
326          */
327         function addEntryItem($id, $langId, $name, $html, $html2, $status, $category, $blogId, $regUserId, $regDt, $startDt, $endDt, $showComment, $receiveComment, &$newSerial)
328         {
329                 $now = date("Y/m/d H:i:s");     // 現在日時
330                 $userId = $this->gEnv->getCurrentUserId();      // 現在のユーザ
331                         
332                 // トランザクション開始
333                 $this->startTransaction();
334                 
335                 if ($id == 0){          // エントリーIDが0のときは、エントリーIDを新規取得
336                         // エントリーIDを決定する
337                         $queryStr = 'select max(be_id) as mid from blog_entry ';
338                         $ret = $this->selectRecord($queryStr, array(), $row);
339                         if ($ret){
340                                 $entryId = $row['mid'] + 1;
341                         } else {
342                                 $entryId = 1;
343                         }
344                 } else {
345                         $entryId = $id;
346                 }
347                 
348                 // 前レコードの削除状態チェック
349                 $historyIndex = 0;
350                 $queryStr = 'SELECT * FROM blog_entry ';
351                 $queryStr .=  'WHERE be_id = ? ';
352                 $queryStr .=    'AND be_language_id = ? ';
353                 $queryStr .=  'ORDER BY be_history_index DESC ';
354                 $ret = $this->selectRecord($queryStr, array($entryId, $langId), $row);
355                 if ($ret){
356                         if (!$row['be_deleted']){               // レコード存在していれば終了
357                                 $this->endTransaction();
358                                 return false;
359                         }
360                         $historyIndex = $row['be_history_index'] + 1;
361                 }
362                 
363                 // データを追加
364                 $queryStr  = 'INSERT INTO blog_entry ';
365                 $queryStr .=   '(be_id, ';
366                 $queryStr .=   'be_language_id, ';
367                 $queryStr .=   'be_history_index, ';
368                 $queryStr .=   'be_name, ';
369                 $queryStr .=   'be_html, ';
370                 $queryStr .=   'be_html_ext, ';
371                 $queryStr .=   'be_status, ';
372                 $queryStr .=   'be_show_comment, ';
373                 $queryStr .=   'be_receive_comment, ';
374                 $queryStr .=   'be_blog_id, ';
375                 $queryStr .=   'be_dt, ';
376                 $queryStr .=   'be_regist_user_id, ';
377                 $queryStr .=   'be_regist_dt, ';
378                 $queryStr .=   'be_active_start_dt, ';
379                 $queryStr .=   'be_active_end_dt, ';
380                 $queryStr .=   'be_create_user_id, ';
381                 $queryStr .=   'be_create_dt) ';
382                 $queryStr .= 'VALUES ';
383                 $queryStr .=   '(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
384                 $this->execStatement($queryStr, array($entryId, $langId, $historyIndex, $name, $html, $html2, $status, 
385                                                                                                 intval($showComment), intval($receiveComment), $blogId, $now, $regUserId, $regDt, $startDt, $endDt, $userId, $now));
386                 
387                 // 新規のシリアル番号取得
388                 $newSerial = 0;
389                 $queryStr = 'select max(be_serial) as ns from blog_entry ';
390                 $ret = $this->selectRecord($queryStr, array(), $row);
391                 if ($ret) $newSerial = $row['ns'];
392                 
393                 // 記事カテゴリーの更新
394                 for ($i = 0; $i < count($category); $i++){
395                         $ret = $this->updateEntryCategory($newSerial, $i, $category[$i]);
396                         if (!$ret){
397                                 $this->endTransaction();
398                                 return false;
399                         }
400                 }
401                         
402                 // トランザクション確定
403                 $ret = $this->endTransaction();
404                 return $ret;
405         }
406         /**
407          * エントリー項目の更新
408          *
409          * @param int     $serial               シリアル番号
410          * @param string  $name                 コンテンツ名
411          * @param string  $html                 HTML
412          * @param string  $html2                HTML(続き)
413          * @param int     $status               エントリー状態(0=未設定、1=編集中、2=公開、3=非公開)
414          * @param array   $category             カテゴリーID
415          * @param string  $blogId               ブログID
416          * @param int     $regUserId    投稿者ユーザID(0のときは更新しない)
417          * @param timestamp $regDt              投稿日時(空のときは更新しない)
418          * @param timestamp     $startDt        期間(開始日)
419          * @param timestamp     $endDt          期間(終了日)
420          * @param bool    $showComment  コメントを表示するかどうか
421          * @param bool $receiveComment  コメントを受け付けるかどうか
422          * @param int     $newSerial    新規シリアル番号
423          * @return bool                                 true = 成功、false = 失敗
424          */
425         function updateEntryItem($serial, $name, $html, $html2, $status, $category, $blogId, $regUserId, $regDt, $startDt, $endDt, $showComment, $receiveComment, &$newSerial)
426         {
427                 $now = date("Y/m/d H:i:s");     // 現在日時
428                 $userId = $this->gEnv->getCurrentUserId();      // 現在のユーザ
429                                                 
430                 // トランザクション開始
431                 $this->startTransaction();
432                 
433                 // 指定のシリアルNoのレコードが削除状態でないかチェック
434                 $historyIndex = 0;              // 履歴番号
435                 $queryStr  = 'select * from blog_entry ';
436                 $queryStr .=   'where be_serial = ? ';
437                 $ret = $this->selectRecord($queryStr, array($serial), $row);
438                 if ($ret){              // 既に登録レコードがあるとき
439                         if ($row['be_deleted']){                // レコードが削除されていれば終了
440                                 $this->endTransaction();
441                                 return false;
442                         }
443                         $historyIndex = $row['be_history_index'] + 1;
444                 } else {                // 存在しない場合は終了
445                         $this->endTransaction();
446                         return false;
447                 }
448                 // 古いレコードを削除
449                 $queryStr  = 'UPDATE blog_entry ';
450                 $queryStr .=   'SET be_deleted = true, ';       // 削除
451                 $queryStr .=     'be_update_user_id = ?, ';
452                 $queryStr .=     'be_update_dt = ? ';
453                 $queryStr .=   'WHERE be_serial = ?';
454                 $this->execStatement($queryStr, array($userId, $now, $serial));
455                 
456                 // データを追加
457                 if (empty($regUserId)){
458                         $rUserId = $row['be_regist_user_id'];
459                 } else {
460                         $rUserId = $regUserId;
461                 }
462                 if (empty($regDt)){
463                         $rDt = $row['be_regist_dt'];
464                 } else {
465                         $rDt = $regDt;
466                 }
467                 $entryId = $row['be_id'];
468                 $langId = $row['be_language_id'];
469                 
470                 // 新規レコード追加             
471                 $queryStr  = 'INSERT INTO blog_entry ';
472                 $queryStr .=   '(be_id, ';
473                 $queryStr .=   'be_language_id, ';
474                 $queryStr .=   'be_history_index, ';
475                 $queryStr .=   'be_name, ';
476                 $queryStr .=   'be_html, ';
477                 $queryStr .=   'be_html_ext, ';
478                 $queryStr .=   'be_status, ';
479                 $queryStr .=   'be_show_comment, ';
480                 $queryStr .=   'be_receive_comment, ';
481                 $queryStr .=   'be_blog_id, ';
482                 $queryStr .=   'be_dt, ';
483                 $queryStr .=   'be_regist_user_id, ';
484                 $queryStr .=   'be_regist_dt, ';
485                 $queryStr .=   'be_active_start_dt, ';
486                 $queryStr .=   'be_active_end_dt, ';
487                 $queryStr .=   'be_create_user_id, ';
488                 $queryStr .=   'be_create_dt) ';
489                 $queryStr .= 'VALUES ';
490                 $queryStr .=   '(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
491                 $this->execStatement($queryStr, array($entryId, $langId, $historyIndex, $name, $html, $html2, $status, 
492                                                                                                 intval($showComment), intval($receiveComment), $blogId, $now, $rUserId, $rDt, $startDt, $endDt, $userId, $now));
493
494                 // 新規のシリアル番号取得
495                 $newSerial = 0;
496                 $queryStr = 'select max(be_serial) as ns from blog_entry ';
497                 $ret = $this->selectRecord($queryStr, array(), $row);
498                 if ($ret) $newSerial = $row['ns'];
499                 
500                 // 記事カテゴリーの更新
501                 for ($i = 0; $i < count($category); $i++){
502                         $ret = $this->updateEntryCategory($newSerial, $i, $category[$i]);
503                         if (!$ret){
504                                 $this->endTransaction();
505                                 return false;
506                         }
507                 }
508                 
509                 // トランザクション確定
510                 $ret = $this->endTransaction();
511                 return $ret;
512         }
513         /**
514          * 記事更新日の更新
515          *
516          * @param string  $id                   エントリーID
517          * @param string  $langId               言語ID
518          * @return bool                                 true = 成功、false = 失敗
519          */
520         function updateEntryDt($id, $langId)
521         {
522                 $serial = $this->getEntrySerialNoByContentId($id, $langId);
523                 if (empty($serial)) return false;
524                 
525                 $now = date("Y/m/d H:i:s");     // 現在日時
526                 $userId = $this->gEnv->getCurrentUserId();      // 現在のユーザ
527                                                 
528                 // トランザクション開始
529                 $this->startTransaction();
530                 
531                 // 指定のシリアルNoのレコードが削除状態でないかチェック
532                 $queryStr  = 'SELECT * FROM blog_entry ';
533                 $queryStr .=   'WHERE be_serial = ? ';
534                 $ret = $this->selectRecord($queryStr, array($serial), $row);
535                 if ($ret){              // 既に登録レコードがあるとき
536                         if ($row['be_deleted']){                // レコードが削除されていれば終了
537                                 $this->endTransaction();
538                                 return false;
539                         }
540                 } else {                // 存在しない場合は終了
541                         $this->endTransaction();
542                         return false;
543                 }
544                 // 日付を更新
545                 $queryStr  = 'UPDATE blog_entry ';
546                 $queryStr .=   'SET be_dt = ?, ';       // 更新日
547                 $queryStr .=     'be_update_user_id = ?, ';
548                 $queryStr .=     'be_update_dt = ? ';
549                 $queryStr .=   'WHERE be_serial = ?';
550                 $this->execStatement($queryStr, array($now, $userId, $now, $serial));
551                 
552                 // トランザクション確定
553                 $ret = $this->endTransaction();
554                 return $ret;
555         }
556         /**
557          * 記事カテゴリーの更新
558          *
559          * @param int        $serial            記事シリアル番号
560          * @param int        $index                     インデックス番号
561          * @param int        $categoryId        カテゴリーID
562          * @return bool          true = 成功、false = 失敗
563          */
564         function updateEntryCategory($serial, $index, $categoryId)
565         {
566                 // 新規レコード追加
567                 $queryStr = 'INSERT INTO blog_entry_with_category ';
568                 $queryStr .=  '(';
569                 $queryStr .=  'bw_entry_serial, ';
570                 $queryStr .=  'bw_index, ';
571                 $queryStr .=  'bw_category_id) ';
572                 $queryStr .=  'VALUES ';
573                 $queryStr .=  '(?, ?, ?)';
574                 $ret =$this->execStatement($queryStr, array($serial, $index, $categoryId));
575                 return $ret;
576         }
577         /**
578          * エントリー項目をシリアル番号で取得
579          *
580          * @param string        $serial                         シリアル番号
581          * @param array     $row                                レコード
582          * @param array     $categoryRow                記事カテゴリー
583          * @return bool                                                 取得 = true, 取得なし= false
584          */
585         function getEntryBySerial($serial, &$row, &$categoryRow)
586         {
587                 $queryStr  = 'select *,reg.lu_name as reg_user_name from blog_entry LEFT JOIN _login_user ON be_create_user_id = lu_id AND lu_deleted = false ';
588                 $queryStr .=   'LEFT JOIN _login_user as reg ON be_regist_user_id = reg.lu_id AND reg.lu_deleted = false ';
589                 $queryStr .=   'WHERE be_serial = ? ';
590                 $ret = $this->selectRecord($queryStr, array($serial), $row);
591                 
592                 if ($ret){
593                         // ブログカテゴリー
594                         $queryStr  = 'SELECT * FROM blog_entry_with_category LEFT JOIN blog_category ON bw_category_id = bc_id AND bc_deleted = false ';
595                         $queryStr .=   'WHERE bw_entry_serial = ? ';
596                         $queryStr .=  'ORDER BY bw_index ';
597                         $this->selectRecords($queryStr, array($serial), $categoryRow);
598                 }
599                 return $ret;
600         }
601         /**
602          * エントリー項目のシリアル番号をエントリーIDで取得
603          *
604          * @param string        $id                                     エントリーID
605          * @param string        $langId                         言語ID
606          * @return int                                                  シリアル番号、取得できないときは0を返す
607          */
608         function getEntrySerialNoByContentId($id, $langId)
609         {
610                 $serial = 0;
611                 $queryStr  = 'SELECT * FROM blog_entry ';
612                 $queryStr .=   'WHERE be_deleted = false ';     // 削除されていない
613                 $queryStr .=   'AND be_id = ? ';
614                 $queryStr .=   'AND be_language_id = ? ';
615                 $ret = $this->selectRecord($queryStr, array($id, $langId), $row);
616                 if ($ret) $serial = $row['be_serial'];
617                 return $serial;
618         }
619         /**
620          * エントリー項目の削除
621          *
622          * @param array   $serial               シリアルNo
623          * @return                                              true=成功、false=失敗
624          */
625         function delEntryItem($serial)
626         {
627                 // 引数のエラーチェック
628                 if (!is_array($serial)) return false;
629                 if (count($serial) <= 0) return true;
630                 
631                 $now = date("Y/m/d H:i:s");     // 現在日時
632                 $userId = $this->gEnv->getCurrentUserId();      // 現在のユーザ
633                 
634                 // トランザクション開始
635                 $this->startTransaction();
636                 
637                 for ($i = 0; $i < count($serial); $i++){
638                         $queryStr  = 'SELECT * FROM blog_entry ';
639                         $queryStr .=   'WHERE be_deleted = false ';             // 未削除
640                         $queryStr .=     'AND be_serial = ? ';
641                         $ret = $this->selectRecord($queryStr, array($serial[$i]), $row);
642                         if ($ret){              // 既に登録レコードがあるとき                      
643                                 // レコードを削除
644                                 $queryStr  = 'UPDATE blog_entry ';
645                                 $queryStr .=   'SET be_deleted = true, ';       // 削除
646                                 $queryStr .=     'be_update_user_id = ?, ';
647                                 $queryStr .=     'be_update_dt = ? ';
648                                 $queryStr .=   'WHERE be_serial = ?';
649                                 $this->execStatement($queryStr, array($userId, $now, $serial[$i]));
650                         } else {// 指定のシリアルNoのレコードが削除状態のときはエラー
651                                 $this->endTransaction();
652                                 return false;
653                         }
654                 }
655                 // トランザクション確定
656                 $ret = $this->endTransaction();
657                 return $ret;
658         }
659         /**
660          * エントリーIDでエントリー項目を削除
661          *
662          * @param array   $serial               シリアルNo
663          * @return                                              true=成功、false=失敗
664          */
665         function delEntryItemById($serial)
666         {
667                 // 引数のエラーチェック
668                 if (!is_array($serial)) return false;
669                 if (count($serial) <= 0) return true;
670                 
671                 $now = date("Y/m/d H:i:s");     // 現在日時
672                 $userId = $this->gEnv->getCurrentUserId();      // 現在のユーザ
673                 
674                 // トランザクション開始
675                 $this->startTransaction();
676                 
677                 // コンテンツIDを取得
678                 $queryStr  = 'select * from blog_entry ';
679                 $queryStr .=   'where be_deleted = false ';             // 未削除
680                 $queryStr .=     'and be_serial = ? ';
681                 $ret = $this->selectRecord($queryStr, array($serial), $row);
682                 if ($ret){              // 既に登録レコードがあるとき
683                         if ($row['be_deleted']){                // レコードが削除されていれば終了
684                                 $this->endTransaction();
685                                 return false;
686                         }
687                 } else {                // 存在しない場合は終了
688                         $this->endTransaction();
689                         return false;
690                 }
691                 $entryId = $row['be_id'];
692                 
693                 // レコードを削除
694                 $queryStr  = 'UPDATE blog_entry ';
695                 $queryStr .=   'SET be_deleted = true, ';       // 削除
696                 $queryStr .=     'be_update_user_id = ?, ';
697                 $queryStr .=     'be_update_dt = now() ';
698                 $queryStr .=   'WHERE be_id = ?';
699                 $this->execStatement($queryStr, array($userId, $entryId));
700                 
701                 // トランザクション確定
702                 $ret = $this->endTransaction();
703                 return $ret;
704         }
705         /**
706          * エントリー項目を取得
707          *
708          * @param int           $id                                     エントリーID
709          * @param string        $langId                         言語
710          * @param array     $row                                レコード
711          * @return bool                                                 取得 = true, 取得なし= false
712          */
713         function getEntryItem($id, $langId, &$row)
714         {
715                 $queryStr  = 'SELECT * FROM blog_entry LEFT JOIN blog_id ON be_blog_id = bl_id AND bl_deleted = false ';
716                 $queryStr .=   'WHERE be_deleted = false ';     // 削除されていない
717                 $queryStr .=   'AND be_id = ? ';
718                 $queryStr .=   'AND be_language_id = ? ';
719                 $ret = $this->selectRecord($queryStr, array($id, $langId), $row);
720                 return $ret;
721         }
722         /**
723          * エントリー項目を取得(表示用)
724          *
725          * @param int           $limit                          取得する項目数
726          * @param int           $page                           取得するページ(1~)
727          * @param timestamp $now                                現在日時(現在日時より未来の投稿日時の記事は取得しない)
728          * @param int           $entryId                        エントリーID(0のときは期間で取得)
729          * @param timestamp     $startDt                        期間(開始日)
730          * @param timestamp     $endDt                          期間(終了日)
731          * @param string        $langId                         言語
732          * @param int           $order                          取得順(0=昇順,1=降順)
733          * @param function      $callback                       コールバック関数
734          * @param string        $blogId                         ブログID(nullのとき指定なし)
735          * @return                      なし
736          */
737         function getEntryItems($limit, $page, $now, $entryId, $startDt, $endDt, $langId, $order, $callback, $blogId = null)
738         {
739                 $offset = $limit * ($page -1);
740                 if ($offset < 0) $offset = 0;
741                 $initDt = $this->gEnv->getInitValueOfTimestamp();               // 日時初期化値
742                 $params = array();
743                 
744                 // エントリーIDの指定がない場合は、期間で取得
745                 if (empty($entryId)){
746                         $queryStr  = 'SELECT * FROM blog_entry LEFT JOIN blog_id ON be_blog_id = bl_id AND bl_deleted = false ';
747                         $queryStr .=   'WHERE be_deleted = false ';             // 削除されていない
748                         $queryStr .=     'AND be_status = ? ';          $params[] = 2;  // 「公開」(2)データを表示
749                         $queryStr .=     'AND be_language_id = ? ';     $params[] = $langId;
750                         $queryStr .=     'AND be_regist_dt <= ? ';      $params[] = $now;               // 投稿日時が現在日時よりも過去のものを取得
751                         
752                         // ブログID
753                         if (isset($blogId)){
754                                 $queryStr .=    'AND be_blog_id = ? ';          $params[] = $blogId;
755                         }
756                 
757                         // 検索条件
758                         if (!empty($startDt)){
759                                 $queryStr .=    'AND ? <= be_regist_dt ';
760                                 $params[] = $startDt;
761                         }
762                         if (!empty($endDt)){
763                                 $queryStr .=    'AND be_regist_dt < ? ';
764                                 $params[] = $endDt;
765                         }
766                         
767                         // 公開期間を指定
768                         $queryStr .=    'AND (be_active_start_dt = ? OR (be_active_start_dt != ? AND be_active_start_dt <= ?)) ';
769                         $queryStr .=    'AND (be_active_end_dt = ? OR (be_active_end_dt != ? AND be_active_end_dt > ?)) ';
770                         $params[] = $initDt;
771                         $params[] = $initDt;
772                         $params[] = $now;
773                         $params[] = $initDt;
774                         $params[] = $initDt;
775                         $params[] = $now;
776                 
777                         $ord = '';
778                         if (!empty($order)) $ord = 'DESC ';
779                         $queryStr .=  'ORDER BY be_regist_dt ' . $ord . 'LIMIT ' . $limit . ' offset ' . $offset;// 投稿順
780                         $this->selectLoop($queryStr, $params, $callback, null);
781                 } else {
782                         //$queryStr = 'SELECT * FROM blog_entry ';
783                         $queryStr  = 'SELECT * FROM blog_entry LEFT JOIN blog_id ON be_blog_id = bl_id AND bl_deleted = false ';
784                         $queryStr .=   'WHERE be_deleted = false ';             // 削除されていない
785                         $queryStr .=     'AND be_status = ? ';  $params[] = 2;  // 「公開」(2)データを表示
786                         $queryStr .=     'AND be_id = ? ';              $params[] = $entryId;
787                         $queryStr .=     'AND be_language_id = ? ';     $params[] = $langId;
788                         $queryStr .=     'AND be_regist_dt <= ? ';      $params[] = $now;               // 投稿日時が現在日時よりも過去のものを取得
789                         
790                         // ブログID
791                         if (isset($blogId)){
792                                 $queryStr .=    'AND be_blog_id = ? ';          $params[] = $blogId;
793                         }
794                         
795                         // 公開期間を指定
796                         $queryStr .=    'AND (be_active_start_dt = ? OR (be_active_start_dt != ? AND be_active_start_dt <= ?)) ';
797                         $queryStr .=    'AND (be_active_end_dt = ? OR (be_active_end_dt != ? AND be_active_end_dt > ?)) ';
798                         $params[] = $initDt;
799                         $params[] = $initDt;
800                         $params[] = $now;
801                         $params[] = $initDt;
802                         $params[] = $initDt;
803                         $params[] = $now;
804                         $this->selectLoop($queryStr, $params, $callback, null);         // 「公開」(2)データを表示
805                 }
806         }
807         
808         /**
809          * エントリー項目数を取得(表示用)
810          *
811          * @param timestamp $now                                現在日時(現在日時より未来の投稿日時の記事は取得しない)
812          * @param timestamp     $startDt                        期間(開始日)
813          * @param timestamp     $endDt                          期間(終了日)
814          * @param string        $langId                         言語
815          * @param string        $blogId                         ブログID(nullのとき指定なし)
816          * @return int                                                  項目数
817          */
818         function getEntryItemsCount($now, $startDt, $endDt, $langId, $blogId = null)
819         {
820                 $initDt = $this->gEnv->getInitValueOfTimestamp();               // 日時初期化値
821                 $params = array();
822                 
823                 $queryStr = 'SELECT * FROM blog_entry ';
824                 $queryStr .=  'WHERE be_deleted = false ';              // 削除されていない
825                 $queryStr .=    'AND be_status = ? ';           $params[] = 2;  // 「公開」(2)データを表示
826                 $queryStr .=    'AND be_language_id = ? ';      $params[] = $langId;
827                 $queryStr .=    'AND be_regist_dt <= ? ';       $params[] = $now;               // 投稿日時が現在日時よりも過去のものを取得
828                 
829                 // ブログID
830                 if (isset($blogId)){
831                         $queryStr .=    'AND be_blog_id = ? ';          $params[] = $blogId;
832                 }
833                 
834                 // 検索条件
835                 if (!empty($startDt)){
836                         $queryStr .=    'AND ? <= be_regist_dt ';
837                         $params[] = $startDt;
838                 }
839                 if (!empty($endDt)){
840                         $queryStr .=    'AND be_regist_dt < ? ';
841                         $params[] = $endDt;
842                 }
843                 
844                 // 公開期間を指定
845                 $queryStr .=    'AND (be_active_start_dt = ? OR (be_active_start_dt != ? AND be_active_start_dt <= ?)) ';
846                 $queryStr .=    'AND (be_active_end_dt = ? OR (be_active_end_dt != ? AND be_active_end_dt > ?)) ';
847                 $params[] = $initDt;
848                 $params[] = $initDt;
849                 $params[] = $now;
850                 $params[] = $initDt;
851                 $params[] = $initDt;
852                 $params[] = $now;
853                 return $this->selectRecordCount($queryStr, $params);
854         }
855         /**
856          * エントリー項目をカテゴリー指定で取得(表示用)
857          *
858          * @param int           $limit                          取得する項目数
859          * @param int           $page                           取得するページ(1~)
860          * @param timestamp $now                                現在日時(現在日時より未来の投稿日時の記事は取得しない)
861          * @param int           $categoryId                     カテゴリーID
862          * @param string        $langId                         言語
863          * @param int           $order                          取得順(0=昇順,1=降順)
864          * @param function      $callback                       コールバック関数
865          * @return                      なし
866          */
867         function getEntryItemsByCategory($limit, $page, $now, $categoryId, $langId, $order, $callback)
868         {
869                 $offset = $limit * ($page -1);
870                 if ($offset < 0) $offset = 0;
871                 $initDt = $this->gEnv->getInitValueOfTimestamp();               // 日時初期化値
872                 $params = array();
873                 
874                 $queryStr = 'SELECT distinct(be_serial) FROM blog_entry RIGHT JOIN blog_entry_with_category ON be_serial = bw_entry_serial ';
875                 $queryStr .=  'WHERE be_language_id = ? '; $params[] = $langId;
876                 $queryStr .=    'AND be_deleted = false ';              // 削除されていない
877                 $queryStr .=    'AND be_status = ? '; $params[] = 2;    // 「公開」(2)データ
878                 $queryStr .=    'AND bw_category_id = ? ';      $params[] = $categoryId;// 記事カテゴリー
879                 $queryStr .=    'AND be_regist_dt <= ? ';       $params[] = $now;                       // 投稿日時が現在日時よりも過去のものを取得
880                 
881                 // 公開期間を指定
882                 $queryStr .=    'AND (be_active_start_dt = ? OR (be_active_start_dt != ? AND be_active_start_dt <= ?)) ';
883                 $queryStr .=    'AND (be_active_end_dt = ? OR (be_active_end_dt != ? AND be_active_end_dt > ?)) ';
884                 $params[] = $initDt;
885                 $params[] = $initDt;
886                 $params[] = $now;
887                 $params[] = $initDt;
888                 $params[] = $initDt;
889                 $params[] = $now;
890                 
891                 // シリアル番号を取得
892                 $serialArray = array();
893                 $ret = $this->selectRecords($queryStr, $params, $serialRows);
894                 if ($ret){
895                         for ($i = 0; $i < count($serialRows); $i++){
896                                 $serialArray[] = $serialRows[$i]['be_serial'];
897                         }
898                 }
899                 $serialStr = implode(',', $serialArray);
900                 if (empty($serialStr)) $serialStr = '0';        // 0レコードのときはダミー値を設定
901         
902                 //$queryStr = 'SELECT * FROM blog_entry ';
903                 $queryStr  = 'SELECT * FROM blog_entry LEFT JOIN blog_id ON be_blog_id = bl_id AND bl_deleted = false ';
904                 $queryStr .=   'WHERE be_serial in (' . $serialStr . ') ';
905                 $ord = '';
906                 if (!empty($order)) $ord = 'DESC ';
907                 $queryStr .=  'ORDER BY be_regist_dt ' . $ord . 'LIMIT ' . $limit . ' offset ' . $offset;// 投稿順
908                 $this->selectLoop($queryStr, array(), $callback, null);
909         }
910         /**
911          * エントリー項目数をカテゴリー指定で取得(表示用)
912          *
913          * @param timestamp $now                                現在日時(現在日時より未来の投稿日時の記事は取得しない)
914          * @param int           $categoryId                     カテゴリーID
915          * @param string        $langId                         言語
916          * @return int                                                  エントリー項目数
917          */
918         function getEntryItemsCountByCategory($now, $categoryId, $langId)
919         {
920                 $initDt = $this->gEnv->getInitValueOfTimestamp();               // 日時初期化値
921                 $params = array();
922                 
923                 $queryStr = 'SELECT distinct(be_serial) FROM blog_entry RIGHT JOIN blog_entry_with_category ON be_serial = bw_entry_serial ';
924                 $queryStr .=  'WHERE be_language_id = ? '; $params[] = $langId;
925                 $queryStr .=    'AND be_deleted = false ';              // 削除されていない
926                 $queryStr .=    'AND be_status = ? '; $params[] = 2;    // 「公開」(2)データ
927                 $queryStr .=    'AND bw_category_id = ? ';      $params[] = $categoryId;// 記事カテゴリー
928                 $queryStr .=    'AND be_regist_dt <= ? ';       $params[] = $now;                       // 投稿日時が現在日時よりも過去のものを取得
929                 
930                 // 公開期間を指定
931                 $queryStr .=    'AND (be_active_start_dt = ? OR (be_active_start_dt != ? AND be_active_start_dt <= ?)) ';
932                 $queryStr .=    'AND (be_active_end_dt = ? OR (be_active_end_dt != ? AND be_active_end_dt > ?)) ';
933                 $params[] = $initDt;
934                 $params[] = $initDt;
935                 $params[] = $now;
936                 $params[] = $initDt;
937                 $params[] = $initDt;
938                 $params[] = $now;
939                 
940                 // シリアル番号を取得
941                 $serialArray = array();
942                 $ret = $this->selectRecords($queryStr, $params, $serialRows);
943                 if ($ret){
944                         for ($i = 0; $i < count($serialRows); $i++){
945                                 $serialArray[] = $serialRows[$i]['be_serial'];
946                         }
947                 }
948                 $serialStr = implode(',', $serialArray);
949                 if (empty($serialStr)) $serialStr = '0';        // 0レコードのときはダミー値を設定
950         
951                 $queryStr = 'SELECT * FROM blog_entry ';
952                 $queryStr .=  'WHERE be_serial in (' . $serialStr . ') ';
953                 return $this->selectRecordCount($queryStr, array());
954         }
955         /**
956          * すべての言語を取得
957          *
958          * @param function      $callback                       コールバック関数
959          * @return                      true=取得、false=取得せず
960          */
961         function getAllLang($callback)
962         {
963                 $queryStr = 'SELECT * FROM _language ORDER BY ln_priority';
964                 $this->selectLoop($queryStr, array(), $callback, null);
965         }
966         /**
967          * 記事カテゴリー一覧を取得
968          *
969          * @param string        $langId                         言語
970          * @param array         $rows                           取得データ
971          * @return bool                                                 true=取得、false=取得せず
972          */
973         function getAllCategory($langId, &$rows)
974         {
975                 $queryStr = 'SELECT * FROM blog_category LEFT JOIN _login_user ON bc_create_user_id = lu_id AND lu_deleted = false ';
976                 $queryStr .=  'WHERE bc_language_id = ? ';
977                 $queryStr .=    'AND bc_deleted = false ';              // 削除されていない
978                 $queryStr .=  'ORDER BY bc_id';
979                 $retValue = $this->selectRecords($queryStr, array($langId), $rows);
980                 return $retValue;
981         }
982         /**
983          * 記事が指定ブログ属するかチェック
984          *
985          * @param int    $serial                記事のシリアルNo
986          * @param string $blogId                ブログID
987          * @return bool                                 true=存在する、false=存在しない
988          */
989         function isExistsEntryInBlogId($serial, $blogId)
990         {
991                 $queryStr  = 'SELECT * FROM blog_entry ';
992                 $queryStr .=   'WHERE be_deleted = false ';             // 削除されていない
993                 $queryStr .=     'AND be_serial = ? ';
994                 $queryStr .=     'AND be_blog_id = ? ';
995                 return $this->isRecordExists($queryStr, array($serial, $blogId));
996         }
997         /**
998          * コメントが指定ブログ属するかチェック
999          *
1000          * @param int    $serial                コメントのシリアルNo
1001          * @param string $blogId                ブログID
1002          * @return bool                                 true=存在する、false=存在しない
1003          */
1004         function isExistsCommentInBlogId($serial, $blogId)
1005         {
1006                 $queryStr  = 'SELECT * FROM blog_comment ';
1007                 $queryStr .=   'LEFT JOIN blog_entry ON bo_entry_id = be_id AND be_deleted = false ';
1008                 $queryStr .=   'WHERE bo_deleted = false ';             // 削除されていない
1009                 $queryStr .=     'AND bo_serial = ? ';
1010                 $queryStr .=     'AND be_blog_id = ? ';
1011                 return $this->isRecordExists($queryStr, array($serial, $blogId));
1012         }
1013         /**
1014          * すべてのブログIDを取得
1015          *
1016          * @param array   $rows                 取得レコード
1017          * @return bool                                 取得 = true, 取得なし= false
1018          */
1019         function getAllBlogId(&$rows)
1020         {
1021                 $queryStr  = 'SELECT * FROM blog_id ';
1022                 $queryStr .=  'WHERE bl_deleted = false ';              // 削除されていない
1023                 $queryStr .=  'ORDER BY bl_index, bl_id';
1024                 $retValue = $this->selectRecords($queryStr, array(), $rows);
1025                 return $retValue;
1026         }
1027         /**
1028          * ブログ一覧を取得(管理用)
1029          *
1030          * @param function      $callback                       コールバック関数
1031          * @return                      なし
1032          */
1033         function getAllBlogInfo($callback)
1034         {
1035                 $queryStr = 'SELECT * FROM blog_id LEFT JOIN _login_user ON bl_owner_id = lu_id AND lu_deleted = false ';
1036                 $queryStr .=  'WHERE bl_deleted = false ';              // 削除されていない
1037                 $queryStr .=  'ORDER BY bl_index, bl_id';
1038                 $this->selectLoop($queryStr, array(), $callback);
1039         }
1040         /**
1041          * ブログ情報を識別IDで取得(管理用)
1042          *
1043          * @param string        $id                                     識別ID
1044          * @param array     $row                                レコード
1045          * @return bool                                                 取得 = true, 取得なし= false
1046          */
1047         function getBlogInfoById($id, &$row)
1048         {
1049                 $queryStr = 'SELECT * FROM blog_id ';
1050                 $queryStr .=  'WHERE bl_deleted = false ';
1051                 $queryStr .=  'AND bl_id = ? ';
1052                 $ret = $this->selectRecord($queryStr, array($id), $row);
1053                 return $ret;
1054         }
1055         /**
1056          * ブログ情報をシリアル番号で取得
1057          *
1058          * @param string        $serial                         シリアル番号
1059          * @param array     $row                                レコード
1060          * @return bool                                                 取得 = true, 取得なし= false
1061          */
1062         function getBlogInfoBySerial($serial, &$row)
1063         {
1064                 $queryStr  = 'SELECT * FROM blog_id LEFT JOIN _login_user ON bl_create_user_id = lu_id AND lu_deleted = false ';
1065                 $queryStr .=   'WHERE bl_serial = ? ';
1066                 $ret = $this->selectRecord($queryStr, array($serial), $row);
1067                 return $ret;
1068         }
1069         /**
1070          * 公開可能なブログ情報かどうか
1071          *
1072          * @param string        $id                     識別ID
1073          * @return bool                                 true=存在する、false=存在しない
1074          */
1075         function isActiveBlogInfo($id)
1076         {
1077                 $queryStr = 'SELECT * FROM blog_id ';
1078                 $queryStr .=  'WHERE bl_deleted = false ';
1079                 $queryStr .=  'AND bl_visible = true ';
1080                 $queryStr .=  'AND bl_id = ? ';
1081                 return $this->isRecordExists($queryStr, array($id));
1082         }
1083         /**
1084          * ブログ情報を更新
1085          *
1086          * @param string $serial                シリアル番号(0のときは新規登録)
1087          * @param string $id                    ブログID
1088          * @param string $name                  名前
1089          * @param int    $index                 表示順
1090          * @param string $templateId    テンプレートID
1091          * @param bool $visible                 表示制御
1092          * @param string  $metaTitle    METAタグ、タイトル
1093          * @param string  $metaDesc             METAタグ、ページ要約
1094          * @param string  $metaKeyword  METAタグ、検索用キーワード
1095          * @param int    $ownerId               所有者ID
1096          * @param int $newSerial        新規シリアル番号
1097          * @return                                      true = 正常、false=異常
1098          */
1099         function updateBlogInfo($serial, $id, $name, $index, $templateId, $visible, $metaTitle, $metaDesc, $metaKeyword, $ownerId, &$newSerial)
1100         {
1101                 $now = date("Y/m/d H:i:s");     // 現在日時
1102                 $userId = $this->gEnv->getCurrentUserId();      // 現在のユーザ
1103                 $contentUpdateDt = $this->gEnv->getInitValueOfTimestamp();
1104                 
1105                 // トランザクション開始
1106                 $this->startTransaction();
1107                 
1108                 // 前レコードの削除状態チェック
1109                 $historyIndex = 0;
1110                 $desc = '';
1111                 if (empty($serial)){            // 新規登録のとき
1112                         $queryStr = 'SELECT * FROM blog_id ';
1113                         $queryStr .=  'WHERE bl_id = ? ';
1114                         $queryStr .=  'ORDER BY bl_history_index DESC ';
1115                         $ret = $this->selectRecord($queryStr, array($id), $row);
1116                         if ($ret){
1117                                 if (!$row['bl_deleted']){               // レコード存在していれば終了
1118                                         $this->endTransaction();
1119                                         return false;
1120                                 }
1121                                 $historyIndex = $row['bl_history_index'] + 1;
1122                         }
1123                 } else {                // 更新のとき
1124                         // 指定のシリアルNoのレコードが削除状態でないかチェック
1125                         $queryStr  = 'SELECT * FROM blog_id ';
1126                         $queryStr .=   'WHERE bl_serial = ? ';
1127                         $ret = $this->selectRecord($queryStr, array($serial), $row);
1128                         if ($ret){              // 既に登録レコードがあるとき
1129                                 if ($row['bl_deleted']){                // レコードが削除されていれば終了
1130                                         $this->endTransaction();
1131                                         return false;
1132                                 }
1133                                 $historyIndex = $row['bl_history_index'] + 1;
1134                                 
1135                                 // 識別IDとコンテンツ更新日時の変更は不可
1136                                 $id = $row['bl_id'];
1137                                 $contentUpdateDt = $row['bl_content_update_dt'];
1138                         } else {                // 存在しない場合は終了
1139                                 $this->endTransaction();
1140                                 return false;
1141                         }
1142                         
1143                         // 古いレコードを削除
1144                         $queryStr  = 'UPDATE blog_id ';
1145                         $queryStr .=   'SET bl_deleted = true, ';       // 削除
1146                         $queryStr .=     'bl_update_user_id = ?, ';
1147                         $queryStr .=     'bl_update_dt = ? ';
1148                         $queryStr .=   'WHERE bl_serial = ?';
1149                         $ret = $this->execStatement($queryStr, array($userId, $now, $serial));
1150                         if (!$ret){
1151                                 $this->endTransaction();
1152                                 return false;
1153                         }
1154                 }
1155                 
1156                 // データを追加
1157                 $queryStr = 'INSERT INTO blog_id ';
1158                 $queryStr .=  '(bl_id, bl_history_index, bl_name, bl_index, bl_template_id, bl_visible, bl_meta_title, bl_meta_description, bl_meta_keywords, bl_owner_id, bl_content_update_dt, bl_create_user_id, bl_create_dt) ';
1159                 $queryStr .=  'VALUES ';
1160                 $queryStr .=  '(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
1161                 $this->execStatement($queryStr, array($id, $historyIndex, $name, $index, $templateId, intval($visible), $metaTitle, $metaDesc, $metaKeyword, intval($ownerId), $contentUpdateDt, $userId, $now));
1162                 
1163                 // 新規のシリアル番号取得
1164                 $queryStr = 'SELECT MAX(bl_serial) AS ns FROM blog_id ';
1165                 $ret = $this->selectRecord($queryStr, array(), $row);
1166                 if ($ret) $newSerial = $row['ns'];
1167                 
1168                 // トランザクション確定
1169                 $ret = $this->endTransaction();
1170                 return $ret;
1171         }
1172         /**
1173          * ブログ情報の削除
1174          *
1175          * @param array $serial                 シリアルNo
1176          * @return                                              true=成功、false=失敗
1177          */
1178         function delBlogInfo($serial)
1179         {
1180                 $now = date("Y/m/d H:i:s");     // 現在日時
1181                 $user = $this->gEnv->getCurrentUserId();        // 現在のユーザ
1182                 
1183                 if (!is_array($serial) || count($serial) <= 0) return true;
1184                 
1185                 // トランザクション開始
1186                 $this->startTransaction();
1187                 
1188                 // 指定のシリアルNoのレコードが削除状態でないかチェック
1189                 for ($i = 0; $i < count($serial); $i++){
1190                         $queryStr  = 'SELECT * FROM blog_id ';
1191                         $queryStr .=   'WHERE bl_deleted = false ';             // 未削除
1192                         $queryStr .=     'AND bl_serial = ? ';
1193                         $ret = $this->isRecordExists($queryStr, array($serial[$i]));
1194                         // 存在しない場合は、既に削除されたとして終了
1195                         if (!$ret){
1196                                 $this->endTransaction();
1197                                 return false;
1198                         }
1199                 }
1200                 
1201                 // レコードを削除
1202                 $queryStr  = 'UPDATE blog_id ';
1203                 $queryStr .=   'SET bl_deleted = true, ';       // 削除
1204                 $queryStr .=     'bl_update_user_id = ?, ';
1205                 $queryStr .=     'bl_update_dt = ? ';
1206                 $queryStr .=   'WHERE bl_serial in (' . implode($serial, ',') . ') ';
1207                 $this->execStatement($queryStr, array($user, $now));
1208                 
1209                 // トランザクション確定
1210                 $ret = $this->endTransaction();
1211                 return $ret;
1212         }
1213         /**
1214          * 最大表示順を取得
1215          *
1216          * @return int                                  最大表示順
1217          */
1218         function getBlogInfoMaxIndex()
1219         {
1220                 $queryStr = 'SELECT max(bl_index) as mi FROM blog_id ';
1221                 $queryStr .=  'WHERE bl_deleted = false ';
1222                 $ret = $this->selectRecord($queryStr, array(), $row);
1223                 if ($ret){
1224                         $index = $row['mi'];
1225                 } else {
1226                         $index = 0;
1227                 }
1228                 return $index;
1229         }
1230         /**
1231          * テンプレートリスト取得
1232          *
1233          * @param int      $type                テンプレートのタイプ(0=PC用、1=携帯用、2=スマートフォン)
1234          * @param function $callback    コールバック関数
1235          * @return                                              なし
1236          */
1237         function getAllTemplateList($type, $callback)
1238         {
1239                 // tm_device_typeは後で追加したため、tm_mobileを残しておく
1240                 $queryStr = 'SELECT * FROM _templates ';
1241                 $queryStr .=  'WHERE tm_deleted = false ';// 削除されていない
1242                 $params = array();
1243                 switch ($type){
1244                         case 0:         // PC用テンプレート
1245                         case 2:         // スマートフォン用テンプレート
1246                         default:
1247                                 $queryStr .=    'AND tm_mobile = false ';               // 携帯用以外
1248                                 $queryStr .=    'AND tm_device_type = ? '; $params[] = $type;
1249                                 break;
1250                         case 1:         // 携帯用のとき
1251                                 $queryStr .=    'AND tm_mobile = true ';                // 携帯用
1252                                 break;
1253                 }
1254                 $queryStr .=  'ORDER BY tm_id';
1255                 $this->selectLoop($queryStr, $params, $callback);
1256         }
1257         /**
1258          * ユーザリスト取得
1259          *
1260          * @param int      $minLevel    最小のユーザレベル
1261          * @param function $callback    コールバック関数
1262          * @return                                              なし
1263          */
1264         function getUserList($minLevel, $callback)
1265         {
1266                 $queryStr  = 'SELECT * FROM _login_user ';
1267                 $queryStr .=   'WHERE lu_deleted = false ';// 削除されていない
1268                 $queryStr .=     'AND lu_user_type >= ? ';              // ユーザレベル
1269                 $queryStr .=   'ORDER BY lu_user_type, lu_account';
1270                 $this->selectLoop($queryStr, array($minLevel), $callback);
1271         }
1272 }
1273 ?>