<?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.DirectoryResource.php 81 2008-01-17 23:08:21Z yannromefort $
*/
//-----------------------------------------------------------------------------
// namespace
if (!defined("DefDirectoryResource")) {
//-------------------------------------------------------------------------
// Define
define("DefDirectoryResource", "1");
//-------------------------------------------------------------------------
// Include
@require_once (FRAMEWORK_DIR . DATAROWOBJECT);
@require_once (FRAMEWORK_DIR . "./filters/filter.forminput.php");
//-------------------------------------------------------------------------
// Class
class DirectoryResource extends DataRow {
//---------------------------------------------------------------------
// Constructor
/**
*
* @param integer pkid DirectoryResource OBJRESOPKID // primary key
*
*/
function DirectoryResource($DIRRESOPKID = 0) {
//
$this->m_tableSet[PRIMARYKEY] = "tbl_directory_resource";
//
$this->m_indexSet[PRIMARYKEY] = "DIRRESOPKID";
$this->m_indexSet[FOREIGNKEY] = "DIRRESTPKID";
$this->m_indexSet[NATURALKEY] = "DIRRESONAME";
//
$this->m_fieldSet["DIRRESOPKID"] = $DIRRESOPKID;
}
//-------------------------------------------------------------------------
// Methods
/**
*
* @param integer index type
* @return string
*/
function getInsertQuery($indexType = FOREIGNKEY) {
//
$table = $this->m_tableSet[PRIMARYKEY];
//
$insertSQL = "INSERT INTO $table ( ";
$valuesSQL = "VALUES ( ";
// DIRECTOPKID = Directory (foreign key)
$value = $this->m_fieldSet["DIRECTOPKID"];
if (!empty($value)) {
$insertSQL.= " DIRECTOPKID";
$valuesSQL.= " $value";
} else {
$this->m_errorSet["DIRECTOPKID"] = true;
return ("");
}
// DIRRESTPKID DirectoryResource Type (foreign key)
$value = $this->m_fieldSet["DIRRESTPKID"];
if (!empty($value)) {
$insertSQL.= " ,DIRRESTPKID";
$valuesSQL.= " ,$value";
} else {
$this->m_errorSet["DIRRESTPKID"] = true;
return ("");
}
// DIRRESOPKID = DirectoryResourceAccess (foreign key)
$value = $this->m_fieldSet["DIRRACCPKID"];
if (!empty($value)) {
$insertSQL.= " ,DIRRACCPKID";
$valuesSQL.= " ,$value";
} else {
$this->m_errorSet["DIRRACCPKID"] = true;
return ("");
}
// DIRRESONAME = DirectoryResource name
$value = FilterFormInput::filter($this->m_fieldSet["DIRRESONAME"]);
if (!empty($value)) {
$insertSQL.= " ,DIRRESONAME";
$valuesSQL.= " ,$value";
} else {
$this->m_errorSet["DIRRESONAME"] = true;
return ("");
}
// DIRRESOTEXT = DirectoryResource description
$value = FilterFormInput::filter($this->m_fieldSet["DIRRESOTEXT"], true);
if (!empty($value)) {
$insertSQL.= " ,DIRRESOTEXT";
$valuesSQL.= " ,$value";
}
// DIRRESODATE = DirectoryResource creation date
$value = Date("Y-m-d H:i:s");
$insertSQL.= " ,DIRRESODATE";
$valuesSQL.= " ,\"$value\"";
// DIRRESOSTAT = DirectoryResource status
$value = 1;
$insertSQL.= " ,DIRRESOSTAT";
$valuesSQL.= " ,$value";
// DIRRESOTYPE = DirectoryResource type
$value = $this->m_fieldSet["DIRRESOTYPE"];
if (!empty($value)) {
$insertSQL.= " ,DIRRESOTYPE";
$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_directory_resource
* ON
* DIRRESOPKID
*
*/
//
$field = $this->m_indexSet[PRIMARYKEY];
$index = $this->m_fieldSet["$field"];
if ($index != 0) {
//
$updateSQL = "UPDATE $table SET ";
// DIRRACCPKID = DirectoryResource Access Type
$value = $this->m_fieldSet["DIRRACCPKID"];
if (!empty($value)) $updateSQL.= " DIRRACCPKID=$value";
else {
$this->m_errorSet["DIRRACCPKID"] = true;
return ("");
}
// DIRRESONAME = DirectoryResource name
$value = FilterFormInput::filter($this->m_fieldSet["DIRRESONAME"]);
if (!empty($value)) $updateSQL.= ",DIRRESONAME=$value";
else {
$this->m_errorSet["DIRRESONAME"] = true;
return ("");
}
// DIRRESOTEXT = DirectoryResource description
$value = FilterFormInput::filter($this->m_fieldSet["DIRRESOTEXT"], true);
$updateSQL.= ",DIRRESOTEXT=$value";
// DIRRESOSTAT = DirectoryResource status
$value = $this->m_fieldSet["DIRRESOSTAT"];
$updateSQL.= ",DIRRESOSTAT=$value";
//
return ($updateSQL . " WHERE $field=$index");
}
break;
case DISPLAYKEY:
/*
* UPDATE
* tbl_directory_resource
* SET
* DIRRESONAME='DIRRESOPKID'
* DIRRESOSTAT=0
* ON
* DIRRESOPKID
*
*/
//
$field = $this->m_indexSet[PRIMARYKEY];
$index = $this->m_fieldSet["$field"];
if ($index != 0) return ("UPDATE $table
SET
DIRRESONAME= CONCAT('~', DIRRESONAME, '$index' ),
DIRRESOSTAT=0
WHERE
$field=$index
AND
DIRRESOSTAT=1");
break;
}
//
return ("");
}
/**
*
* @param integer index type
* @return string
*/
function getSelectQuery($indexType = PRIMARYKEY) {
//
switch ($indexType) {
case PRIMARYKEY:
/*
*
* SELECT
* tbl_directory_resource as t1
* <-> tbl_directory_resource_access as t2
* ON
* DIRRESOPKID
*
*/
//
$field = $this->m_indexSet["$indexType"];
$index = $this->m_fieldSet["$field"];
if ($index != 0) return ("SELECT
t1.*,
t2.DIRRACCNAME,
t2.DIRRACCCODE
FROM
tbl_directory_resource as t1,
tbl_directory_resource_access as t2
WHERE
t1.DIRRESOPKID=$index
AND
t1.DIRRESOSTAT>0
AND
t1.DIRRACCPKID=t2.DIRRACCPKID");
break;
}
//
return ("");
}
};
// Class
//-------------------------------------------------------------------------
}
// namespace
//-----------------------------------------------------------------------------
?>