Location: PHPKode > projects > Entier Studio > entierstudio/studio/classes/views/view.RepositoryModelComponentExporter.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.RepositoryModelComponentExporter.php 97 2008-02-05 21:08:53Z yannromefort $
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefRepositoryModelComponentExporter")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefRepositoryModelComponentExporter", "1");
    define(PANEVIEW, 20);
    //-------------------------------------------------------------------------
    //	Include
    @require_once (FRAMEWORK_DIR . VIEWHELPER);
    //-------------------------------------------------------------------------
    //	Class
    class RepositoryModelComponentExporter extends ViewObject {
        //---------------------------------------------------------------------
        //	Constructor
        
        /**
         *
         */
        function RepositoryModelComponentExporter() {
            //
            
        }
        //---------------------------------------------------------------------
        //	Methods
        /*
        *
        * @access	private
        *
        * @param	object	DataSource object
        * @param	object	ViewTemplate object
        * @param	string	block name in layout
        * @param	integer	key value
        *
        */
        function RenderTemporaryTree(&$datasource, &$template, $block, $value) {
            //
            $componentSet = new TemporaryComponentSet($this->m_fieldSet["OBJCOMPPKID"], $value);
            if ($componentSet->selectSet($datasource, REFLECTKEY, REFLECTKEY) == true) {
                //
                for ($i = 0;$i < $componentSet->rowCount();$i++) {
                    //	select next row
                    if ($componentSet->fetchCursorRow($datasource) == false) return (false);
                    //
                    $template->select($block);
                    $template->assign($componentSet->fieldSet());
                    $template->render($block);
                    //	select dependent rows
                    if ($this->RenderTemporaryTree($datasource, $template, $block, $componentSet->get_field_value("TMPCOMPPKID")) == false) return (false);
                }
            }
            //
            return (true);
        }
        /*
        *
        * @access	private
        *
        * @param	object	DataSource object
        * @param	object	ViewTemplate object
        * @param	string	block name in layout
        * @param	integer	key value
        *
        */
        function RenderRepositoryTree(&$datasource, &$template, $block, $value) {
            //
            @include_once (COMPONENTS_DATA . "data.TemporaryModelComponentSet.php");
            //
            $componentSet = new TemporaryModelComponentSet($value);
            if ($componentSet->selectSet($datasource, REFLECTKEY) == true) {
                //
                for ($i = 0;$i < $componentSet->rowCount();$i++) {
                    //	select next row
                    if ($componentSet->fetchCursorRow($datasource) == false) return (false);
                    //
                    $template->select($block);
                    $template->assign($componentSet->fieldSet());
                    $template->render($block);
                    //	select base element
                    if ($this->RenderRepositoryTree($datasource, $template, $block, $componentSet->get_field_value("REPMCOMPKID")) == 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 ctrl.RepositoryComponentExport-form.php
                    */
                    /*
                    * 1- TemporaryComponent
                    * 2- ObjectoryComponent
                    * 3- RepositoryModelComponent
                    * 4- ObjectoryComponentType
                    * 5- RepositoryCoreElementPropertySet
                    * 6- RepositoryModelComponentPropertySet list
                    * 7- RepositoryCoreElementPropertySet
                    * 8- RepositoryModelComponentPropertySet list
                    */
                    /*
                    * 1- TemporaryComponent
                    */
                    //
                    @include_once (COMPONENTS_DATA . "data.TemporaryComponent.php");
                    //
                    $component = new TemporaryComponent($this->m_fieldSet["TMPCOMPPKID"]);
                    if ($component->selectRow($datasource) == false) {
                        //
                        $this->m_errorSet[VIEW_OBJECT_ERROR] = true;
                        //
                        return (false);
                    }
                    //
                    $template->assign($component->fieldSet());
                    if ($component->get_field_value("OBJCTYPTYPE") == MODEL_FILE_TYPE) {
                        //
                        /*
                        * 2.1- TemporaryComponentTemplate
                        */
                        //
                        @include_once (COMPONENTS_DATA . "data.TemporaryComponentTemplate.php");
                        //
                        $componentTemplate = new TemporaryComponentTemplate($this->m_fieldSet["TMPCOMPPKID"], false);
                        $componentTemplate->selectRow($datasource);
                        //
                        @include_once (COMPONENTS_HTML . "html.ApplicationCodificationDDL.php");
                        //
                        // 2.2- Language processor
                        $codificationSet = NULL;
                        $codificationSetDDL = new ApplicationCodificationDDL("lang", "formInput", 6);
                        $this->m_blockSet["LangList"] = $codificationSetDDL->renderObject($datasource, $codificationSet, $componentTemplate->get_field_value("TMPFILELANG"));
                        unset($codificationSetDDL);
                        unset($codificationSet);
                        //
                        // 2.3- Output mime
                        $codificationSet = NULL;
                        $codificationSetDDL = new ApplicationCodificationDDL("mime", "formInput", 7);
                        $this->m_blockSet["MimeList"] = $codificationSetDDL->renderObject($datasource, $codificationSet, $componentTemplate->get_field_value("TMPMAKEMIME"));
                        unset($codificationSetDDL);
                        unset($codificationSet);
                        //
                        // 2.3- Generation mode
                        $codificationSet = NULL;
                        $codificationSetDDL = new ApplicationCodificationDDL("mode", "formInput", 5);
                        $this->m_blockSet["ModeList"] = $codificationSetDDL->renderObject($datasource, $codificationSet, $componentTemplate->get_field_value("TMPMAKEMODE"));
                        unset($codificationSetDDL);
                        unset($codificationSet);
                        //
                        // 2.4- Element Type target
                        //
                        @include_once (COMPONENTS_HTML . "html.ObjectoryElementTargetDDL.php");
                        //
                        $targetSet = NULL;
                        $targetSetDDL = new ObjectoryElementTargetDDL("goal", "formInput", $component->get_field_value("REPTYPEPKID"));
                        $this->m_blockSet["OBJTYPELIST"] = $targetSetDDL->renderObject($datasource, $targetSet, $componentTemplate->get_field_value("OBJETYPPKID"));
                        unset($targetSetDDL);
                        unset($targetSet);
                        //
                        unset($componentTemplate);
                        //
                        $template->assign($this->m_blockSet);
                    }
                    //
                    
                break;
                case ITEMVIEW:
                    /*
                    * @see handler ctrl.RepositoryComponentExport-view.php
                    */
                    //
                    /*
                    * 1- ObjectoryComponent
                    * 2- RepositoryModelComponent
                    */
                    //
                    /*
                    * 1- 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($component->fieldSet());
                    //
                    /*
                    * 2- RepositoryModelComponent
                    */
                    //
                    if (!empty($this->m_fieldSet["REPMCOMPKID"])) {
                        //
                        @include_once (COMPONENTS_DATA . "data.RepositoryModelComponent.php");
                        //
                        $model = new RepositoryModelComponent($this->m_fieldSet["REPMCOMPKID"]);
                        if ($model->selectRow($datasource) == false) {
                            //
                            $this->m_errorSet[VIEW_OBJECT_ERROR] = true;
                            //
                            return (false);
                        }
                        //
                        $template->assign($model->fieldSet());
                    }
                    //
                    
                break;
                case LISTVIEW:
                    /*
                    * @see handler ctrl.RepositoryComponentExport-grid.php
                    */
                    /*
                    * 1- ObjectoryComponent
                    * 2- TemporaryComponentSet
                    */
                    /*
                    * 1- 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($component->fieldSet());
                    //
                    /*
                    * 2- TemporaryComponentSet
                    */
                    //
                    @include_once (COMPONENTS_DATA . "data.TemporaryComponentSet.php");
                    //
                    $componentSet = new TemporaryComponentSet($component->get_field_value("OBJCOMPPKID"));
                    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->RenderTemporaryTree($datasource, $template, $block[1], $componentSet->get_field_value("TMPCOMPPKID")) == false) return (false);
                            //
                            $template->render($block[0]);
                        }
                    }
                    //
                    break;
                case TREEVIEW:
                    /*
                    * @see handler ctrl.RepositoryComponentExport-tree.php
                    */
                    //
                    /*
                    * 1- ObjectoryComponent
                    * 2- TemporaryModelComponentSet
                    */
                    //
                    /*
                    * 1- 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);
                    }
                    //
                    $this->m_fieldSet["OBJLINKPKID"] = $component->get_field_value("OBJCOMPPKID");
                    $this->m_fieldSet["OBJLINKTYPE"] = $component->get_field_value("OBJCTYPTYPE");
                    //
                    $template->assign($this->m_fieldSet);
                    //
                    //
                    /*
                    * 2- TemporaryModelComponentSet
                    */
                    //
                    $template->assign($this->fieldSet());
                    //
                    /*
                    * 1- TemporaryModelComponentSet
                    */
                    //
                    @include_once (COMPONENTS_DATA . "data.TemporaryModelComponentSet.php");
                    //
                    $componentSet = new TemporaryModelComponentSet(NULL, 1);
                    if ($componentSet->selectSet($datasource) == 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->RenderRepositoryTree($datasource, $template, $block[1], $componentSet->get_field_value("REPMCOMPKID")) == false) return (false);
                            //
                            $template->render($block[0]);
                        }
                    }
                    //
                    break;
                case FRAMEVIEW:
                    /*
                    * * @see handler ctrl.RepositoryComponentExport-frame.php
                    */
                    /*
                    * 1- ObjectoryComponent
                    */
                    /*
                    * 1- 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($component->fieldSet());
                    //
                    break;
                case MENUVIEW:
                    /*
                    * * @see handler ctrl.RepositoryComponentExport-menu.php
                    */
                    //
                    /*
                    * 1- ObjectoryComponent
                    * 2- TemporaryElementSet
                    */
                    //
                    /*
                    * 1- 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($component->fieldSet());
                    //
                    /*
                    * 2- TemporaryComponentSet
                    */
                    //
                    @include_once (COMPONENTS_DATA . "data.TemporaryComponentSet.php");
                    //
                    $componentSet = new TemporaryComponentSet($component->get_field_value("OBJCOMPPKID"));
                    if ($componentSet->selectSet($datasource) == true) $template->toggle("proc", true);
                    //
                    break;
                case PANEVIEW:
                    /*
                    * * @see handler ctrl.RepositoryComponentExport-pane.php
                    */
                    //
                    /*
                    * 1- ObjectoryComponent
                    * 2- TemporaryComponentSet
                    * 3- RepositoryModelComponent
                    * 4- ComponentRepositoryToTemporaryImport
                    */
                    /*
                    * 1- 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($component->fieldSet());
                    /*
                    * 2- Procedure step
                    */
                    switch ($this->m_fieldSet["TMPPROCSTEP"]) {
                        case 0: // delete all temporary tables
                            /*
                            * 2.0.1- TemporaryComponentSet
                            */
                            //
                            @include_once (COMPONENTS_DATA . "data.TemporaryComponentSet.php");
                            // Multi-tables DELETE Query in TemporaryComponentSet
                            $componentSet = new TemporaryComponentSet($component->get_field_value("OBJCOMPPKID"));
                            $componentSet->deleteSet($datasource);
                            //
                            
                        break;
                        case 1: // insert a model in temporary tables
                            /*
                            * 3- RepositoryModelComponent
                            */
                            //
                            @include_once (COMPONENTS_DATA . "data.RepositoryModelComponent.php");
                            //
                            $repComponent = new RepositoryModelComponent($this->m_fieldSet["REPMCOMPKID"]);
                            if ($repComponent->selectRow($datasource) == false) {
                                //
                                $this->m_errorSet[VIEW_OBJECT_ERROR] = true;
                                //
                                return (false);
                            } else {
                                /*
                                *
                                */
                                //
                                @include_once (COMPONENTS_PROC . "proc.ComponentRepositoryToTemporaryImport.php");
                                //
                                $importator = new ComponentRepositoryToTemporaryImport();
                                //
                                if (!empty($this->m_fieldSet["TMPPREFNAME"])) $repComponent->set_field_value("REPMCOMNAME", $this->m_fieldSet["TMPPREFNAME"]);
                                if (!empty($this->m_fieldSet["TMPPREFPATH"])) $repComponent->set_field_value("REPMCOMPATH", $this->m_fieldSet["TMPPREFPATH"]);
                                //
                                if ($importator->Import($datasource, $repComponent->fieldSet() , $component->fieldSet()) == false) {
                                    //
                                    $this->m_errorSet[PROC_OBJECT_ERROR] = true;
                                    //
                                    return (false);
                                }
                            }
                            //
                            break;
                        }
                        //
                        break;
                    case PROCVIEW:
                        /*
                        * * @see handler ctrl.RepositoryComponentExport-pane.php
                        */
                        //
                        /*
                        * 1- ObjectoryComponent
                        * 2- ComponentTemporaryToObjectoryImport
                        */
                        //
                        /*
                        * 1- 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($component->fieldSet());
                        //
                        /*
                        * 2- ComponentTemporaryToObjectoryImport
                        */
                        //
                        @include_once (COMPONENTS_PROC . "proc.ComponentTemporaryToObjectoryImport.php");
                        //
                        $importator = new ComponentTemporaryToObjectoryImport();
                        if ($importator->import($datasource, $component->fieldSet()) == false) {
                            //
                            $discardedObject = $importator->DiscardedObject();
                            $this->m_fieldSet["GARBAGEOB"] = $discardedObject["TMPCOMPNAME"];
                        } else {
                            //
                            $this->m_fieldSet["RELEASENB"] = $importator->releasedCount();
                        }
                        //
                        $template->assign($this->m_fieldSet);
                        $template->assign($this->m_blockSet);
                        //
                        break;
                    case CODEVIEW:
                        /*
                        * * @see handler ctrl.RepositoryComponentExport-code.php
                        */
                        //
                        /*
                        * 1- TemporaryComponentTemplate
                        */
                        //
                        @include_once (COMPONENTS_DATA . "data.TemporaryComponentTemplate.php");
                        //
                        $component = new TemporaryComponentTemplate($this->m_fieldSet["TMPCOMPPKID"]);
                        if ($component->selectRow($datasource) == false) {
                            //
                            return (false);
                        }
                        //
                        //
                        $TMPFILETEXT = $component->get_field_value("TMPFILETEXT");
                        if (empty($TMPFILETEXT)) {
                            //
                            return (false);
                        }
                        //
                        $TMPFILEMIME = $component->get_field_value("TMPFILEMIME");
                        //
                        header("Content-Type: " . $TMPFILEMIME . "\n ");
                        header("Content-Transfer-Encoding: 8bit\n");
                        header("Content-length: " . strlen($TMPFILETEXT) . "\n");
                        //
                        return (print ($TMPFILETEXT));
                        //
                        break;
                    }
                    //
                    $template->output($mode);
                    //
                    return (true);
            }
        };
        //	Class
        //-------------------------------------------------------------------------
        
    }
    //	namespace
    //-----------------------------------------------------------------------------
    
?>
Return current item: Entier Studio