Location: PHPKode > projects > Entier Studio > entierstudio/studio/classes/views/view.ObjectoryElementExporter.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: view.ObjectoryElementExporter.php 115 2008-03-07 22:29:12Z yannromefort $
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefObjectoryElementExporter")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefObjectoryElementExporter", "1");
    define(ROOTVIEW, 1);
    define(TESTVIEW, 30);
    define(FILEVIEW, 50);
    define(TRASHVIEW, 60);
    //-------------------------------------------------------------------------
    //	Include
    @require_once (FRAMEWORK_DIR . VIEWHELPER);
    //-------------------------------------------------------------------------
    //	Class
    class ObjectoryElementExporter extends ViewObject {
        //---------------------------------------------------------------------
        //	Constructor
        
        /**
         *
         */
        function ObjectoryElementExporter() {
            //
            
        }
        //---------------------------------------------------------------------
        //	Methods
        /*
        *
        * @access	private
        *
        * @param	object	DataSource object
        * @param	object	ViewTemplate object
        * @param	string	layout name is a template file name or a layer name in a template file
        * @param	string	block name in layout
        *
        */
        function renderTree(&$datasource, &$template, $block, $value) {
            //
            $elementSet = new ObjectoryComponentSet($this->m_fieldSet["OBJECTOPKID"], $value);
            if ($elementSet->selectSet($datasource, REFLECTKEY) == true) {
                //
                for ($i = 0;$i < $elementSet->rowCount();$i++) {
                    //	select next ObjectoryComponentSet row
                    if ($elementSet->fetchCursorRow($datasource) == false) return (false);
                    //
                    $template->select($block);
                    $template->assign($elementSet->fieldSet());
                    $template->render($block);
                    //	select ObjectoryComponentSet dependent rows
                    if ($this->renderTree($datasource, $template, $block, $elementSet->get_field_value("OBJCOMPPKID")) == false) return (false);
                }
            }
            //
            return (true);
        }
        /*
        *
        * @access	public
        *
        * @param	object	DataSource object
        * @param	object	ViewTemplate object
        * @param	string	layout name is a template file name or a layer name in a template file
        * @param	string	block name in layout
        * @param	integer	view type	{ ITEMVIEW, LISTVIEW, TREEVIEW }
        * @param	integer	outputmode
        *
        */
        function renderView(&$datasource, &$template, $layout, $block = NULL, $view = NULL, $mode = OUTPUT) {
            //            
            if (!is_object($template)) {
                //
                $this->m_errorSet[VIEW_SYSTEM_ERROR] = true;
                //
                return (false);
            }
            //            
            if (!empty($layout) && ($template->define($layout) == false)) {
                //
                $this->m_errorSet[VIEW_LAYOUT_ERROR] = $layout;
                //
                return (false);
            }
            //
            switch ($view) {
                case FORMVIEW:
                    /*
                    * @see handler InterchangeElement-form.php
                    */
                    /*
                    * 1- ObjectoryElement
                    * 2- ObjectoryComponent
                    */
                    /*
                    * 1- ObjectoryElement
                    */
                    @include_once (COMPONENTS_DATA . "data.ObjectoryElement.php");
                    //
                    $element = new ObjectoryElement($this->m_fieldSet["OBJELEMPKID"]);
                    if ($element->selectRow($datasource) == false) {
                        //
                        return (false);
                    }
                    /*
                    * 2- ObjectoryComponent
                    */
                    //
                    @include_once (COMPONENTS_DATA . "data.ObjectoryComponent.php");
                    //
                    $component = new ObjectoryComponent($this->m_fieldSet["OBJCOMPPKID"]);
                    if ($component->selectRow($datasource) == false) {
                        //
                        $this->m_errorSet[VIEW_OBJECT_ERROR] = true;
                        //
                        return (false);
                    }
                    //
                    $template->assign($element->fieldSet());
                    $template->assign($component->fieldSet());
                    //
                    
                break;
                case ITEMVIEW:
                    /*
                    * @see handler InterchangeElement-view.php
                    */
                    /*
                    * 1- ObjectoryElement
                    */
                    @include_once (COMPONENTS_DATA . "data.ObjectoryElement.php");
                    //
                    $element = new ObjectoryElement($this->m_fieldSet["OBJELEMPKID"]);
                    if ($element->selectRow($datasource) == false) {
                        //
                        $this->m_errorSet[VIEW_OBJECT_ERROR] = true;
                        //
                        return (false);
                    }
                    //
                    $template->assign($element->fieldSet());
                    //
                    @include_once (INTERCHANGE_PROC. "proc.InterchangeElementNamespace.php");
                    //
                    $this->m_blockSet["OBJELEMNASP"] = InterchangeElementNamespace::getNamespacePath($datasource, $element->get_field_value("OBJELEMPKID") , ".");
                    $template->assign($this->m_blockSet);
                    //
                    
                break;
                case LISTVIEW:
                    /*
                    * @see handler ObjectoryElementExporter-list.php
                    */
                    /*
                    * 2- ObjectoryComponentReleaseSet
                    */
                    //
                    @include_once (COMPONENTS_DATA . "data.ObjectoryElementReleaseSet.php");
                    //
                    $releaseSet = new ObjectoryElementReleaseSet($this->m_fieldSet["OBJELEMPKID"]);
                    if ($releaseSet->selectSet($datasource, FOREIGNKEY, FOREIGNKEY) == true) {
                        //
                        for ($i = 0;$i < $releaseSet->rowCount();$i++) {
                            //	select next row
                            if ($releaseSet->fetchCursorRow($datasource) == false) return (false);
                            //
                            $template->select($block);
                            $template->assign($releaseSet->fieldSet());
                            $template->render($block);
                        }
                    }
                    //
                break;
                case GRIDVIEW:
                    /*
                    * @see handler ObjectoryElementExporter-grid.php
                    */
                    /*
                    * 1- ObjectoryResourceReleasedSet
                    */
                    //
                    @include_once (COMPONENTS_DATA . "data.ObjectoryElementReleasedSet.php");
                    //
                    $releaseSet = new ObjectoryElementReleasedSet($this->m_fieldSet["RELEASEID"]);
                    if ($releaseSet->selectSet($datasource, FOREIGNKEY, FOREIGNKEY) == true) {
                        //
                        for ($i = 0;$i < $releaseSet->rowCount();$i++) {
                            //	select next row
                            if ($releaseSet->fetchCursorRow($datasource) == false) return (false);
                            //
                            $template->select($block);
                            $template->assign($releaseSet->fieldSet());
                            $template->render($block);
                        }
                    }
                    //
                break;
                case TREEVIEW:
                    /*
                    * @see handler InterchangeElement-tree.php
                    */
                    //
                    /*
                    * 1- ObjectoryElement
                    * 2- ObjectoryComponentSet
                    */
                    //
                    /*
                    * 1- ObjectoryElement
                    */
                    @include_once (COMPONENTS_DATA . "data.ObjectoryElement.php");
                    //
                    $element = new ObjectoryElement($this->m_fieldSet["OBJELEMPKID"]);
                    if ($element->selectRow($datasource) == false) {
                        //
                        return (false);
                    }
                    //
                    $template->assign($element->fieldSet());
                    //
                    /*
                    * 2- ObjectoryComponentSet
                    */
                    //
                    @include_once (COMPONENTS_DATA . "data.ObjectoryComponentSet.php");
                    //
                    $componentSet = new ObjectoryComponentSet($element->get_field_value("OBJECTOPKID"));
                    if ($componentSet->selectSet($datasource, FOREIGNKEY, FOREIGNKEY) == true) {
                        //
                        for ($i = 0;$i < $componentSet->rowCount();$i++) {
                            //	select next row
                            if ($componentSet->fetchCursorRow($datasource) == false) return (false);
                            //
                            $template->select($block[0]);
                            $template->assign($componentSet->fieldSet());
                            //	select dependent rows
                            if ($this->renderTree($datasource, $template, $block[1], $componentSet->get_field_value("OBJCOMPPKID")) == false) return (false);
                            $template->render($block[0]);
                        }
                    }
                    //
                break;
                case FRAMEVIEW:
                    /*
                    * * @see handler InterchangeElement-pane.php
                    */
                    /*
                    * 1- ObjectoryElement
                    */
                    @include_once (COMPONENTS_DATA . "data.ObjectoryElement.php");
                    //
                    $element = new ObjectoryElement($this->m_fieldSet["OBJELEMPKID"]);
                    if ($element->selectRow($datasource) == false) {
                        //
                        $this->m_errorSet[VIEW_OBJECT_ERROR] = true;
                        //
                        return (false);
                    }
                    //
                    $template->assign($element->fieldSet());
                    //
                break;
                case PROCVIEW:
                    /*
                    * * @see handler InterchangeElement-proc.php
                    */
                    /*
                    * 1- ObjectoryElement
                    * 2- ObjectoryComponent
                    * 3- ElementInterchange
                    */
                    /*
                    * 1- ObjectoryElement
                    */
                    //
                    @include_once (COMPONENTS_DATA . "data.ObjectoryElement.php");
                    //
                    $element = new ObjectoryElement($this->m_fieldSet["OBJELEMPKID"]);
                    if ($element->selectRow($datasource) == false) {
                        //
                        $this->m_errorSet[VIEW_OBJECT_ERROR] = true;
                        //
                        return (false);
                    }
                    /*
                    * 2- ObjectoryComponent
                    */
                    //
                    @include_once (COMPONENTS_DATA . "data.GenerationComponent.php");
                    //
                    $component = new GenerationComponent($this->m_fieldSet["OBJCOMPPKID"]);
                    if ($component->selectRow($datasource) == false) {
                        //
                        $this->m_errorSet[VIEW_OBJECT_ERROR] = true;
                        //
                        return (false);
                    }
                    /*
                    * 3- ComponentGeneration
                    */
                    //
                    @set_time_limit(180);
                    //
                    @include_once (COMPONENTS_PROC . "proc.ComponentGeneration.php");
                    //
                    $generator = new ComponentGeneration();
                    if ($generator->generate($datasource, $component->fieldSet() , $element->fieldSet() , $this->m_fieldSet) == false) {
                        //
                        $this->m_errorSet[PROCW_OBJECT_ERROR] = $generator->errorSet();
                        //
                        return (false);
                    }
                    //
                    $this->m_fieldSet["RELEASEID"] = $generator->releaseId();
                    $this->m_fieldSet["RELEASENB"] = $generator->releasedCount();
                    $this->m_fieldSet["GARBAGENB"] = $generator->discardedCount();
                    //
                    $template->assign($this->m_fieldSet);
                    $template->assign($element->fieldSet());
                    $template->assign($component->fieldSet());
                    //
                    if ($this->m_fieldSet["GENFILEFLAG"] == true) {
                        //
                        $this->m_blockSet["TabTitle"] = "File";
                        $this->m_blockSet["MakeFile"] = $generator->InterchangeFile();
                        //
                        $template->assign($this->m_blockSet);
                        $template->select("tabs");
                        $template->render("tabs");
                    }
                    //
                break;
                case CODEVIEW:
                    /*
                    * * @see handler ObjectoryElement-code.php
                    */
                    /*
                    * 1- ObjectoryElement
                    */
                    //
                    @include_once (COMPONENTS_DATA . "data.ObjectoryElement.php");
                    //
                    $element = new ObjectoryElement($this->m_fieldSet["OBJELEMPKID"]);
                    if ($element->selectRow($datasource) == false) {
                        //
                        $this->m_errorSet[VIEW_OBJECT_ERROR] = true;
                        //
                        return (false);
                    }
                    //
                    @include_once (INTERCHANGE_PROC. "proc.ElementModelInterchange.php");
                    //                    
                    $modelInterchange	= new ElementModelInterchange();
                    $modelElement		= NULL;
                    if( MODEL_TYPE != $element->get_field_value("OBJETYPPKID")) {						
				        $rootElement = new ObjectoryElement($element->get_field_value("OBJELEMROOT"));
						if (false == $rootElement->selectRow($datasource)) 
							return (false);
						$modelElement = $rootElement->fieldSet();
					}
					else
						$modelElement = $element->fieldSet();
					//
                    if (false == $modelInterchange->generateDocument($datasource, $modelElement))
					   return (false);
                    //
                    $interchangeXML = $modelInterchange->InterchangeFile();
                    //
                    header("Content-Type: text/xml\n ");
                    header("Content-Transfer-Encoding: 8bit\n");
                    header("Content-length: " . @strlen($interchangeXML) . "\n");
                    //
                    print $interchangeXML;
                    return (true);
                    //
                break;
                case FILEVIEW:
                    /*
                    * * @see handler ObjectoryElement-file.php
                    */
                    /*
                    * 1- ObjectoryComponentRelease
                    */
                    //
                    @include_once (COMPONENTS_DATA . "data.ObjectoryComponentRelease.php");
                    //
                    $release = new ObjectoryComponentRelease($this->m_fieldSet["OBJCRELPKID"]);
                    if ($release->selectRow($datasource, PRIMARYKEY+1) == false) {
                        //
                        $this->m_errorSet[VIEW_OBJECT_ERROR] = true;
                        //
                        return (false);
                    }
                    //
                    //
                    $outputFile = "<XMP>" . $release->get_field_value("OBJCRELFILE") . "</XMP>";
                    $outputMime = $release->get_field_value("OBJCRELMIME");
                    //
                    /*
                    header( "Content-Type: text/xml\n " );
                    header( "Content-Transfer-Encoding: 8bit\n"	);
                    header( "Content-length: " . @strlen($outputFile) . "\n" );
                    */
                    //
                    print $outputFile;
                    //
                    return (true);
                    //
                break;
                case TRASHVIEW:
                    /*
                    * @see handler ObjectoryElementExporter-trash.php
                    */
                    /*
                    * 1- ObjectoryResourceReleasedSet
                    */
                    //
                    @include_once (COMPONENTS_DATA . "data.GenerationElementDiscardedSet.php");
                    //
                    $discardedSet = new GenerationElementDiscardedSet($this->m_fieldSet["RELEASEID"]);
                    if ($discardedSet->selectSet($datasource, FOREIGNKEY, FOREIGNKEY) == true) {
                        //
                        for ($i = 0;$i < $discardedSet->rowCount();$i++) {
                            //	select next row
                            if ($discardedSet->fetchCursorRow($datasource) == false) return (false);
                            //
                            $template->select($block);
                            $template->assign($discardedSet->fieldSet());
                            $template->render($block);
                        }
                    }
                    //
                break;
            }
            //
            $template->output($mode);
            //
            return (true);
        }
    };
    //	Class
    //-------------------------------------------------------------------------
            
}
//	namespace
//-----------------------------------------------------------------------------        
?>
Return current item: Entier Studio