Location: PHPKode > projects > Entier Studio > entierstudio/studio/classes/procs/proc.ComponentRepositoryToTemporaryImport.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.ComponentRepositoryToTemporaryImport.php 81 2008-01-17 23:08:21Z yannromefort $
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefComponentRepositoryToTemporaryImport")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefComponentRepositoryToTemporaryImport", "1");
    //-------------------------------------------------------------------------
    //	Include
    @include_once (COMPONENTS_DATA . "data.TemporaryComponent.php");
    @include_once (COMPONENTS_DATA . "data.TemporaryComponentSet.php");
    @include_once (COMPONENTS_DATA . "data.TemporaryModelComponent.php");
    @include_once (COMPONENTS_DATA . "data.TemporaryModelComponentSet.php");
    @include_once (COMPONENTS_DATA . "data.TemporaryComponentTemplate.php");
    @include_once (COMPONENTS_DATA . "data.RepositoryModelComponentTemplate.php");
    //
    //-------------------------------------------------------------------------
    //	Class
    class ComponentRepositoryToTemporaryImport {
        //---------------------------------------------------------------------
        //	Constructor
        
        /**
         *
         */
        function ComponentRepositoryToTemporaryImport() {
        }
        //---------------------------------------------------------------------
        //	Methods
        
        /**
         *
         * @access	protected
         *
         * @param	object		name="datasource"
         * @param	array		name="repository"
         * @param	array		name="objectory"
         * @param	object		name="temporary"
         *
         */
        function importTreeItem(&$datasource, &$repository, &$objectory, $temporary) {
            //
            $component = new TemporaryComponent();
            //
            $component->set_field_value("OBJECTOPKID", $temporary["OBJECTOPKID"]);
            $component->set_field_value("OBJCOMPPKID", $temporary["OBJCOMPPKID"]);
            $component->set_field_value("TMPCOMPLINK", $temporary["TMPCOMPPKID"]);
            //
            $component->set_field_value("REPMCOMPKID", $repository["REPMCOMPKID"]);
            $component->set_field_value("OBJCTYPPKID", $repository["OBJCTYPPKID"]);
            //
            $component->set_field_value("TMPCOMPNAME", $repository["REPMCOMNAME"]);
            $component->set_field_value("TMPCOMPPATH", $repository["REPMCOMPATH"]);
            $component->set_field_value("TMPCOMPTEXT", $repository["REPMCOMTEXT"]);
            //
            switch ($repository["REPMCOTTYPE"]) {
                case MODEL_FILE_TYPE:
                    //
                    if ($component->insertRow($datasource, REFLECTKEY) == true) {
                        //
                        $componentTemplate = new RepositoryModelComponentTemplate($repository["REPMCOMPKID"]);
                        //
                        if ($componentTemplate->selectRow($datasource) == true) {
                            //
                            $temporaryTemplate = new TemporaryComponentTemplate($component->get_field_value("TMPCOMPPKID"));
                            //
                            $temporaryTemplate->set_field_value("OBJETYPPKID", $componentTemplate->get_field_value("OBJETYPPKID"));
                            $temporaryTemplate->set_field_value("TMPFILETEXT", $componentTemplate->get_field_value("REPFILETEXT"));
                            $temporaryTemplate->set_field_value("TMPFILELANG", $componentTemplate->get_field_value("REPFILELANG"));
                            $temporaryTemplate->set_field_value("TMPFILEMIME", $componentTemplate->get_field_value("REPFILEMIME"));
                            $temporaryTemplate->set_field_value("TMPMAKEMODE", $componentTemplate->get_field_value("REPMAKEMODE"));
                            $temporaryTemplate->set_field_value("TMPMAKEMIME", $componentTemplate->get_field_value("REPMAKEMIME"));
                            //
                            if ($temporaryTemplate->set_import() == true) $temporaryTemplate->insertRow($datasource);
                        }
                        //
                        return (true);
                    }
                    //
                    return (false);
                    //
                    break;
                default:
                    //
                    if ($component->insertRow($datasource, REFLECTKEY) == true) {
                        //	select dependent rows
                        return ($this->importTree($datasource, $repository, $objectory, $component->fieldSet()));
                    }
                    //
                    break;
                }
                //
                return (false);
        }
        /**
         *
         * @access	protected
         *
         * @param	object		name="datasource"
         * @param	array		name="repository"
         * @param	array		name="objectory"
         * @param	array		name="temporary"
         *
         */
        function importTree(&$datasource, &$repository, &$objectory, $temporary) {
            //
            $componentSet = new TemporaryModelComponentSet($repository["REPMCOMPKID"]);
            if ($componentSet->selectSet($datasource, REFLECTKEY, NATURALKEY) == true) {
                //
                for ($i = 0;$i < $componentSet->rowCount();$i++) {
                    //	select next row
                    if ($componentSet->fetchCursorRow($datasource) == false) return (false);
                    //
                    if ($this->importTreeItem($datasource, $componentSet->fieldSet() , $objectory, $temporary) == false) return (false);
                }
            }
            //
            return (true);
        }
        /**
         *
         * @access	protected
         *
         * @param	object		name="datasource"
         * @param	array		name="repository"
         * @param	array		name="objectory"
         * @param	object		name="temporary"
         *
         */
        function importItem(&$datasource, &$repository, &$objectory, $temporary) {
            //
            $component = new TemporaryComponent();
            //
            $component->set_field_value("OBJECTOPKID", $temporary["OBJECTOPKID"]);
            $component->set_field_value("OBJCOMPPKID", $temporary["OBJCOMPPKID"]);
            //
            $component->set_field_value("REPMCOMPKID", $repository["REPMCOMPKID"]);
            $component->set_field_value("OBJCTYPPKID", $repository["OBJCTYPPKID"]);
            //
            $component->set_field_value("TMPCOMPNAME", $repository["REPMCOMNAME"]);
            $component->set_field_value("TMPCOMPPATH", $repository["REPMCOMPATH"]);
            $component->set_field_value("TMPCOMPTEXT", $repository["REPMCOMTEXT"]);
            //
            switch ($repository["REPMCOTTYPE"]) {
                case MODEL_FILE_TYPE:
                    //
                    if ($component->insertRow($datasource) == true) {
                        //
                        $componentTemplate = new RepositoryModelComponentTemplate($repository["REPMCOMPKID"]);
                        //
                        if ($componentTemplate->selectRow($datasource) == true) {
                            //
                            $temporaryTemplate = new TemporaryComponentTemplate($component->get_field_value("TMPCOMPPKID"));
                            //
                            $temporaryTemplate->set_field_value("OBJETYPPKID", $componentTemplate->get_field_value("OBJETYPPKID"));
                            $temporaryTemplate->set_field_value("TMPFILETEXT", $componentTemplate->get_field_value("REPFILETEXT"));
                            $temporaryTemplate->set_field_value("TMPFILELANG", $componentTemplate->get_field_value("REPFILELANG"));
                            $temporaryTemplate->set_field_value("TMPFILEMIME", $componentTemplate->get_field_value("REPFILEMIME"));
                            $temporaryTemplate->set_field_value("TMPMAKEMODE", $componentTemplate->get_field_value("REPMAKEMODE"));
                            $temporaryTemplate->set_field_value("TMPMAKEMIME", $componentTemplate->get_field_value("REPMAKEMIME"));
                            //
                            if ($temporaryTemplate->set_import() == true) $temporaryTemplate->insertRow($datasource);
                        }
                        //
                        return (true);
                    }
                    //
                    return (false);
                    //
                    break;
                default:
                    //
                    if ($component->insertRow($datasource) == true) {
                        //	select dependent rows
                        return ($this->importTree($datasource, $repository, $objectory, $component->fieldSet()));
                    }
                    //
                    break;
                }
                //
                return (false);
        }
        /**
         *
         * @access	public
         *
         * @param	object		name="datasource"
         * @param	array		name="repository"
         * @param	array		name="objectory"
         * @param	boolean		name="deletion"
         * @return	boolean
         *
         */
        function import(&$datasource, &$repository, &$objectory, $deletion = false) {
            //
            if (!is_object($datasource)) return (false);
            //
            if (!is_array($repository)) return (false);
            //
            if (!is_array($objectory)) return (false);
            /*
            * 1 - Delete TemporaryComponentSet
            */
            //
            if ($deletion == true) {
                $temporaryComponentSet = new TemporaryComponentSet($objectory["OBJCOMPPKID"]);
                $temporaryComponentSet->deleteSet($datasource);
            }
            //
            /*
            * 2 Initialize a TemporaryElement + check if already in temporary model set
            */
            //
            $temporary = new TemporaryComponent();
            //
            $temporary->set_field_value("OBJCOMPPKID", $objectory["OBJCOMPPKID"]);
            $temporary->set_field_value("OBJECTOPKID", $objectory["OBJECTOPKID"]);
            $temporary->set_field_value("REPMCOMPKID", $repository["REPMCOMPKID"]);
            if ($temporary->selectRow($datasource, FOREIGNKEY) == true) return (true);
            //
            /*
            * 3 Insert Repository model item
            */
            //
            $modelComponent = new TemporaryModelComponent($repository["REPMCOMPKID"]);
            if ($modelComponent->selectRow($datasource) == true) {
                //
                $modelComponent->set_field_value("REPMCOMNAME", $repository["REPMCOMNAME"]);
                $modelComponent->set_field_value("REPMCOMPATH", $repository["REPMCOMPATH"]);
                //	insert relevant row
                return ($this->importItem($datasource, $modelComponent->fieldSet() , $objectory, $temporary->fieldSet()));
            }
            //
            return (false);
        }
    };
    //	Class
    //-------------------------------------------------------------------------
    
}
//	namespace
//-----------------------------------------------------------------------------
?>
Return current item: Entier Studio