Location: PHPKode > projects > Entier Studio > entierstudio/studio/classes/datas/data.ObjectoryElement.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.ObjectoryElement.php 81 2008-01-17 23:08:21Z yannromefort $
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefObjectoryElement")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefObjectoryElement", "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 ObjectoryElement extends DataRow {
        //---------------------------------------------------------------------
        //	Constructor
        
        /**
         *
         * @param	integer	ObjectoryElement	$OBJELEMPKID	primary key
         *
         */
        function ObjectoryElement($OBJELEMPKID = 0) {
            //
            $this->m_tableSet[PRIMARYKEY] = "tbl_objectory_element";
            //
            $this->m_indexSet[PRIMARYKEY] = "OBJELEMPKID";
            $this->m_indexSet[FOREIGNKEY] = "OBJECTOPKID";
            $this->m_indexSet[NATURALKEY] = "OBJELEMNAME";
            $this->m_indexSet[REFLECTKEY] = "OBJELEMLINK";
            //
            $this->m_fieldSet["OBJELEMPKID"] = $OBJELEMPKID;
        }
        //---------------------------------------------------------------------
        //	Methods
        
        /**
         *
         * @param	integer	 index type
         * @return	string
         */
        function getInsertQuery($indexType = FOREIGNKEY) {
            //
            $table = $this->m_tableSet[PRIMARYKEY];
            //
            $insertSQL = "INSERT INTO $table ( ";
            $valuesSQL = "VALUES ( ";
            //	OBJECTOPKID Objectory
            $value = $this->m_fieldSet["OBJECTOPKID"];
            if (!empty($value)) {
                $insertSQL.= "  OBJECTOPKID";
                $valuesSQL.= "  $value";
            } else {
                $this->m_errorSet["OBJECTOPKID"] = true;
                return ("");
            }
            //	OBJETYPPKID ObjectoryElementType
            $value = $this->m_fieldSet["OBJETYPPKID"];
            if (!empty($value)) {
                $insertSQL.= " ,OBJETYPPKID";
                $valuesSQL.= " ,$value";
            } else {
                $this->m_errorSet["OBJETYPPKID"] = true;
                return ("");
            }
            //	OBJELEMROOT ObjectoryElement root key
            $value = $this->m_fieldSet["OBJELEMROOT"];
            switch ($indexType) {
                case FOREIGNKEY:
                    // @mock isRoot==true && hasRoot==false
                    if (!empty($value)) {
                        $this->m_errorSet["OBJELEMROOT"] = true;
                        return ("");
                    }
                    //
                    
                break;
                case REFLECTKEY:
                    // @mock isChild==true && hasRoot==true
                    if (empty($value)) {
                        $this->m_errorSet["OBJELEMROOT"] = true;
                        return ("");
                    }
                    //
                    
                break;
            }
            if (!empty($value)) {
                $insertSQL.= " ,OBJELEMROOT";
                $valuesSQL.= " ,$value";
            }
            //	OBJELEMLINK ObjectoryElement reflection key
            $value = $this->m_fieldSet["OBJELEMLINK"];
            switch ($indexType) {
                case FOREIGNKEY:
                    // @mock isRoot==true && hasChild==false
                    if (!empty($value)) {
                        $this->m_errorSet["OBJELEMLINK"] = true;
                        return ("");
                    }
                    //
                    
                break;
                case REFLECTKEY:
                    // @mock isChild==true && hasParent==true
                    if (empty($value)) {
                        $this->m_errorSet["OBJELEMLINK"] = true;
                        return ("");
                    }
                    //
                    
                break;
            }
            if (!empty($value)) {
                $insertSQL.= " ,OBJELEMLINK";
                $valuesSQL.= " ,$value";
            }
            // OBJELEMNAME ObjectoryElement name
            $value = FilterFormInput::filter($this->m_fieldSet["OBJELEMNAME"]);
            if (!empty($value)) {
                $insertSQL.= " ,OBJELEMNAME";
                $valuesSQL.= " ,$value";
            } else {
                $this->m_errorSet["OBJELEMNAME"] = true;
                return ("");
            }
            // OBJELEMCODE ObjectoryElement identifier
            $value = @trim($this->m_fieldSet["OBJELEMCODE"]);
            if (ValidatorIdentifier::isValid($value)) {
                $insertSQL.= " ,OBJELEMCODE";
                $valuesSQL.= " ,\"$value\"";
            } else {
                $this->m_errorSet["OBJELEMCODE"] = true;
                return ("");
            }
            // OBJELEMTEXT ObjectoryElement description
            $value = FilterFormInput::filter($this->m_fieldSet["OBJELEMTEXT"], true);
            if (!empty($value)) {
                $insertSQL.= " ,OBJELEMTEXT";
                $valuesSQL.= " ,$value";
            }
            // OBJELEMINAM ObjectoryElement instance name
            $value = @trim($this->m_fieldSet["OBJELEMINAM"]);
            if (ValidatorIdentifier::isValid($value)) {
                $insertSQL.= " ,OBJELEMINAM";
                $valuesSQL.= " ,\"$value\"";
            }
            // OBJELEMRANK ObjectoryElement rank number
            $value = $this->m_fieldSet["OBJELEMRANK"];
            if (!empty($value)) {
                $insertSQL.= " ,OBJELEMRANK";
                $valuesSQL.= " ,$value";
            }
            // OBJELEMDATE ObjectoryElement creation date
            $value = Date("Y-m-d H:i:s");
            $insertSQL.= " ,OBJELEMDATE";
            $valuesSQL.= " ,\"$value\"";
            // OBJELEMSTAT ObjectoryElement status
            $value = 1;
            $insertSQL.= " ,OBJELEMSTAT";
            $valuesSQL.= " ,$value";
            // OBJELEMTYPE ObjectoryElement type
            $value = $this->m_fieldSet["OBJELEMTYPE"];
            if (!empty($value)) {
                $insertSQL.= " ,OBJELEMTYPE";
                $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_objectory_element
                    *	ON
                    *			OBJELEMPKID
                    *
                    */
                    //
                    $field = $this->m_indexSet[PRIMARYKEY];
                    $index = $this->m_fieldSet["$field"];
                    //
                    if ($index != 0) {
                        //
                        $updateSQL = "UPDATE $table SET ";
                        // OBJELEMNAME ObjectoryElement name
                        $value = FilterFormInput::filter($this->m_fieldSet["OBJELEMNAME"]);
                        if (!empty($value)) $updateSQL.= " OBJELEMNAME=$value";
                        else {
                            $this->m_errorSet["OBJELEMNAME"] = true;
                            return ("");
                        }
                        //	OBJELEMLINK ObjectoryElement reflection key
                        $value = $this->m_fieldSet["OBJELEMLINK"];
                        if (!empty($value)) $updateSQL.= ",OBJELEMLINK=$value";
                        else {
                            if ($this->m_fieldSet["OBJETYPPKID"] != MODEL_TYPE) {
                                $this->m_errorSet["OBJELEMLINK"] = true;
                                return ("");
                            }
                        }
                        // OBJELEMCODE ObjectoryElement identifier
                        $value = @trim($this->m_fieldSet["OBJELEMCODE"]);
                        if (ValidatorIdentifier::isValid($value)) $updateSQL.= ",OBJELEMCODE=\"$value\"";
                        else {
                            $this->m_errorSet["OBJELEMCODE"] = true;
                            return ("");
                        }
                        // OBJELEMINAM ObjectoryElement instance name
                        $value = @trim($this->m_fieldSet["OBJELEMINAM"]);
                        if (ValidatorIdentifier::isValid($value)) $updateSQL.= ",OBJELEMINAM=\"$value\"";
                        // OBJELEMTEXT ObjectoryElement description
                        $value = FilterFormInput::filter($this->m_fieldSet["OBJELEMTEXT"], true);
                        $updateSQL.= ",OBJELEMTEXT=$value";
                        // OBJELEMRANK ObjectoryElement rank number
                        $value = $this->m_fieldSet["OBJELEMRANK"];
                        if (!empty($value)) $updateSQL.= ",OBJELEMRANK=$value";
                        // OBJELEMSTAT ObjectoryElement status
                        $value = $this->m_fieldSet["OBJELEMSTAT"];
                        $updateSQL.= ",OBJELEMSTAT=$value";
                        //
                        return ($updateSQL . " WHERE $field=$index");
                    }
                    break;
                case DISPLAYKEY:
                    /*
                    *	UPDATE
                    *			tbl_objectory_element
                    *	SET
                    *			OBJELEMCODE='~OBJELEMCODE'
                    *			OBJELEMSTAT=0
                    *	ON
                    *			OBJELEMPKID
                    *
                    */
                    //
                    $field = $this->m_indexSet[PRIMARYKEY];
                    $index = $this->m_fieldSet["$field"];
                    if ($index != 0) return ("UPDATE 
									$table 
								SET 
									OBJELEMCODE= CONCAT('~', OBJELEMCODE, '$index' ),
									OBJELEMSTAT=0 
								WHERE 
									$field=$index 
								AND 
									OBJELEMSTAT=1");
                    //
                    break;
                }
                //
                return ("");
            }
            /**
             *
             * @param	integer	 index type
             * @return	string
             */
            function getSelectQuery($indexType = PRIMARYKEY) {
                //
                switch ($indexType) {
                    case PRIMARYKEY:
                        /*
                        *
                        *	SELECT
                        *			tbl_objectory_element		as t1
                        *		<-> tbl_objectory_element_type	as t2
                        *		<-> tbl_objectory				as t3
                        *	ON
                        *			OBJELEMPKID
                        *
                        */
                        //
                        $index = $this->m_fieldSet["OBJELEMPKID"];
                        if ($index != 0) return ("SELECT  
									t1.*, 
									t2.OBJETYPTYPE, 
									t2.OBJETYPLINK, 
									t2.REPCELTPKID, 
									t2.REPMELTPKID, 
									t2.OBJETYPNAME, 
									t2.OBJETYPCODE, 
									t2.OBJETYPEGEN, 
									t2.OBJETYPNASP,
									t3.DIRPROJPKID
								FROM 
									tbl_objectory_element as t1, 
									tbl_objectory_element_type as t2,
									tbl_objectory as t3
								WHERE 
									t1.OBJELEMPKID=$index
								AND
									t1.OBJELEMSTAT>0
								AND 
									t1.OBJETYPPKID=t2.OBJETYPPKID
								AND
									t1.OBJECTOPKID=t3.OBJECTOPKID");
                        break;
                    }
                    //
                    return ("");
            }
        };
        //	Class
        //-------------------------------------------------------------------------
        
    }
    //	namespace
    //-----------------------------------------------------------------------------
    
?>
Return current item: Entier Studio