Location: PHPKode > projects > Entier Studio > entierstudio/studio/classes/datas/data.DictionaryPropertyRule.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.DictionaryPropertyRule.php 81 2008-01-17 23:08:21Z yannromefort $
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefDictionaryPropertyRule")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefDictionaryPropertyRule", "1");
    //-------------------------------------------------------------------------
    //	Include
    @require_once (FRAMEWORK_DIR . DATAROWOBJECT);
    //-------------------------------------------------------------------------
    //	Class
    class DictionaryPropertyRule extends DataRow {
        //---------------------------------------------------------------------
        //	Constructor
        
        /**
         *
         * @param	integer	 pkid	DictionaryPropertyRule		DICPRULPKID	//	primary key
         * @param	integer	 fkid	DictionaryPropertyRuleType	DICPRUTPKID //	foreign key
         */
        function DictionaryPropertyRule($DICPRULPKID = 0) {
            //
            $this->m_tableSet[PRIMARYKEY] = "tbl_dictionary_property_rule";
            //
            $this->m_indexSet[PRIMARYKEY] = "DICPRULPKID";
            $this->m_indexSet[FOREIGNKEY] = "DICPRUTPKID";
            //
            $this->m_fieldSet["DICPRULPKID"] = $DICPRULPKID;
        }
        //-------------------------------------------------------------------------
        //	Methods
        
        /**
         *
         * @param	integer	 index type
         * @return	string
         */
        function getInsertQuery($indexType = FOREIGNKEY) {
            //
            $table = $this->m_tableSet[PRIMARYKEY];
            //
            $insertSQL = "INSERT INTO $table ( ";
            $valuesSQL = "VALUES ( ";
            //	DICPRUTPKID = DictionaryPropertyRuleType (foreign key)
            $value = $this->m_fieldSet["DICPRUTPKID"];
            if (!empty($value)) {
                $insertSQL.= "  DICPRUTPKID";
                $valuesSQL.= "  $value";
            } else {
                $this->m_errorSet["DICPRUTPKID"] = true;
                return ("");
            }
            //	DICPVALPKID = DictionaryPropertyValue (foreign key)
            $value = $this->m_fieldSet["DICPVALPKID"];
            if (!empty($value)) {
                $insertSQL.= " ,DICPVALPKID";
                $valuesSQL.= " ,$value";
            } else {
                $this->m_errorSet["DICPVALPKID"] = true;
                return ("");
            }
            //	DICPROPPKID = DictionaryProperty (foreign key)
            $value = $this->m_fieldSet["DICPROPPKID"];
            if (!empty($value)) {
                $insertSQL.= " ,DICPROPPKID";
                $valuesSQL.= " ,$value";
            } else {
                $this->m_errorSet["DICPROPPKID"] = true;
                return ("");
            }
            //	DICPRULDATE = DictionaryPropertyRule creation date
            $value = Date("Y-m-d H:i:s");
            $insertSQL.= " ,DICPRULDATE";
            $valuesSQL.= " ,\"$value\"";
            //	DICPRULSTAT = DictionaryPropertyRule status
            $value = 1;
            $insertSQL.= " ,DICPRULSTAT";
            $valuesSQL.= " ,$value";
            //	DICPRULTYPE = DictionaryPropertyRule scope
            $value = $this->m_fieldSet["DICPRULTYPE"];
            if (!empty($value)) {
                $insertSQL.= " ,DICPRULTYPE";
                $valuesSQL.= " ,$value";
            } else {
                $this->m_errorSet["DICPRULTYPE"] = true;
                return ("");
            }
            //
            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_rule
                    *	ON
                    *			DICPRULPKID
                    *
                    */
                    //
                    $field = $this->m_indexSet[PRIMARYKEY];
                    $index = $this->m_fieldSet["$field"];
                    if ($index != 0) {
                        //
                        $updateSQL = "UPDATE $table SET ";
                        //	DICPROPPKID = DictionaryProperty
                        $value = $this->m_fieldSet["DICPROPPKID"];
                        if ($value != "") $updateSQL.= " DICPROPPKID=$value";
                        else {
                            $this->m_errorSet["DICPROPPKID"] = true;
                            return ("");
                        }
                        //	DICPRULTYPE = DictionaryPropertyRule scope
                        $value = $this->m_fieldSet["DICPRULTYPE"];
                        if ($value != "") $updateSQL.= ", DICPRULTYPE=$value";
                        else {
                            $this->m_errorSet["DICPRULTYPE"] = true;
                            return ("");
                        }
                        //	DICPRULSTAT = DictionaryPropertyRule status
                        $value = $this->m_fieldSet["DICPRULSTAT"];
                        $updateSQL.= ",DICPRULSTAT=$value";
                        //
                        return ($updateSQL . " WHERE $field=$index");
                    }
                    //
                    break;
                case DISPLAYKEY:
                    /*
                    *	UPDATE
                    *			tbl_dictionary_property_rule
                    *	SET
                    *			DICPRUTPKID= -DICPROPPKID // trick
                    *			DICPRULSTAT=0
                    *	ON
                    *			DICPRULPKID
                    *
                    */
                    //
                    $field = $this->m_indexSet[PRIMARYKEY];
                    $index = $this->m_fieldSet["$field"];
                    if ($index != 0) return ("UPDATE $table 
								SET 
									DICPRUTPKID=-DICPRULPKID, 
									DICPRULSTAT=0 
								WHERE 
									$field=$index 
								AND 
									DICPRULSTAT=1");
                    break;
                }
                //
                return ("");
            }
            /**
             *
             * @param	integer	 index type
             * @return	string
             */
            function getSelectQuery($indexType = PRIMARYKEY) {
                //
                $table = $this->m_tableSet[PRIMARYKEY];
                //
                switch ($indexType) {
                    case PRIMARYKEY:
                        /*
                        * SELECT
                        *			tbl_dictionary_property_rule		as t1,
                        *		<-> tbl_dictionary_property_rule_type	as t2,
                        *		<-> tbl_dictionary_property_value		as t4,
                        *		<-> tbl_dictionary_property				as t5
                        * ON
                        *		DICPRULPKID
                        */
                        //
                        $index = $this->m_fieldSet["DICPRULPKID"];
                        if ($index != 0) return ("SELECT 
									t1.*, 
									t2.DICPTYPLKID,
									t2.DICPTYPRKID,
									t2.DICPRUTNAME,
									t3.DICPSCONAME,
									t4.DICPVALNAME,
									t5.DICPROPNAME,
									t5.DICPROPCODE,
									t5.DICPTYPPKID,
									t5.DICPROPTYPE
								FROM 
									tbl_dictionary_property_rule as t1, 
									tbl_dictionary_property_rule_type as t2, 
									tbl_dictionary_property_rule_scope as t3, 
									tbl_dictionary_property_value as t4, 
									tbl_dictionary_property as t5 
								WHERE 
									t1.DICPRULPKID=$index 
								AND 
									t1.DICPRULSTAT>0 
								AND
									t1.DICPRUTPKID=t2.DICPRUTPKID 
								AND
									t1.DICPRULTYPE=t3.DICPSCOPKID 
								AND 
									t1.DICPVALPKID=t4.DICPVALPKID 
								AND 
									t4.DICPVALSTAT>0 
								AND 
									t1.DICPROPPKID=t5.DICPROPPKID 
								AND 
									t5.DICPROPSTAT>0");
                        //
                        break;
                    }
                    //
                    return ("");
            }
        };
        //	Class
        //-------------------------------------------------------------------------
        
    }
    //	namespace
    //-----------------------------------------------------------------------------
    
?>
Return current item: Entier Studio