Location: PHPKode > projects > Entier Studio > entierstudio/studio/classes/datas/data.TemporaryElement.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.TemporaryElement.php 81 2008-01-17 23:08:21Z yannromefort $
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefTemporaryElement")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefTemporaryElement", "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 TemporaryElement extends DataRow {
        //---------------------------------------------------------------------
        //	Constructor
        
        /**
         *
         * @param	integer	TemporaryElement	$TMPELEMPKID	primary key
         *
         */
        function TemporaryElement($TMPELEMPKID = 0) {
            //
            $this->m_tableSet[PRIMARYKEY] = "tbl_temporary_element";
            //
            $this->m_indexSet[PRIMARYKEY] = "TMPELEMPKID";
            $this->m_indexSet[FOREIGNKEY] = "OBJECTOPKID";
            $this->m_indexSet[NATURALKEY] = "TMPELEMNAME";
            $this->m_indexSet[REFLECTKEY] = "TMPELEMLINK";
            //
            $this->m_fieldSet["TMPELEMPKID"] = $TMPELEMPKID;
        }
        //---------------------------------------------------------------------
        //	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 ("");
            }
            //	OBJELEMPKID ObjectoryElement pkid
            $value = $this->m_fieldSet["OBJELEMPKID"];
            if (!empty($value)) {
                $insertSQL.= " ,OBJELEMPKID";
                $valuesSQL.= " ,$value";
            } else {
                $this->m_errorSet["OBJELEMPKID"] = true;
                return ("");
            }
            //	OBJETYPPKID TemporaryElementType
            $value = $this->m_fieldSet["OBJETYPPKID"];
            if (!empty($value)) {
                $insertSQL.= " ,OBJETYPPKID";
                $valuesSQL.= " ,$value";
            } else {
                $this->m_errorSet["OBJETYPPKID"] = true;
                return ("");
            }
            //	REPMELEPKID RepositoryModelElement	Pkid
            $value = $this->m_fieldSet["REPMELEPKID"];
            if (!empty($value)) {
                $insertSQL.= " ,REPMELEPKID";
                $valuesSQL.= " ,$value";
            }
            //	REPCELEPKID RepositoryCoreElement	Pkid
            $value = $this->m_fieldSet["REPCELEPKID"];
            if (!empty($value)) {
                $insertSQL.= " ,REPCELEPKID";
                $valuesSQL.= " ,$value";
            }
            //	TMPELEMLINK TemporaryElement reflection key
            $value = $this->m_fieldSet["TMPELEMLINK"];
            switch ($indexType) {
                case FOREIGNKEY:
                    //
                    if ($value != 0) {
                        $this->m_errorSet["TMPELEMLINK"] = true;
                        return ("");
                    }
                    //
                    
                break;
                case REFLECTKEY:
                    //
                    if ($value == 0) {
                        $this->m_errorSet["TMPELEMLINK"] = true;
                        return ("");
                    }
                    //
                    
                break;
            }
            if (!empty($value)) {
                $insertSQL.= " ,TMPELEMLINK";
                $valuesSQL.= " ,$value";
            }
            // TMPELEMNAME TemporaryElement name
            $value = FilterFormInput::filter($this->m_fieldSet["TMPELEMNAME"]);
            if (!empty($value)) {
                $insertSQL.= " ,TMPELEMNAME";
                $valuesSQL.= " ,$value";
            } else {
                $this->m_errorSet["TMPELEMNAME"] = true;
                return ("");
            }
            // TMPELEMCODE TemporaryElement identifier
            $value = @trim($this->m_fieldSet["TMPELEMCODE"]);
            if (ValidatorIdentifier::isValid($value)) {
                $insertSQL.= " ,TMPELEMCODE";
                $valuesSQL.= " ,\"$value\"";
            } else {
                $this->m_errorSet["TMPELEMCODE"] = true;
                return ("");
            }
            // TMPELEMTEXT TemporaryElement description
            $value = FilterFormInput::filter($this->m_fieldSet["TMPELEMTEXT"], true);
            if (!empty($value)) {
                $insertSQL.= " ,TMPELEMTEXT";
                $valuesSQL.= " ,$value";
            }
            // TMPELEMINAM TemporaryElement instance name
            $value = @trim($this->m_fieldSet["TMPELEMINAM"]);
            if (ValidatorIdentifier::isValid($value)) {
                $insertSQL.= " ,TMPELEMINAM";
                $valuesSQL.= " ,\"$value\"";
            }
            // TMPELEMRANK TemporaryElement rank number
            $value = $this->m_fieldSet["TMPELEMRANK"];
            if (!empty($value)) {
                $insertSQL.= " ,TMPELEMRANK";
                $valuesSQL.= " ,$value";
            }
            // TMPELEMDATE TemporaryElement creation date
            $value = Date("Y-m-d H:i:s");
            $insertSQL.= " ,TMPELEMDATE";
            $valuesSQL.= " ,\"$value\"";
            // TMPELEMSTAT TemporaryElement status
            $value = 1;
            $insertSQL.= " ,TMPELEMSTAT";
            $valuesSQL.= " ,$value";
            // TMPELEMTYPE TemporaryElement type
            $value = $this->m_fieldSet["TMPELEMTYPE"];
            if (!empty($value)) {
                $insertSQL.= " ,TMPELEMTYPE";
                $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 ";
                        // TMPELEMNAME TemporaryElement name
                        $value = FilterFormInput::filter($this->m_fieldSet["TMPELEMNAME"]);
                        if ($value != "") $updateSQL.= " TMPELEMNAME=$value";
                        else {
                            $this->m_errorSet["TMPELEMNAME"] = true;
                            return ("");
                        }
                        //	TMPELEMLINK TemporaryElement reflection key
                        $value = $this->m_fieldSet["TMPELEMLINK"];
                        if (!empty($value)) $updateSQL.= ",TMPELEMLINK=$value";
                        // TMPELEMCODE TemporaryElement identifier
                        $value = @trim($this->m_fieldSet["TMPELEMCODE"]);
                        if (ValidatorIdentifier::isValid($value)) $updateSQL.= ",TMPELEMCODE=\"$value\"";
                        else {
                            $this->m_errorSet["TMPELEMCODE"] = true;
                            return ("");
                        }
                        // TMPELEMINAM TemporaryElement instance name
                        $value = @trim($this->m_fieldSet["TMPELEMINAM"]);
                        if (ValidatorIdentifier::isValid($value)) $updateSQL.= ",TMPELEMINAM=\"$value\"";
                        // TMPELEMTEXT TemporaryElement description
                        $value = FilterFormInput::filter($this->m_fieldSet["TMPELEMTEXT"], true);
                        $updateSQL.= ",TMPELEMTEXT=$value";
                        // TMPELEMRANK TemporaryElement rank number
                        $value = $this->m_fieldSet["TMPELEMRANK"];
                        if (!empty($value)) $updateSQL.= ",TMPELEMRANK=$value";
                        // TMPELEMSTAT TemporaryElement status
                        $value = $this->m_fieldSet["TMPELEMSTAT"];
                        $updateSQL.= ",TMPELEMSTAT=$value";
                        //
                        return ($updateSQL . " WHERE $field=$index");
                    }
                    break;
                case DISPLAYKEY:
                    # index = Pkid
                    $field = $this->m_indexSet[PRIMARYKEY];
                    $index = $this->m_fieldSet["$field"];
                    if ($index != 0) return ("UPDATE $table SET TMPELEMSTAT=0 WHERE $field=$index");
                    break;
                }
                //
                return ("");
            }
            /**
             * Builds an SQL DELETE query
             *
             * @access	protected
             *
             * @param	integer	Index Type
             * @return	STRING	SQL query
             *
             * @see		deleteRow
             *
             */
            function getDeleteQuery($indexType = PRIMARYKEY) {
                //
                $table = $this->m_tableSet[PRIMARYKEY];
                //
                switch ($indexType) {
                    case PRIMARYKEY:
                        /*
                        *
                        *	DELETE
                        *		   tbl_temporary_element
                        *		-> tbl_temporary_element_reference
                        *		-> tbl_temporary_element_property_value
                        *	ON
                        *		TMPEPROPKID
                        *
                        */
                        //
                        # index = Pkid
                        $field = $this->m_indexSet[PRIMARYKEY];
                        $index = $this->m_fieldSet["$field"];
                        if ($index != 0) return ("
								DELETE 
									t1,
									t2,
									t3
								FROM 
									tbl_temporary_element as t1
								LEFT JOIN
									tbl_temporary_element_reference as t2
								ON 
									t2.TMPELEMPKID=t1.TMPELEMPKID
								LEFT JOIN 
									tbl_temporary_element_property_value as t3
								ON 
									t3.TMPELEMPKID=t1.TMPELEMPKID
								WHERE 
									t1.TMPELEMPKID=$index");
                        //
                        break;
                    }
                    //
                    return ("");
            }
            /**
             *
             * @param	integer	 index type
             * @return	string
             */
            function getSelectQuery($indexType = PRIMARYKEY) {
                //
                switch ($indexType) {
                    case PRIMARYKEY:
                        /*
                        *
                        *	SELECT
                        *			tbl_temporary_element		as t1
                        *		<-> tbl_objectory_element_type	as t2
                        *	ON TMPELEMPKID
                        *
                        */
                        //
                        $index = $this->m_fieldSet["TMPELEMPKID"];
                        if ($index != 0) return ("SELECT
									t1.*, 
									t2.OBJETYPTYPE, 
									t2.OBJETYPLINK, 
									t2.REPCELTPKID, 
									t2.REPMELTPKID, 
									t2.OBJETYPNAME, 
									t2.OBJETYPCODE, 
									t2.OBJETYPEGEN, 
									t2.OBJETYPNASP 
								FROM 
									tbl_temporary_element		as t1, 
									tbl_objectory_element_type	as t2 
								WHERE 
									t1.TMPELEMPKID=$index 
								AND 
									t1.OBJETYPPKID=t2.OBJETYPPKID");
                        break;
                    case FOREIGNKEY:
                        /*
                        *
                        *	SELECT
                        *			tbl_temporary_element		as t1
                        *		<-> tbl_objectory_element_type	as t2
                        *	ON
                        *		REPMELEPKID & OBJELEMPKID
                        *
                        */
                        //
                        $index1 = $this->m_fieldSet["REPMELEPKID"];
                        $index2 = $this->m_fieldSet["OBJELEMPKID"];
                        if (($index1 != 0) && ($index2 != 0)) return ("SELECT  
									t1.*, 
									t2.OBJETYPTYPE, 
									t2.OBJETYPLINK, 
									t2.REPCELTPKID, 
									t2.REPMELTPKID, 
									t2.OBJETYPNAME,
									t2.OBJETYPCODE, 
									t2.OBJETYPEGEN, 
									t2.OBJETYPNASP 
								FROM 
									tbl_temporary_element as t1, 
									tbl_objectory_element_type as t2 
								WHERE 
									t1.REPMELEPKID=$index1 
								AND 
									t1.OBJELEMPKID=$index2 
								AND 
									t1.OBJETYPPKID=t2.OBJETYPPKID");
                        break;
                    case NATURALKEY:
                        /*
                        *
                        *	SELECT
                        *			tbl_temporary_element		as t1
                        *		<-> tbl_objectory_element_type	as t2
                        *	ON
                        *		TMPELEMCODE & TMPELEMLINK & OBJETYPPKID & OBJELEMPKID
                        *
                        */
                        //
                        $index1 = $this->m_fieldSet["TMPELEMCODE"];
                        $index2 = $this->m_fieldSet["TMPELEMLINK"];
                        $index3 = $this->m_fieldSet["OBJETYPPKID"];
                        $index4 = $this->m_fieldSet["OBJELEMPKID"];
                        if (($index1 != "") && ($index3 != 0)) {
                            //
                            if (empty($index2)) return ("SELECT
										t1.*, 
										t2.OBJETYPTYPE, 
										t2.OBJETYPLINK, 
										t2.REPCELTPKID, 
										t2.REPMELTPKID, 
										t2.OBJETYPNAME,
										t2.OBJETYPCODE, 
										t2.OBJETYPEGEN, 
										t2.OBJETYPNASP 
									FROM 
										tbl_temporary_element		as t1, 
										tbl_objectory_element_type	as t2 
									WHERE 
										t1.TMPELEMCODE='$index1'
									AND
										t1.TMPELEMLINK IS NULL 
									AND
										t1.OBJETYPPKID=$index3 
									AND
										t1.OBJELEMPKID=$index4 
									AND 
										t1.OBJETYPPKID=t2.OBJETYPPKID");
                            else {
                                //
                                return ("SELECT
										t1.*, 
										t2.OBJETYPTYPE, 
										t2.OBJETYPLINK, 
										t2.REPCELTPKID, 
										t2.REPMELTPKID, 
										t2.OBJETYPNAME,
										t2.OBJETYPCODE, 
										t2.OBJETYPEGEN, 
										t2.OBJETYPNASP 
									FROM 
										tbl_temporary_element		as t1, 
										tbl_objectory_element_type	as t2 
									WHERE 
										t1.TMPELEMCODE='$index1'
									AND
										t1.TMPELEMLINK=$index2 
									AND
										t1.OBJETYPPKID=$index3 
									AND 
										t1.OBJETYPPKID=t2.OBJETYPPKID");
                            }
                        }
                        //
                        break;
                    }
                    //
                    return ("");
                }
            };
            //	Class
            //-------------------------------------------------------------------------
            
    }
    //	namespace
    //-----------------------------------------------------------------------------
    
?>
Return current item: Entier Studio