<?php
/**
* Entier Studio
*
* LICENSE
*
* Copyright 2006 Entier Studio team.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package entier.studio
* @copyright Copyright (c) 2006 Entier Studio team. All rights reserved.
* @version $Id: data.RepositoryCoreElement.php 90 2008-01-31 22:02:05Z yannromefort $
*/
//-----------------------------------------------------------------------------
// namespace
if (!defined("DefRepositoryCoreElement")) {
//-------------------------------------------------------------------------
// Define
define("DefRepositoryCoreElement", "1");
//-------------------------------------------------------------------------
// Include
@require_once (FRAMEWORK_DIR . DATAROWOBJECT);
@require_once (FRAMEWORK_DIR . "./filters/filter.forminput.php");
@require_once (FRAMEWORK_DIR . "./validators/validator.identifier.php");
//-------------------------------------------------------------------------
// Class
class RepositoryCoreElement extends DataRow {
//---------------------------------------------------------------------
// Constructor
/**
*
* @param integer pkid REPCELEPKID Repository core element // primary key
*
*/
function RepositoryCoreElement($REPCELEPKID = 0) {
//
$this->m_tableSet[PRIMARYKEY] = "tbl_repository_core_element";
//
$this->m_indexSet[PRIMARYKEY] = "REPCELEPKID";
$this->m_indexSet[FOREIGNKEY] = "REPCELTPKID";
$this->m_indexSet[NATURALKEY] = "REPCELENAME";
//
$this->m_fieldSet["REPCELEPKID"] = $REPCELEPKID;
}
//---------------------------------------------------------------------
// Methods
/**
*
* @param integer index type
* @return string
*/
function getInsertQuery($indexType = FOREIGNKEY) {
//
$table = $this->m_tableSet[PRIMARYKEY];
//
$insertSQL = "INSERT INTO $table ( ";
$valuesSQL = "VALUES ( ";
// REPOSITPKID = Repository pkid (foreign key)
$value = $this->m_fieldSet["REPOSITPKID"];
if (!empty($value)) {
$insertSQL.= " REPOSITPKID";
$valuesSQL.= " $value";
} else {
$this->m_errorSet["REPOSITPKID"] = true;
return ("");
}
// REPCELTPKID = RepositoryCoreElementType pkid (foreign key)
$value = $this->m_fieldSet["REPCELTPKID"];
if (!empty($value)) {
$insertSQL.= " ,REPCELTPKID";
$valuesSQL.= " ,$value";
} else {
$this->m_errorSet["REPCELTPKID"] = true;
return ("");
}
// REPCELENAME = RepositoryCoreElement name
$value = FilterFormInput::filter($this->m_fieldSet["REPCELENAME"]);
if (!empty($value)) {
$insertSQL.= " ,REPCELENAME";
$valuesSQL.= " ,$value";
} else {
$this->m_errorSet["REPCELENAME"] = true;
return ("");
}
// REPCELETEXT = RepositoryCoreElement description
$value = FilterFormInput::filter($this->m_fieldSet["REPCELETEXT"], true);
if (!empty($value)) {
$insertSQL.= " ,REPCELETEXT";
$valuesSQL.= " ,$value";
}
// REPCELECODE = RepositoryCoreElement identifier
$value = @trim($this->m_fieldSet["REPCELECODE"]);
if (ValidatorIdentifier::isValid($value)) {
$insertSQL.= " ,REPCELECODE";
$valuesSQL.= " ,\"$value\"";
} else {
$this->m_errorSet["REPCELECODE"] = true;
return ("");
}
// REPCELEDATE = RepositoryCoreElement creation date
$value = Date("Y-m-d H:i:s");
$insertSQL.= " ,REPCELEDATE";
$valuesSQL.= " ,\"$value\"";
// REPCELESTAT = RepositoryCoreElement status
$value = 1;
$insertSQL.= " ,REPCELESTAT";
$valuesSQL.= " ,$value";
// REPCELETYPE = RepositoryCoreElement type
$value = $this->m_fieldSet["REPCELETYPE"];
if (!empty($value)) {
$insertSQL.= " ,REPCELETYPE";
$valuesSQL.= " ,$value";
}
//
return ($insertSQL . ") " . $valuesSQL . ")");
}
/**
*
* @param integer index type
* @return string
*/
function getUpdateQuery($indexType = PRIMARYKEY) {
//
$table = $this->m_tableSet[PRIMARYKEY];
//
switch ($indexType) {
case PRIMARYKEY:
/*
* UPDATE
* tbl_repository_core_element
* ON
* REPCELEPKID
*
*/
//
$field = $this->m_indexSet[PRIMARYKEY];
$index = $this->m_fieldSet["$field"];
//
if ($index != 0) {
//
$updateSQL = "UPDATE $table SET ";
// REPCELENAME = RepositoryCoreElement name
$value = FilterFormInput::filter($this->m_fieldSet["REPCELENAME"]);
if (!empty($value))
$updateSQL.= " REPCELENAME=$value";
else {
$this->m_errorSet["REPCELENAME"] = true;
return ("");
}
// REPCELECODE = RepositoryCoreElement identifier
$value = @trim($this->m_fieldSet["REPCELECODE"]);
if (ValidatorIdentifier::isValid($value))
$updateSQL.= ",REPCELECODE=\"$value\"";
else {
$this->m_errorSet["REPCELECODE"] = true;
return ("");
}
// REPCELETEXT = RepositoryCoreElement description
$value = FilterFormInput::filter($this->m_fieldSet["REPCELETEXT"], true);
$updateSQL.= ",REPCELETEXT=$value";
// REPCELESTAT = RepositoryCoreElement status
$value = $this->m_fieldSet["REPCELESTAT"];
$updateSQL.= ",REPCELESTAT=$value";
//
return ($updateSQL . " WHERE $field=$index");
}
break;
case DISPLAYKEY:
/*
* UPDATE
* tbl_repository_core_element
* SET
* REPCELECODE='~REPCELECODE'
* REPCELESTAT=0
* ON
* REPCELEPKID
*
*/
//
$field = $this->m_indexSet[PRIMARYKEY];
$index = $this->m_fieldSet["$field"];
if ($index != 0) return ("UPDATE
$table
SET
REPCELECODE= CONCAT('~', REPCELECODE, '$index' ),
REPCELESTAT=0
WHERE
$field=$index
AND
REPCELESTAT=1");
//
break;
}
//
return ("");
}
/**
*
* @param integer index type
* @return string
*/
function getSelectQuery($indexType = PRIMARYKEY) {
//
switch ($indexType) {
case PRIMARYKEY:
/*
*
* SELECT
* tbl_repository_core_element as t1
* <-> tbl_repository_core_element_type as t2
* ON REPCELEPKID
*
*/
//
$field = $this->m_indexSet["$indexType"];
$index = $this->m_fieldSet["$field"];
if ($index != 0) return ("SELECT
t1.*,
t2.REPCELTNAME,
t2.REPCELTTYPE
FROM
tbl_repository_core_element as t1,
tbl_repository_core_element_type as t2
WHERE
t1.REPCELEPKID=$index
AND
t1.REPCELESTAT>0
AND
t1.REPCELTPKID=t2.REPCELTPKID");
//
break;
}
//
return ("");
}
};
// Class
//-------------------------------------------------------------------------
}
// namespace
//-----------------------------------------------------------------------------
?>