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