Location: PHPKode > projects > Entier Studio > entierstudio/studio/classes/datas/data.TemporaryComponent.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.TemporaryComponent.php 121 2008-03-11 20:17:41Z yannromefort $
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefTemporaryComponent")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefTemporaryComponent", "1");
    //-------------------------------------------------------------------------
    //	Include
    @require_once (FRAMEWORK_DIR . DATAROWOBJECT);
    @require_once (FRAMEWORK_DIR . "./filters/filter.locator.php");
    @require_once (FRAMEWORK_DIR . "./filters/filter.forminput.php");
    @require_once (FRAMEWORK_DIR . "./validators/validator.locator.php");
    @require_once (FRAMEWORK_DIR . "./validators/validator.identifier.php");
    //-------------------------------------------------------------------------
    //	Class
    class TemporaryComponent extends DataRow {
        //---------------------------------------------------------------------
        //	Constructor
        
        /**
         *
         * @param	integer	TemporaryComponent	$TMPCOMPPKID	primary key
         *
         */
        function TemporaryComponent($TMPCOMPPKID = 0) {
            //
            $this->m_tableSet[PRIMARYKEY] = "tbl_temporary_component";
            //
            $this->m_indexSet[PRIMARYKEY] = "TMPCOMPPKID";
            $this->m_indexSet[FOREIGNKEY] = "DIRPROJPKID";
            $this->m_indexSet[NATURALKEY] = "TMPCOMPNAME";
            $this->m_indexSet[REFLECTKEY] = "TMPCOMPLINK";
            //
            $this->m_fieldSet["TMPCOMPPKID"] = $TMPCOMPPKID;
        }
        //---------------------------------------------------------------------
        //	Properties
        
        /**
         *
         * @param	string		filename
         * @return	boolean
         *
         */
        function set_upload($uploadFile = "") {
            //
            $this->m_Upload = false;
            //
            if (!empty($uploadFile)) {
                //
                $temp = $_FILES[$uploadFile]['tmp_name'];
                $mime = $_FILES[$uploadFile]['type'];
                //
                $load = @fopen($temp, "rb");
                if ($load == false) {
                    $this->m_errorSet["TMPFILETEXT"] = true;
                    return (false);
                }
                //
                while (!feof($load)) {
                    $blob.= @fread($load, 1024);
                }
                fclose($load);
                //
                $data = @addslashes($blob);
                if ($data == "") {
                    $this->m_errorSet["TMPFILETEXT"] = true;
                    return (false);
                }
                //
                $this->m_fieldSet["TMPFILETEXT"] = $data;
                $this->m_fieldSet["TMPFILEMIME"] = $mime;
                //
                $this->m_Upload = true;
                //
                return (true);
            }
            //
            return (false);
        }
        //---------------------------------------------------------------------
        //	Methods
        
        /**
         *
         * @param	integer	 index type
         * @return	string
         */
        function getInsertQuery($indexType = FOREIGNKEY) {
            //
            $table = $this->m_tableSet[PRIMARYKEY];
            //
            $insertSQL = "INSERT INTO $table ( ";
            $valuesSQL = "VALUES ( ";
            //	OBJECTOPKID  Objectory
            $value = $this->m_fieldSet["OBJECTOPKID"];
            if (!empty($value)) {
                $insertSQL.= "  OBJECTOPKID ";
                $valuesSQL.= "  $value";
            } else {
                $this->m_errorSet["OBJECTOPKID"] = true;
                return ("");
            }
            //	REPMCOMPKID RepositoryModelComponent pkid
            $value = $this->m_fieldSet["REPMCOMPKID"];
            if (!empty($value)) {
                $insertSQL.= " ,REPMCOMPKID";
                $valuesSQL.= " ,$value";
            } else {
                $this->m_errorSet["REPMCOMPKID"] = true;
                return ("");
            }
            //	OBJCOMPPKID ObjectoryComponent pkid
            $value = $this->m_fieldSet["OBJCOMPPKID"];
            if (!empty($value)) {
                $insertSQL.= " ,OBJCOMPPKID";
                $valuesSQL.= " ,$value";
            } else {
                $this->m_errorSet["OBJCOMPPKID"] = true;
                return ("");
            }
            //	OBJCTYPPKID TemporaryComponentType
            $value = $this->m_fieldSet["OBJCTYPPKID"];
            if (!empty($value)) {
                $insertSQL.= " ,OBJCTYPPKID";
                $valuesSQL.= " ,$value";
            } else {
                $this->m_errorSet["OBJCTYPPKID"] = true;
                return ("");
            }
            //	TMPCOMPLINK TemporaryComponent reflection key
            $value = $this->m_fieldSet["TMPCOMPLINK"];
            switch ($indexType) {
                case FOREIGNKEY:
                    //
                    if ($value != 0) {
                        $this->m_errorSet["TMPCOMPLINK"] = true;
                        return ("");
                    }
                    //
                    
                break;
                case REFLECTKEY:
                    //
                    if ($value == 0) {
                        $this->m_errorSet["TMPCOMPLINK"] = true;
                        return ("");
                    }
                    //
                    
                break;
            }
            if (!empty($value)) {
                $insertSQL.= " ,TMPCOMPLINK";
                $valuesSQL.= " ,$value";
            }
            // TMPCOMPNAME TemporaryComponent name
            $value = FilterFormInput::filter($this->m_fieldSet["TMPCOMPNAME"]);
            if (!empty($value)) {
                $insertSQL.= " ,TMPCOMPNAME";
                $valuesSQL.= " ,$value";
            } else {
                $this->m_errorSet["TMPCOMPNAME"] = true;
                return ("");
            }
            // TMPCOMPPATH TemporaryComponent locator
            $value = FilterLocator::filter($this->m_fieldSet["TMPCOMPPATH"]);
            if (ValidatorLocator::isValid($value, $this->m_fieldSet["OBJCTYPPKID"])) {
                $insertSQL.= " ,TMPCOMPPATH";
                $valuesSQL.= " ,$value";
            } else {
                $this->m_errorSet["TMPCOMPPATH"] = true;
                return ("");
            }
            // TMPCOMPTEXT TemporaryComponent description
            $value = FilterFormInput::filter($this->m_fieldSet["TMPCOMPTEXT"], true);
            if (!empty($value)) {
                $insertSQL.= " ,TMPCOMPTEXT";
                $valuesSQL.= " ,$value";
            }
            //	TMPFILETEXT TemporaryComponent file
            $value = @trim($this->m_fieldSet["TMPFILETEXT"]);
            if (!empty($value)) {
                $value = @addslashes($value);
                $insertSQL.= " ,TMPFILETEXT";
                $valuesSQL.= " ,\"$value\"";
            }
            //	TMPFILELANG TemporaryComponent processor
            $value = @trim($this->m_fieldSet["TMPFILELANG"]);
            if (!empty($value)) {
                $insertSQL.= " ,TMPFILELANG";
                $valuesSQL.= " ,\"$value\"";
            }
            //	TMPFILEMIME TemporaryComponent file mime
            $value = @trim($this->m_fieldSet["TMPFILEMIME"]);
            if (!empty($value)) {
                $insertSQL.= " ,TMPFILEMIME";
                $valuesSQL.= " ,\"$value\"";
            }
            //	TMPMAKEMODE TemporaryComponent mode
            $value = @trim($this->m_fieldSet["TMPMAKEMODE"]);
            if (!empty($value)) {
                $insertSQL.= " ,TMPMAKEMODE";
                $valuesSQL.= " ,$value";
            }
            //	TMPMAKEMIME TemporaryComponent output type
            $value = @trim($this->m_fieldSet["TMPMAKEMIME"]);
            if (!empty($value)) {
                $insertSQL.= " ,TMPMAKEMIME";
                $valuesSQL.= " ,$value";
            }
            // TMPCOMPDATE TemporaryComponent creation date
            $value = Date("Y-m-d H:i:s");
            $insertSQL.= " ,TMPCOMPDATE";
            $valuesSQL.= " ,\"$value\"";
            // TMPCOMPSTAT TemporaryComponent status
            $value = 1;
            $insertSQL.= " ,TMPCOMPSTAT";
            $valuesSQL.= " ,$value";
            // TMPCOMPTYPE TemporaryComponent type
            $value = $this->m_fieldSet["TMPCOMPTYPE"];
            if (!empty($value)) {
                $insertSQL.= " ,TMPCOMPTYPE";
                $valuesSQL.= " ,$value";
            }
            //
            //
            return ($insertSQL . ") " . $valuesSQL . ")");
        }
        /**
         *
         * @param	integer	 index type
         * @return	string
         */
        function getUpdateQuery($indexType = PRIMARYKEY) {
            //
            $table = $this->m_tableSet[PRIMARYKEY];
            //
            switch ($indexType) {
                case PRIMARYKEY:
                    # index = Pkid
                    $field = $this->m_indexSet[PRIMARYKEY];
                    $index = $this->m_fieldSet["$field"];
                    if ($index != 0) {
                        //
                        $updateSQL = "UPDATE $table SET ";

                        // TMPCOMPNAME TemporaryComponent name
                        $value = FilterFormInput::filter($this->m_fieldSet["TMPCOMPNAME"]);
                        if (!empty($value)) $updateSQL.= " TMPCOMPNAME=$value";
                        else {
                            $this->m_errorSet["TMPCOMPNAME"] = true;
                            return ("");
                        }

                        //	TMPCOMPLINK TemporaryComponent reflection key
                        $value = $this->m_fieldSet["TMPCOMPLINK"];
                        if (!empty($value)) $updateSQL.= ",TMPCOMPLINK=$value";

                        // TMPCOMPPATH TemporaryComponent locator
                        $value = FilterLocator::filter($this->m_fieldSet["TMPCOMPPATH"]);
                        if (ValidatorLocator::isValid($value, $this->m_fieldSet["OBJCTYPPKID"]))
                            $updateSQL.= ",TMPCOMPPATH=$value";
                        else {
                            $this->m_errorSet["TMPCOMPPATH"] = true;
                            return ("");
                        }

                        // TMPCOMPTEXT TemporaryComponent description
                        $value = FilterFormInput::filter($this->m_fieldSet["TMPCOMPTEXT"], true);
                        $updateSQL.= ",TMPCOMPTEXT=$value";

                        //	TMPFILELANG TemporaryComponent processor
                        $value = $this->m_fieldSet["TMPFILELANG"];
                        if (!empty($value)) $updateSQL.= ",TMPFILELANG=\"$value\"";

                        //	TMPMAKEMODE TemporaryComponent mode
                        $value = $this->m_fieldSet["TMPMAKEMODE"];
                        if (!empty($value)) $updateSQL.= ",TMPMAKEMODE=$value";

                        //	TMPMAKEMIME TemporaryComponent output type
                        $value = $this->m_fieldSet["TMPMAKEMIME"];
                        if (!empty($value)) $updateSQL.= ",TMPMAKEMIME=\"$value\"";
                        //
                        if ($this->m_Upload == true) {
                            $value = $this->m_fieldSet["TMPFILETEXT"];
                            $updateSQL.= ",TMPFILETEXT=\"$value\"";
                            //
                            $value = $this->m_fieldSet["TMPFILEMIME"];
                            $updateSQL.= ",TMPFILEMIME=\"$value\"";
                        }
                        // TMPCOMPSTAT TemporaryComponent status
                        $value = $this->m_fieldSet["TMPCOMPSTAT"];
                        $updateSQL.= ",TMPCOMPSTAT=$value";
                        //
                        //
                        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 TMPCOMPSTAT=0 WHERE $field=$index");
                    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_temporary_component
                        *	ON
                        *		TMPCOMPPKID
                        *
                        */
                        //
                        # index = Pkid
                        $field = $this->m_indexSet[PRIMARYKEY];
                        $index = $this->m_fieldSet["$field"];
                        if ($index != 0) return ("
								DELETE 
									t1,
									t2
								FROM 
									tbl_temporary_component	as t1
								LEFT JOIN
									tbl_temporary_component_template as t2
								ON 
									t2.TMPCOMPPKID=t1.TMPCOMPPKID
								WHERE 
									t1.TMPCOMPPKID=$index");
                        //
                        break;
                    }
                    //
                    return ("");
            }
            /**
             *
             * @param	integer	 index type
             * @return	string
             */
            function getSelectQuery($indexType = PRIMARYKEY) {
                //
                switch ($indexType) {
                    case PRIMARYKEY:
                        /*
                        *
                        *	SELECT
                        *			tbl_temporary_component			as t1
                        *		<-> tbl_objectory_component_type	as t2
                        *	ON TMPCOMPPKID
                        *
                        */
                        //
                        $index = $this->m_fieldSet["TMPCOMPPKID"];
                        if ($index != 0) return ("SELECT  
									t1.*,
									t2.REPTYPEPKID,
									t2.OBJCTYPNAME, 
									t2.OBJCTYPTYPE 
								FROM 
									tbl_temporary_component as t1, 
									tbl_objectory_component_type as t2 
								WHERE 
									t1.TMPCOMPPKID=$index 
								AND 
									t1.OBJCTYPPKID=t2.OBJCTYPPKID");
                        //
                        break;
                    }
                    //
                    return ("");
            }
        };
        //	Class
        //-------------------------------------------------------------------------
        
    }
    //	namespace
    //-----------------------------------------------------------------------------
    
?>
Return current item: Entier Studio