Location: PHPKode > projects > Entier Studio > entierstudio/studio/classes/procs/interchange/proc.ElementReferenceWriter.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.ElementReferenceWriter.php 84 2008-01-19 23:49:20Z yannromefort $
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefElementReferenceWriter")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefElementReferenceWriter", "1");
    //-------------------------------------------------------------------------
    //	Include
    @require_once (INTERCHANGE_PROC. "proc.ElementWriter.php");
    @require_once (INTERCHANGE_PROC. "proc.ElementReferenceClassWriter.php");
    @require_once (INTERCHANGE_DATA. "data.InterchangeElementReferenceSet.php");
    //-------------------------------------------------------------------------
    //	Class
    class ElementReferenceWriter extends ElementWriter {
        //---------------------------------------------------------------------
        //	Constructor        
        /**
         *
         */
        function ElementReferenceWriter() {
            //            
        }
        //---------------------------------------------------------------------
        //	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 addReferenceClass(&$datasource, &$template, $parent, $block, $primarykey) {
            //
            $element = new ObjectoryElement($primarykey);
            if ($element->selectRow($datasource) == true) {
                //
                $writer = NULL;
                //
                $handle = $template->import("reference.xml");
                if ($handle == -1)
                    return (false);
                //
                $template->select($block, $handle);
                //
                $writer = new ElementReferenceClassWriter();
                if (false == $writer->addElement($datasource, $template, $element->fieldSet() , $handle))
                    return (false);
                unset($writer);
                //
                $template->render($block, $handle);
                $template->render(".", $handle);
                $template->insert("ReferenceXML", $handle, $parent);
                //
                return (true);
            }
            //
            return (false);
        }
        /**
         *
         * @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 addReferenceAssociation(&$datasource, &$template, $handle, $block, $primarykey) {
            //	1- Element
            $element = new ObjectoryElement($primarykey, $type);
            if ($element->selectRow($datasource) == true) {
                //
                $template->select($block[0], $handle);
                //
                $template->assign($element->fieldSet() , NULL, $handle);
                //
                if (false == $this->addPropertySet($datasource, $template, $handle, $block[1], $element->get_field_value("OBJELEMPKID")))
                    return (false);                
                //
                $template->render($block[0], $handle);
            }
            //
            return (true);
        }
        /**
         *
         * @access	public
         *
         * @param	object		name="datasource"
         * @param	object		name="template"
         * @param	integer		name="handle"
         * @param	string		name="block"
         * @param	integer		name="primarykey"
         * @return	boolean
         */
        function addReferenceSet(&$datasource, &$template, $handle, $block, $primarykey) {
            //	1- Reference set
            $referenceSet = new InterchangeElementReferenceSet($primarykey);
            if (true == $referenceSet->selectSet($datasource)) {
                for ($i = 0;$i < $referenceSet->rowCount();$i++) {
                    //	select next row
                    if (false == $referenceSet->fetchCursorRow($datasource))
                        return (false);
                    //
                    $template->select($block[0], $handle);
                    $template->assign($referenceSet->fieldSet() , NULL, $handle);
                    // <properties>
                    if (false == $this->addPropertySet(
									$datasource, $template, $handle, $block[1], $referenceSet->get_field_value("OBJELEMPKID")))
                        return (false);
                    // <association>
                    if (false == $this->addReferenceAssociation(
									$datasource, $template, $handle, $block[2], $referenceSet->get_field_value("OBJELEMLINK")))
                        return (false);
                    // <class>
					if (false == $this->addReferenceClass(
									$datasource, $template, $handle, $block[3], $referenceSet->get_field_value("OBJELEMRFID")))
					    return (false);
                    //
                    $template->render($block[0], $handle);
                }
            }
            //
            return (true);
        }
    };
    //	Class
    //-------------------------------------------------------------------------    
}
//	namespace
//-----------------------------------------------------------------------------
?>
Return current item: Entier Studio