<?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 templates of RVSiteBuilder
*
* @package sitebuilder
* @author Pairote Manunphol <pairote@rvglobalsoft.com>
* @author Parinya <parinya@rvglobalsoft.com>
* @version $Revision$
* @since PHP 5.1
*/
class TemplateDao extends DbWrapper implements SitebuilderInf
{
function TemplateDao()
{
parent::DbWrapper();
}
/**
* Returns a singleton TemplateDao 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 template by template id
* Resulting SQL
* SELECT
* *
* FROM
* rvs_template
* WHERE
* template_id = {$templateId}
*
* @author Parinya Chaipetch
*
* @param string $templateId
* @param string $fetchMode
* @access public
* @return array
*/
public function findTemplateByTemplateId($templateId = null, $fetchMode = 'getassoc', $aResultFields = array() )
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplate = DB_DataObject::factory($this->aConf['table']['rvs_template']);
if (!is_null($templateId)) {
$oTemplate->template_id = $templateId;
}
$oTemplate->find();
$aCloneData = array();
while ($oTemplate->fetch()) {
$aCloneData[$oTemplate->template_id] = clone($oTemplate);
}
DB_DataObject::debugLevel();
$oTemplate = DbWrapper::buildResultFields($oTemplate, $aResultFields);
return DbWrapper::fetchDatas($oTemplate, $aCloneData, $fetchMode);
}
public function findTemplateProFolder($fetchMode='getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
$query = "
SELECT
ti.template_item_id, ti.template_item_folder
FROM
{$this->aConf['table']['rvs_template_item']} ti
WHERE
ti.template_item_folder LIKE 'pro_%_2'
"
;
//echo '1===>'. $query;exit;
$oTemplateItem->query($query);
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
/**
* Find ref data template by category id and template item id
*
* Resulting SQL
* SELECT
* DISTINCT(t.template_id)
* , c.category_name
* , x.rvs_category_id
* , it.template_item_id
* , it.template_item_folder
* , it.template_type_s_preview
* , it.color_id
* , it.products_id
* , cl.color_name
* , p.picture_name
* FROM
* rvs_template t
* , rvs_category c
* , rvs_template_categories_xref x
* , rvs_template_item it
* , rvs_color cl
* , rvs_navigator na
* , rvs_picture p
* WHERE
* x.rvs_category_id = c.rvs_category_id
* AND it.color_id = cl.color_id
* AND it.picture_id = p.picture_id
* if ($input->ref_category_id) {
* AND x.rvs_category_id = '$input->ref_category_id'
* }
* if ($input->ref_template_item_id) {
* AND it.template_item_id = '$input->ref_template_item_id'
* } else {
* AND t.default_template_item_id = it.template_item_id
* }
* AND t.template_id = it.template_id
* AND t.template_id = x.template_id
* $res = $this->objDbh->query($query);
*
* @author Darawan Taorong crate date : 30/04/2552 10:30 AM
*
* @param string $categoryId
* @param string $templateItemId
* @param string $fetchMode
* @access public
* @return array
*/
public function findRefTemplateDataByCategoryIdAndTemplateItemId($categoryId = null, $templateItemId = null, $fetchMode='getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
$query = sprintf("
SELECT
DISTINCT(t.template_id)
, c.category_name
, x.rvs_category_id
, it.template_item_id
, it.template_item_folder
, it.template_type_s_preview
, it.color_id
, it.products_id
, cl.color_name
, p.picture_name
FROM
%s t
, %s c
, %s x
, %s it
, %s cl
, %s na
, %s p
WHERE
x.rvs_category_id = c.rvs_category_id
AND it.color_id = cl.color_id
AND it.picture_id = p.picture_id
%s
%s
AND t.template_id = it.template_id
AND t.template_id = x.template_id
"
, $this->aConf['table']['rvs_template']
, $this->aConf['table']['rvs_category']
, $this->aConf['table']['rvs_template_categories_xref']
, $this->aConf['table']['rvs_template_item']
, $this->aConf['table']['rvs_color']
, $this->aConf['table']['rvs_navigator']
, $this->aConf['table']['rvs_picture']
, (!is_null($categoryId) && $categoryId)
? sprintf(' AND x.rvs_category_id = %s',RvsLibs_String::quoteSmart($categoryId))
: ''
, (!is_null($templateItemId) && $templateItemId)
? sprintf(' AND it.template_item_id = %s',RvsLibs_String::quoteSmart($templateItemId))
: ' AND t.default_template_item_id = it.template_item_id '
);
$oTemplateItem->query($query);
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
public function findRefTemplateDataByCustomCategoryId($categoryId = null, $templateItemId = null, $fetchMode='getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
$query = sprintf("
SELECT
DISTINCT(t.template_id)
, cc.custom_category_name
, x.rvs_category_id
, it.template_item_id
, it.template_item_folder
, it.template_type_s_preview
, it.color_id
, it.products_id
, cl.color_name
, p.picture_name
FROM
%s t
, %s cc
, %s x
, %s it
, %s cl
, %s na
, %s p
WHERE
x.rvs_category_id = cc.custom_category_id
AND it.color_id = cl.color_id
AND it.picture_id = p.picture_id
%s
%s
AND t.template_id = it.template_id
AND t.template_id = x.template_id
"
, $this->aConf['table']['rvs_template']
, $this->aConf['table']['rvs_custom_category']
, $this->aConf['table']['rvs_template_categories_xref']
, $this->aConf['table']['rvs_template_item']
, $this->aConf['table']['rvs_color']
, $this->aConf['table']['rvs_navigator']
, $this->aConf['table']['rvs_picture']
, (!is_null($categoryId) && $categoryId)
? sprintf(' AND x.rvs_category_id = %s',RvsLibs_String::quoteSmart($categoryId))
: ''
, (!is_null($templateItemId) && $templateItemId)
? sprintf(' AND it.template_item_id = %s',RvsLibs_String::quoteSmart($templateItemId))
: ' AND t.default_template_item_id = it.template_item_id '
);
$oTemplateItem->query($query);
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
function findRefTemplateDataByCustomCategoryIdAndTemplateItemId($categoryId, $fetchMode='getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
$query = sprintf("SELECT
*
FROM
%s as tp
, %s as ti
, %s as tmp
, %s as tcx
, %s as cc
WHERE
tp.template_id = ti.template_id
AND ti.template_id = tmp.template_id
AND tmp.template_id = tcx.template_id
AND tcx.rvs_category_id = cc.custom_category_id
AND cc.custom_category_id = %s
"
, $this->aConf['table']['rvs_template']
, $this->aConf['table']['rvs_template_item']
, $this->aConf['table']['rvs_template_import']
, $this->aConf['table']['rvs_template_categories_xref']
, $this->aConf['table']['rvs_custom_category']
, RvsLibs_String::quoteSmart($categoryId)
);
$oTemplateItem->query($query);
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
function findTemplateIdByproductId($productId, $colorGroup, $fetchMode='getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
$query = sprintf("SELECT
DISTINCT(template_id)
FROM
%s
WHERE
template_item_folder
LIKE
%s
AND
template_item_folder
LIKE
%s
"
, $this->aConf['table']['rvs_template_item']
, RvsLibs_String::quoteSmart('%' . $productId . '%')
, RvsLibs_String::quoteSmart('%' . $colorGroup . '%')
);
$oTemplateItem->query($query);
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
/**
* Selete template item by template_id WHERE products_id
* @author nipaporn
* @param $productId
* @param $fetchMode
* @return array
*/
function findTemplateIdByproductIdTemplateTopHundred($productId, $fetchMode='getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
$query = sprintf("SELECT
DISTINCT(template_id)
FROM
%s
WHERE
products_id
LIKE
%s
"
, $this->aConf['table']['rvs_template_item']
, RvsLibs_String::quoteSmart('%' . $productId . '%')
);
$oTemplateItem->query($query);
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
/**
* Selece template item by template id, template item id, menustyle id
* @author Parinya Chaipetch
*
* @param string $templateId
* @param string $templateItemId
* @param string $menustyleId
* @param string $fetchMode
* @access public
* @return array
*/
public function findTemplateItemByTemplateData($templateId=null, $templateItemId = null, $menustyleId= null, $fetchMode='getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplate = DB_DataObject::factory($this->aConf['table']['rvs_template']);
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
$query = sprintf("
SELECT
*
FROM
%s as t
, %s as it
WHERE
it.template_id = t.template_id
AND it.template_item_id = %s
AND it.template_id = %s
%s
"
, $this->aConf['table']['rvs_template']
, $this->aConf['table']['rvs_template_item']
, RvsLibs_String::quoteSmart($templateItemId)
, RvsLibs_String::quoteSmart($templateId)
, (empty($menustyleId) || $menustyleId == 0) ? '' : 'AND t.menustyle_id = ' . RvsLibs_String::quoteSmart($menustyleId)
);
$oTemplate->query($query);
$aCloneData = array();
while ($oTemplate->fetch()) {
$aCloneData[$oTemplate->template_id] = clone($oTemplate);
}
return DbWrapper::fetchDatas($oTemplate->_resultFields, $aCloneData, $fetchMode);
}
/**
* Selece list color by template id, picture id in table template item
*
* Resulting SQL
* SELECT
* DISTINCT(c.color_id)
* , it.template_item_id
* , it.template_item_folder
* , it.picture_id
* FROM
* rvs_color c
* , rvs_template_item it
* WHERE
* it.template_id = '$templateId'
* AND it.picture_id = '$pictureId' (!=)
* AND c.color_id = it.color_id
* ORDER BY
* color_name
*
* @author Darawan Taorong create date : 30/04/2552 16:00PM
*
* @param string $templateId
* @param string $pictureId
* @param boolean $equalPictureId ex. true(it.picture_id = '$pictureId') ,false (it.picture_id != '$pictureId')
* @param string $fetchMode
* @access public
* @return array
* @from TemplateList.php Fn : _listColor
*/
public function findListColorByTemplateIdAndPictureId($templateId = null, $pictureId = null, $equalPictureId = true , $fetchMode='getassoc')
{
DB_DataObject::debugLevel();
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
if ( !is_null($templateId) && !is_null($pictureId) ){
$query = sprintf("
SELECT
DISTINCT(c.color_id)
, it.template_item_id
, it.template_item_folder
, it.picture_id
FROM
%s c
, %s it
WHERE
it.template_id = %s
AND it.picture_id %s
AND c.color_id = it.color_id
"
, $this->aConf['table']['rvs_color']
, $this->aConf['table']['rvs_template_item']
, RvsLibs_String::quoteSmart($templateId)
, ($equalPictureId === true) ? " = " . RvsLibs_String::quoteSmart($pictureId) : " != " . RvsLibs_String::quoteSmart($pictureId)
);
$oTemplateItem->query($query);
}
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
public function findAllColorByTemplateId($templateId = null, $fetchMode='getassoc')
{
DB_DataObject::debugLevel(0);
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
if ( !is_null($templateId) ){
$query = sprintf("
SELECT
it.template_item_id
, it.color_id
, it.template_item_folder
, it.picture_id
FROM
%s as c
, %s as cg
, %s as cn
, %s as it
WHERE it.template_id = %s
AND it.color_id = c.color_id
AND it.color_id = cg.color_id
AND cg.color_group_id = cn.color_group_id
order by it.template_item_id desc
"
, $this->aConf['table']['rvs_color']
, $this->aConf['table']['rvs_color_group']
, $this->aConf['table']['rvs_color_group_name']
, $this->aConf['table']['rvs_template_item']
, RvsLibs_String::quoteSmart($templateId)
);
$oTemplateItem->query($query);
}
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
/**
* Selece template item data by template item id
*
* Resulting SQL
* SELECT
* *
* FROM
* rvs_template_item
* WHERE
* template_item_id = {$templateItemId}
*
* @author Parinya Chaipetch
*
* @param array $aResultFields
* @param string $templateItemId
* @param string $fetchMode
* @access public
* @return array
*/
public function findTemplateItemByTemplateItemId($templateItemId=null, $fetchMode='getassoc', $aResultFields = array())
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
if (!is_null($templateItemId)) {
$oTemplateItem->template_item_id = $templateItemId;
}
$oTemplateItem->find();
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
$oTemplateItem = DbWrapper::buildResultFields($oTemplateItem, $aResultFields);
return DbWrapper::fetchDatas($oTemplateItem, $aCloneData, $fetchMode);
}
/** Selece template item data by template id
*
* Resulting SQL
* SELECT
* *
* FROM
* rvs_template_item
* WHERE
* template_id = {$templateId}
*
* @author Darawan Taorong
*
* @param string $templateItemId
* @param string $fetchMode
* @access public
* @return array
**/
public function findTemplateItemByTemplateId($templateId = null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
if (!is_null($templateId)) {
$oTemplateItem->template_id = $templateId;
$oTemplateItem->find();
}
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
/** Selece template item data by group template item id and template id
*
* Resulting SQL
* SELECT
* it.template_item_id
* , t.template_id
* , it.template_item_folder
* , it.template_type_s_preview
* , it.products_id
* , it.picture_id
* FROM
* rvs_template t
* , rvs_template_item it
* WHERE
* template_id =
* foreach ($aTemplate as $k=>$v) {
* if ($count == 0) {
* $queryD1 .= " IN ('" . $v . "'";
* } else {
* $queryD1 .= ",'$v'";
* }
* $count++;
* if ($count == count($aTemplate)) {
* $queryD1 .= ")";
* }
* }
* AND t.template_id = it.template_id
* ORDER BY
* t.cdate DESC, t.sort_priority DESC
* $aTem1 = $this->objDbh->getAssoc($queryD1);
*
* @author Darawan Taorong create data: 29/04/2552 11:53 AM
*
* @param array $aTemplateItemId ex. result getassoc in database
* @param string $fetchMode
* @access public
* @return array
* @from TemoplateList.php Fn: _getAllTemplateData
* หารวมกันไม่ได้เพราะว่า customcategory เจนเป็น md5 หาค่า categoryid
* ในตาราง rvs_template_item ไม่ได้ จะต้องหาในตาราง rvs_template_categories_xref
* แสดงเมนู import template กับ เมนู category ทั้งหมด ไม่รวม diy กับ all category
*/
public function findTemplateItemDataByGroupTemplateItemIdAndTemplateId($aTemplateItemId = null, $selectCategoryId, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
$count = 0;
foreach ($aTemplateItemId as $k=>$v) {
if ($count == 0) {
$queryD1 = " it.template_item_id IN ('" . $v . "'";
} else {
$queryD1 .= ",'$v'";
}
$count++;
if ($count == count($aTemplateItemId)) {
$queryD1 .= ")";
}
}
$query = sprintf('
SELECT
it.template_item_id
, t.template_id
, t.menustyle_id
, it.template_item_folder
, it.template_type_s_preview
, it.products_id
, it.picture_id
, tcx.rvs_category_id
, ix.template_type_id
FROM
%s t
, %s it
, %s tcx
, %s ix
WHERE
t.template_id = it.template_id
AND it.template_id = tcx.template_id
AND ix.template_id = t.template_id
AND %s
%s
ORDER BY
t.cdate DESC, t.sort_priority DESC
'
, $this->aConf['table']['rvs_template']
, $this->aConf['table']['rvs_template_item']
, $this->aConf['table']['rvs_template_categories_xref']
, $this->aConf['table']['rvs_template_type_xref']
, $queryD1
, ($selectCategoryId)
? sprintf('AND tcx.rvs_category_id = %s', RvsLibs_String::quoteSmart($selectCategoryId))
: ''
);
//echo $query;
$oTemplateItem->query($query);
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
//ImportTemplate query หาเฉพาะ Importtemplate ไม่มี Diy
public function findTemplateItemDataByGroupTemplateItemIdAndTemplateIdImport($selectCategoryId, $usrId, $ownerId,$fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
$count = 0;
if (strlen($selectCategoryId) == 32) {
$Query2 = sprintf('AND tcx.rvs_category_id = %s', RvsLibs_String::quoteSmart($selectCategoryId));
} else {
$Query2 = ($usrId && $ownerId) ? 'AND (ip.rvs_usr_id LIKE ' . RvsLibs_String::quoteSmart($usrId)
. ' OR ip.rvs_usr_id LIKE ' . RvsLibs_String::quoteSmart($ownerId) . ')' : '';
}
$query = sprintf('
SELECT
it.template_item_id
, t.template_id
, t.menustyle_id
, it.template_item_folder
, it.template_type_s_preview
, it.products_id
, it.picture_id
, tcx.rvs_category_id
, ix.template_type_id
FROM
%s t
, %s it
, %s tcx
, %s ix
, %s ip
WHERE
t.template_id = it.template_id
AND it.template_id = tcx.template_id
AND ix.template_id = t.template_id
AND ip.template_id = t.template_id
AND ix.template_type_id != %s
AND it.template_item_folder NOT LIKE %s
%s
ORDER BY
t.cdate DESC, t.sort_priority DESC
'
, $this->aConf['table']['rvs_template']
, $this->aConf['table']['rvs_template_item']
, $this->aConf['table']['rvs_template_categories_xref']
, $this->aConf['table']['rvs_template_type_xref']
, $this->aConf['table']['rvs_template_import']
/* , $this->aConf['table']['rvs_custom_category'] */
, RvsLibs_String::quoteSmart('10')
, RvsLibs_String::quoteSmart('%_DiyPicture_%')
, $Query2
);
//, %s cc
//echo $query;
$oTemplateItem->query($query);
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
//Diy query หาเฉพาะ diytemplate
public function findTemplateItemDataByGroupTemplateItemIdAndTemplateIdDiy($aTemplateItemId, $selectCategoryId, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
$count = 0;
foreach ($aTemplateItemId as $k=>$v) {
if ($count == 0) {
$queryD1 = " it.template_item_id IN ('" . $v . "'";
} else {
$queryD1 .= ",'$v'";
}
$count++;
if ($count == count($aTemplateItemId)) {
$queryD1 .= ")";
}
}
$query = sprintf('
SELECT
it.template_item_id
, t.template_id
, t.menustyle_id
, it.template_item_folder
, it.template_type_s_preview
, it.products_id
, it.picture_id
, ix.template_type_id
FROM
%s t
, %s it
, %s ix
WHERE
%s
AND %s
AND t.template_id = it.template_id
AND ix.template_id = t.template_id
ORDER BY
t.cdate DESC, t.sort_priority DESC
'
, $this->aConf['table']['rvs_template']
, $this->aConf['table']['rvs_template_item']
, $this->aConf['table']['rvs_template_type_xref']
, $queryD1
, ($selectCategoryId)
? sprintf('it.template_item_folder LIKE %s', RvsLibs_String::quoteSmart('%'.$selectCategoryId.'%'))
: ''
);
//echo $query;
$oTemplateItem->query($query);
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
public function findTemplateItemDataByGroupTemplateItemIdAndTemplateIdAllCategoryNoDiyImport($aTemplateItemId = null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
$count = 0;
foreach ($aTemplateItemId as $k=>$v) {
if ($count == 0) {
$queryD1 = " it.template_item_id IN ('" . $v . "'";
} else {
$queryD1 .= ",'$v'";
}
$count++;
if ($count == count($aTemplateItemId)) {
$queryD1 .= ")";
}
}
$query = sprintf('
SELECT
DISTINCT(it.template_item_id)
, t.template_id
, t.menustyle_id
, it.template_item_folder
, it.template_type_s_preview
, it.products_id
, it.picture_id
, ix.template_type_id
FROM
%s t
, %s it
, %s ix
, %s rc
, %s cx
WHERE
t.template_id = it.template_id
AND ix.template_id = t.template_id
AND cx.template_id = t.template_id
AND cx.rvs_category_id = rc.rvs_category_id
AND ix.template_type_id != %s
AND cx.rvs_category_id != %s
AND it.template_item_folder NOT LIKE %s
AND %s
ORDER BY
t.cdate DESC, t.sort_priority DESC
'
, $this->aConf['table']['rvs_template']
, $this->aConf['table']['rvs_template_item']
, $this->aConf['table']['rvs_template_type_xref']
, $this->aConf['table']['rvs_category']
, $this->aConf['table']['rvs_template_categories_xref']
, RvsLibs_String::quoteSmart('10')
, RvsLibs_String::quoteSmart('23')
, RvsLibs_String::quoteSmart('%_DiyPicture_%')
, $queryD1
);
//echo $query;
$oTemplateItem->query($query);
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
//All template reseller
public function findTemplateItemDataByGroupTemplateItemIdAndTemplateIdAllCategoryNoDiyImportReseller($aTemplateItemId = null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
$count = 0;
foreach ($aTemplateItemId as $k=>$v) {
if ($count == 0) {
$queryD1 = " it.template_item_id IN ('" . $v . "'";
} else {
$queryD1 .= ",'$v'";
}
$count++;
if ($count == count($aTemplateItemId)) {
$queryD1 .= ")";
}
}
$query = sprintf('
SELECT
DISTINCT(it.template_item_id)
, t.template_id
, t.menustyle_id
, it.template_item_folder
, it.template_type_s_preview
, it.products_id
, it.picture_id
, ix.template_type_id
FROM
%s t
, %s it
, %s im
, %s ix
WHERE
t.template_id = it.template_id
AND ix.template_id = t.template_id
AND im.template_id != it.template_id
AND ix.template_type_id != %s
AND it.template_item_folder NOT LIKE %s
AND %s
ORDER BY
t.cdate DESC, t.sort_priority DESC
'
, $this->aConf['table']['rvs_template']
, $this->aConf['table']['rvs_template_item']
, $this->aConf['table']['rvs_template_import']
, $this->aConf['table']['rvs_template_type_xref']
, RvsLibs_String::quoteSmart('10')
, RvsLibs_String::quoteSmart('%_DiyPicture_%')
, $queryD1
);
//echo $query;
$oTemplateItem->query($query);
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
//All category query นี้หา template ทั้งหมดไม่ต้องส่งค่า category มา
public function findTemplateItemDataByGroupTemplateItemIdAndTemplateIdAllCategory($aTemplateItemId = null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
$count = 0;
foreach ($aTemplateItemId as $k=>$v) {
if ($count == 0) {
$queryD1 = " it.template_item_id IN ('" . $v . "'";
} else {
$queryD1 .= ",'$v'";
}
$count++;
if ($count == count($aTemplateItemId)) {
$queryD1 .= ")";
}
}
$query = sprintf('
SELECT
it.template_item_id
, t.template_id
, t.menustyle_id
, it.template_item_folder
, it.template_type_s_preview
, it.products_id
, it.picture_id
, ix.template_type_id
FROM
%s t
, %s it
, %s ix
WHERE
t.template_id = it.template_id
AND ix.template_id = t.template_id
AND %s
ORDER BY
t.cdate DESC, t.sort_priority DESC
'
, $this->aConf['table']['rvs_template']
, $this->aConf['table']['rvs_template_item']
, $this->aConf['table']['rvs_template_type_xref']
, $queryD1
);
//echo $query;
$oTemplateItem->query($query);
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
/** Selece color id by template id in table template item
*
* Resulting SQL
* SELECT
* DISTINCT(it.color_id)
* , t.template_id
* FROM
* rvs_template t
* , rvs_template_item it
* WHERE
* t.template_id = '$templateId'
* AND t.template_id = it.template_id
* $aTem1 = $this->objDbh->getAssoc($query);
*
* @author Darawan Taorong create data: 30/04/2552 14:48 PM
*
* @param string $projectId
* @param string $fetchMode
* @access public
* @return array
* @from TemoplateList.php Fn: _countTemplateColor
*/
public function findColorIdByTemplateId($templateId = null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oTemplate = DB_DataObject::factory($this->aConf['table']['rvs_template']);
$query = sprintf('
SELECT
DISTINCT(it.color_id)
, t.template_id
FROM
%s t
, %s it
WHERE
t.template_id = %s
AND t.template_id = it.template_id
'
, $this->aConf['table']['rvs_template']
, $this->aConf['table']['rvs_template_item']
, RvsLibs_String::quoteSmart($templateId)
);
$oTemplate->query($query);
$aCloneData = array();
while ($oTemplate->fetch()) {
$aCloneData[] = clone($oTemplate);
}
return DbWrapper::fetchDatas($oTemplate->_resultFields, $aCloneData, $fetchMode);
}
/** Selece picture id by template id in table template item
*
* Resulting SQL
* SELECT
* DISTINCT(it.picture_id)
* , t.template_id
* FROM
* rvs_template t
* , rvs_template_item it
* WHERE
* t.template_id = '$templateId'
* AND t.template_id = it.template_id
* $aTem1 = $this->objDbh->getAssoc($query);
*
* @author Darawan Taorong create data: 30/04/2552 14:48 PM
*
* @param string $projectId
* @param string $fetchMode
* @access public
* @return array
* @from TemoplateList.php Fn: _countTemplatePicture
*/
public function findPictureIdByTemplateId($templateId = null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oTemplate = DB_DataObject::factory($this->aConf['table']['rvs_template']);
$query = sprintf('
SELECT
DISTINCT(it.picture_id)
, t.template_id
FROM
%s t
, %s it
WHERE
t.template_id = %s
AND t.template_id = it.template_id
'
, $this->aConf['table']['rvs_template']
, $this->aConf['table']['rvs_template_item']
, RvsLibs_String::quoteSmart($templateId)
);
$oTemplate->query($query);
$aCloneData = array();
while ($oTemplate->fetch()) {
$aCloneData[] = clone($oTemplate);
}
return DbWrapper::fetchDatas($oTemplate->_resultFields, $aCloneData, $fetchMode);
}
/** find Data Template By User Id
* $query = "SELECT
* DISTINCT(ti.template_id)
* , ti.template_item_id
* , ti.template_item_folder
* , t.cdate
* FROM
* {$this->conf['table']['rvs_template']} t
* , {$this->conf['table']['rvs_template_item']} ti
* , {$this->conf['table']['rvs_template_import']} tp
* WHERE
* t.template_id = tp.template_id
* AND t.template_id = ti.template_id
* AND t.default_template_item_id = ti.template_item_id
* AND tp.rvs_usr_id = '$input->rvs_usr_id'
* ORDER BY
* t.cdate DESC
* ";
* $res = $this->dbh->getAssoc($query);
*
* @author Darawan Taorong 24/04/2552 15:18PM
* @param <string> $usrId
* @param <string> $fetchMode
* @return <array>
* form file EditDeleteTemplateMgr.php
**/
public function findDataTemplateByUsrId($usrId, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template']);
$query = sprintf('
SELECT
DISTINCT(ti.template_id)
, ti.template_item_id
, ti.template_item_folder
, t.cdate
FROM
%s as t
, %s as ti
, %s as tp
WHERE
t.template_id = tp.template_id
AND t.template_id = ti.template_id
AND t.default_template_item_id = ti.template_item_id
AND tp.rvs_usr_id = %s
ORDER BY
t.cdate DESC
'
, $this->aConf['table']['rvs_template']
, $this->aConf['table']['rvs_template_item']
, $this->aConf['table']['rvs_template_import']
, RvsLibs_String::quoteSmart($usrId)
);
$oTemplateItem->query($query);
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
/**
* find template footer data by owner user id
* @author Parinya Chaipetch
* @tutorial SQL Command
* SELECT
* *
* FROM
* rvs_template_footer
* WHERE
* rvs_owner_usr_id = {$ownerUsrId}
*
* @param string $ownerUsrId
* @param string $fetchMode
* @access public
* @return array
*/
function findTemplateFooterByOwnerUsrId($ownerUsrId=null, $fetchMode='getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplateFooter = DB_DataObject::factory($this->aConf['table']['rvs_template_footer']);
if (!is_null($ownerUsrId)) {
$oTemplateFooter->rvs_owner_usr_id = $ownerUsrId;
}
$oTemplateFooter->find();
$aCloneData = array();
while ($oTemplateFooter->fetch()) {
$aCloneData[] = clone($oTemplateFooter);
}
return DbWrapper::fetchDatas($oTemplateFooter->_resultFields, $aCloneData, $fetchMode);
}
/**
* Find Data from table rvs_template_item and rvs_picture
*
* @author duangdao.k
* @param string $templateId
* @param string $fetchMode
* @return arrayojb
*/
public function findTemplateItemDataAndPictureDataByTemplateId($templateId = null, $fetchMode='getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
if (!is_null($templateId)) {
$query = sprintf('
SELECT
*
FROM
%s ti
, %s p
WHERE
ti.picture_id = p.picture_id
AND ti.template_id =%s
ORDER BY
p.picture_id ASC
'
, $this->aConf['table']['rvs_template_item']
, $this->aConf['table']['rvs_picture']
, RvsLibs_String::quoteSmart($templateId)
);
$oTemplateItem->query($query);
}
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
public function findTemplateItemFolderByTemplateId($templateId = null, $fetchMode='getassoc')
{
//SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
if (!is_null($templateId)) {
$query = sprintf('
SELECT
ti.template_item_id
,ti.template_item_folder
FROM
%s as ti
,%s as tp
WHERE tp.template_id = ti.template_id
AND ti.template_id= %s
'
, $this->aConf['table']['rvs_template_item']
, $this->aConf['table']['rvs_template']
, RvsLibs_String::quoteSmart($templateId)
);
$oTemplateItem->query($query);
}
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
public function findTemplateIdByCategoryIdAndTemplateId($categoryId, $templateId, $fetchMode='getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_type_xref']);
$query = sprintf('
SELECT
ti.template_id
,tp.cdate
FROM
%s as ct
,%s as ti
,%s as tp
WHERE ct.template_id = ti.template_id
AND tp.template_id = ti.template_id
AND ti.template_type_id = %s
AND ct.rvs_category_id = %s
ORDER BY tp.cdate DESC
'
, $this->aConf['table']['rvs_template_categories_xref']
, $this->aConf['table']['rvs_template_type_xref']
, $this->aConf['table']['rvs_template']
, RvsLibs_String::quoteSmart($templateId)
, RvsLibs_String::quoteSmart($categoryId)
);
$oTemplateItem->query($query);
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[$oTemplateItem->template_id] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
public function findTemplateItemAndTemplateByTemplateItemId($templateItemId = null, $fetchMode='getassoc')
{
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
if (!is_null($templateItemId)) {
$query = sprintf('
SELECT
*
FROM
%s as tp
,%s as ti
WHERE
ti.template_item_id = %s
AND
tp.template_id = ti.template_id
'
, $this->aConf['table']['rvs_template']
, $this->aConf['table']['rvs_template_item']
, RvsLibs_String::quoteSmart($templateItemId)
);
$oTemplateItem->query($query);
}
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
/**
* Find Data from table rvs_template, rvs_template_item and rvs_navigator by template_item_id
*
* @author duangdao.k
* @param string $templateItemId
* @param string $fetchMode
* @return obj
*/
public function findTemplateDataByTemplateItemIdAndTemplateId($templateItemId = null, $fetchMode='getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template']);
if (!is_null($templateItemId)) {
$query = sprintf('
SELECT
*
FROM
%s t
,%s it
,%s rn
WHERE
it.template_item_id = %s
and
t.template_id = it.template_id
and
t.navigator_id = rn.navigator_id
'
, $this->aConf['table']['rvs_template']
, $this->aConf['table']['rvs_template_item']
, $this->aConf['table']['rvs_navigator']
, RvsLibs_String::quoteSmart($templateItemId)
);
$oTemplateItem->query($query);
}
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
//TODO used tryout
public function findTemplateAndNavigatorAndCategoriesXrefDataByTemplateItemId($templateItemId = null, $fetchMode='getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template']);
if (!is_null($templateItemId)) {
$query = sprintf('
SELECT
*
FROM
%s t
,%s it
,%s rn
, %s tc
WHERE
it.template_item_id = %s
and
t.template_id = it.template_id
and
t.navigator_id = rn.navigator_id
and
t.template_id = tc.template_id
'
, $this->aConf['table']['rvs_template']
, $this->aConf['table']['rvs_template_item']
, $this->aConf['table']['rvs_navigator']
, $this->aConf['table']['rvs_template_categories_xref']
, RvsLibs_String::quoteSmart($templateItemId)
);
$oTemplateItem->query($query);
}
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
/**
* Find Data from table rvs_template And rvs_template_item by template_id, $colorId , $pictureId and template_id
*
* Resulting SQL
* SELECT
* *
* FROM
* rvs_template t
* , rvs_template_item it
* WHERE
* it.template_id= {$templateId}
* if ({$colorId}) {
* AND it.color_id = {$colorId}
* }
* if ({$pictureId}) {
* AND it.picture_id = {$pictureId}
* }
* AND it.template_id = t.template_id
*
*
* @author duangdao.k
* @param string $templateId
* @param string $colorId
* @param string $pictureId
* @param string $fetchMode
* @return arrayboj
*/
public function findtemplateDataAndTemplateItemByTemplateId($templateId = null, $colorId = null, $pictureId = null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template']);
if (!is_null($templateId)) {
$query = sprintf('
SELECT
*
FROM
%s t
, %s it
WHERE
it.template_id= %s
AND it.template_id = t.template_id
%s
%s
'
, $this->aConf['table']['rvs_template']
, $this->aConf['table']['rvs_template_item']
, RvsLibs_String::quoteSmart($templateId)
, ($colorId) ? sprintf('AND it.color_id = %s',RvsLibs_String::quoteSmart($colorId)) : ''
, ($pictureId) ? sprintf('AND it.picture_id = %s', RvsLibs_String::quoteSmart($pictureId)) : ''
);
$oTemplateItem->query($query);
}
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
/**
* Get all template type data
*
* Resulting SQL
* SELECT
* *
* FROM
* rvs_template_type
* ORDER BY
* template_type_id
*
* @param string $fetchMode
* @param array $aResultFields
* @author Parinya Chaipetch
* @access public
* @return array
*/
public function findTemplateTypeData($fetchMode = 'getassoc',$aResultFields = array(), $templateTypeId = null)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oTemplateType = DB_DataObject::factory($this->aConf['table']['rvs_template_type']);
if (!is_null($templateTypeId)) {
$oTemplateType->template_type_id = $templateTypeId;
}
$oTemplateType->orderBy('template_type_id');
$oTemplateType->find();
$aCloneData = array();
while ($oTemplateType->fetch()) {
$aCloneData[] = clone($oTemplateType);
}
$oTemplateType = DbWrapper::buildResultFields($oTemplateType, $aResultFields );
return DbWrapper::fetchDatas($oTemplateType, $aCloneData, $fetchMode);
}
/**
* find is import template exist
* @author Pharadol
* @param <string> $templateItemId
* @param <string> $fetchMode
* @return <array>
* form file ImportProjectMgr.php
*/
public function findIsImportTemplateExist($templateItemId = null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
if (!is_null($templateItemId)) {
$query = sprintf(' SELECT
template_item_id
FROM
%s
WHERE
template_item_id = %s
'
, $this->aConf['table']['rvs_template_item']
, RvsLibs_String::quoteSmart($templateItemId)
);
$oTemplateItem->query($query);
}
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
/**
* find is import template exist On Other User
* @author Pharadol
* @param <string> $templateId
* @param <string> $usrId
* @param <string> $fetchMode
* @return <array>
* form file ImportProjectMgr.php
*/
public function findIsImportTemplateExistOnOtherUser($templateId = null, $usrId = null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
if (!is_null($templateId) && !is_null($usrId)) {
$query = sprintf(' SELECT
ti.template_item_id,ip.rvs_usr_id
FROM
%s as ti
, %s as tp
, %s as ip
WHERE
ti.template_item_id = %s
AND ip.rvs_usr_id != %s
AND ti.template_id = tp.template_id
AND tp.template_id = ip.template_id
'
, $this->aConf['table']['rvs_template_item']
, $this->aConf['table']['rvs_template']
, $this->aConf['table']['rvs_template_import']
, RvsLibs_String::quoteSmart($templateId)
, RvsLibs_String::quoteSmart($usrId)
);
$oTemplateItem->query($query);
}
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
/*
public function findIsImportTemplateExist($templateItemId, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
$query = sprintf('SELECT
template_item_id
FROM
%s
WHERE
template_item_id = %s
'
, $this->aConf['table']['rvs_template_item']
, RvsLibs_String::quoteSmart($templateItemId)
);
$oTemplateItem->query($query);
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
*/
/**
* Find Layout Template by templateid
* @author Pharadol
* @param <string> $parentTemplateId
* @param <string> $fetchMode
* @return array
* form file ImportTemplateMgr.php
/*
$query = "
SELECT
*
FROM
{$this->conf['table']['rvs_template']} t
, {$this->conf['table']['rvs_layout_template']} lt
WHERE
t.default_layout_id = lt.layout_template_id
AND t.template_id = '$input->parent_template_id'
";
$res = $this->dbh->getRow($query);
*/
public function findLayoutTemplateDataByTemplateId($parentTemplateId = null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template']);
if (!is_null($parentTemplateId)) {
$query = sprintf('
SELECT
*
FROM
%s t
, %s lt
WHERE
t.template_id = %s
AND t.default_layout_id = lt.layout_template_id
'
, $this->aConf['table']['rvs_template']
, $this->aConf['table']['rvs_layout_template']
, RvsLibs_String::quoteSmart($parentTemplateId)
);
$oTemplateItem->query($query);
$oTemplateItem->query($query);
}
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
/**
* find template type name by template type id
* @author Pharadol
* @param <string> $templateTypeId
* @param <string> $fetchMode
* @return <array>
* form file ImportTemplate
/*
$query = "
SELECT
*
FROM
{$this->conf['table']['rvs_template_type']}
WHERE
template_type_id = '$templateTypeId'
";
$res = $this->dbh->getRow($query);
*/
public function findTemplateTypeNameByTemplateTypeId($templateTypeId = null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_type']);
if (!is_null($templateTypeId)) {
$query = sprintf('
SELECT
*
FROM
%s
WHERE
template_type_id = %s
'
, $this->aConf['table']['rvs_template_type']
, RvsLibs_String::quoteSmart($templateTypeId)
);
$oTemplateItem->query($query);
}
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
/**
* find projucts id
* @author Pharadol
* @param <string> $fetchMode
* @return <array>
* form file ImportTemplateMgr.php
/*
$query = "
SELECT
products_id
FROM
{$this->conf['table']['rvs_template_item']}
";
$res = $this->dbh->getAll($query, DB_FETCHMODE_ASSOC);
*/
public function findProductsId($productId = null, $fetchMode = 'getassoc', $aResultFields = array('products_id'))
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
if (is_null($productId) === false) {
$oTemplateItem->products_id = $productId;
}
/*
$query = sprintf('
SELECT
products_id
FROM
%s
'
, $this->aConf['table']['rvs_template_item']
);
$oTemplateItem->query($query);
*/
$oTemplateItem->find();
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
DB_DataObject::debugLevel();
$oProductId = DbWrapper::buildResultFields($oTemplateItem, $aResultFields);
return DbWrapper::fetchDatas($oProductId, $aCloneData, $fetchMode);
}
/**
* Find layout template id by layout category id
*
* Resulting SQL
* SELECT
* DISTINCT(ti.template_item_id)
* , ti.template_item_folder
* , ti.products_id
* FROM
* {$this->conf['table']['rvs_template_item']} ti
* , {$this->conf['table']['rvs_project_info']} pi
* WHERE
* ti.template_id = '$input->template_id' ";
* if ( $input->default_template_item_id && count(array_keys($this->getAllTemplate($input->template_id))) != 1) {
* $query .= " AND ti.template_item_id != '$input->default_template_item_id' ";
* }
* AND ti.template_item_id != pi.template_item_id
* ORDER BY
* ti.products_id
* $res = $this->dbh->getAll($query);
*
* @param string $templateId
* @param string $templateItemId
* @param string $fetchMode
*
* @author Darawan Taorong add by dara 28/04/2552
* @access public
* @return array
* @form EditDeleteTemplate.php , Fn: listTemplateDelete
**/
public function findDataTemplateItemByTemplateIdOrTemplateItemId( $templateId = null, $templateItemId = null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
$query = sprintf('
SELECT
DISTINCT(ti.template_item_id)
, ti.template_item_folder
, ti.products_id
FROM
%s ti
, %s pi
WHERE
ti.template_id = %s
%s
AND ti.template_item_id != pi.template_item_id
ORDER BY
ti.products_id
'
, $this->aConf['table']['rvs_template_item']
, $this->aConf['table']['rvs_project_info']
, RvsLibs_String::quoteSmart($templateId)
, (!is_null($templateItemId)) ? 'AND ti.template_item_id != '.RvsLibs_String::quoteSmart($templateItemId) : ''
, RvsLibs_String::quoteSmart($templateId)
);
$oTemplateItem->query($query);
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
/**
* find AllData TemplateItem By TemplateId in table rvs_template_item
* Resulting SQL
* SELECT
* *
* FROM
* rvs_template_item
* WHERE
* template_id = {$res['template_id']}
*
* @author Pornthip Phothong
* @param <string> $templateId
* @param <string> $fetchMode
* @return array obj
* @from UploadTemplateMgr.php
*/
public function findAllDataTemplateItemByTemplateId($templateId = null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
if (!is_null($templateId)) {
$query = sprintf('
SELECT
*
FROM
%s
WHERE
template_id = %s
'
, $this->aConf['table']['rvs_template_item']
, RvsLibs_String::quoteSmart($templateId)
);
$oTemplateItem->query($query);
}
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
/** Find template_idd by category id or template_type_id
*
* Resulting SQL
* SELECT
* DISTINCT(t.template_id)
* , t.default_template_item_id
* FROM
* {$this->conf['table']['rvs_template']} t
* , {$this->conf['table']['rvs_template_item']} it
* if ($input->category_id) {
* $query .= ", rvs_template_categories_xref x";
* }
* if ($input->template_type_id) {
* $query .= " , rvs_template_type_xref tt";
* }
* $query .= "WHERE t.template_id = it.template_id";
* if ($input->category_id) {
* $query .= " AND t.template_id = x.template_id
* AND x.rvs_category_id = '$input->category_id'";
* }
* if ($input->template_type_id) {
* $query .= " AND t.template_id = tt.template_id
* AND tt.template_type_id = '$input->template_type_id'
* ";
* }
* $aTemplate = $this->objDbh->getAssoc($query);
*
* @param string $templateId
* @param string $templateItemId
* @param string $fetchMode
*
* @author Darawan Taorong add by dara 28/04/2552 13:16 PM
* @access public
* @return array
* @form TemplateList.php , Fn: _getTemplate
**/
public function findDataTemplateByCategoryIdOrTemplateTypeId($catoryid = null, $templateTypeId = null, $fetchMode = 'getassoc', $whereCase=null)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
//DbWrapper::rDebug($this->aConf['table'],array(),1);
$query = sprintf('
SELECT
DISTINCT t.template_id
, t.default_template_item_id
FROM
%s t
, %s it
%s
%s
WHERE
t.template_id = it.template_id
%s
%s
%s
'
, $this->aConf['table']['rvs_template']
, $this->aConf['table']['rvs_template_item']
, ( $catoryid && !is_null($catoryid) ) ? sprintf(', %s x', $this->aConf['table']['rvs_template_categories_xref']) : ''
, ( $templateTypeId && !is_null($templateTypeId) ) ? sprintf(', %s tt', $this->aConf['table']['rvs_template_type_xref']) : ''
, ( $catoryid && !is_null($catoryid) ) ? 'AND t.template_id = x.template_id AND x.rvs_category_id = ' . RvsLibs_String::quoteSmart($catoryid) : ''
, ( $templateTypeId && !is_null($templateTypeId) ) ? 'AND t.template_id = tt.template_id AND tt.template_type_id = '. RvsLibs_String::quoteSmart($templateTypeId) : ''
, ($whereCase) ? 'AND t.template_id IN (\'' . $whereCase . '\')' : ''
);
$oTemplateItem->query($query);
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
public function findImportTemplateByUsrIdAndOwnerId($usrId=null, $usrOwnerId=null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oTemplate = DB_DataObject::factory($this->aConf['table']['rvs_template']);
if (!is_null($usrId)) {
$query = sprintf('
SELECT
*
FROM
%s t
, %s ti
, %s tp
, %s tx
WHERE
(tp.rvs_usr_id = %s OR tp.rvs_usr_id = %s)
AND t.default_template_item_id = ti.template_item_id
AND t.template_id = tp.template_id
AND t.template_id = tx.template_id
ORDER BY
t.cdate DESC
'
, $this->aConf['table']['rvs_template']
, $this->aConf['table']['rvs_template_item']
, $this->aConf['table']['rvs_template_import']
, $this->aConf['table']['rvs_template_type_xref']
, RvsLibs_String::quoteSmart($usrId)
, RvsLibs_String::quoteSmart($usrOwnerId)
);
$oTemplate->query($query);
}
$aCloneData = array();
while ($oTemplate->fetch()) {
$aCloneData[] = clone($oTemplate);
}
return DbWrapper::fetchDatas($oTemplate->_resultFields, $aCloneData, $fetchMode);
}
/**
* find AllTemplate Data By UsrId in rvs_template and rvs_template_item and rvs_template_import
* Resulting SQL
* SELECT
* *
* FROM
* {$this->conf['table']['rvs_template']} t
* , {$this->conf['table']['rvs_template_item']} ti
* , {$this->conf['table']['rvs_template_import']} tp
* WHERE
* t.default_template_item_id = ti.template_item_id
* AND t.template_id = tp.template_id
* AND tp.rvs_usr_id = '$input->rvs_usr_id'
* ORDER BY
* t.cdate DESC";
*
* @author Pornthip Phothong
* @param <string> $usrId
* @param <string> $fetchMode
* @return array obj
* from file UploadTemplateMgr.php
*/
public function findAllTemplateDataByUsrId($usrId=null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oTemplate = DB_DataObject::factory($this->aConf['table']['rvs_template']);
if (!is_null($usrId)) {
$query = sprintf('
SELECT
*
FROM
%s t
, %s ti
, %s tp
WHERE
tp.rvs_usr_id = %s
AND t.default_template_item_id = ti.template_item_id
AND t.template_id = tp.template_id
ORDER BY
t.cdate DESC
'
, $this->aConf['table']['rvs_template']
, $this->aConf['table']['rvs_template_item']
, $this->aConf['table']['rvs_template_import']
, RvsLibs_String::quoteSmart($usrId)
);
$oTemplate->query($query);
}
$aCloneData = array();
while ($oTemplate->fetch()) {
$aCloneData[] = clone($oTemplate);
}
return DbWrapper::fetchDatas($oTemplate->_resultFields, $aCloneData, $fetchMode);
}
/**
* find AllData From rvs_template and rvs_template_item table
*
* Resulting SQL
* SELECT
* *
* FROM
* {$this->conf['table']['rvs_template']} t
* , {$this->conf['table']['rvs_template_item']} ti
* WHERE
* t.default_template_item_id = ti.template_item_id
* ORDER BY
* t.cdate DESC
*
* @author Pornthip Phothong
* @param <string> $fetchMode
* @return array obj
* from file UploadTemplateMgr.php
/* $query = "
SELECT
*
FROM
{$this->conf['table']['rvs_template']} t
, {$this->conf['table']['rvs_template_item']} ti
WHERE
t.default_template_item_id = ti.template_item_id
ORDER BY
t.cdate DESC
";
$res = $this->dbh->getAssoc($query);
*/
public function findAllDataFromRvsTemplate($fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oTemplate = DB_DataObject::factory($this->aConf['table']['rvs_template']);
$query = sprintf('
SELECT
*
FROM
%s t
,%s ti
WHERE
t.default_template_item_id = ti.template_item_id
ORDER BY
t.cdate DESC
'
, $this->aConf['table']['rvs_template']
, $this->aConf['table']['rvs_template_item']
);
$oTemplate->query($query);
$aCloneData = array();
while ($oTemplate->fetch()) {
$aCloneData[] = clone($oTemplate);
}
return DbWrapper::fetchDatas($oTemplate->_resultFields, $aCloneData, $fetchMode);
}
/**
* find Data Navigator color by template item id in table template item , template item navigator color
*
* Resulting SQL
* SELECT
* *
* FROM
* rvs_template_item ti
* , rvs_template_item_navigator_color inc
* WHERE
* ti.template_item_id = inc.template_item_id
* AND inc.template_item_id = '$input->template_item_id'
* $resCustom = $this->objDbh->getRow($queryCustomColor);
*
* @author Darawan Taorong crate date 30/04/2552 17:09 PM
*
* @param <string> $templateItemId
* @param <string> $fetchMode
* @return array obj
* from file TemplateList.php Fn : _getCategoryIdNavigatorId
*/
public function findDataNavigatorColorByTemplateItemId($templateItemId = null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
if (!is_null($templateItemId)) {
$query = sprintf('
SELECT
*
FROM
%s ti
, %s inc
WHERE
ti.template_item_id = inc.template_item_id
AND inc.template_item_id = %s
'
, $this->aConf['table']['rvs_template_item']
, $this->aConf['table']['rvs_template_item_navigator_color']
, RvsLibs_String::quoteSmart($templateItemId)
);
$oTemplateItem->query($query);
}
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
/**
* find Category id by template item id in table rvs_template_item,rvs_template_categories_xref
*
* Resulting SQL
* SELECT
* cx.rvs_category_id
* FROM
* rvs_template_item ti
* , rvs_template_categories_xref cx
* WHERE
* ti.template_id = cx.template_id
* AND ti.template_item_id = '$input->template_item_id'
* $aDataCate = $this->objDbh->query($queryCate);
* $aTemplateCate = $aDataCate->fetchRow();
*
* @author Darawan Taorong crate date 30/04/2552 17:09 PM
*
* @param <string> $templateItemId
* @param <string> $fetchMode
* @return array obj
* from file TemplateList.php Fn : _getCategoryIdNavigatorId
*/
public function findCategoryIdByTemplateItemId($templateItemId = null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
if (!is_null($templateItemId)) {
$query = sprintf('
SELECT
cx.rvs_category_id
FROM
%s ti
, %s cx
WHERE
ti.template_id = cx.template_id
AND ti.template_item_id = %s
'
, $this->aConf['table']['rvs_template_item']
, $this->aConf['table']['rvs_template_categories_xref']
, RvsLibs_String::quoteSmart($templateItemId)
);
$oTemplateItem->query($query);
}
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
/**
* find menustyle, navigator name, color group by template item id
*
* Resulting SQL
* SELECT
* t.menustyle_id
* , na.navigator_name_id
* , c.color_group_id
* FROM
* rvs_template ti
* , rvs_template_item cx
* , rvs_navigator na
* , rvs_color_group c
* WHERE
* t.template_id = ti.template_id
* AND t.navigator_id = na.navigator_id
* AND t.menustyle_id = na.menustyle_id
* AND ti.color_id = c.color_id
* AND ti.template_item_id = %s
* $aDataCate = $this->objDbh->query($queryCate);
* $aTemplateCate = $aDataCate->fetchRow();
*
* @author Darawan Taorong crate date 30/04/2552 17:09 PM
*
* @param <string> $templateItemId
* @param <string> $fetchMode
* @return array obj
* from file TemplateList.php Fn : _getCategoryIdNavigatorId
*/
public function findMenuStyleIdNavigatorNameColorGroupIdByTemplateItemId($templateItemId, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oTemplate = DB_DataObject::factory($this->aConf['table']['rvs_template']);
if (!is_null($templateItemId)) {
$query = sprintf('
SELECT
t.menustyle_id
, na.navigator_name_id
, c.color_group_id
FROM
%s t
, %s ti
, %s na
, %s c
WHERE
t.template_id = ti.template_id
AND t.navigator_id = na.navigator_id
AND t.menustyle_id = na.menustyle_id
AND ti.color_id = c.color_id
AND ti.template_item_id = %s
'
, $this->aConf['table']['rvs_template']
, $this->aConf['table']['rvs_template_item']
, $this->aConf['table']['rvs_navigator']
, $this->aConf['table']['rvs_color_group']
, RvsLibs_String::quoteSmart($templateItemId)
);
$oTemplate->query($query);
}
$aCloneData = array();
while ($oTemplate->fetch()) {
$aCloneData[] = clone($oTemplate);
}
return DbWrapper::fetchDatas($oTemplate->_resultFields, $aCloneData, $fetchMode);
}
public function findTemplateCategoryReferenceByTemplateId($templateId = null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$oTemplateCategoryReference = DB_DataObject::factory($this->aConf['table']['rvs_template_categories_xref']);
if (!is_null($templateId)) {
$oTemplateCategoryReference->template_id = $templateId;
}
$oTemplateCategoryReference->find();
$aCloneData = array();
while ($oTemplateCategoryReference->fetch()) {
$aCloneData[] = clone($oTemplateCategoryReference);
}
return DbWrapper::fetchDatas($oTemplateCategoryReference->_resultFields, $aCloneData, $fetchMode);
}
public function findTemplateItemNavigatorColorByTemplateItemId($templateItemId = null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$oTemplateItemNavigatorColor = DB_DataObject::factory($this->aConf['table']['rvs_template_item_navigator_color']);
if (!is_null($templateItemId)) {
$oTemplateItemNavigatorColor->template_item_id = $templateItemId;
}
$oTemplateItemNavigatorColor->find();
$aCloneData = array();
while ($oTemplateItemNavigatorColor->fetch()) {
$aCloneData[] = clone($oTemplateItemNavigatorColor);
}
return DbWrapper::fetchDatas($oTemplateItemNavigatorColor->_resultFields, $aCloneData, $fetchMode);
}
public function findTemplateTypeReferenceByTemplateId($templateId = null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$oTemplateTypeReference = DB_DataObject::factory($this->aConf['table']['rvs_template_type_xref']);
if (!is_null($templateId)) {
$oTemplateTypeReference->template_id = $templateId;
}
$oTemplateTypeReference->find();
$aCloneData = array();
while ($oTemplateTypeReference->fetch()) {
$aCloneData[] = clone($oTemplateTypeReference);
}
return DbWrapper::fetchDatas($oTemplateTypeReference->_resultFields, $aCloneData, $fetchMode);
}
/**
* find tempitemid random
*
* $query = sprintf('SELECT
*
FROM
%s order by rand()
'
, $this->conf['table']['rvs_template_item']
);
$res = $this->dbh->getAll($quer
* @author Pharadol
* @param unknown_type $fetchMode
* @return string
*/
public function findgetTemplateItemIdRandDom($fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oTemplate = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
$query = sprintf('SELECT
template_item_id
FROM
%s order by rand()
'
, $this->aConf['table']['rvs_template_item']
);
$oTemplate->query($query);
$aCloneData = array();
while ($oTemplate->fetch()) {
$aCloneData[] = clone($oTemplate);
}
return DbWrapper::fetchDatas($oTemplate->_resultFields, $aCloneData, $fetchMode);
}
public function findgetTemplateItemIdRandDomByCateId($categoryId = null, $fetchMode = 'getrow')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oTemplate = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
$query = sprintf('SELECT
it.template_item_id
FROM
%s it
, %s tcx
WHERE it.template_id = tcx.template_id
AND tcx.rvs_category_id = %s
ORDER BY rand()
LIMIT 0,1
'
, $this->aConf['table']['rvs_template_item']
, $this->aConf['table']['rvs_template_categories_xref']
, RvsLibs_String::quoteSmart($categoryId)
);
$oTemplate->query($query);
$aCloneData = array();
while ($oTemplate->fetch()) {
$aCloneData[] = clone($oTemplate);
}
return DbWrapper::fetchDatas($oTemplate->_resultFields, $aCloneData, $fetchMode);
}
/**
* findTemplateItemId By ProductsId And TemplateItemFolder
* @param string $productId
* @param string $templateItem
* @author duangdao.k
* @return array
*/
function findTemplateItemIdByProductsIdAndTemplateItemFolder($productId, $templateItem, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oTemplate = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
$query = sprintf('SELECT
template_item_id
FROM
%s
WHERE products_id = %s
AND template_item_folder LIKE %s
'
, $this->aConf['table']['rvs_template_item']
, RvsLibs_String::quoteSmart($productId)
,RvsLibs_String::quoteSmart('%' . $templateItem . '%')
);
$oTemplate->query($query);
$aCloneData = array();
while ($oTemplate->fetch()) {
$aCloneData[] = clone($oTemplate);
}
return DbWrapper::fetchDatas($oTemplate->_resultFields, $aCloneData, $fetchMode);
}
/**
* findTemplateItemId By ProductsId And TemplateItemFolder
* @param string $productId
* @param string $templateItem
* @return array
*/
function findAllTemplateItem($fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oTemplate = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
$query = sprintf('SELECT
DISTINCT ti.template_item_id
,ti.template_id
,ti.template_item_folder
FROM
%s as ti
,%s as im
WHERE
ti.template_id != im.template_id
ORDER BY template_item_id
'
, $this->aConf['table']['rvs_template_item']
, $this->aConf['table']['rvs_template_import']
);
$oTemplate->query($query);
$aCloneData = array();
while ($oTemplate->fetch()) {
$aCloneData[] = clone($oTemplate);
}
return DbWrapper::fetchDatas($oTemplate->_resultFields, $aCloneData, $fetchMode);
}
/// INSERT INTO ///
/**
* insert Template Footer Data
* Resulting SQL
* INSERT INTO
* rvs_template_footer (
* rvs_template_footer_id
* , rvs_owner_usr_id
* , created_by
* , powered_by
* , powered_text
* , powered_url
* )
* VALUES (
* {$templateFooterId}
* , {$ownerUsrId}
* , {$createdBy}
* , {$poweredBy}
* , {$poweredText}
* , {$poweredUrl}
* )
*
* @author Pornthip Phothong
* @param $templateFooterId
* @param $ownerUsrId
* @param $createdBy
* @param $poweredBy
* @param $poweredText
* @param $poweredUrl
* from file CreateByPowerByIconMgr.php
*/
public function insertTemplateFooterData($templateFooterId, $ownerUsrId, $createdBy, $poweredBy, $poweredText, $poweredUrl)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$aTemplateFooter = DB_DataObject::factory($this->aConf['table']['rvs_template_footer']);
$query = sprintf('
INSERT INTO
%s
( rvs_template_footer_id
, rvs_owner_usr_id
, created_by
, powered_by
, powered_text
, powered_url
)
VALUES (
%s
, %s
, %s
, %s
, %s
, %s );
'
, $this->aConf['table']['rvs_template_footer']
, RvsLibs_String::quoteSmart($templateFooterId)
, RvsLibs_String::quoteSmart($ownerUsrId)
, RvsLibs_String::quoteSmart($createdBy)
, RvsLibs_String::quoteSmart($poweredBy)
, RvsLibs_String::quoteSmart($poweredText)
, RvsLibs_String::quoteSmart($poweredUrl)
);
$aTemplateFooter->query($query);
}
/**
* insert template item
* @author Pharadol
* @param <string> $templateUniqueId
* @param <string> $productsId
* @param <string> $templateId
* @param <string> $templateNameMix
* @param <string> $templateTypePreview
* @param <string> $colorId
* @param <string> $pictureId
// insert
/*
$query = "
INSERT INTO
{$this->conf['table']['rvs_template_item']} (
template_item_id
, products_id
, template_id
, template_item_folder
, template_type_s_preview
, color_id
, picture_id
)
VALUES (
'$input->templateUniqueId'
, '$input->products_id'
, '$input->template_id'
, '$input->templateNameMix'
, '$input->template_type_s_preview'
, '$input->color_id'
, '$input->picture_id'
)
";
*/
public function insertTemplateItem($templateUniqueId, $productsId, $templateId, $templateNameMix, $templateTypePreview, $colorId, $pictureId)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$aTemplateFooter = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
$query = sprintf('
INSERT INTO
%s
(
template_item_id
, products_id
, template_id
, template_item_folder
, template_type_s_preview
, color_id
, picture_id
)
VALUES (
%s
, %s
, %s
, %s
, %s
, %s
, %s
)
'
, $this->aConf['table']['rvs_template_item']
, RvsLibs_String::quoteSmart($templateUniqueId)
, RvsLibs_String::quoteSmart($productsId)
, RvsLibs_String::quoteSmart($templateId)
, RvsLibs_String::quoteSmart($templateNameMix)
, RvsLibs_String::quoteSmart($templateTypePreview)
, RvsLibs_String::quoteSmart($colorId)
, RvsLibs_String::quoteSmart($pictureId)
);
$res = $aTemplateFooter->query($query);
return (isset($res) && $res) ? true : false;
}
/** Find Template By ProductId
*
* @author puttipong
* @param <string> $templateId
* @param <string> $fetchMode
* @return array
* from file TemplateList.php
*/
public function findTemplateByProductId($productId = null, $fetchMode='getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
$productFirst = '-1';
if (!is_null($productId)){
$query = sprintf('
SELECT
template_item_id
, template_id
, template_item_folder
, template_type_s_preview
, products_id
, picture_id
FROM
%s
WHERE
%s
%s
%s
%s
%s
AND
products_id LIKE %s
ORDER BY
products_id DESC
'
, $this->aConf['table']['rvs_template_item']
, (strlen($productId) == 1) ? sprintf('products_id LIKE %s',RvsLibs_String::quoteSmart($productId . '-%')) : ''
, (strlen($productId) == 2)
? sprintf('(products_id LIKE %s
OR products_id LIKE %s
OR products_id LIKE %s
OR products_id LIKE %s)'
,RvsLibs_String::quoteSmart('%' . $productId . '%')
,RvsLibs_String::quoteSmart($productId[0] . "-" . substr($productId,1,strlen($productId)) . '%')
,RvsLibs_String::quoteSmart($productId . '-%')
,RvsLibs_String::quoteSmart('%-' . $productId)) : ''
, ((strlen($productId) == 3) || (strlen($productId) == 4) || (strlen($productId) == 5) || (strlen($productId) == 6))
? sprintf('(products_id LIKE %s
OR products_id LIKE %s
OR products_id LIKE %s
OR products_id LIKE %s)'
,RvsLibs_String::quoteSmart('%' . $productId . '%')
,RvsLibs_String::quoteSmart('%' . $productId[0] . "-" . substr($productId,1,strlen($productId)) . '%')
,RvsLibs_String::quoteSmart($productId[0] . $productId[1] . "-" . substr($productId,2,strlen($productId)) . '%')
,RvsLibs_String::quoteSmart('%-' . $productId)) : ''
, (strlen($productId) == 7)
? sprintf('(products_id LIKE %s
OR products_id LIKE %s)'
,RvsLibs_String::quoteSmart('%' . $productId[0] . "-" . RvsLibs_String::dbeSubstr($productId,1,strlen($productId)) . '%')
,RvsLibs_String::quoteSmart($productId[0] . $productId[1] . "-" . RvsLibs_String::dbeSubstr($productId,2,strlen($productId)) . '%')) : ''
, (strlen($productId) == 8)
? sprintf('(products_id LIKE %s)'
,RvsLibs_String::quoteSmart($productId[0] . $productId[1] . "-" . RvsLibs_String::dbeSubstr($productId,2,strlen($productId)) . '%')) : ''
, RvsLibs_String::quoteSmart('%' . $productFirst)
);
$oTemplateItem->query($query);
}
$aCloneData = array();
while ($oTemplateItem->fetch()) {
$aCloneData[] = clone($oTemplateItem);
}
return DbWrapper::fetchDatas($oTemplateItem->_resultFields, $aCloneData, $fetchMode);
}
/**
* get the first record for template_type_name
*
* @param unknown_type $templateID
* @return unknown
*/
function findTemplateTypeNameByTemplateId($templateID, $fetchMode='getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oTemplateType = DB_DataObject::factory($this->aConf['table']['rvs_template_type']);
if (is_null($templateID) === false) {
$query = sprintf("
SELECT
ty.template_type_name
FROM
%s as ty
,%s as tyx
WHERE
tyx.template_id = %s
AND tyx.template_type_id = ty.template_type_id"
,$this->aConf['table']['rvs_template_type']
,$this->aConf['table']['rvs_template_type_xref']
,RvsLibs_String::quoteSmart($templateID)
);
$oTemplateType->query($query);
}
$aCloneData = array();
while ($oTemplateType->fetch()) {
$aCloneData[] = clone($oTemplateType);
}
return DbWrapper::fetchDatas($oTemplateType->_resultFields, $aCloneData, $fetchMode);
}
/**
* @author duangdao.k
* @param $fetchMode
* @return array
*/
function findTemplateItemFolderAndTypePreviewByRandam($fetchMode='getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$oTemplateType = DB_DataObject::factory($this->aConf['table']['rvs_template_type']);
$query = sprintf("
SELECT
template_item_folder,
template_type_s_preview
FROM
%s
ORDER BY RAND()
"
, $this->aConf['table']['rvs_template_item']
);
$oTemplateType->query($query);
$aCloneData = array();
while ($oTemplateType->fetch()) {
$aCloneData[] = clone($oTemplateType);
}
return DbWrapper::fetchDatas($oTemplateType->_resultFields, $aCloneData, $fetchMode);
}
/// UPDATE ///
/**
* update template footer by $ownerUsrId in rvs_template_footer table
* Resulting SQL
* UPDATE
* rvs_template_footer
* SET
* created_by = {$createdBy}
* , powered_by = {$poweredBy}
* , powered_text = {$poweredText}
* , powered_url = {$poweredUrl}
* WHERE
* rvs_owner_usr_id = {$ownerUsrId}
*
* @author Pornthip Phothong
* @param $ownerUsrId
* @param $createdBy
* @param $poweredBy
* @param $poweredText
* @param $poweredUrl
* @form CreateByPowerByIconMgr.php
*/
public function updateTemplateFooterByOwnerUsrId($ownerUsrId, $createdBy, $poweredBy, $poweredText, $poweredUrl)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplateFooter = DB_DataObject::factory($this->aConf['table']['rvs_template_footer']);
$query = sprintf('
UPDATE
%s
SET
created_by = %s
, powered_by = %s
, powered_text = %s
, powered_url = %s
WHERE
rvs_owner_usr_id = %s
'
, $this->aConf['table']['rvs_template_footer']
, RvsLibs_String::quoteSmart($createdBy)
, RvsLibs_String::quoteSmart($poweredBy)
, RvsLibs_String::quoteSmart($poweredText)
, RvsLibs_String::quoteSmart($poweredUrl)
, RvsLibs_String::quoteSmart($ownerUsrId)
);
// optimize :nipaporn
return $oTemplateFooter->query($query);
}
/**
* Update modify template data
* @author Pharadol
* @param <string> $templateItemId
* @param <string> $newTemplateItemFolder
* @return <bool>
* form file DiyMain.php
*/
public function updatemodifyTemplateItemData($templateItemId = null, $newTemplateItemFolder = null)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplateFooter = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
if (!is_null($templateItemId) && !is_null($newTemplateItemFolder)) {
$query = sprintf('
UPDATE
%s
SET
template_item_folder = %s
WHERE
template_item_id = %s
'
, $this->aConf['table']['rvs_template_item']
, RvsLibs_String::quoteSmart($newTemplateItemFolder)
, RvsLibs_String::quoteSmart($templateItemId)
);
$res = $oTemplateFooter->query($query);
}
return (isset($res) && $res)? true : false;
}
/**
* Update modify template data
* @author Pharadol
* @param <string> $templateId
* @param <string> $navigatorId
* @param <string> $newMenustyleId
* @return bool
* form file DiyMgain.php
*/
public function updatemodifyTemplateItemData2($templateId, $navigatorId, $newMenustyleId)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplateFooter = DB_DataObject::factory($this->aConf['table']['rvs_template']);
$query = sprintf('
UPDATE
%s
SET
menustyle_id = %s
, navigator_id = %s
WHERE
template_id = %s
'
, $this->aConf['table']['rvs_template']
, RvsLibs_String::quoteSmart($newMenustyleId)
, RvsLibs_String::quoteSmart($navigatorId)
, RvsLibs_String::quoteSmart($templateId)
);
$res = $oTemplateFooter->query($query);
return (isset($res) && $res)? true : false;
}
/// DELETE ///
/**
* delete template by template_id and user_id in template table
* $query = "
* DELETE
* {$this->conf['table']['rvs_template']} as tp
* FROM
* {$this->conf['table']['rvs_template']} as tp
* , {$this->conf['table']['rvs_template_import']} as ti
* WHERE
* tp.template_id = ti.template_id
* AND tp.template_id = '$input->template_id'
* AND ti.rvs_usr_id = '$input->rvs_usr_id'
* ";
* $res = $this->dbh->query($query);
*
* @author Darawan Taorong
* @param string $templateId
* @param string $usrId
* @form EditDeleteTemplate.php , Fn: table_rvs_template
**/
public function deleteTemplateByTemplateIdAndUsrId($templateId = null, $usrId = null)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplate = DB_DataObject::factory($this->aConf['table']['rvs_template']);
if ( !is_null($templateId) && !is_null($usrId)){
$query = sprintf('
DELETE
FROM
%s
WHERE
template_id = %s
'
, $this->aConf['table']['rvs_template']
, RvsLibs_String::quoteSmart($templateId)
);
// optimize :nipaporn
return $oTemplate->query($query);
}
}
/** delete template_categories_xref by template_id and user_id in template table
* $query = "
* DELETE
* {$this->conf['table']['rvs_template_categories_xref']} as cx
* FROM
* {$this->conf['table']['rvs_template_categories_xref']} as cx
* , {$this->conf['table']['rvs_template_import']} as ti
* WHERE
* cx.template_id = ti.template_id
* AND tp.template_id = '$input->template_id'
* AND ti.rvs_usr_id = '$input->rvs_usr_id'
* ";
* $res = $this->dbh->query($query);
*
* @author Darawan Taorong
* @param string $templateId
* @param string $usrId
* @form EditDeleteTemplate.php , Fn: template_categories_xref
**/
public function deleteTemplateCategoriesXrefByTemplateIdAndUsrId($templateId = null, $usrId = null)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplate = DB_DataObject::factory($this->aConf['table']['rvs_template_categories_xref']);
if ( !is_null($templateId) && !is_null($usrId)){
/*
$query = sprintf('
DELETE
%s
FROM
%s cx
, %s ti
WHERE
cx.template_id = ti.template_id
AND cx.template_id = %s
AND ti.rvs_usr_id = %s
'
, $this->aConf['table']['rvs_template_categories_xref']
, $this->aConf['table']['rvs_template_categories_xref']
, $this->aConf['table']['rvs_template_import']
, RvsLibs_String::quoteSmart($templateId)
, RvsLibs_String::quoteSmart($usrId)
);
*/
$query = sprintf('
DELETE
FROM
%s
WHERE
template_id = %s
'
, $this->aConf['table']['rvs_template_categories_xref']
, RvsLibs_String::quoteSmart($templateId)
);
// optimize :nipaporn
return $oTemplate->query($query);
}
}
/** delete rvs_template_type_xref by template_id and user_id in template table
* $query = "
* DELETE
* {$this->conf['table']['rvs_template_type_xref']} as tx
* FROM
* {$this->conf['table']['rvs_template_type_xref']} as tx
* , {$this->conf['table']['rvs_template_import']} as ti
* WHERE
* tx.template_id = ti.template_id
* AND tx.template_id = '$input->template_id'
* AND ti.rvs_usr_id = '$input->rvs_usr_id'
* ";
* $res = $this->dbh->query($query);
*
* @author Darawan Taorong
* @param string $templateId
* @param string $usrId
* @form EditDeleteTemplate.php , Fn: table_rvs_template_type_xref
**/
public function deleteTemplateTypeXrefByTemplateIdAndUsrId($templateId = null, $usrId = null)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplate = DB_DataObject::factory($this->aConf['table']['rvs_template_type_xref']);
if ( !is_null($templateId) && !is_null($usrId)){
/*
$query = sprintf('
DELETE
%s tx
FROM
%s tx
, %s ti
WHERE
tx.template_id = ti.template_id
AND tx.template_id = %s
AND ti.rvs_usr_id = %s
'
, $this->aConf['table']['rvs_template_type_xref']
, $this->aConf['table']['rvs_template_type_xref']
, $this->aConf['table']['rvs_template_import']
, RvsLibs_String::quoteSmart($templateId)
, RvsLibs_String::quoteSmart($usrId)
);
*/
$query = sprintf('
DELETE
FROM
%s
WHERE
template_id = %s
'
, $this->aConf['table']['rvs_template_type_xref']
, RvsLibs_String::quoteSmart($templateId)
);
// optimize :nipaporn
return $oTemplate->query($query);
}
}
/** delete rvs_template_item by template_id and template_item_id and user_id in template table
* Resulting SQL
* DELETE
* {$this->conf['table']['rvs_template_item']} as tm
* FROM
* {$this->conf['table']['rvs_template_item']} as tm
* , {$this->conf['table']['rvs_template_import']} as ti
* WHERE
* tm.template_id = ti.template_id
* AND tm.template_id = '$input->template_id'
* AND tm.template_item_id = '$input->template_item_id'
* AND ti.rvs_usr_id = '$input->rvs_usr_id'
*
* @author Darawan Taorong
* @param string $templateId
* @param string $templateItemId
* @param string $usrId
* @form EditDeleteTemplate.php , Fn: table_rvs_template_item
**/
public function deleteTemplateItemByTemplateIdAndTemplateItemIdAndUsrId($templateId = null, $templateItemId = null, $usrId = null)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplate = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
if ( !is_null($templateId) && !is_null($templateItemId) && !is_null($usrId)){
$query = sprintf('
DELETE
FROM
%s
WHERE
template_id = %s
AND template_item_id = %s
'
, $this->aConf['table']['rvs_template_item']
, RvsLibs_String::quoteSmart($templateId)
, RvsLibs_String::quoteSmart($templateItemId)
);
// optimize :nipaporn
return $oTemplate->query($query);
}
}
/** delete rvs_template_item_navigator_color by template_item_id in rvs_template_item_navigator_color table
* Resulting SQL
* DELETE
* rvs_template_item_navigator_color
* FROM
* rvs_template_item_navigator_color}
* WHERE
* template_item_id = {$templateItemId}
*
* @author Darawan Taorong
* @param string $templateItemId
* @form EditDeleteTemplate.php , Fn: template_item_navigator_color
**/
public function deleteTemplateItemNavigatorColorByTemplateItemId( $templateItemId = null )
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplate = DB_DataObject::factory($this->aConf['table']['rvs_template_item_navigator_color']);
if ( !is_null($templateItemId) ){
$query = sprintf('
DELETE
%s
FROM
%s
WHERE
template_item_id = %s
'
, $this->aConf['table']['rvs_template_item_navigator_color']
, $this->aConf['table']['rvs_template_item_navigator_color']
, RvsLibs_String::quoteSmart($templateItemId)
);
// optimize :nipaporn
return $oTemplate->query($query);
}
}
public function findTemplateAndTemplateItemByTemplateItemId($templateItemId = null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$oTemplate = DB_DataObject::factory($this->aConf['table']['rvs_template']);
$oTemplateItem = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
/*
if(!is_null($templateItemId)) {
$oTemplateItem->template_item_id = $templateItemId;
}
$oTemplateItem->joinAdd($oTemplate);
$oTemplateItem->find();
*/
$query = sprintf('
SELECT
*
FROM
%s as tp
, %s as ti
WHERE
tp.template_id = ti.template_id
%s
'
, $this->aConf['table']['rvs_template']
, $this->aConf['table']['rvs_template_item']
, !is_null($templateItemId) ? sprintf(' AND ti.template_item_id = %s', RvsLibs_String::quoteSmart($templateItemId))
: ''
);
$oTemplate->query($query);
$aCloneData = array();
while ($oTemplate->fetch()) {
$aCloneData[]= clone($oTemplate);
}
return DbWrapper::fetchDatas($oTemplate->_resultFields, $aCloneData, $fetchMode);
}
public function findMenuStyleByMenuStyleId($menustyleId = null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$oMenustyle = DB_DataObject::factory($this->aConf['table']['rvs_menustyle']);
if (!is_null($menustyleId)) {
$oMenustyle->menustyle_id = $menustyleId;
}
$oMenustyle->find();
$aCloneData = array();
while ($oMenustyle->fetch()) {
$aCloneData[]= clone($oMenustyle);
}
DB_DataObject::debugLevel();
return DbWrapper::fetchDatas($oMenustyle->_resultFields, $aCloneData, $fetchMode);
}
public function backupsql($projectId, $usrId)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$aSQLData = array();
$aTemplate = array();
$aMenustyle = array();
$aTemplateId = array();
$aTemplateType = array();
$aTemplateItem = array();
$aTemplateItemId = array();
$aProjectInfoId = array();
$aMenustyleId = array();
$oTemplateTypeReference = array();
$aTemplateCategoryReference = array();
$aTemplateItemNavigatorColor = array();
/// Get Project info id By project_id
$aProjectInfoId = DaoFactory::Project()->findProjectInfoDataByProjectId($projectId, 'getDataObject');
if (count($aProjectInfoId) > 0 && !empty($aProjectInfoId[0]->template_item_id)) {
/// Backup table rvs_template_item
$aTemplateItem = DaoFactory::Template()->findTemplateItemByTemplateItemId($aProjectInfoId[0]->template_item_id, 'getDataObject');
foreach ($aTemplateItem as $k => $v) {
$aTemplateItemId[] = $v->template_item_id;
$aTemplateId[] = $v->template_id;
$aSQLData[] = DbWrapper::buildSQLFormat($v);
}
}
/// Backup table rvs_template_item_navigator_color
foreach ($aTemplateItemId as $templateItemId) {
$aTemplateItemNavigatorColor = DaoFactory::Template()->findTemplateItemNavigatorColorByTemplateItemId($templateItemId, 'getDataObject');
foreach ($aTemplateItemNavigatorColor as $k => $v) {
$aSQLData[] = DbWrapper::buildSQLFormat($v);
}
}
/// Backup table rvs_template
foreach ($aTemplateId as $templateId) {
$aTemplate = DaoFactory::Template()->findTemplateByTemplateId($templateId, 'getDataObject');
foreach ($aTemplate as $k => $v) {
$aMenustyleId[] = $v->menustyle_id;
$aSQLData[] = DbWrapper::buildSQLFormat($v);
}
}
/// Backup table rvs_menustyle
foreach ($aMenustyleId as $menustyleId) {
$aMenustyle = DaoFactory::Template()->findMenuStyleByMenuStyleId($menustyleId, 'getDataObject');
foreach ($aMenustyle as $k => $v) {
$aSQLData[] = DbWrapper::buildSQLFormat($v);
}
}
/// Backup table rvs_template_categories_xref
foreach ($aTemplateId as $templateId) {
$aTemplateCategoryReference = DaoFactory::Template()->findTemplateCategoryReferenceByTemplateId($templateId, 'getDataObject');
foreach ($aTemplateCategoryReference as $k => $v) {
$aSQLData[] = DbWrapper::buildSQLFormat($v);
}
}
/// Backup table rvs_template_type_xref
foreach ($aTemplateId as $templateId) {
$oTemplateTypeReference = DaoFactory::Template()->findTemplateTypeReferenceByTemplateId($templateId, 'getDataObject');
foreach ($oTemplateTypeReference as $k => $v) {
$aTemplateType[] = $v->template_type_id;
$aSQLData[] = DbWrapper::buildSQLFormat($v);
}
}
/// Backup table rvs_template_type
foreach ($aTemplateType as $templateType) {
$aTemplateType = DaoFactory::Template()->findTemplateTypeData('getDataObject', $aResultFields = array(), $templateType);
foreach ($aTemplateType as $k => $v) {
$aSQLData[] = DbWrapper::buildSQLFormat($v);
}
}
return $aSQLData;
}
public function deleteProjectOfUserId($projectId, $usrId, $aProjectPageId=array()) {
SGL::logMessage(null, PEAR_LOG_DEBUG);
}
/**
* find rvs_template By template_id <array>
* @author maythapon.p
* @param <array> $aTemplateId
* @param <string> $fetchMode
* @return <array>
*/
public function findTemplateByArrayTemplateId($aTemplateId, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$strId = (count($aTemplateId) > 1) ? implode("','", $aTemplateId) : implode('', $aTemplateId);
$oProject = DB_DataObject::factory($this->aConf['table']['rvs_template']);
if ( !is_null($aTemplateId) && is_array($aTemplateId) ) {
$query = sprintf ('
SELECT
*
FROM
%s
WHERE
template_id IN (\'%s\');',
$this->aConf['table']['rvs_template'],
$strId );
$oProject->query($query);
}
$aCloneData = array();
while ( $oProject->fetch() ) {
$aCloneData[] = clone($oProject);
}
return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
}
/**
* find rvs_template_item By template_id <array>
* @author maythapon.p
* @param <array> $aTemplateId
* @param <string> $fetchMode
* @return <array>
*/
public function findTemplateItemByArrayTemplateId($aTemplateId, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$strId = (count($aTemplateId) > 1) ? implode("','", $aTemplateId) : implode('', $aTemplateId);
$oProject = DB_DataObject::factory($this->aConf['table']['rvs_template_item']);
if ( !is_null($aTemplateId) && is_array($aTemplateId) ) {
$query = sprintf ('
SELECT
*
FROM
%s
WHERE
template_id IN (\'%s\');',
$this->aConf['table']['rvs_template_item'],
$strId );
$oProject->query($query);
}
$aCloneData = array();
while ( $oProject->fetch() ) {
$aCloneData[] = clone($oProject);
}
return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
}
/**
* find rvs_template_type_xref By template_id <array>
* @author maythapon.p
* @param <array> $aTemplateId
* @param <string> $fetchMode
* @return <array>
*/
public function findTemplateTypeXrefByArrayTemplateId($aTemplateId, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$strId = (count($aTemplateId) > 1) ? implode("','", $aTemplateId) : implode('', $aTemplateId);
$oProject = DB_DataObject::factory($this->aConf['table']['rvs_template_type_xref']);
if ( !is_null($aTemplateId) && is_array($aTemplateId) ) {
$query = sprintf ('
SELECT
*
FROM
%s
WHERE
template_id IN (\'%s\');',
$this->aConf['table']['rvs_template_type_xref'],
$strId );
$oProject->query($query);
}
$aCloneData = array();
while ( $oProject->fetch() ) {
$aCloneData[] = clone($oProject);
}
return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
}
/**rvs_picture
* find rvs_template_item_navigator_color By template_item_id <array>
* @author maythapon.p
* @param <array> $aTemplateItemId
* @param <string> $fetchMode
* @return <array>
*/
public function findTemplateItemNavigatorColorByArrayTemplateItemId($aTemplateItemId, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$strId = (count($aTemplateItemId) > 1) ? implode("','", $aTemplateItemId) : implode('', $aTemplateItemId);
$oProject = DB_DataObject::factory($this->aConf['table']['rvs_template_item_navigator_color']);
if ( !is_null($aTemplateItemId) && is_array($aTemplateItemId) ) {
$query = sprintf ('
SELECT
*
FROM
%s
WHERE
template_item_id IN (\'%s\');',
$this->aConf['table']['rvs_template_item_navigator_color'],
$strId );
$oProject->query($query);
}
$aCloneData = array();
while ( $oProject->fetch() ) {
$aCloneData[] = clone($oProject);
}
return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
}
/**findTemplateCategoryXrefByTemplateId
* find rvs_template_categories_xref By template_id <array>
* @author maythapon.p
* @param <array> $aTemplateItemId
* @param <string> $fetchMode
* @return <array>
*/
public function findTemplateCategoryXrefByTemplateId($aTemplateId, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$oProject = DB_DataObject::factory ( $this->aConf ['table'] ['rvs_template_categories_xref'] );
if ( !is_null($aTemplateId) ) {
$strId = (count($aTemplateId) > 1) ? implode("','", $aTemplateId) : implode('', $aTemplateId);
$query = sprintf ('
SELECT
*
FROM
%s
WHERE
template_id IN (\'%s\');',
$this->aConf['table']['rvs_template_categories_xref'],
$strId );
$oProject->query($query);
}
$aCloneData = array();
while ( $oProject->fetch() ) {
$aCloneData[] = clone($oProject);
}
return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
}
public function randTemplateItemDataByCategoryId($aTemplateId, $categoryId=7, $fetchMode = 'getRow')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$oProject = DB_DataObject::factory ( $this->aConf ['table'] ['rvs_template_item'] );
if ( !is_null($aTemplateId) ) {
$strId = (count($aTemplateId) > 1) ? implode("','", $aTemplateId) : implode('', $aTemplateId);
$query = sprintf ('
SELECT
ti.*
FROM
%s ti,
%s tc
WHERE
ti.template_id IN (\'%s\')
AND tc.rvs_category_id = %s
AND tc.template_id = ti.template_id
ORDER BY RAND()
LIMIT 1
;',
$this->aConf['table']['rvs_template_item'],
$this->aConf['table']['rvs_template_categories_xref'],
$strId,
RvsLibs_String::quoteSmart($categoryId)
);
$oProject->query($query);
}
$aCloneData = array();
while ( $oProject->fetch() ) {
$aCloneData[] = clone($oProject);
}
return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
}
/**
* build sql INSERT INTO rvs_template, rvs_template_item, rvs_template_type_xref By template_id <array>
* @author maythapon
* @param <array> $aTemplateId
* @return <array> $aSQLData
*/
public function backupsqlTemplateId($aTemplateId)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$aSQLData = array();
$aSQLData[] = "\n" . '-- rvs_template by template_id --' . "\n\n";
$aTemplate = $this->findTemplateByArrayTemplateId($aTemplateId, 'getDataObject');
foreach ($aTemplate as $oTemplateVal) {
$aSQLData[] = DbWrapper::buildSQLFormat($oTemplateVal);
}
$aSQLData[] = "\n" . '-- rvs_template_item by template_id --' . "\n\n";
$aTemplateItem = $this->findTemplateItemByArrayTemplateId($aTemplateId, 'getDataObject');
foreach ($aTemplateItem as $oTemplateItemVal) {
$aSQLData[] = DbWrapper::buildSQLFormat($oTemplateItemVal);
}
$aSQLData[] = "\n" . '-- rvs_template_categories_xref by template_id --' . "\n\n";
$aTemplateCategoryXref = $this->findTemplateCategoryXrefByTemplateId($aTemplateId, 'getDataObject');
foreach ($aTemplateCategoryXref as $oTemplateCategoryXrefVal) {
$aSQLData[] = DbWrapper::buildSQLFormat($oTemplateCategoryXrefVal);
}
$aSQLData[] = "\n" . '-- rvs_template_type_xref by template_id --' . "\n\n";
$aTemplateTypeXref = $this->findTemplateTypeXrefByArrayTemplateId($aTemplateId, 'getDataObject');
foreach ($aTemplateTypeXref as $oTemplateTypeXrefVal) {
$aSQLData[] = DbWrapper::buildSQLFormat($oTemplateTypeXrefVal);
}
return $aSQLData;
}
/**
* build sql INSERT INTO rvs_template_item_navigator_color By template_item_id <array>
* @author maythapon
* @param <array> $aTemplateItemId
* @return <array> $aSQLData
*/
public function backupsqlTemplateItemId($aTemplateItemId)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$aSQLData = array();
$aSQLData[] = "\n" . '-- rvs_template_item_navigator_color by template_item_id --' . "\n\n";
$aTemplateTypeXref = $this->findTemplateItemNavigatorColorByArrayTemplateItemId($aTemplateItemId, 'getDataObject');
foreach ($aTemplateTypeXref as $oTemplateTypeXrefVal) {
$aSQLData[] = DbWrapper::buildSQLFormat($oTemplateTypeXrefVal);
}
return $aSQLData;
}
}
?>
Copyright 2K16 - 2K18 Indonesian Hacker Rulez