Location: PHPKode > projects > Entier Studio > entierstudio/studio/classes/datas/data.RepositoryModelResource.php
<?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.RepositoryModelResource.php 94 2008-02-03 23:35:48Z yannromefort $
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefRepositoryModelResource")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefRepositoryModelResource", "1");
    //
    define(EXTFLAGKEY, 20);
    //-------------------------------------------------------------------------
    //	Include
    @require_once (FRAMEWORK_DIR . DATAROWOBJECT);
    @require_once (FRAMEWORK_DIR . "./filters/filter.forminput.php");
    @require_once (FRAMEWORK_DIR . "./validators/validator.identifier.php");
    //-------------------------------------------------------------------------
    //	Class
    class RepositoryModelResource extends DataRow {
        //---------------------------------------------------------------------
        //	Constructor
        /*
        *
        * @param	integer		RepositoryModelResource pkid		REPMRESPKID
        *
        */
        //
        function RepositoryModelResource($pkid = 0) {
            //
            $this->m_tableSet[PRIMARYKEY] = "tbl_repository_model_resource";
            //
            $this->m_indexSet[PRIMARYKEY] = "REPMRESPKID";
            $this->m_indexSet[FOREIGNKEY] = "REPCELEPKID";
            $this->m_indexSet[NATURALKEY] = "REPMRESNAME";
            //
            $this->m_fieldSet["REPMRESPKID"] = $pkid;
        }
        //---------------------------------------------------------------------
        //	Methods
        /*
        *
        * @access	protected
        *
        * @param	integer	index type
        */
        function getInsertQuery($indexType = FOREIGNKEY) {
            //
            $table = $this->m_tableSet[PRIMARYKEY];
            //
            $insertSQL = "INSERT INTO $table ( ";
            $valuesSQL = "VALUES ( ";
            //	REPMELTPKID = RepositoryModelResourceType Pkid
            $value = $this->m_fieldSet["REPMRETPKID"];
            if (!empty($value)) {
                $insertSQL.= " REPMRETPKID";
                $valuesSQL.= " $value";
            } else {
                $this->m_errorSet["REPMRETPKID"] = true;
                return ("");
            }
            //	DIRRESOPKID = DirectoryResource Pkid
            $value = $this->m_fieldSet["DIRRESOPKID"];
            if (!empty($value)) {
                $insertSQL.= " ,DIRRESOPKID";
                $valuesSQL.= " ,$value";
            } else {
                $this->m_errorSet["DIRRESOPKID"] = true;
                return ("");
            }
            //	REPCELEPKID = RepositoryCoreElementType Pkid
            $value = $this->m_fieldSet["REPCELEPKID"];
            if (!empty($value)) {
                $insertSQL.= " ,REPCELEPKID";
                $valuesSQL.= " ,$value";
            } else {
                $this->m_errorSet["REPCELEPKID"] = true;
                return ("");
            }
            //	REPMRESLINK = RepositoryModelResource reflection link
            $value = $this->m_fieldSet["REPMRESLINK"];
            switch ($indexType) {
                case FOREIGNKEY:
                    // @mock isRoot==true && hasChild==false
                    if (!empty($value)) {
                        $this->m_errorSet["REPMRESLINK"] = true;
                        return ("");
                    }
                    //
                    
                break;
                case REFLECTKEY:
                    //
                    if (empty($value)) {
                        $this->m_errorSet["REPMRESLINK"] = true;
                        return ("");
                    }
                    //
                    
                break;
            }
            if (!empty($value)) {
                $insertSQL.= " ,REPMRESLINK";
                $valuesSQL.= " ,$value";
            }
            //	REPMRESNAME = RepositoryModelResource name
            $value = FilterFormInput::filter($this->m_fieldSet["REPMRESNAME"]);
            if (!empty($value)) {
                $insertSQL.= " ,REPMRESNAME";
                $valuesSQL.= " ,$value";
            } else {
                $this->m_errorSet["REPMRESNAME"] = true;
                return ("");
            }
            //	REPMRESFLAG = RepositoryModelResource extension string
            $value = @trim($this->m_fieldSet["REPMRESFLAG"]);
            if (!empty($value)) {
                $insertSQL.= " ,REPMRESFLAG";
                $valuesSQL.= " ,\"$value\"";
            } else {
                $this->m_errorSet["REPMRESFLAG"] = true;
                return ("");
            }
            //	REPMRESCODE = RepositoryModelResource identifier
            $value = @trim($this->m_fieldSet["REPMRESCODE"]);
            if (ValidatorIdentifier::isValid($value)) {
                $insertSQL.= " ,REPMRESCODE";
                $valuesSQL.= " ,\"$value\"";
            } else {
                $this->m_errorSet["REPMRESCODE"] = true;
                return ("");
            }
            //	REPMRESTEXT = RepositoryModelResource description
            $value = FilterFormInput::filter($this->m_fieldSet["REPMRESTEXT"], true);
            if (!empty($value)) {
                $insertSQL.= " ,REPMRESTEXT";
                $valuesSQL.= " ,$value";
            }
            //	REPMRESINAM = RepositoryModelResource instancier
            $value = @trim($this->m_fieldSet["REPMRESINAM"]);
            if (ValidatorIdentifier::isValid($value)) {
                $insertSQL.= " ,REPMRESINAM";
                $valuesSQL.= " ,\"$value\"";
            }
            //	REPMRESRANK = RepositoryModelResource rank
            $value = $this->m_fieldSet["REPMRESRANK"];
            if (!empty($value)) {
                $insertSQL.= " ,REPMRESRANK";
                $valuesSQL.= " ,$value";
            }
            //	REPMRESDATE = RepositoryModelResource date
            $value = Date("Y-m-d H:i:s");
            $insertSQL.= " ,REPMRESDATE";
            $valuesSQL.= " ,\"$value\"";
            //	REPMRESSTAT = RepositoryModelResource status
            $value = 1;
            $insertSQL.= " ,REPMRESSTAT";
            $valuesSQL.= " ,$value";
            //	REPMRESTYPE = RepositoryModelResource type
            $value = $this->m_fieldSet["REPMRESTYPE"];
            if (!empty($value)) {
                $insertSQL.= " ,REPMRESTYPE";
                $valuesSQL.= " ,$value";
            }
            //
            return ($insertSQL . ") " . $valuesSQL . ")");
        }
        /**
         *
         * @access	protected
         *
         * @param	integer	index type
         */
        function getUpdateQuery($indexType = PRIMARYKEY) {
            //
            $table = $this->m_tableSet[PRIMARYKEY];
            //
            switch ($indexType) {
                case PRIMARYKEY:
                    /*
                    *	UPDATE
                    *			tbl_repository_model_resource
                    *	ON
                    *			REPMRESPKID
                    *
                    */
                    //
                    $field = $this->m_indexSet[PRIMARYKEY];
                    $index = $this->m_fieldSet["$field"];
                    if ($index != 0) {
                        //
                        $updateSQL = "UPDATE $table SET ";
                        //	REPMRESNAME = RepositoryModelResource name
                        $value = FilterFormInput::filter($this->m_fieldSet["REPMRESNAME"]);
                        if (!empty($value)) $updateSQL.= " REPMRESNAME=$value";
                        else {
                            $this->m_errorSet["REPMRESNAME"] = true;
                            return ("");
                        }
                        //	REPMRESCODE = RepositoryModelResource identifier
                        $value = @trim($this->m_fieldSet["REPMRESCODE"]);
                        if (ValidatorIdentifier::isValid($value)) $updateSQL.= ",REPMRESCODE=\"$value\"";
                        else {
                            $this->m_errorSet["REPMRESCODE"] = true;
                            return ("");
                        }
                        //	REPMRESFLAG = RepositoryModelResource identifier
                        $value = @trim($this->m_fieldSet["REPMRESFLAG"]);
                        if (!empty($value)) $updateSQL.= ",REPMRESFLAG=\"$value\"";
                        else {
                            $this->m_errorSet["REPMRESFLAG"] = true;
                            return ("");
                        }
                        //	REPMRESTEXT = RepositoryModelResource description
                        $value = FilterFormInput::filter($this->m_fieldSet["REPMRESTEXT"], true);
                        $updateSQL.= ",REPMRESTEXT=$value";
                        //	REPMRESINAM = RepositoryModelResource description
                        $value = @trim($this->m_fieldSet["REPMRESINAM"]);
                        if (ValidatorIdentifier::isValid($value) || empty($value)) $updateSQL.= ",REPMRESINAM=\"$value\"";
                        //	REPMRESRANK = RepositoryModelResource status
                        $value = $this->m_fieldSet["REPMRESRANK"];
                        $updateSQL.= ",REPMRESRANK=$value";
                        //	REPMRESSTAT = RepositoryModelResource status
                        $value = $this->m_fieldSet["REPMRESSTAT"];
                        $updateSQL.= ",REPMRESSTAT=$value";
                        //
                        return ($updateSQL . " WHERE $field=$index");
                    }
                    break;
                case DISPLAYKEY:
                    /*
                    *	UPDATE
                    *			tbl_repository_model_resource
                    *	SET
                    *			REPMRESCODE='REPMRESPKID"
                    *			REPMRESSTAT=0
                    *	ON
                    *			REPMRESPKID
                    *
                    */
                    //
                    $field = $this->m_indexSet[PRIMARYKEY];
                    $index = $this->m_fieldSet["$field"];
                    if ($index != 0) return ("UPDATE $table 
								SET 
									REPMRESCODE='$index', 
									REPMRESSTAT=0 
								WHERE 
									$field=$index 
								AND 
									REPMRESSTAT=1");
                break;
            }
            //
            return ("");
        }
        /*
        *
        * @access	protected
        *
        * @param	integer	index type
        */
        function getSelectQuery($indexType = PRIMARYKEY) {
            //
            $table = $this->m_tableSet[PRIMARYKEY];
            //
            switch ($indexType) {
                case PRIMARYKEY:
                    /*
                    *	SELECT
                    *			tbl_repository_model_resource
                    *		<-> tbl_repository_core_element
                    *		<-> tbl_repository_model_resource_type
                    *	ON
                    *		REPCELEPKID
                    *
                    * @see
                    *
                    */
                    //
                    $index = $this->m_fieldSet["REPMRESPKID"];
                    if ($index != 0) return ("SELECT 
								t1.*,
								t2.REPOSITPKID,
								t2.REPCELTPKID,
								t2.REPCELENAME,
								t3.REPMELTPKID,
								t3.REPMRETNAME, 
								t3.REPMRETCODE 
							FROM 
								tbl_repository_model_resource as t1, 
								tbl_repository_core_element as t2, 
								tbl_repository_model_resource_type as t3
							WHERE 
								t1.REPMRESPKID=$index 
							AND 
								t1.REPMRESSTAT<>0 
							AND 
								t1.REPCELEPKID=t2.REPCELEPKID 
							AND 
								t2.REPCELESTAT<>0 
							AND
								t1.REPMRETPKID=t3.REPMRETPKID");
                    break;
                case EXTFLAGKEY:
                    /*
                    *	SELECT
                    *			tbl_repository_model_resource
                    *		<-> tbl_repository_core_element
                    *		<-> tbl_repository_model_resource_type
                    *	ON
                    *		REPMRESFLAG
                    *
                    */
                    //
                    $index = $this->m_fieldSet["REPMRESFLAG"];
                    if ($index != "") return ("SELECT 
								t1.*, 
								t2.REPOSITPKID, 
								t2.REPCELTPKID,
								t2.REPCELENAME, 
								t3.REPMELTPKID, 
								t3.REPMRETNAME,
								t3.REPMRETCODE,
								t4.OBJETYPPKID
							FROM 
								tbl_repository_model_resource as t1, 
								tbl_repository_core_element as t2, 
								tbl_repository_model_resource_type as t3,
								tbl_repository_model_element_type as t4 
							WHERE 
								t1.REPMRESFLAG='$index' 
							AND 
								t1.REPMRESSTAT<>0 
							AND 
								t1.REPCELEPKID=t2.REPCELEPKID 
							AND 
								t2.REPCELESTAT<>0 
							AND 
								t1.REPMRETPKID=t3.REPMRETPKID
							AND
								t3.REPMELTPKID=t4.REPMELTPKID");
                    break;
                }
            //
            return ("");
        }
    };
    //	Class
    //-------------------------------------------------------------------------       
}
//	namespace
//-----------------------------------------------------------------------------    
?>
Return current item: Entier Studio