OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / access_count / include / db / access_countDb.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-2007 Magic3 Project.
12  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
13  * @version    SVN: $Id: access_countDb.php 2 2007-11-03 04:59:01Z fishbone $
14  * @link       http://www.magic3.org
15  */
16 require_once($gEnvManager->getDbPath() . '/baseDb.php');
17
18 class access_countDb extends BaseDb
19 {       
20         /**
21          * 同じセッションIDのレコードがあるかどうかチェック
22          *
23          * @param string        $ssid                   セッションID
24          * @return bool                                         true=あり、false=なし
25          */
26         function isSessionExists($ssid)
27         {
28                 // トランザクション開始
29                 $this->startTransaction();
30                 
31                 $queryStr = 'select * from ac_access ';
32                 $queryStr .=  'where ac_ssid = ?';
33                 $ret = $this->isRecordExists($queryStr, array($ssid));
34                 if ($ret){              // 存在している場合は時間を更新
35                         $queryStr = 'UPDATE ac_access ';
36                         $queryStr .=  'SET ac_time = ? ';
37                         $queryStr .=  'WHERE ac_ssid = ?';
38                         $this->execStatement($queryStr, array(time(), $ssid));
39                 } else {
40                         $queryStr = 'INSERT INTO ac_access ';
41                         $queryStr .=  '(ac_ssid, ac_time) ';
42                         $queryStr .=  'VALUES ';
43                         $queryStr .=  '(?, ?)';
44                         $this->execStatement($queryStr, array($ssid, time()));
45                 }
46                 
47                 // トランザクション確定
48                 $this->endTransaction();
49                 return $ret;
50         }
51         /**
52          * カウンタを更新
53          *
54          * @param string        $date                   年月日(yyyy-mm-dd)
55          * @return なし
56          */
57         function incrementCount($date)
58         {
59                 // トランザクション開始
60                 $this->startTransaction();
61                 
62                 $queryStr = 'select * from ac_count ';
63                 $queryStr .=  'where co_date = ?';
64                 $ret = $this->selectRecord($queryStr, array($date), $row);
65                 if ($ret){              // 存在している場合はカウンタを更新
66                         $count = $row['co_count'] + 1;
67                         $queryStr = 'UPDATE ac_count ';
68                         $queryStr .=  'SET co_count = ? ';
69                         $queryStr .=  'WHERE co_date = ?';
70                         $this->execStatement($queryStr, array($count, $date));
71                 } else {
72                         $queryStr = 'INSERT INTO ac_count ';
73                         $queryStr .=  '(co_date, co_count) ';
74                         $queryStr .=  'VALUES ';
75                         $queryStr .=  '(?, ?)';
76                         $this->execStatement($queryStr, array($date, 1));
77                 }
78                 
79                 // トランザクション確定
80                 $this->endTransaction();
81                 return $ret;
82         }
83         
84         /**
85          * 現在のカウントを取得
86          *
87          * @param string        $date                   年月日(yyyy-mm-dd)
88          * @return なし
89          */
90         function getCount($date)
91         {
92                 $count = 0;
93                 $queryStr = 'select sum(co_count) as count from ac_count ';
94                 $queryStr .=  'where co_date <= ?';
95                 $ret = $this->selectRecord($queryStr, array($date), $row);
96                 if ($ret) $count = $row['count'];
97                 return $count;
98         }
99 }
100 ?>