Location: PHPKode > projects > Entier Studio > entierstudio/studio/classes/procs/interchange/proc.ElementWriter.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 
 * @version	   $Id: proc.ElementWriter.php 115 2008-03-07 22:29:12Z yannromefort $
 * @copyright  Copyright (c) 2006 Entier Studio team. All rights reserved.
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefElementWriter")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefElementWriter", "1");
    //-------------------------------------------------------------------------
    //	Include
    @include_once (COMPONENTS_DATA . "data.ObjectoryElement.php");
    @include_once (COMPONENTS_DATA . "data.ObjectoryContainedElementSet.php");
    //
    @include_once (INTERCHANGE_DATA. "data.InterchangeElementPropertyValueSet.php");
    //-------------------------------------------------------------------------
    //	Class
    class ElementWriter {
        //---------------------------------------------------------------------
        //	Constructor
        
        /**
         *
         */
        function ElementWriter() {
            //
        }
        //---------------------------------------------------------------------
        //	Methods        
        /**
         *
         * @access	protected
         *
         * @param	object		name="datasource"
         * @param	integer		name="primarykey"
         * @return	string		namespace root
         */
        function getNamespaceRoot(&$datasource, $primarykey) {
            //
            $element = new ObjectoryElement($primarykey);
            if ($element->selectRow($datasource) == true) {
                return ($element->get_field_value("OBJELEMCODE"));
            }
            //
            return ("");
        }
        /**
         *
         * @access	protected
         *
         * @param	object		name="datasource"
         * @param	integer		name="primarykey"
         * @param	string		name="namespace"
         * @return	string		namespace
         */
        function getNamespacePath(&$datasource, $primarykey, $namespace = "") {
            //
            $element = new ObjectoryElement($primarykey);
            if ($element->selectRow($datasource) == true) {
                //
                $link = $element->get_field_value("OBJELEMLINK");
                if (!empty($link)) {
                    //
                    if ($namespace == "")
                        $namespace = $element->get_field_value("OBJELEMCODE");
                    else
                        $namespace = $element->get_field_value("OBJELEMCODE") . "." . $namespace;
                    //
                    return ($this->getNamespacePath($datasource, $link, $namespace));
                }
            }
            //
            return ($namespace);
        }
        /**
         *
         * @access	protected
         *
         * @param	object		name="datasource"
         * @param	object		name="template"
         * @param	integer		name="handle"
         * @param	string		name="block"
         * @param	integer		name="primarykey"
         * @return	boolean
         */
        function addPropertySet(&$datasource, &$template, $handle, $block, $primarykey) {
            //
            //	1.2- Generate Properties
            $propertySet = new InterchangeElementPropertyValueSet($primarykey);
            if ($propertySet->selectSet($datasource) == true) {
                //
                for ($i = 0;$i < $propertySet->rowCount();$i++) {
                    //	select next row
                    if ($propertySet->fetchCursorRow($datasource) == false) return (false);
                    //
                    $template->select($block, $handle);
                    $template->assign($propertySet->fieldSet() , NULL, $handle);
                    $template->render($block, $handle);
                }
            }
            //
            return (true);
        }        
        /**
         *
         * @access	protected
         *
         * @param	object		name="datasource"
         * @param	object		name="template"
         * @param	integer		name="handle"
         * @param	string		name="block"
         * @param	integer		name="type"
         * @param	integer		name="primarykey"
         * @return	boolean
         */
        function addContainedElementSet(&$datasource, &$template, $handle, $block, $type, $primarykey) {
            //	1- ElementSet set
            $elementSet = new ObjectoryContainedElementSet($primarykey, $type);
            if ($elementSet->selectSet($datasource, FOREIGNKEY, FOREIGNKEY) == true) {
                //
                for ($i = 0;$i < $elementSet->rowCount();$i++) {
                    //	select row
                    if ($elementSet->fetchCursorRow($datasource) == false)
                        return (false);
                    //
                    $template->select($block[0], $handle);
                    $template->assign($elementSet->fieldSet() , NULL, $handle);
                    //
                    if ($this->addPropertySet($datasource, $template, $handle, $block[1], $elementSet->get_field_value("OBJELEMPKID")) == false)
                        return (false);
                    //
                    $template->render($block[0], $handle);
                }
            }
            //
            return (true);
        }
        /**
         *
         * @access	public
         *
         * @param	object		name="datasource"
         * @param	object		name="template"
         * @param	array		name="element"
         * @param	integer		name="handle"
         * @return	boolean
         */
        function addElement(&$datasource, &$template, &$element, $handle) {
            //
            $template->assign($element, NULL, $handle);
            // Properties
            if (false == $this->addPropertySet($datasource, $template, $handle, "properties", $element["OBJELEMPKID"]))
                return (false);
            //
            return (true);
        }
    };
    //	Class
    //-------------------------------------------------------------------------    
}
//	namespace
//-----------------------------------------------------------------------------
?>
Return current item: Entier Studio