Location: PHPKode > projects > Entier Studio > entierstudio/studio/classes/procs/interchange/proc.ElementPackageWriter.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.ElementPackageWriter.php 115 2008-03-07 22:29:12Z yannromefort $
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefElementPackageWriter")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefElementPackageWriter", "1");
    //-------------------------------------------------------------------------
    //	Include
    @require_once (INTERCHANGE_PROC. "proc.ElementInterfaceWriter.php");
    @require_once (INTERCHANGE_PROC. "proc.ElementPackageClassWriter.php");
    @require_once (INTERCHANGE_PROC. "proc.ElementPackageAssociationWriter.php");
    //-------------------------------------------------------------------------
    //	Class
    class ElementPackageWriter extends ElementWriter {
        //---------------------------------------------------------------------
        //	Constructor
        
        /**
         *
         */
        function ElementPackageWriter() {
            //            
        }
        //---------------------------------------------------------------------
        //	Methods        
        /**
         *
         * @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 addAssociationSet(&$datasource, &$template, $handle, $block, $primarykey) {
            //	1- ElementSet set
            $elementSet = new ObjectoryContainedElementSet($primarykey, ASSOCIATION_TYPE);
            if (true == $elementSet->selectSet($datasource, FOREIGNKEY, FOREIGNKEY)) {
                //
                $writer = NULL;
                //
                for ($i = 0;$i < $elementSet->rowCount();$i++) {
                    //	select row
                    if (false == $elementSet->fetchCursorRow($datasource))
                        return (false);
                    //
                    $template->select($block, $handle);
                    //
                    $writer = new ElementPackageAssociationWriter();
                    if (false == $writer->addElement($datasource, $template, $elementSet->fieldSet(), $handle)) 
                        return (false);
                    unset($writer);
                    //
                    $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="primarykey"
         *
         * @return	boolean
         *
         */
        function addInterfaceSet(&$datasource, &$template, $handle, $block, $primarykey) {
            //	1- ElementSet set
            $elementSet = new ObjectoryContainedElementSet($primarykey, INTERFACE_TYPE);
            if (true == $elementSet->selectSet($datasource, FOREIGNKEY, FOREIGNKEY)) {
                //
                $writer = NULL;
                //
                for ($i = 0;$i < $elementSet->rowCount();$i++) {
                    //	select row
                    if (false == $elementSet->fetchCursorRow($datasource))
                        return (false);
                    //
                    $template->select($block, $handle);
                    //
                    $writer = new ElementInterfaceWriter();
                    if (false == $writer->addElement($datasource, $template, $elementSet->fieldSet(), $handle))
                        return (false);
                    unset($writer);
                    //
                    $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="primarykey"
         * @return	boolean
         */
        function addClassSet(&$datasource, &$template, $handle, $block, $primarykey) {
            //	1- ElementSet set
            $elementSet = new ObjectoryContainedElementSet($primarykey, CLASS_TYPE);
            if (true == $elementSet->selectSet($datasource, FOREIGNKEY, FOREIGNKEY)) {
                //
                $writer = NULL;
                //
                for ($i = 0;$i < $elementSet->rowCount();$i++) {
                    //	select row
                    if (false == $elementSet->fetchCursorRow($datasource))
                        return (false);
                    //
                    $template->select($block, $handle);
                    //
                    $writer = new ElementPackageClassWriter();
                    if (false == $writer->addElement($datasource, $template, $elementSet->fieldSet() , $handle))
                        return (false);
                    unset($writer);
                    //
                    $template->render($block, $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 addPackageSet(&$datasource, &$template, $parent, $block, $primarykey) {
            //	1- ElementSet set
            $elementSet = new ObjectoryContainedElementSet($primarykey, PACKAGE_TYPE);
            if (true == $elementSet->selectSet($datasource, FOREIGNKEY, FOREIGNKEY)) {
                //
                $writer = NULL;
                //
                $handle = $template->import("package.packages.xml");
                if ($handle == -1)
                    return (false);
                //
                for ($i = 0;$i < $elementSet->rowCount();$i++) {
                    //	select row
                    if (false == $elementSet->fetchCursorRow($datasource))
                        return (false);
                    //
                    $template->select($block, $handle);
                    //
                    $writer = new ElementPackageWriter();
                    if (false == $writer->addElement($datasource, $template, $elementSet->fieldSet(), $handle))
                        return (false);
                    unset($writer);
                    //
                    $template->render($block, $handle);
                }
                //
                $template->render(".", $handle);
                $template->insert("PackageXML", $handle, $parent);
            }
            //
            return (true);
        }
        /**
         * Package element XML template is :
		 * <package>
		 *		<packages>
		 *		<classes>
		 *		<interfaces>
		 *		<Associations>
		 * </package>
		 *
         * @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);
            // Packages
            if (false == $this->addPackageSet(
							$datasource, $template, $handle, "package-packages", $element["OBJELEMPKID"]))
                return (false);
            // Classes
            if (false == $this->addClassSet(
							$datasource, $template, $handle, "package-classes", $element["OBJELEMPKID"]))
                return (false);
            // Interfaces
            if (false == $this->addInterfaceSet(
							$datasource, $template, $handle, "package-interfaces", $element["OBJELEMPKID"]))
                return (false);
            // Associations
            if (false == $this->addAssociationSet(
							$datasource, $template, $handle, "package-associations", $element["OBJELEMPKID"]))
                return (false);
            //
            return (true);
        }
    };
    //	Class
    //-------------------------------------------------------------------------
    
}
//	namespace
//-----------------------------------------------------------------------------
?>
Return current item: Entier Studio