Location: PHPKode > projects > Entier Studio > entierstudio/studio/classes/datas/data.ObjectoryElementDependence.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.ObjectoryElementDependence.php 81 2008-01-17 23:08:21Z yannromefort $
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefObjectoryElementDependence")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefObjectoryElementDependence", "1");
    //-------------------------------------------------------------------------
    //	Include
    @require_once (FRAMEWORK_DIR . DATAROWOBJECT);
    //-------------------------------------------------------------------------
    //	Class
    class ObjectoryElementDependence extends DataRow {
        //---------------------------------------------------------------------
        //	Constructor
        
        /**
         *
         * @param	integer	ObjectoryElementDependence	$OBJELEMPKID	primary key
         *
         */
        function ObjectoryElementDependence($OBJEREFPKID = 0, $OBJELEMPKID = 0) {
            //
            $this->m_tableSet[PRIMARYKEY] = "tbl_objectory_element_dependence";
            //
            $this->m_indexSet[PRIMARYKEY] = "OBJEREFPKID";
            $this->m_indexSet[FOREIGNKEY] = "OBJELEMPKID";
            //
            $this->m_fieldSet["OBJEREFPKID"] = $OBJEREFPKID;
            $this->m_fieldSet["OBJELEMPKID"] = $OBJELEMPKID;
        }
        //---------------------------------------------------------------------
        //	Methods
        
        /**
         *
         * @param	integer	 index type
         * @return	string
         */
        function getInsertQuery($indexType = FOREIGNKEY) {
            //
            $table = $this->m_tableSet[PRIMARYKEY];
            //
            $insertSQL = "INSERT INTO $table ( ";
            $valuesSQL = "VALUES ( ";
            // OBJERETPKID ObjectoryElementDependenceType id
            $value = $this->m_fieldSet["OBJERETPKID"];
            if (!empty($value)) {
                $insertSQL.= "  OBJERETPKID";
                $valuesSQL.= "  $value";
            } else {
                $this->m_errorSet["OBJERETPKID"] = true;
                return ("");
            }
            //	OBJELEMLINK	ObjectoryElement assocation id
            $value = $this->m_fieldSet["OBJELEMLINK"];
            if (!empty($value)) {
                $insertSQL.= " ,OBJELEMLINK";
                $valuesSQL.= " ,$value";
            } else {
                $this->m_errorSet["OBJELEMLINK"] = true;
                return ("");
            }
            //	OBJELEMPKID	ObjectoryElement assocation end id
            $value = $this->m_fieldSet["OBJELEMPKID"];
            if (!empty($value)) {
                $insertSQL.= " ,OBJELEMPKID";
                $valuesSQL.= " ,$value";
            } else {
                $this->m_errorSet["OBJELEMPKID"] = true;
                return ("");
            }
            // OBJELEMRFID ObjectoryElement related element id
            $value = $this->m_fieldSet["OBJELEMRFID"];
            if (!empty($value)) {
                $insertSQL.= " ,OBJELEMRFID";
                $valuesSQL.= " ,$value";
            } else {
                $this->m_errorSet["OBJELEMRFID"] = true;
                return ("");
            }
            // OBJEREFDATE ObjectoryElementDependence creation date
            $value = Date("Y-m-d H:i:s");
            $insertSQL.= " ,OBJEREFDATE";
            $valuesSQL.= " ,\"$value\"";
            // OBJEREFSTAT ObjectoryElementDependence status
            $value = 1;
            $insertSQL.= " ,OBJEREFSTAT";
            $valuesSQL.= " ,$value";
            // OBJEREFTYPE ObjectoryElementDependence type
            $value = 1;
            $insertSQL.= " ,OBJEREFTYPE";
            $valuesSQL.= " ,$value";
            //
            return ($insertSQL . ") " . $valuesSQL . ")");
        }
        /**
         *
         * @param	integer	 index type
         * @return	string
         */
        function getUpdateQuery($indexType = PRIMARYKEY) {
            //
            $table = $this->m_tableSet[PRIMARYKEY];
            //
            switch ($indexType) {
                case FOREIGNKEY:
                    //
                    $field = $this->m_indexSet[FOREIGNKEY];
                    $index = $this->m_fieldSet["$field"];
                    if ($index != 0) {
                        //
                        $updateSQL = "UPDATE $table SET ";
                        // OBJELEMRFID ObjectoryElement related element
                        $value = $this->m_fieldSet["OBJELEMRFID"];
                        if (!empty($value)) $updateSQL.= " OBJELEMRFID=$value";
                        else {
                            $this->m_errorSet["OBJELEMRFID"] = true;
                            return ("");
                        }
                        //
                        return ($updateSQL . " WHERE $field=$index");
                    }
                    //
                    break;
                case PRIMARYKEY:
                    //
                    $field = $this->m_indexSet[PRIMARYKEY];
                    $index = $this->m_fieldSet["$field"];
                    if ($index != 0) {
                        //
                        $updateSQL = "UPDATE $table SET ";
                        // OBJELEMRFID ObjectoryElement related element
                        $value = $this->m_fieldSet["OBJELEMRFID"];
                        if (!empty($value)) $updateSQL.= " OBJELEMRFID=$value";
                        else {
                            $this->m_errorSet["OBJELEMRFID"] = true;
                            return ("");
                        }
                        //
                        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 OBJEREFSTAT=0 WHERE $field=$index");
                    break;
                }
                //
                return ("");
            }
            /**
             *
             * @param	integer	 index type
             * @return	string
             */
            function getSelectQuery($indexType = PRIMARYKEY) {
                //
                switch ($indexType) {
                    case FOREIGNKEY:
                        /*
                        *
                        *	SELECT
                        *				tbl_objectory_element_dependence		as t1
                        *			<->	tbl_objectory_element				as t2
                        *	ON OBJELEMPKID
                        *
                        */
                        //
                        $index = $this->m_fieldSet["OBJELEMPKID"];
                        if ($index != 0) return ("SELECT 
									t1.OBJEREFPKID,
									t1.OBJELEMPKID,
									t1.OBJERETPKID,
									t1.OBJELEMRFID,
									t2.OBJELEMNAME
								FROM 
									tbl_objectory_element_dependence as t1, 
									tbl_objectory_element as t2
								WHERE
									t1.OBJELEMPKID=$index
								AND
									t1.OBJEREFSTAT>0
								AND
									t1.OBJELEMRFID=t2.OBJELEMPKID
								AND
									t2.OBJELEMSTAT>0");
                        break;
                    case PRIMARYKEY:
                        /*
                        *
                        *	SELECT
                        *				tbl_objectory_element_dependence		as t1
                        *			<->	tbl_objectory_element				as t2
                        *	ON OBJEREFPKID
                        *
                        */
                        //
                        $index = $this->m_fieldSet["OBJEREFPKID"];
                        if ($index != 0) return ("SELECT
									t1.OBJEREFPKID,
									t1.OBJELEMPKID,
									t1.OBJERETPKID,
									t1.OBJELEMRFID,
									t2.OBJELEMNAME
								FROM
									tbl_objectory_element_dependence as t1,
									tbl_objectory_element as t2
								WHERE
									t1.OBJEREFPKID=$index
								AND
									t1.OBJEREFSTAT>0
								AND
									t1.OBJELEMRFID=t2.OBJELEMPKID
								AND
									t2.OBJELEMSTAT>0");
                        break;
                    }
                    //
                    return ("");
                }
        };
        //	Class
        //-------------------------------------------------------------------------
        
    }
    //	namespace
    //-----------------------------------------------------------------------------
    
?>
Return current item: Entier Studio