Location: PHPKode > projects > Entier Studio > entierstudio/studio/classes/procs/interchange/proc.ElementAssociationWriter.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.ElementAssociationWriter.php 115 2008-03-07 22:29:12Z yannromefort $
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefElementAssociationWriter")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefElementAssociationWriter", "1");
    //-------------------------------------------------------------------------
    //	Include
    @require_once (INTERCHANGE_PROC. "proc.ElementWriter.php");
    @require_once (INTERCHANGE_PROC. "proc.ElementAssociationClassWriter.php");
    //-------------------------------------------------------------------------
    //	Class
    class ElementAssociationWriter extends ElementWriter {
        //---------------------------------------------------------------------
        //	Constructor
        
        /**
         *
         */
        function ElementAssociationWriter() {
            //
            
        }
        //---------------------------------------------------------------------
        //	Methods        
        /**
         *
         * @access	protected
         *
         * @param	object		name="datasource"
         * @param	object		name="template"
         * @param	integer		name="handle"
         * @param	string		name="block"
         * @param	integer		element pkid
         * @return	boolean
         */
        function addAssociatedClass(&$datasource, &$template, $handle, $block, $primarykey) {
            //
            $reference = new InterchangeElementReference($primarykey);
            if ($reference->selectRow($datasource, FOREIGNKEY) == true) {
                //
                $element = new ObjectoryElement($reference->get_field_value("OBJELEMRFID"));
                if ($element->selectRow($datasource) == true) {
                    //
                    $template->select($block, $handle);
                    //
                    $writer = new ElementAssociationClassWriter();
                    if ($writer->addElement($datasource, $template, $element->fieldSet() , $handle) == false)
					    return (false);
                    unset($writer);
                    //
                    $template->render($block, $handle);
                    //
                    return (true);
                }
            }
            //
            return (true);
        }
        /**
         *
         * @access	protected
         *
         * @param	object		name="datasource"
         * @param	object		name="template"
         * @param	integer		name="handle"
         * @param	integer		name="primarykey"
         * @return	boolean
         */
        function addAssociationEndSet(&$datasource, &$template, $handle, $primarykey) {
            //	1- AssociationEnd set
            $elementSet = new ObjectoryContainedElementSet($primarykey, ASSOCIATIONEND_TYPE);
            if ($elementSet->selectSet($datasource, FOREIGNKEY, FOREIGNKEY) == true) {
                //
                $block = array(
                    "association-ends", // block 0
                    "association-end-properties", // block 1
                    "association-end-class"
                    // block 2
                    
                );
                //
                for ($i = 0;$i < $elementSet->rowCount();$i++) {
                    //	select row
                    if ($elementSet->fetchCursorRow($datasource) == false)
                        return (false);
                    //
                    $template->select($block[0], $handle);
                    // association-end
                    $template->assign($elementSet->fieldSet() , NULL, $handle);
                    // association-end-properties
                    if ($this->addPropertySet($datasource, $template, $handle, $block[1], $elementSet->get_field_value("OBJELEMPKID")) == false)
                        return (false);
                    // association-class
                    if ($this->addAssociatedClass($datasource, $template, $handle, $block[2], $elementSet->get_field_value("OBJELEMPKID")) == false)
                        return (false);
                    //
                    $template->render($block[0], $handle);
                }
            }
            //
            return (true);
        }
        /**
         * This function renders the xml <attributes> block of the element(primarykey) class
         *
         * @access	protected
         * @param	object		name="datasource"
         * @param	object		name="template"
         * @param	integer		name="handle"
         * @param	integer		name="primarykey"
         * @return	boolean
         */
        function addClassAttributeSet(&$datasource, &$template, $handle, $primarykey) {
			//
            $block = array (
                  "association-attributes",				// block 0
                  "association-attribute-properties"	// block 1
			);
            //	1- Attribute set
            return ($this->addContainedElementSet($datasource, $template, $handle, $block, ATTRIBUTE_TYPE, $primarykey));
        }
        /**
         *
         * @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) {
            //
            $element["OBJPATHROOT"] = $this->getNamespaceRoot($datasource, $element["OBJELEMROOT"]);
            $element["OBJELEMPATH"] = $this->getNamespacePath($datasource, $element["OBJELEMLINK"]);
            //
            $template->assign($element, NULL, $handle);
            // Properties
            if (false == $this->addPropertySet(
							$datasource, $template, $handle, "association-properties", $element["OBJELEMPKID"]))
                return (false);
            // Attributes
            if (false == $this->addClassAttributeSet(
							$datasource, $template, $handle, $element["OBJELEMPKID"]))
                return (false);            
            // AssociationEnds
            if (false == $this->addAssociationEndSet(
							$datasource, $template, $handle, $element["OBJELEMPKID"]))
                return (false);            
            //
            return (true);
        }
    };
    //	Class
    //-------------------------------------------------------------------------
    
}
//	namespace
//-----------------------------------------------------------------------------
?>
Return current item: Entier Studio