Location: PHPKode > projects > Entier Studio > entierstudio/studio/classes/datas/data.DictionaryPropertyValue.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.DictionaryPropertyValue.php 81 2008-01-17 23:08:21Z yannromefort $
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefDictionaryPropertyValue")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefDictionaryPropertyValue", "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 DictionaryPropertyValue extends DataRow {
        //---------------------------------------------------------------------
        //	Constructor
        
        /**
         *
         * @param	integer	 pkid	DictionaryPropertyValue		DICPVALPKID	//	primary key
         */
        function DictionaryPropertyValue($DICPVALPKID = 0) {
            //
            $this->m_tableSet[PRIMARYKEY] = "tbl_dictionary_property_value";
            //
            $this->m_indexSet[PRIMARYKEY] = "DICPVALPKID";
            $this->m_indexSet[FOREIGNKEY] = "DICPROPPKID";
            $this->m_indexSet[NATURALKEY] = "DICPVALNAME";
            //
            $this->m_fieldSet["DICPVALPKID"] = $DICPVALPKID;
        }
        //-------------------------------------------------------------------------
        //	Methods
        
        /**
         *
         * @param	integer	 index type
         * @return	string
         */
        function getInsertQuery($indexType = FOREIGNKEY) {
            //
            $table = $this->m_tableSet[PRIMARYKEY];
            //
            $insertSQL = "INSERT INTO $table ( ";
            $valuesSQL = "VALUES ( ";
            //	DICPROPPKID = DictionaryProperty (foreign key)
            $value = $this->m_fieldSet["DICPROPPKID"];
            if (!empty($value)) {
                $insertSQL.= "  DICPROPPKID";
                $valuesSQL.= "  $value";
            } else {
                $this->m_errorSet["DICPTYPPKID"] = true;
                return ("");
            }
            //	DICPVALNAME = DictionaryPropertyValue name
            $value = FilterFormInput::filter($this->m_fieldSet["DICPVALNAME"]);
            if (!empty($value)) {
                $insertSQL.= " ,DICPVALNAME";
                $valuesSQL.= " ,$value";
            } else {
                $this->m_errorSet["DICPVALNAME"] = true;
                return ("");
            }
            //	DICPVALCODE = DictionaryPropertyValue identifier
            $value = @trim($this->m_fieldSet["DICPVALCODE"]);
            if (ValidatorIdentifier::isValid($value)) {
                $insertSQL.= " ,DICPVALCODE";
                $valuesSQL.= " ,\"$value\"";
            } else {
                $this->m_errorSet["DICPVALCODE"] = true;
                return ("");
            }
            //	DICPVALTEXT = DictionaryPropertyValue description
            $value = FilterFormInput::filter($this->m_fieldSet["DICPVALTEXT"], true);
            if (!empty($value)) {
                $insertSQL.= " ,DICPVALTEXT";
                $valuesSQL.= " ,$value";
            }
            //	DICPVALDATE = DictionaryPropertyValue creation date
            $value = Date("Y-m-d H:i:s");
            $insertSQL.= " ,DICPVALDATE";
            $valuesSQL.= " ,\"$value\"";
            //	DICPVALSTAT = DictionaryPropertyValue status
            $value = 1;
            $insertSQL.= " ,DICPVALSTAT";
            $valuesSQL.= " ,$value";
            //	DICPVALTYPE = DictionaryPropertyValue type
            $value = $this->m_fieldSet["DICPVALTYPE"];
            if (!empty($value)) {
                $insertSQL.= " ,DICPVALTYPE";
                $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_dictionary_property_value
                    *	ON
                    *			DICPVALPKID
                    *
                    */
                    //
                    $field = $this->m_indexSet[PRIMARYKEY];
                    $index = $this->m_fieldSet["$field"];
                    if ($index != 0) {
                        //
                        $updateSQL = "UPDATE $table SET ";
                        //	DICPVALNAME = DictionaryPropertyValue name : required
                        $value = FilterFormInput::filter($this->m_fieldSet["DICPVALNAME"]);
                        if (!empty($value)) $updateSQL.= " DICPVALNAME=$value";
                        else {
                            $this->m_errorSet["DICPVALNAME"] = true;
                            return ("");
                        }
                        //	DICPVALCODE = DictionaryPropertyValue identifier : required
                        $value = @trim($this->m_fieldSet["DICPVALCODE"]);
                        if (ValidatorIdentifier::isValid($value)) $updateSQL.= ",DICPVALCODE=\"$value\"";
                        else {
                            $this->m_errorSet["DICPVALCODE"] = true;
                            return ("");
                        }
                        //	DICPVALTEXT = DictionaryPropertyValue description
                        $value = FilterFormInput::filter($this->m_fieldSet["DICPVALTEXT"], true);
                        $updateSQL.= ",DICPVALTEXT=$value";
                        //	DICPVALSTAT = DictionaryPropertyValue status
                        $value = $this->m_fieldSet["DICPVALSTAT"];
                        $updateSQL.= ",DICPVALSTAT=$value";
                        //
                        return ($updateSQL . " WHERE $field=$index");
                    }
                    break;
                case DISPLAYKEY:
                    /*
                    *	UPDATE
                    *			tbl_dictionary_property_value
                    *	SET
                    *			DICPVALCODE='DICPVALPKID'
                    *			DICPVALSTAT=0
                    *	ON
                    *			DICPVALPKID
                    *
                    */
                    //
                    $field = $this->m_indexSet[PRIMARYKEY];
                    $index = $this->m_fieldSet["$field"];
                    if ($index != 0) return ("UPDATE 
									$table 
								SET 
									DICPVALCODE= CONCAT('~', DICPVALCODE, '$index' ),
									DICPVALSTAT=0 
								WHERE 
									$field=$index 
								AND 
									DICPVALSTAT=1");
                    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_dictionary_property_value
                        *		-> tbl_repository_core_element_property_value
                        *		-> tbl_repository_model_element_property_value
                        *		-> tbl_repository_core_element_property_value
                        *		-> tbl_repository_model_resource_property_value
                        *		-> tbl_objectory_element_property_value
                        *	ON
                        *		DICPVALPKID
                        *
                        */
                        //
                        # index = Pkid
                        $field = $this->m_indexSet[PRIMARYKEY];
                        $index = $this->m_fieldSet["$field"];
                        if ($index != 0) return ("
								DELETE 
									t1, 
									t2,
									t3,
									t4,
									t5
								FROM 
									tbl_dictionary_property_value as t1
								LEFT JOIN 
									tbl_repository_core_element_property_value as t2
								ON 
									t2.DICPVALPKID=t1.DICPVALPKID
								LEFT JOIN 
									tbl_repository_model_element_property_value as t3
								ON 
									t3.DICPVALPKID=t1.DICPVALPKID
								LEFT JOIN
									tbl_repository_model_resource_property_value as t4
								ON 
									t4.DICPVALPKID=t1.DICPVALPKID
								LEFT JOIN
									tbl_objectory_element_property_value as t5
								ON 
									t5.DICPVALPKID=t1.DICPVALPKID
								WHERE 
									t1.DICPVALPKID=$index");
                        //
                        break;
                    }
                    //
                    return ("");
            }
            /**
             *
             * @param	integer	 index type
             * @return	string
             */
            function getSelectQuery($indexType = PRIMARYKEY) {
                //
                switch ($indexType) {
                    case PRIMARYKEY:
                        /*
                        * SELECT
                        *			tbl_dictionary_property_value
                        *		<-> tbl_dictionary_property
                        *		<-> tbl_dictionary_property_type
                        * ON
                        *		DICPVALPKID
                        */
                        //
                        $index = $this->m_fieldSet["DICPVALPKID"];
                        if ($index != 0) return ("SELECT 
									t1.DICPVALPKID,
									t1.DICPROPPKID, 
									t1.DICPVALNAME, 
									t1.DICPVALCODE, 
									t1.DICPVALTEXT, 
									t1.DICPVALSTAT,
									t2.REPOSITPKID,
									t2.DICPTYPPKID, 
									t2.DICPROPNAME,									
									t3.REPTYPEPKID, 
									t3.DICPTYPNAME 
								FROM 
									tbl_dictionary_property_value as t1, 
									tbl_dictionary_property as t2, 
									tbl_dictionary_property_type as t3 
								WHERE 
									t1.DICPVALPKID=$index 
								AND 
									t1.DICPROPPKID=t2.DICPROPPKID 
								AND 
									t2.DICPTYPPKID =t3.DICPTYPPKID");
                        //
                        break;
                    }
                    //
                    return ("");
            }
        };
        //	Class
        //-------------------------------------------------------------------------
        
    }
    //	namespace
    //-----------------------------------------------------------------------------
    
?>
Return current item: Entier Studio