Location: PHPKode > projects > Entier Studio > entierstudio/studio/classes/procs/proc.ElementTemporaryToObjectoryImport.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.ElementTemporaryToObjectoryImport.php 97 2008-02-05 21:08:53Z yannromefort $
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefElementTemporaryToObjectoryImport")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefElementTemporaryToObjectoryImport", "1");
    //-------------------------------------------------------------------------
    //	Include
    @include_once (COMPONENTS_DATA . "data.ObjectoryElement.php");
    @include_once (COMPONENTS_DATA . "data.ObjectoryElementPropertyValue.php");
    //
    @include_once (COMPONENTS_DATA . "data.TemporaryElementSet.php");
    @include_once (COMPONENTS_DATA . "data.TemporaryElementPropertyValueSet.php");
    //
    //-------------------------------------------------------------------------
    //	Class
    class ElementTemporaryToObjectoryImport {
        //---------------------------------------------------------------------
        //	Attributes
        
        /**
         * Released number
         *
         * @var	integer
         */
        var $m_releasedNumber = 0;
        /**
         * Garbage object
         *
         * @var	object
         */
        var $m_discardedObject = NULL;
        /**
         * objectory set
         * array of <TMPELEMPKID,OBJELEMPKID> pairs
         *
         * @var	array
         */
        var $m_objectorySet = array();
        //---------------------------------------------------------------------
        //	Constructor
        
        /**
         *
         */
        function ElementTemporaryToObjectoryImport() {
        }
        //---------------------------------------------------------------------
        //	Properties
        /*
        * releasedCount property
        * @return	integer
        */
        function releasedCount() {
            //
            return ($this->m_releasedNumber);
        }
        /*
        * DiscardedObject property
        * @return	integer
        */
        function DiscardedObject() {
            //
            return ($this->m_discardedObject);
        }
        //---------------------------------------------------------------------
        //	Methods
        
        /**
         *
         * @access	private
         *
         * @param	object		name="datasource"
         * @param	array		name="objectory"
         *
         */
        function importElementReferenceSet(&$datasource, &$objectory) {
            //
            @include_once (COMPONENTS_DATA . "data.TemporaryElementReferenceSet.php");
            $referenceSet = new TemporaryElementReferenceSet($objectory["OBJELEMPKID"]);
            if ($referenceSet->selectSet($datasource) == true) {
                // ObjectoryElementReference
                @include_once (COMPONENTS_DATA . "data.ObjectoryElementReference.php");
                //
                for ($i = 0;$i < $referenceSet->rowCount();$i++) {
                    //	select next item
                    if ($referenceSet->fetchCursorRow($datasource) == false) return (false);
                    //	insert item
                    $reference = new ObjectoryElementReference();
                    // Insert reference
                    $OBJERETPKID = $referenceSet->get_field_value("OBJERETPKID");
                    $TMPELEMLINK = $referenceSet->get_field_value("TMPELEMLINK");
                    $TMPELEMPKID = $referenceSet->get_field_value("TMPELEMPKID");
                    $TMPELEMRFID = $referenceSet->get_field_value("TMPELEMRFID");
                    //
                    $reference->set_field_value("OBJERETPKID", $OBJERETPKID);
                    $reference->set_field_value("OBJELEMLINK", $this->m_objectorySet[$TMPELEMLINK]);
                    $reference->set_field_value("OBJELEMPKID", $this->m_objectorySet[$TMPELEMPKID]);
                    $reference->set_field_value("OBJELEMRFID", $this->m_objectorySet[$TMPELEMRFID]);
                    //
                    if ($reference->insertRow($datasource) == false) return (false);
                    //
                    unset($reference);
                }
            }
            //
            return (true);
        }
        /**
         *
         * @access	private
         *
         * @param	object		name="datasource"
         * @param	array		name="temporary"
         * @param	array		name="objectory"
         *
         */
        function importElementPropertyValueSet(&$datasource, &$temporary, &$objectory) {
            //
            $propertyValue = null;
            $propertyValueSet = new TemporaryElementPropertyValueSet($temporary["TMPELEMPKID"]);
            if ($propertyValueSet->selectSet($datasource) == true) {
                //
                for ($i = 0;$i < $propertyValueSet->rowCount();$i++) {
                    //	select next row
                    if ($propertyValueSet->fetchCursorRow($datasource) == false) return (false);
                    //	insert relevant item
                    $propertyValue = new ObjectoryElementPropertyValue();
                    $propertyValue->set_field_value("OBJELEMPKID", $objectory["OBJELEMPKID"]);
                    $propertyValue->set_field_value("DICPROPPKID", $propertyValueSet->get_field_value("DICPROPPKID"));
                    $propertyValue->set_field_value("DICPVALPKID", $propertyValueSet->get_field_value("DICPVALPKID"));
                    $propertyValue->set_field_value("OBJEPRODATA", $propertyValueSet->get_field_value("TMPEPRODATA"));
                    $propertyValue->set_field_value("OBJEPROTYPE", $propertyValueSet->get_field_value("TMPEPROTYPE"));
                    //
                    if ($propertyValue->insertRow($datasource) == false) return (false);
                    //
                    unset($propertyValue);
                }
            }
            //
            return (true);
        }
        /**
         *
         * @access	private
         *
         * @param	object		name="datasource"
         * @param	array		name="temporary"
         * @param	array		name="objectory"
         *
         */
        function importElementTree(&$datasource, &$temporary, &$objectory) {
            //
            $elementSet = new TemporaryElementSet($temporary["OBJELEMPKID"], $temporary["TMPELEMPKID"]);
            if ($elementSet->selectSet($datasource, REFLECTKEY, REFLECTKEY) == true) {
                //
                for ($i = 0;$i < $elementSet->rowCount();$i++) {
                    //	select next row
                    if ($elementSet->fetchCursorRow($datasource) == false) return (false);
                    //	insert relevant row
                    if ($this->importElement($datasource, $elementSet->fieldSet() , $objectory) == false) return (false);
                }
            }
            //
            return (true);
        }
        /**
         *
         * @access	private
         *
         * @param	object		name="datasource"
         * @param	array		name="temporary"
         * @param	array		name="objectory"
         *
         */
        function importElement(&$datasource, &$temporary, &$objectory) {
            //
            $element = new ObjectoryElement();
            //
            $element->set_field_value("OBJELEMLINK", $objectory["OBJELEMPKID"]);
            $element->set_field_value("OBJECTOPKID", $objectory["OBJECTOPKID"]);
            $element->set_field_value("OBJELEMROOT", $objectory["OBJELEMROOT"]);
            //
            $element->set_field_value("OBJETYPPKID", $temporary["OBJETYPPKID"]);
            $element->set_field_value("OBJELEMNAME", $temporary["TMPELEMNAME"]);
            $element->set_field_value("OBJELEMTEXT", $temporary["TMPELEMTEXT"]);
            $element->set_field_value("OBJELEMCODE", $temporary["TMPELEMCODE"]);
            $element->set_field_value("OBJELEMINAM", $temporary["TMPELEMINAM"]);
            $element->set_field_value("OBJELEMRANK", $temporary["TMPELEMRANK"]);
            //
            if ($element->insertRow($datasource, REFLECTKEY) == true) {
                // importation management
                $this->m_objectorySet[$temporary["TMPELEMPKID"]] = $element->get_field_value("OBJELEMPKID");
                //	insert relevant properties
                if ($this->importElementPropertyValueSet($datasource, $temporary, $element->fieldSet()) == true) {
                    //
                    $this->m_releasedNumber++;
                    //
                    return ($this->importElementTree( //	import dependent elements
                    $datasource, $temporary, $element->fieldSet()));
                }
            }
            //
            $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- TemporaryElementSet
            */
            //
            @include_once (COMPONENTS_DATA . "data.TemporaryElementSet.php");
            //
            $elementSet = new TemporaryElementSet($objectory["OBJELEMPKID"]);
            if ($elementSet->selectSet($datasource) == true) {
                //	OBJELEMROOT setting
                if ($objectory["OBJETYPPKID"] == MODEL_TYPE) $objectory["OBJELEMROOT"] = $objectory["OBJELEMPKID"];
                //
                for ($i = 0;$i < $elementSet->rowCount();$i++) {
                    //	select next row
                    if ($elementSet->fetchCursorRow($datasource) == false) return (false);
                    //	insert relevant row
                    if ($this->importElement($datasource, $elementSet->fieldSet() , $objectory) == false) return (false);
                }
                //
                if ($this->importElementReferenceSet($datasource, $objectory) == false) return (false);
            }
            //
            /*
            * 2 - Delete TemporaryElementSet
            */
            //
            $temporarySet = new TemporaryElementSet($objectory["OBJELEMPKID"]);
            $temporarySet->deleteSet($datasource);
            //
            return (true);
        }
    };
    //	Class
    //-------------------------------------------------------------------------
    
}
//	namespace
//-----------------------------------------------------------------------------
?>
Return current item: Entier Studio