Location: PHPKode > projects > Entier Studio > entierstudio/studio/classes/procs/proc.ComponentTemporaryToObjectoryImport.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: proc.ComponentTemporaryToObjectoryImport.php 97 2008-02-05 21:08:53Z yannromefort $
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefComponentTemporaryToObjectoryImport")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefComponentTemporaryToObjectoryImport", "1");
    //-------------------------------------------------------------------------
    //	Include
    @include_once (COMPONENTS_DATA . "data.ObjectoryComponent.php");
    @include_once (COMPONENTS_DATA . "data.TemporaryComponentSet.php");
    @include_once (COMPONENTS_DATA . "data.TemporaryComponentTemplate.php");
    @include_once (COMPONENTS_DATA . "data.ObjectoryComponentTemplate.php");
    //-------------------------------------------------------------------------
    //	Class
    class ComponentTemporaryToObjectoryImport {
        //---------------------------------------------------------------------
        //	Attributes
        
        /**
         * Released number
         *
         * @var	integer
         */
        var $m_releasedCount = 0;
        /**
         * Garbage object
         *
         * @var	object
         */
        var $m_DiscardedObject = NULL;
        //---------------------------------------------------------------------
        //	Constructor
        
        /**
         *
         */
        function ComponentTemporaryToObjectoryImport() {
        }
        //---------------------------------------------------------------------
        //	Properties
        /*
        * releasedCount property
        * @return	integer
        */
        function releasedCount() {
            //
            return ($this->m_releasedCount);
        }
        /*
        * DiscardedObject property
        * @return	integer
        */
        function DiscardedObject() {
            //
            return ($this->m_DiscardedObject);
        }
        //---------------------------------------------------------------------
        //	Methods
        
        /**
         *
         * @access	private
         *
         * @param	object		name="datasource"
         * @param	array		name="temporary"
         * @param	array		name="objectory"
         *
         */
        function importTree(&$datasource, &$temporary, &$objectory) {
            //
            $componentSet = new TemporaryComponentSet($temporary["OBJCOMPPKID"], $temporary["TMPCOMPPKID"]);
            if ($componentSet->selectSet($datasource, REFLECTKEY, REFLECTKEY) == true) {
                //
                for ($i = 0;$i < $componentSet->rowCount();$i++) {
                    //	select next row
                    if ($componentSet->fetchCursorRow($datasource) == false) return (false);
                    //	insert relevant row
                    if ($this->importItem($datasource, $componentSet->fieldSet() , $objectory) == false) return (false);
                }
            }
            //
            return (true);
        }
        /**
         *
         * @access	private
         *
         * @param	object		name="datasource"
         * @param	array		name="temporary"
         * @param	array		name="objectory"
         *
         */
        function importItem(&$datasource, &$temporary, &$objectory) {
            //
            $component = new ObjectoryComponent();
            //
            $component->set_field_value("OBJECTOPKID", $objectory["OBJECTOPKID"]);
            $component->set_field_value("OBJCOMPLINK", $objectory["OBJCOMPPKID"]);
            $component->set_field_value("OBJCOMPROOT", $objectory["OBJCOMPROOT"]);
            //
            $component->set_field_value("OBJCTYPPKID", $temporary["OBJCTYPPKID"]);
            $component->set_field_value("OBJCOMPNAME", $temporary["TMPCOMPNAME"]);
            $component->set_field_value("OBJCOMPPATH", $temporary["TMPCOMPPATH"]);
            $component->set_field_value("OBJCOMPTEXT", $temporary["TMPCOMPTEXT"]);
            //
            switch ($temporary["OBJCTYPTYPE"]) {
                case MODEL_FILE_TYPE:
                    //
                    if ($component->insertRow($datasource, REFLECTKEY) == true) {
                        //
                        $this->m_releasedCount++;
                        //
                        //
                        $temporaryTemplate = new TemporaryComponentTemplate($temporary["TMPCOMPPKID"]);
                        if ($temporaryTemplate->selectRow($datasource) == true) {
                            //
                            $componentTemplate = new ObjectoryComponentTemplate($component->get_field_value("OBJCOMPPKID"));
                            //
                            //
                            $componentTemplate->set_field_value("OBJETYPPKID", $temporaryTemplate->get_field_value("OBJETYPPKID"));
                            $componentTemplate->set_field_value("OBJFILETEXT", $temporaryTemplate->get_field_value("TMPFILETEXT"));
                            $componentTemplate->set_field_value("OBJFILELANG", $temporaryTemplate->get_field_value("TMPFILELANG"));
                            $componentTemplate->set_field_value("OBJFILEMIME", $temporaryTemplate->get_field_value("TMPFILEMIME"));
                            $componentTemplate->set_field_value("OBJMAKEMODE", $temporaryTemplate->get_field_value("TMPMAKEMODE"));
                            $componentTemplate->set_field_value("OBJMAKEMIME", $temporaryTemplate->get_field_value("TMPMAKEMIME"));
                            //
                            if ($componentTemplate->set_import() == true) $componentTemplate->insertRow($datasource);
                        }
                        //
                        return (true);
                    }
                    //
                    return (false);
                    //
                    break;
                default:
                    //
                    if ($component->insertRow($datasource, REFLECTKEY) == true) {
                        //
                        $this->m_releasedCount++;
                        //
                        return ($this->importTree( //	import dependent components
                        $datasource, $temporary, $component->fieldSet()));
                    }
                    //
                    break;
                }
                //
                $this->m_DiscardedObject = $temporary;
                //
                return (false);
        }
        /**
         *
         * @access	public
         *
         * @param	object		name="datasource"
         * @param	array		name="objectory"
         */
        function import(&$datasource, &$objectory) {
            //
            if (!is_object($datasource)) return (false);
            //
            if (!is_array($objectory)) return (false);
            //
            /*
            * 1- TemporaryComponentSet
            */
            //
            @include_once (COMPONENTS_DATA . "data.TemporaryComponentSet.php");
            //
            $componentSet = new TemporaryComponentSet($objectory["OBJCOMPPKID"]);
            if ($componentSet->selectSet($datasource) == true) {
                //	OBJCOMPROOT setting
                
                /**
                 * @mock $objectory["OBJCTYPPKID"] == ARCHITECTURE_TYPE )
                 */
                //
                if ($objectory["OBJCTYPPKID"] == MODEL_ROOT_TYPE) $objectory["OBJCOMPROOT"] = $objectory["OBJCOMPPKID"];
                //
                for ($i = 0;$i < $componentSet->rowCount();$i++) {
                    //	select next row
                    if ($componentSet->fetchCursorRow($datasource) == false) return (false);
                    //	insert relevant row
                    if ($this->importItem($datasource, $componentSet->fieldSet() , $objectory) == false) return (false);
                }
            }
            //
            /*
            * 2 - Delete TemporaryComponentSet
            */
            //
            $temporaryComponentSet = new TemporaryComponentSet($objectory["OBJCOMPPKID"]);
            $temporaryComponentSet->deleteSet($datasource);
            //
            return (true);
        }
    };
    //	Class
    //-------------------------------------------------------------------------
    
}
//	namespace
//-----------------------------------------------------------------------------
?>
Return current item: Entier Studio