File: //proc/self/root/usr/local/lib/php/RVSeagullMod/lib/RVSGL/SitebuilderDao/OnlineCounterDao.php
<?php
/* Reminder: always indent with 4 spaces (no tabs). */
// +---------------------------------------------------------------------------+
// WebSite: http://www.rvglobalsoft.com
// Unauthorized copying is strictly forbidden and may result in severe legal action.
// Copyright (c) 2006 RV Global Soft Co.,Ltd. All rights reserved.
//
// =====YOU MUST KEEP THIS COPYRIGHTS NOTICE INTACT AND CAN NOT BE REMOVE =======
// Copyright (c) 2006 RV Global Soft Co.,Ltd. All rights reserved.
// This Agreement is a legal contract, which specifies the terms of the license
// and warranty limitation between you and RV Global Soft Co.,Ltd. and RV Site Builder.
// You should carefully read the following terms and conditions before
// installing or using this software. Unless you have a different license
// agreement obtained from RV Global Soft Co.,Ltd., installation or use of this software
// indicates your acceptance of the license and warranty limitation terms
// contained in this Agreement. If you do not agree to the terms of this
// Agreement, promptly delete and destroy all copies of the Software.
//
// ===== Grant of License =======
// The Software may only be installed and used on a single host machine.
//
// ===== Disclaimer of Warranty =======
// THIS SOFTWARE AND ACCOMPANYING DOCUMENTATION ARE PROVIDED "AS IS" AND
// WITHOUT WARRANTIES AS TO PERFORMANCE OF MERCHANTABILITY OR ANY OTHER
// WARRANTIES WHETHER EXPRESSED OR IMPLIED. BECAUSE OF THE VARIOUS HARDWARE
// AND SOFTWARE ENVIRONMENTS INTO WHICH RV SITE BUILDER MAY BE USED, NO WARRANTY OF
// FITNESS FOR A PARTICULAR PURPOSE IS OFFERED. THE USER MUST ASSUME THE
// ENTIRE RISK OF USING THIS PROGRAM. ANY LIABILITY OF RV GLOBAL SOFT CO.,LTD. WILL BE
// LIMITED EXCLUSIVELY TO PRODUCT REPLACEMENT OR REFUND OF PURCHASE PRICE.
// IN NO CASE SHALL RV GLOBAL SOFT CO.,LTD. BE LIABLE FOR ANY INCIDENTAL, SPECIAL OR
// CONSEQUENTIAL DAMAGES OR LOSS, INCLUDING, WITHOUT LIMITATION, LOST PROFITS
// OR THE INABILITY TO USE EQUIPMENT OR ACCESS DATA, WHETHER SUCH DAMAGES ARE
// BASED UPON A BREACH OF EXPRESS OR IMPLIED WARRANTIES, BREACH OF CONTRACT,
// NEGLIGENCE, STRICT TORT, OR ANY OTHER LEGAL THEORY. THIS IS TRUE EVEN IF
// RV GLOBAL SOFT CO.,LTD. IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN NO CASE WILL
// RV GLOBAL SOFT CO.,LTD.'S LIABILITY EXCEED THE AMOUNT OF THE LICENSE FEE ACTUALLY PAID
// BY LICENSEE TO RV GLOBAL SOFT CO.,LTD.
// +---------------------------------------------------------------------------+
// $Id$
// +---------------------------------------------------------------------------+
/**
* Data access methods for the component of RVSiteBuilder
*
* @package sitebuilder
* @author Pairote Manunphol <pairote@rvglobalsoft.com>
* @author Parinya <parinya@rvglobalsoft.com>
* @version $Revision$
* @since PHP 5.1
*/
class OnlineCounterDao extends DbWrapper implements SitebuilderInf
{
function OnlineCounterDao()
{
parent::DbWrapper();
}
/**
* Returns a singleton ComponentDao instance.
*
* @param bool $autoload
* @return obj
*/
public static function singleton($autoload=false)
{
static $instance;
// If the instance is not there, create one
if (!isset($instance) || $autoload) {
$class = __CLASS__;
$instance = new $class();
}
return $instance;
}
/// SELECT ///
/**
* find AllData in rvs_online_counter table By CounterId And ProjectId
* @author Pornthip
* @param $counterId
* @param $projectId
* @param $fetchMode
* @return array
* @form GeneralAPIMgr.php
/* $query = "
SELECT
*
FROM
{$this->conf['table']['rvs_online_counter']}
WHERE
counter_id = '$counterID'
AND project_id = '$projectID'
";
$aCounterTag = $this->dbh->getAssoc($query);
*/
public function findAllDataByCounterIdAndProjectId($counterId=null, $projectId=null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oOnlineCounter = DB_DataObject::factory($this->aConf['table']['rvs_online_counter']);
if (!is_null($counterId)) {
$query = sprintf('
SELECT
*
FROM
%s
WHERE
counter_id = %s
AND project_id = %s
'
, $this->aConf['table']['rvs_online_counter']
, RvsLibs_String::quoteSmart($counterId)
, RvsLibs_String::quoteSmart($projectId)
);
$oOnlineCounter->query($query);
}
$aCloneData = array();
while ($oOnlineCounter->fetch()) {
$aCloneData[] = clone($oOnlineCounter);
}
DB_DataObject::debugLevel();
return DbWrapper::fetchDatas($oOnlineCounter->_resultFields, $aCloneData, $fetchMode);
}
/**
* find CounterName in rvs_online_counter table By ProjectId
* @author Pornthip Phothong
* @param $exportProjectId
* @param $fetchMode
* @return array
* @form ExportProjectMgr.php
*/
public function findCounterNameByProjectId($projectId, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oOnlineCounter = DB_DataObject::factory($this->aConf['table']['rvs_online_counter']);
if (!is_null($projectId)) {
$query = sprintf('
SELECT
counter_name
FROM
%s
WHERE
project_id = %s
'
, $this->aConf['table']['rvs_online_counter']
, RvsLibs_String::quoteSmart($projectId)
);
$oOnlineCounter->query($query);
}
$aCloneData = array();
while ($oOnlineCounter->fetch()) {
$aCloneData[] = clone($oOnlineCounter);
}
DB_DataObject::debugLevel();
return DbWrapper::fetchDatas($oOnlineCounter->_resultFields, $aCloneData, $fetchMode);
}
/**
* find All CounterData By CounterId Or CounterName in rvs_online_counter table
* @author Pornthip Phothong
* @param $counterId
* @param $counterName
* @param $fetchMode
* @return array obj
* @form Online_CounterMgr.php
/* $query = "
SELECT
*
FROM
{$this->conf['table']['rvs_online_counter']}
";
if ($counterId) {
$query .= "
WHERE
counter_id = '$counterId' ";
} elseif ($counterName) {
$query .= "
WHERE counter_name = '$counterName'
";
}
$res = $this->dbh->getAssoc($query);
*/
public function findAllCounterDataByCounterIdOrCounterName($counterId=null, $counterName=null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oOnlineCounter = DB_DataObject::factory($this->aConf['table']['rvs_online_counter']);
$query = sprintf('
SELECT
*
FROM
%s
WHERE
%s
'
, $this->aConf['table']['rvs_online_counter']
, (!is_null($counterId))
? 'counter_id=' . RvsLibs_String::quoteSmart($counterId)
: 'counter_name=' . RvsLibs_String::quoteSmart($counterName)
);
$oOnlineCounter->query($query);
$aCloneData = array();
while ($oOnlineCounter->fetch()) {
$aCloneData[] = clone($oOnlineCounter);
}
DB_DataObject::debugLevel();
return DbWrapper::fetchDatas($oOnlineCounter->_resultFields, $aCloneData, $fetchMode);
}
/**
* find counter data
*
* @param <string> $fetchMode
* @return array
* form file Import ProjectMgr.php
*/
public function findCounterData($fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oOnlineCounter = DB_DataObject::factory($this->aConf['table']['rvs_online_counter']);
$query = sprintf('
SELECT
counter_name
FROM
%s
'
, $this->aConf['table']['rvs_online_counter']
);
$oOnlineCounter->query($query);
$aCloneData = array();
while ($oOnlineCounter->fetch()) {
$aCloneData[] = clone($oOnlineCounter);
}
DB_DataObject::debugLevel();
return DbWrapper::fetchDatas($oOnlineCounter->_resultFields, $aCloneData, $fetchMode);
}
public function findCounterByProjectId($projectId=null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oOnlineCounter = DB_DataObject::factory($this->aConf['table']['rvs_online_counter']);
if (!is_null($projectId)) {
$oOnlineCounter->project_id = $projectId;
}
$oOnlineCounter->find();
$aCloneData = array();
while ($oOnlineCounter->fetch()) {
$aCloneData[] = clone($oOnlineCounter);
}
DB_DataObject::debugLevel();
return DbWrapper::fetchDatas($oOnlineCounter->_resultFields, $aCloneData, $fetchMode);
}
public function findCounterNameByUserIdAndCounterName($counterName, $rvsUsrId, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oOnlineCounter = DB_DataObject::factory($this->aConf['table']['rvs_online_counter']);
$query = sprintf('
SELECT
*
FROM
%s
WHERE
counter_name = %s
AND rvs_usr_id != %s
'
, $this->aConf['table']['rvs_online_counter']
, $counterName
, $rvsUsrId
);
$oOnlineCounter->query($query);
$aCloneData = array();
while ($oOnlineCounter->fetch()) {
$aCloneData[] = clone($oOnlineCounter);
}
DB_DataObject::debugLevel();
return DbWrapper::fetchDatas($oOnlineCounter->_resultFields, $aCloneData, $fetchMode);
}
/// INSERT ///
/**
* insert OnlineCounterData in rvs_online_counter
* @author Pornthip Phothong
* @param $counterId
* @param $counterName
* @param $usrId
* @param $projectId
* @param $projectPageId
* @param $counterStyle
* @param $maxDigit
* @param $frame
* @param $cpmode
* @param $counterTag
*
$aCounterOption = array(
'counterId' => $counterId,
'counterName' => $counterName,
'counterStyle' => $counterStyle,
'maxDigit' => $maxDigit,
'frame' => $frame,
'cpmode' => $cpmode,
'counterTag' => $counterTag,
);
* @form Online_CounterMgr.php
/* $query = "
INSERT INTO
{$this->conf['table']['rvs_online_counter']} (
counter_id
, counter_name
, rvs_usr_id
, project_id
, project_page_id
, counter_style
, max_digit
, frame
, cpmode
, counter_tag
)
VALUES (
'$counterId'
,'$input->counter_name'
, '$input->rvs_usr_id'
, '$input->project_id'
, '$input->project_page_id'
, '$input->ct_style'
, '$input->ct_maxdigit'
, '$input->ct_frame'
, '" . CPMODE . "'
, ''
)
";
$res = $this->dbh->query($query);
*/
public function insertOnlineCounterData($usrId, $projectId, $projectPageId, $aCounterOption)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oOnlineCounter = DB_DataObject::factory($this->aConf['table']['rvs_online_counter']);
$query = sprintf('
INSERT INTO
%s
( counter_id
, counter_name
, rvs_usr_id
, project_id
, project_page_id
, counter_style
, max_digit
, frame
, cpmode
, counter_tag
)
VALUES (
%s
, %s
, %s
, %s
, %s
, %s
, %s
, %s
, %s
, %s
);
'
, $this->aConf['table']['rvs_online_counter']
, RvsLibs_String::quoteSmart($aCounterOption['counterId'])
, RvsLibs_String::quoteSmart($aCounterOption['counterName'])
, RvsLibs_String::quoteSmart($usrId)
, RvsLibs_String::quoteSmart($projectId)
, RvsLibs_String::quoteSmart($projectPageId)
, RvsLibs_String::quoteSmart($aCounterOption['counterStyle'])
, RvsLibs_String::quoteSmart($aCounterOption['maxDigit'])
, RvsLibs_String::quoteSmart($aCounterOption['frame'])
, RvsLibs_String::quoteSmart($aCounterOption['cpmode'])
, RvsLibs_String::quoteSmart($aCounterOption['counterTag'])
);
$oOnlineCounter->query($query);
}
/// UPDATE ///
/**
* update CounterTag By CounterId And ProjectId And UsrId in table rvs_online_counter
* @author Pornthip Phothong
* @param $counterId
* @param $counterTag
* @param $projectId
* @param $rvsUsrId
* @form Online_CounterMgr.php
/* $query = "
UPDATE
{$this->conf['table']['rvs_online_counter']}
SET
counter_tag = '$counterTag'
WHERE
counter_id = '$counterId'
AND project_id = '$projectId'
AND rvs_usr_id = '$rvsUsrId'
";
$res = $this->dbh->query($query);
*/
public function updateCounterTagByCounterIdAndProjectIdAndUsrId($counterId, $counterTag, $projectId, $rvsUsrId)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oOnlineCounter = DB_DataObject::factory($this->aConf['table']['rvs_online_counter']);
$query = sprintf('
UPDATE
%s
SET
counter_tag = %s
WHERE
counter_id = %s
AND project_id = %s
AND rvs_usr_id = %s
'
, $this->aConf['table']['rvs_online_counter']
, RvsLibs_String::quoteSmart($counterTag)
, RvsLibs_String::quoteSmart($counterId)
, RvsLibs_String::quoteSmart($projectId)
, RvsLibs_String::quoteSmart($rvsUsrId)
);
$res = $oOnlineCounter->query($query);
DB_DataObject::debugLevel();
return $res;
}
/**
* update OnlineCounter Data By CounterId And ProjectId And UsrId in table rvs_online_counter
* @author Pornthip Phothong
* @param $counterStyle
* @param $maxDigit
* @param $frame
* @param $counterId
* @param $rvsUsrId
* @param $projectId
* @form Online_CounterMgr.php
/* $query = "
UPDATE
{$this->conf['table']['rvs_online_counter']}
SET
counter_style = '$input->ct_style'
, max_digit = '$input->ct_maxdigit'
, frame = '$input->ct_frame'
WHERE
counter_id = '$input->counter_id'
AND rvs_usr_id = '$input->rvs_usr_id'
AND project_id = '$input->project_id'
";
$res = $this->dbh->query($query);
*/
public function updateOnlineCounterDataByCounterIdAndProjectIdAndUsrId($counterStyle, $maxDigit, $frame, $counterId, $rvsUsrId, $projectId, $counterName)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oOnlineCounter = DB_DataObject::factory($this->aConf['table']['rvs_online_counter']);
$query = sprintf('
UPDATE
%s
SET
counter_style = %s
, max_digit = %s
, frame = %s
, counter_name = %s
WHERE
counter_id = %s
AND rvs_usr_id = %s
AND project_id = %s
'
, $this->aConf['table']['rvs_online_counter']
, RvsLibs_String::quoteSmart($counterStyle)
, RvsLibs_String::quoteSmart($maxDigit)
, RvsLibs_String::quoteSmart($frame)
, RvsLibs_String::quoteSmart($counterName)
, RvsLibs_String::quoteSmart($counterId)
, RvsLibs_String::quoteSmart($rvsUsrId)
, RvsLibs_String::quoteSmart($projectId)
);
$res = $oOnlineCounter->query($query);
DB_DataObject::debugLevel();
return $res;
}
// DELETE //
/**
* delete online counter by userid and projectid
* $query = "
DELETE
{$this->conf['table'][' ']} as oc
FROM
{$this->conf['table']['rvs_online_counter']} as oc
, {$this->conf['table']['rvs_project_page']} as pa
WHERE
oc.project_page_id = pa.project_page_id
AND oc.rvs_usr_id = '$input->rvs_usr_id'
AND oc.project_id = '$input->project_id'
";
* @author pharadol
* @param <string> $usrId
* @param <string> $projectId
* @return Bool
*/
public function deleteOnlineCounterByUsrIdAndProjectId($usrId = null, $projectId = null)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oOnlineCounter = DB_DataObject::factory($this->aConf['table']['rvs_online_counter']);
if (!is_null($usrId) && !is_null($projectId)) {
/*$query = sprintf('
DELETE
%s as oc
FROM
%s as oc
, %s as pa
WHERE
oc.rvs_usr_id = %s
AND oc.project_id = %s
AND oc.project_page_id = pa.project_page_id
'
, $this->aConf['table']['rvs_online_counter']
, $this->aConf['table']['rvs_online_counter']
, $this->aConf['table']['rvs_project_page']
, RvsLibs_String::quoteSmart($usrId)
, RvsLibs_String::quoteSmart($projectId)
);
*/
$query = sprintf('
DELETE
FROM
%s
WHERE
project_id = %s
'
, $this->aConf['table']['rvs_online_counter']
, RvsLibs_String::quoteSmart($projectId)
);
$res = $oOnlineCounter->query($query);
}
return (isset($res) && $res) ? true : false;
}
public function backupsql($projectId, $usrId)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$aSQLData = array();
/// Backup table rvs_online_counter
$oOnlineCounter = DaoFactory::OnlineCounter()->findCounterByProjectId($projectId, 'getDataObject');
foreach ($oOnlineCounter as $k => $v) {
$aSQLData[] = DbWrapper::buildSQLFormat($v);
}
return $aSQLData;
}
public function deleteProjectOfUserId($projectId, $usrId, $aProjectPageId = array())
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$result = DaoFactory::OnlineCounter()->deleteOnlineCounterByUsrIdAndProjectId($usrId, $projectId);
}
}
?>