Location: PHPKode > projects > Entier Studio > entierstudio/studio/classes/datas/data.ObjectoryComponent.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
 * @version	   $Id: data.ObjectoryComponent.php 121 2008-03-11 20:17:41Z yannromefort $
 * @copyright  Copyright (c) 2006 Entier Studio team. All rights reserved.
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefObjectoryComponent")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefObjectoryComponent", "1");
    //-------------------------------------------------------------------------
    //	Include
    @require_once (FRAMEWORK_DIR . DATAROWOBJECT);
    @require_once (FRAMEWORK_DIR . "./filters/filter.locator.php");
    @require_once (FRAMEWORK_DIR . "./filters/filter.forminput.php");
    @require_once (FRAMEWORK_DIR . "./validators/validator.locator.php");
    @require_once (FRAMEWORK_DIR . "./validators/validator.identifier.php");
    //-------------------------------------------------------------------------
    //	Class
    class ObjectoryComponent extends DataRow {
        //---------------------------------------------------------------------
        //	Constructor
        
        /**
         *
         * @param	integer	ObjectoryComponent	$OBJCOMPPKID	primary key
         *
         */
        function ObjectoryComponent($OBJCOMPPKID = 0) {
            //
            $this->m_tableSet[PRIMARYKEY] = "tbl_objectory_component";
            //
            $this->m_indexSet[PRIMARYKEY] = "OBJCOMPPKID";
            $this->m_indexSet[FOREIGNKEY] = "DIRPROJPKID";
            $this->m_indexSet[REFLECTKEY] = "OBJCOMPLINK";
            $this->m_indexSet[NATURALKEY] = "OBJCOMPNAME";
            //
            $this->m_fieldSet["OBJCOMPPKID"] = $OBJCOMPPKID;
        }
        //---------------------------------------------------------------------
        //	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 ("");
            }
            //	OBJCTYPPKID ObjectoryComponentType
            $value = $this->m_fieldSet["OBJCTYPPKID"];
            if (!empty($value)) {
                $insertSQL.= " ,OBJCTYPPKID";
                $valuesSQL.= " ,$value";
            } else {
                $this->m_errorSet["OBJCTYPPKID"] = true;
                return ("");
            }
            //	OBJCOMPROOT ObjectoryElement root key
            $value = $this->m_fieldSet["OBJCOMPROOT"];
            switch ($indexType) {
                case FOREIGNKEY:
                    // @mock isRoot==true && hasRoot==false
                    if (!empty($value)) {
                        $this->m_errorSet["OBJCOMPROOT"] = true;
                        return ("");
                    }
                    //
                    
                break;
                case REFLECTKEY:
                    // @mock isChild==true && hasRoot==true
                    if (empty($value)) {
                        $this->m_errorSet["OBJCOMPROOT"] = true;
                        return ("");
                    }
                    //
                    
                break;
            }
            if (!empty($value)) {
                $insertSQL.= " ,OBJCOMPROOT";
                $valuesSQL.= " ,$value";
            }
            //	OBJCOMPLINK ObjectoryComponent reflection key
            $value = $this->m_fieldSet["OBJCOMPLINK"];
            switch ($indexType) {
                case FOREIGNKEY:
                    // @mock isRoot==true && hasChild==false
                    if (!empty($value)) {
                        $this->m_errorSet["OBJCOMPLINK"] = true;
                        return ("");
                    }
                    //
                    
                break;
                case REFLECTKEY:
                    // @mock isChild==true && hasParent==true
                    if (empty($value)) {
                        $this->m_errorSet["OBJCOMPLINK"] = true;
                        return ("");
                    }
                    //
                    
                break;
            }
            if (!empty($value)) {
                $insertSQL.= " ,OBJCOMPLINK";
                $valuesSQL.= " ,$value";
            }
            // OBJCOMPNAME ObjectoryComponent name
            $value = FilterFormInput::filter($this->m_fieldSet["OBJCOMPNAME"]);
            if (!empty($value)) {
                $insertSQL.= " ,OBJCOMPNAME";
                $valuesSQL.= " ,$value";
            } else {
                $this->m_errorSet["OBJCOMPNAME"] = true;
                return ("");
            }
            // OBJCOMPPATH ObjectoryComponent locator
            $value = FilterLocator::filter($this->m_fieldSet["OBJCOMPPATH"]);
            if (ValidatorLocator::isValid($value, $this->m_fieldSet["OBJCTYPPKID"])) {
                $insertSQL.= " ,OBJCOMPPATH";
                $valuesSQL.= " ,$value";
            } else {
                $this->m_errorSet["OBJCOMPPATH"] = true;
                return ("");
            }
            // OBJCOMPTEXT ObjectoryComponent description
            $value = FilterFormInput::filter($this->m_fieldSet["OBJCOMPTEXT"], true);
            if (!empty($value)) {
                $insertSQL.= " ,OBJCOMPTEXT";
                $valuesSQL.= " ,$value";
            }
            // OBJCOMPDATE ObjectoryComponent creation date
            $value = Date("Y-m-d H:i:s");
            $insertSQL.= " ,OBJCOMPDATE";
            $valuesSQL.= " ,\"$value\"";
            // OBJCOMPSTAT ObjectoryComponent status
            $value = 1;
            $insertSQL.= " ,OBJCOMPSTAT";
            $valuesSQL.= " ,$value";
            // OBJCOMPTYPE ObjectoryComponent type
            $value = $this->m_fieldSet["OBJCOMPTYPE"];
            if (!empty($value)) {
                $insertSQL.= " ,OBJCOMPTYPE";
                $valuesSQL.= " ,$value";
            }
            //
            return ($insertSQL . ") " . $valuesSQL . ")");
        }
        /**
         *
         * @param	integer	 index type
         * @return	string
         */
        function getUpdateQuery($indexType = PRIMARYKEY) {
            //
            $table = $this->m_tableSet[PRIMARYKEY];
            //
            switch ($indexType) {
                case PRIMARYKEY:
                    # index = Pkid
                    $field = $this->m_indexSet[PRIMARYKEY];
                    $index = $this->m_fieldSet["$field"];
                    if ($index != 0) {
                        //
                        $updateSQL = "UPDATE $table SET ";

                        // OBJCOMPNAME ObjectoryComponent name
                        $value = FilterFormInput::filter($this->m_fieldSet["OBJCOMPNAME"]);
                        if (!empty($value)) $updateSQL.= " OBJCOMPNAME=$value";
                        else {
                            $this->m_errorSet["OBJCOMPNAME"] = true;
                            return ("");
                        }

                        //	OBJCOMPLINK ObjectoryComponent reflection key
                        $value = $this->m_fieldSet["OBJCOMPLINK"];
                        if (!empty($value))
                            $updateSQL.= ",OBJCOMPLINK=$value";
                        else {
                            if ($this->m_fieldSet["OBJCTYPPKID"] != ARCHITECTURE_TYPE) {
                                $this->m_errorSet["OBJCOMPLINK"] = true;
                                return ("");
                            }
                        }

                        // OBJCOMPPATH ObjectoryComponent locator
                        $value = FilterLocator::filter($this->m_fieldSet["OBJCOMPPATH"]);
                        if (ValidatorLocator::isValid($value, $this->m_fieldSet["OBJCTYPPKID"]))
                            $updateSQL.= ",OBJCOMPPATH=$value";
                        else {
                            $this->m_errorSet["OBJCOMPPATH"] = true;
                            return ("");
                        }
                        // OBJCOMPTEXT ObjectoryElement description
                        $value = FilterFormInput::filter($this->m_fieldSet["OBJCOMPTEXT"], true);
                        $updateSQL.= ",OBJCOMPTEXT=$value";

                        // OBJCOMPSTAT ObjectoryComponent status
                        $value = $this->m_fieldSet["OBJCOMPSTAT"];
                        $updateSQL.= ",OBJCOMPSTAT=$value";

                        // OBJCOMPTYPE ObjectoryComponent status
                        $value = $this->m_fieldSet["OBJCOMPTYPE"];
                        $updateSQL.= ",OBJCOMPTYPE=$value";
                        //
                        return ($updateSQL . " WHERE $field=$index");
                    }
                    break;
                case DISPLAYKEY:
                    /*
                    *	UPDATE
                    *			tbl_objectory_component
                    *	SET
                    *			OBJCOMPNAME='~OBJCOMPNAME'
                    *			OBJCOMPSTAT=0
                    *	ON
                    *			OBJCOMPPKID
                    *
                    */
                    //
                    $field = $this->m_indexSet[PRIMARYKEY];
                    $index = $this->m_fieldSet["$field"];
                    if ($index != 0) return ("UPDATE 
									$table 
								SET 
									OBJCOMPNAME= CONCAT('~', OBJCOMPNAME, '$index' ),
									OBJCOMPSTAT=0 
								WHERE $field=$index");
                    break;
                }
                //
                return ("");
            }
            /**
             *
             * @param	integer	 index type
             * @return	string
             */
            function getSelectQuery($indexType = PRIMARYKEY) {
                //
                switch ($indexType) {
                    case PRIMARYKEY:
                        /*
                        *
                        *	SELECT
                        *			tbl_objectory_component			as t1
                        *		<-> tbl_objectory_component_type	as t2
                        *		<->	tbl_objectory					as t3
                        *	ON
                        *		OBJCOMPPKID
                        *
                        */
                        //
                        $index = $this->m_fieldSet["OBJCOMPPKID"];
                        if ($index != 0) return ("SELECT 
									t1.*, 
									t2.OBJCTYPTYPE,
									t2.REPTYPEPKID,
									t2.OBJCTYPNAME,
									t3.DIRPROJPKID
								FROM 
									tbl_objectory_component			as t1, 
									tbl_objectory_component_type	as t2,
									tbl_objectory					as t3  
								WHERE 
									t1.OBJCOMPPKID=$index
								AND
									t1.OBJCOMPSTAT>0
								AND
									t1.OBJCTYPPKID=t2.OBJCTYPPKID
								AND 
									t1.OBJECTOPKID=t3.OBJECTOPKID");
                        //
                        break;
                    }
                    //
                    return ("");
            }
        };
        //	Class
        //-------------------------------------------------------------------------
        
    }
    //	namespace
    //-----------------------------------------------------------------------------
    
?>
Return current item: Entier Studio