Location: PHPKode > projects > Entier Studio > entierstudio/studio/classes/datas/data.RepositoryModelElement.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.RepositoryModelElement.php 81 2008-01-17 23:08:21Z yannromefort $
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefRepositoryModelElement")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefRepositoryModelElement", "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 RepositoryModelElement extends DataRow {
        //---------------------------------------------------------------------
        //	Constructor
        /*
        *
        * @param	integer		RepositoryModelElement pkid		REPMELEPKID
        *
        */
        //
        function RepositoryModelElement($pkid = 0) {
            //
            $this->m_tableSet[PRIMARYKEY] = "tbl_repository_model_element";
            //
            $this->m_indexSet[PRIMARYKEY] = "REPMELEPKID";
            $this->m_indexSet[FOREIGNKEY] = "REPCELEPKID";
            $this->m_indexSet[NATURALKEY] = "REPMELENAME";
            $this->m_indexSet[REFLECTKEY] = "REPMELELINK";
            //
            $this->m_fieldSet["REPMELEPKID"] = $pkid;
            $this->m_fieldSet["REPCELEPKID"] = 0;
            $this->m_fieldSet["REPMELTPKID"] = 0;
            $this->m_fieldSet["REPMELTLINK"] = 0;
        }
        //---------------------------------------------------------------------
        //	Methods
        /*
        *
        * @access	protected
        *
        * @param	integer	index type
        */
        function getInsertQuery($indexType = FOREIGNKEY) {
            //
            $table = $this->m_tableSet[PRIMARYKEY];
            //
            $insertSQL = "INSERT INTO $table ( ";
            $valuesSQL = "VALUES ( ";
            //	REPMELTPKID = RepositoryModelElementType Pkid
            $value = $this->m_fieldSet["REPMELTPKID"];
            if (!empty($value)) {
                $insertSQL.= " REPMELTPKID";
                $valuesSQL.= " $value";
            } else {
                $this->m_errorSet["REPMELTPKID"] = true;
                return ("");
            }
            //	REPMELELINK = RepositoryModelElement reflection link
            $value = $this->m_fieldSet["REPMELELINK"];
            switch ($indexType) {
                case FOREIGNKEY:
                    //
                    if (isset($value)) {
                        $this->m_errorSet["REPMELELINK"] = true;
                        return ("");
                    }
                    //
                    
                break;
                case REFLECTKEY:
                    //
                    if (empty($value)) {
                        $this->m_errorSet["REPMELELINK"] = true;
                        return ("");
                    }
                    //
                    
                break;
            }
            if (isset($value)) {
                $insertSQL.= " ,REPMELELINK";
                $valuesSQL.= " ,$value";
            }
            //	REPCELEPKID = RepositoryCoreElementType Pkid
            $value = $this->m_fieldSet["REPCELEPKID"];
            if (!empty($value)) {
                $insertSQL.= " ,REPCELEPKID";
                $valuesSQL.= " ,$value";
            } else {
                $this->m_errorSet["REPCELEPKID"] = true;
                return ("");
            }
            //	REPMELENAME = RepositoryModelElement name
            $value = FilterFormInput::filter($this->m_fieldSet["REPMELENAME"]);
            if (!empty($value)) {
                $insertSQL.= " ,REPMELENAME";
                $valuesSQL.= " ,$value";
            } else {
                $this->m_errorSet["REPMELENAME"] = true;
                return ("");
            }
            //	REPMELECODE = RepositoryModelElement identifier
            $value = @trim($this->m_fieldSet["REPMELECODE"]);
            if (ValidatorIdentifier::isValid($value)) {
                $insertSQL.= " ,REPMELECODE";
                $valuesSQL.= " ,\"$value\"";
            } else {
                $this->m_errorSet["REPMELECODE"] = true;
                return ("");
            }
            //	REPMELETEXT = RepositoryModelElement description
            $value = FilterFormInput::filter($this->m_fieldSet["REPMELETEXT"], true);
            if (!empty($value)) {
                $insertSQL.= " ,REPMELETEXT";
                $valuesSQL.= " ,$value";
            }
            //	REPMELEINAM = RepositoryModelElement instancier
            $value = @trim($this->m_fieldSet["REPMELEINAM"]);
            if (ValidatorIdentifier::isValid($value)) {
                $insertSQL.= " ,REPMELEINAM";
                $valuesSQL.= " ,\"$value\"";
            }
            //	REPMELERANK = RepositoryModelElement rank number
            $value = $this->m_fieldSet["REPMELERANK"];
            if (!empty($value)) {
                $insertSQL.= " ,REPMELERANK";
                $valuesSQL.= " ,$value";
            }
            //	REPMELEDATE = RepositoryModelElement date
            $value = Date("Y-m-d H:i:s");
            $insertSQL.= " ,REPMELEDATE";
            $valuesSQL.= " ,\"$value\"";
            //	REPMELESTAT = RepositoryModelElement status
            $value = 1;
            $insertSQL.= " ,REPMELESTAT";
            $valuesSQL.= " ,$value";
            //	REPMELETYPE = RepositoryModelElement type
            $value = $this->m_fieldSet["REPMELETYPE"];
            if (!empty($value)) {
                $insertSQL.= " ,REPMELETYPE";
                $valuesSQL.= " ,$value";
            }
            //
            return ($insertSQL . ") " . $valuesSQL . ")");
        }
        /**
         *
         * @access	protected
         *
         * @param	integer	index type
         */
        function getUpdateQuery($indexType = PRIMARYKEY) {
            //
            $table = $this->m_tableSet[PRIMARYKEY];
            //
            switch ($indexType) {
                case PRIMARYKEY:
                    /*
                    *	UPDATE
                    *			tbl_repository_model_element
                    *	ON
                    *			REPMELEPKID
                    *
                    */
                    //
                    $field = $this->m_indexSet[PRIMARYKEY];
                    $index = $this->m_fieldSet["$field"];
                    if ($index != 0) {
                        //
                        $updateSQL = "UPDATE $table SET ";
                        //	REPMELENAME = RepositoryModelElement name
                        $value = FilterFormInput::filter($this->m_fieldSet["REPMELENAME"]);
                        if (!empty($value)) $updateSQL.= " REPMELENAME=$value";
                        else {
                            $this->m_errorSet["REPMELENAME"] = true;
                            return ("");
                        }
                        //	REPMELECODE = RepositoryModelElement identifier
                        $value = @trim($this->m_fieldSet["REPMELECODE"]);
                        if (ValidatorIdentifier::isValid($value)) $updateSQL.= ",REPMELECODE=\"$value\"";
                        else {
                            $this->m_errorSet["REPMELECODE"] = true;
                            return ("");
                        }
                        //	REPCELEPKID = RepositoryCoreElementType Pkid
                        $value = $this->m_fieldSet["REPCELEPKID"];
                        if (!empty($value)) $updateSQL.= ",REPCELEPKID=$value";
                        //	REPMELETEXT = RepositoryModelElement description
                        $value = FilterFormInput::filter($this->m_fieldSet["REPMELETEXT"], true);
                        $updateSQL.= ",REPMELETEXT=$value";
                        //	REPMELEINAM = RepositoryModelElement description
                        $value = @trim($this->m_fieldSet["REPMELEINAM"]);
                        if (ValidatorIdentifier::isValid($value) || empty($value)) $updateSQL.= ",REPMELEINAM=\"$value\"";
                        //	REPMELERANK = RepositoryModelElement rank
                        $value = $this->m_fieldSet["REPMELERANK"];
                        if (!empty($value)) $updateSQL.= ",REPMELERANK=$value";
                        //	REPMELESTAT = RepositoryModelElement status
                        $value = $this->m_fieldSet["REPMELESTAT"];
                        $updateSQL.= ",REPMELESTAT=$value";
                        //
                        return ($updateSQL . " WHERE $field=$index");
                    }
                    break;
                case DISPLAYKEY:
                    /*
                    *	UPDATE
                    *			tbl_repository_model_element
                    *	SET
                    *			REPMELECODE='~REPMELECODE'
                    *			REPMELESTAT=0
                    *	ON
                    *			REPMELEPKID
                    *
                    */
                    //
                    $field = $this->m_indexSet[PRIMARYKEY];
                    $index = $this->m_fieldSet["$field"];
                    if ($index != 0) return ("UPDATE $table 
								SET 
									REPMELECODE= CONCAT('~', REPMELECODE, '$index' ),
									REPMELESTAT=0 
								WHERE 
									$field=$index
								AND
									REPMELESTAT=1");
                    //
                    break;
                }
                //
                return ("");
            }
            /*
            *
            * @access	protected
            *
            * @param	integer	index type
            */
            function getSelectQuery($indexType = PRIMARYKEY) {
                //
                $table = $this->m_tableSet[PRIMARYKEY];
                //
                switch ($indexType) {
                    case FOREIGNKEY:
                        /*
                        *	SELECT
                        *				tbl_repository_core_element			as t1
                        *			<-> tbl_repository_core_element_type	as t2
                        *			<-> tbl_repository_model_element_type	as t3
                        *			<-> tbl_repository_model_element		as t4
                        *	ON
                        *			REPCELEPKID WITH REPMELELINK=NULL
                        *
                        * @see class RepositoryModelElementExplorer.renderView in view.RepositoryModelElementExplorer.php line 77
                        */
                        //
                        $index = $this->m_fieldSet["REPCELEPKID"];
                        if ($index != 0) return ("SELECT 
									t1.REPCELEPKID,
									t1.REPOSITPKID,
									t1.REPCELTPKID, 
									t1.REPCELENAME, 
									t3.REPMELTPKID, 
									t4.REPMELEPKID, 
									t4.REPMELECODE 
								FROM 
									tbl_repository_core_element as t1, 
									tbl_repository_core_element_type as t2, 
									tbl_repository_model_element_type as t3, 
									tbl_repository_model_element as t4 
								WHERE 
									t1.REPCELEPKID=$index 
								AND 
									t1.REPCELTPKID=t2.REPCELTPKID 
								AND 
									t2.REPCELTPKID=t3.REPCELTPKID 
								AND 
									t3.REPMELTTYPE=1 
								AND 
									t3.REPMELTSTAT>0 
								AND 
									t3.REPMELTPKID=t4.REPMELTPKID 
								AND 
									t4.REPMELELINK IS NULL 
								AND 
									t4.REPMELESTAT<>0 
								AND 
									t4.REPCELEPKID=t1.REPCELEPKID");
                        //
                        break;
                    case PRIMARYKEY:
                        /*
                        *	SELECT
                        *			tbl_repository_model_element
                        *		<-> tbl_repository_core_element
                        *		<-> tbl_repository_core_element_type
                        *	ON
                        *		REPCELEPKID
                        *
                        * @see
                        *
                        */
                        //
                        $index = $this->m_fieldSet["REPMELEPKID"];
                        if ($index != 0) return ("SELECT 
									t1.*,
									t2.REPOSITPKID,
									t2.REPCELTPKID,
									t2.REPCELENAME, 
									t3.REPCELTNAME, 
									t3.REPCELTCODE 
								FROM 
									tbl_repository_model_element as t1, 
									tbl_repository_core_element as t2, 
									tbl_repository_core_element_type as t3 
								WHERE 
									t1.REPMELEPKID=$index 
								AND 
									t1.REPMELESTAT<>0 
								AND 
									t1.REPCELEPKID=t2.REPCELEPKID 
								AND 
									t2.REPCELESTAT<>0 
								AND 
									t2.REPCELTPKID=t3.REPCELTPKID");
                        break;
                    }
                    //
                    return ("");
                }
        };
        //	Class
        //-------------------------------------------------------------------------
        
    }
    //	namespace
    //-----------------------------------------------------------------------------
    
?>
Return current item: Entier Studio