Location: PHPKode > projects > Entier Studio > entierstudio/studio/classes/views/view.RepositoryModelComponentExplorer.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.RepositoryModelComponentExplorer.php 121 2008-03-11 20:17:41Z yannromefort $
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefRepositoryModelComponentExplorer")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefRepositoryModelComponentExplorer", "1");
    //
    define(TESTVIEW, 30);
    //-------------------------------------------------------------------------
    //	Include
    @require_once (FRAMEWORK_DIR . VIEWHELPER);
    //-------------------------------------------------------------------------
    //	Class
    class RepositoryModelComponentExplorer extends ViewObject {
        //---------------------------------------------------------------------
        //	Constructor
        
        /**
         *
         */
        function RepositoryModelComponentExplorer() {
            //
            
        }
        //---------------------------------------------------------------------
        //	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
         * @return	boolean
         */
        function renderTree(&$datasource, &$template, $block, $value) {
            //
            $componentSet = new RepositoryModelComponentSet($value);
            if ($componentSet->selectSet($datasource, REFLECTKEY, NATURALKEY) == 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->renderTree($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
         * @return	boolean
         */
        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);
            }
            //
            @include_once (COMPONENTS_DATA . "data.RepositoryModelComponent.php");
            //
            /*
            * *- Error management
            */
            //
            if ($this->get_error_count() > 0) {
                //
                @include_once (FRAMEWORK_VIEW . "view.ErrorMessage.php");
                //
                $errorMessage = new ErrorMessage($this->errorSet());
                if ($errorMessage->renderView($template, $block, $view) == false) {
                    //
                    $this->m_errorSet[VIEW_RENDER_ERROR] = true;
                    //
                    return (false);
                }
            }
            //
            switch ($view) {
                case FORMVIEW:
                    /*
                    * @see handler ctrl.RepositoryModelComponent-form.php
                    */
                    //
                    /*
                    *
                    * 1- RepositoryModelComponent
                    * 2- RepositoryModelComponentType
                    * 3- RepositoryCoreComponentSet
                    * 4- ApplicationCodificationSet
                    *
                    */
                    //
                    /*
                    * 1- RepositoryModelComponent
                    */
                    //
                    $component = new RepositoryModelComponent($this->m_fieldSet["REPMCOMPKID"]);
                    if ($component->selectRow($datasource) == false) {
                        //
                        $this->m_errorSet[VIEW_OBJECT_ERROR] = true;
                        //
                        return (false);
                    }
                    //
                    if ($component->get_field_value("REPMCOTTYPE") == MODEL_ROOT_TYPE) {
                        $component->set_field_value("REPMCOMROOT", $component->get_field_value("REPMCOMPKID"));
                    }
                    //
                    $template->assign($component->fieldSet());
                    //
                    /*
                    * 2- RepositoryModelComponentType
                    *
                    */
                    //
                    @include_once (COMPONENTS_DATA . "data.RepositoryModelComponentType.php");
                    //
                    $componentType = new RepositoryModelComponentType($this->m_fieldSet["REPMCOTPKID"]);
                    if ($componentType->selectRow($datasource) == false) {
                        //
                        $this->m_errorSet[VIEW_OBJECT_ERROR] = true;
                        //
                        return (false);
                    }
                    //
                    $template->assign($componentType->fieldSet());
                    //
                    /*
                    * 3- RepositoryCoreComponentSet Dropdownlist
                    *
                    */
                    //
                    @include_once (COMPONENTS_DATA . "data.RepositoryCoreComponentSet.php");
                    //
                    $componentSet = new RepositoryCoreComponentSet($component->get_field_value("REPOSITPKID") , $componentType->get_field_value("REPCCOTPKID"));
                    if ($componentSet->selectSet($datasource, FOREIGNKEY) == false) {
                        //
                        $this->m_errorSet[HTML_OBJECT_ERROR] = true;
                        //
                        return (false);
                    }
                    //
                    @include_once (FRAMEWORK_DIR . "htmldropdownlist.php");
                    //
                    $componentTypeDDL = new HTMLDropdownList("fkid", "formInput");
                    $this->m_blockSet["REPMCOTLIST"] = $componentTypeDDL->renderObject($datasource, $componentSet, $component->get_field_value("REPMCOTPKID"));
                    //
                    /*
                    * 2- ApplicationCodificationSet Status Dropdownlist
                    */
                    //
                    @include_once (COMPONENTS_HTML . "html.ApplicationCodificationDDL.php");
                    //
                    $codificationSet = NULL;
                    $codificationSetDDL = new ApplicationCodificationDDL("stat", "formInput", 1);
                    $this->m_blockSet["REPSTATLIST"] = $codificationSetDDL->renderObject($datasource, $codificationSet, 1);
                    //
                    $template->assign($this->m_blockSet);
                    //
                    //
                    
                break;
                case ITEMVIEW:
                    /*
                    * @see handler ctrl.RepositoryModelComponent-view.php
                    */
                    //
                    /*
                    * 1- RepositoryModelComponent
                    * 2- RepositoryModelElement parent
                    * 3- RepositoryModelElement namespace
                    * 4- RepositoryCoreComponentSet
                    * 5- ApplicationCodificationSet
                    * 6- RepositoryModelComponentTemplate
                    * 7- ModelComponentTypeSet
                    */
                    //
                    /*
                    * 1- RepositoryModelComponent
                    */
                    //
                    $component = new RepositoryModelComponent($this->m_fieldSet["REPMCOMPKID"]);
                    if ($component->selectRow($datasource) == false) {
                        //
                        $this->m_errorSet[VIEW_OBJECT_ERROR] = true;
                        //
                        return (false);
                    }
                    //
                    $template->assign($component->fieldSet());
                    //
                    /*
                    * 2- RepositoryModelComponent Parent
                    */
                    //
                    $parent = new RepositoryModelComponent($component->get_field_value("REPMCOMLINK"));
                    if ($parent->selectRow($datasource) == true) $this->m_blockSet["REPLINKTYPE"] = $parent->get_field_value("REPMCOTTYPE");
                    //
                    /*
                    * 3- RepositoryModelElement namespace
                    */
                    //
                    @include_once (COMPONENTS_DATA . "data.RepositoryModelComponentNamespace.php");
                    //
                    $namespace = new RepositoryModelComponentNamespace($component->get_field_value("REPMCOMROOT") , $component->get_field_value("REPMCOTPKID"));
                    if ($namespace->selectSet($datasource, REFLECTKEY) == true) {
                        //
                        $template->select("namespace");
                        //
                        @include_once (COMPONENTS_HTML . "html.RepositoryModelComponentNamespaceDDL.php");
                        //
                        $namespaceDDL = new RepositoryModelComponentNamespaceDDL("lkid", "formInput", $component->get_field_value("REPMCOMPKID") , $component->get_field_value("REPMCOMROOT") , $component->get_field_value("REPMCOTPKID"));
                        $template->assign("REPMCOMLIST", $namespaceDDL->renderObject($datasource, $namespace, $component->get_field_value("REPMCOMLINK")));
                        //
                        $template->render("namespace");
                    } else $template->toggle("no-namespace", true);
                    //
                    /*
                    * 4- RepositoryCoreComponentSet Dropdownlist
                    */
                    //
                    @include_once (COMPONENTS_DATA . "data.RepositoryCoreComponentSet.php");
                    //
                    $componentSet = new RepositoryCoreComponentSet($component->get_field_value("REPOSITPKID") , $component->get_field_value("REPCCOTPKID"));
                    if ($componentSet->selectSet($datasource, FOREIGNKEY, PRIMARYKEY) == false) {
                        //
                        $this->m_errorSet[HTML_OBJECT_ERROR] = true;
                        //
                        return (false);
                    }
                    //
                    @include_once (FRAMEWORK_DIR . "htmldropdownlist.php");
                    //
                    $modelComponentTypeDDL = new HTMLDropdownList("fkid", "formInput");
                    $this->m_blockSet["REPMCOTLIST"] = $modelComponentTypeDDL->renderObject($datasource, $componentSet, $component->get_field_value("REPCCOMPKID"));
                    //
                    /*
                    * 5- ApplicationCodificationSet Status Dropdownlist
                    */
                    //
                    @include_once (COMPONENTS_HTML . "html.ApplicationCodificationDDL.php");
                    //
                    $codificationSet = NULL;
                    $codificationSetDDL = new ApplicationCodificationDDL("stat", "formInput", 1);
                    $this->m_blockSet["REPSTATLIST"] = $codificationSetDDL->renderObject($datasource, $codificationSet, $component->get_field_value("REPMCOMSTAT"));
                    //
                    unset($codificationSetDDL);
                    unset($codificationSet);
                    //
                    if ($component->get_field_value("REPMCOTTYPE") == MODEL_FILE_TYPE) {
                        //
                        /*
                        * 6.1- RepositoryModelComponentTemplate
                        */
                        //
                        @include_once (COMPONENTS_DATA . "data.RepositoryModelComponentTemplate.php");
                        //
                        $componentTemplate = new RepositoryModelComponentTemplate($this->m_fieldSet["REPMCOMPKID"], false);
                        if ($componentTemplate->selectRow($datasource) == true) {
                            //
                            $template->assign("REPFILELANG", $componentTemplate->get_field_value("REPFILELANG"));
                            $template->toggle("dbug", $componentTemplate->get_field_value("REPMAKEMODE") == DYNAMIC_TYPE);
                        }
                        //
                        // 6.2- Language processor
                        $codificationSet = NULL;
                        $codificationSetDDL = new ApplicationCodificationDDL("lang", "formInput", 6);
                        $this->m_blockSet["LangList"] = $codificationSetDDL->renderObject($datasource, $codificationSet, $componentTemplate->get_field_value("REPFILELANG"));
                        unset($codificationSetDDL);
                        unset($codificationSet);
                        //
                        // 6.3- Output mime
                        $codificationSet = NULL;
                        $codificationSetDDL = new ApplicationCodificationDDL("mime", "formInput", 7);
                        $this->m_blockSet["MimeList"] = $codificationSetDDL->renderObject($datasource, $codificationSet, $componentTemplate->get_field_value("REPMAKEMIME"));
                        unset($codificationSetDDL);
                        unset($codificationSet);
                        //
                        // 6.4- Generation mode
                        $codificationSet = NULL;
                        $codificationSetDDL = new ApplicationCodificationDDL("mode", "formInput", 5);
                        $this->m_blockSet["ModeList"] = $codificationSetDDL->renderObject($datasource, $codificationSet, $componentTemplate->get_field_value("REPMAKEMODE"));
                        unset($codificationSetDDL);
                        unset($codificationSet);
                        //
                        // 6.5- 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);
                    //
                    //	Add component menu
                    if ($component->get_field_value("REPMCOTTYPE") != MODEL_FILE_TYPE) {
                        // NOT MODEL_FILE_TYPE
                        /*
                        * 7- ModelComponentTypeSet
                        */
                        //
                        @include_once (COMPONENTS_DATA . "data.RepositoryModelComponentTypeMap.php");
                        //
                        $memberTypeSet = new RepositoryModelComponentTypeMap($component->get_field_value("REPMCOTPKID"));
                        if ($memberTypeSet->selectSet($datasource) == true) {
                            //
                            $template->select("show");
                            //
                            for ($i = 0;$i < $memberTypeSet->rowCount();$i++) {
                                //
                                if ($memberTypeSet->fetchCursorRow($datasource) == false) return (false);
                                //
                                $template->select("menu");
                                $template->assign($memberTypeSet->fieldSet());
                                $template->render("menu");
                            }
                            $template->render("show");
                        }
                    }
                    //
                    break;
                case LISTVIEW:
                    /*
                    * @see handler ctrl.RepositoryModelComponent-list.php
                    */
                    /*
                    * 1- RepositoryModelComponentSet
                    */
                    //
                    @include_once (COMPONENTS_DATA . "data.RepositoryModelComponentSet.php");
                    //
                    $componentSet = new RepositoryModelComponentSet($this->m_fieldSet["REPMCOMPKID"], $this->m_fieldSet["REPMCOTPKID"]);
                    if ($componentSet->selectSet($datasource, FOREIGNKEY, NATURALKEY) == 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->renderTree($datasource, $template, $block, $componentSet->get_field_value("REPMCOMPKID")) == false) return (false);
                        }
                    }
                    //
                    break;
                case TREEVIEW:
                    /*
                    * @see handler ctrl.RepositoryModelComponent-side.php
                    */
                    /*
                    *
                    * 1- RepositoryModelComponent
                    * 2- RepositoryModelComponentSet
                    *
                    */
                    /*
                    * 1- RepositoryModelComponent Root
                    */
                    //
                    $modelComponent = new RepositoryModelComponent($this->m_fieldSet["REPMCOMPKID"]);
                    if ($modelComponent->selectRow($datasource) == false) {
                        //
                        $this->m_errorSet[VIEW_OBJECT_ERROR] = true;
                        //
                        return (false);
                    }
                    //
                    $template->assign($modelComponent->fieldSet());
                    /*
                    * 2- RepositoryModelComponentSet Tree
                    */
                    // select ModelComponentSet on reflect key ( REPMCOMPKID )
                    @include_once (COMPONENTS_DATA . "data.RepositoryModelComponentSet.php");
                    //
                    $componentSet = new RepositoryModelComponentSet($this->m_fieldSet["REPMCOMPKID"]);
                    if ($componentSet->selectSet($datasource, REFLECTKEY, NATURALKEY) == 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->renderTree($datasource, $template, $block, $componentSet->get_field_value("REPMCOMPKID")) == false) return (false);
                        }
                    }
                    //
                    break;
                case FRAMEVIEW:
                    /*
                    * * @see handler ctrl.RepositoryModelComponent-pane.php
                    */
                    //
                    /*
                    * 1- RepositoryModelComponent Root
                    */
                    //
                    $component = new RepositoryModelComponent();
                    $component->set_field_value("REPCCOMPKID", $this->m_fieldSet["REPCCOMPKID"]);
                    if ($component->selectRow($datasource, FOREIGNKEY) == false) {
                        /* select ComponentModelType on primary key ( REPCCOMPKID )
                        */
                        @include_once (COMPONENTS_DATA . "data.RepositoryCoreComponentModelType.php");
                        //
                        $componentModel = new RepositoryCoreComponentModelType($this->m_fieldSet["REPCCOMPKID"]);
                        if ($componentModel->selectRow($datasource) == false) {
                            //
                            $this->m_errorSet[VIEW_OBJECT_ERROR] = true;
                            //
                            return (false);
                        }
                        /* select ModelComponent based on CoreElementModelType
                        */
                        $component->set_field_value("REPMCOTPKID", $componentModel->get_field_value("REPMCOTPKID"));
                        $component->set_field_value("REPCCOMPKID", $componentModel->get_field_value("REPCCOMPKID"));
                        $component->set_field_value("REPMCOMNAME", $componentModel->get_field_value("REPCCOMNAME"));
                        $component->set_field_value("REPMCOMPATH", ".");
                        $component->set_field_value("REPMCOMTYPE", $componentModel->get_field_value("REPMCOTTYPE"));
                        //
                        if ($component->insertRow($datasource) == false) {
                            //
                            return (false);
                        }
                    }
                    //
                    $template->assign($component->fieldSet());
                    //
                    break;
                case TESTVIEW:
                    /*
                    * * @see handler ctrl.RepositoryModelComponent-dbug.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());
                    $template->assign($this->m_fieldSet);
                    //
                    break;
                case CODEVIEW:
                    /*
                    * * @see handler ctrl.RepositoryModelComponent-code.php
                    */
                    //
                    /*
                    * 1- RepositoryModelComponentTemplate
                    */
                    //
                    @include_once (COMPONENTS_DATA . "data.RepositoryModelComponentTemplate.php");
                    //
                    $component = new RepositoryModelComponentTemplate($this->m_fieldSet["REPMCOMPKID"]);
                    if ($component->selectRow($datasource) == false) {
                        //
                        return (false);
                    }
                    //
                    $REPFILETEXT = $component->get_field_value("REPFILETEXT");
                    if (empty($REPFILETEXT)) {
                        //
                        return (false);
                    }
                    //
                    $REPFILEMIME = $component->get_field_value("REPFILEMIME");
                    //                    
                    header("Content-Type: " . $REPFILEMIME . "; charset=UTF-8\n ");
                    header("Content-Transfer-Encoding: 8bit\n");
                    header("Content-length: " . strlen($REPFILETEXT) . "\n");
                    //
                    return (print ($REPFILETEXT));
                    //
                    break;
                case NULLVIEW:
                    //
                    /*
                    * 1- RepositoryModelComponent Root
                    * 2- DirectoryProjectUser
                    * 3- Objectory
                    */
                    //
                    /*
                    * 1- RepositoryModelComponent Root
                    */
                    //
                    $component = new RepositoryModelComponent($this->m_fieldSet["REPMCOMROOT"]);
                    if ($component->selectRow($datasource) == false) {
                        //
                        $this->m_errorSet[VIEW_OBJECT_ERROR] = true;
                        //
                        return (false);
                    }
                    //
                    $this->m_blockSet["URLBACKLINK"] = @urlencode("mainpage.php?__ctrl=RepositoryModelComponent&__mode=frame&__view=frame&__user=" . $this->m_fieldSet["DIRPUSRPKID"] . "&pkid=" . $component->get_field_value("REPCCOMPKID"));
                    //
                    /*
                    * 2- DirectoryProjectUser
                    */
                    //
                    @include_once (COMPONENTS_DATA . "data.DirectoryProjectUser.php");
                    //
                    $projectUser = new DirectoryProjectUser($this->m_fieldSet["DIRPUSRPKID"]);
                    if ($projectUser->selectRow($datasource) == false) {
                        //
                        $this->m_errorSet[VIEW_OBJECT_ERROR] = true;
                        //
                        return (false);
                    }
                    //
                    /*
                    * 2- Objectory
                    */
                    //
                    @include_once (COMPONENTS_DATA . "data.Objectory.php");
                    //
                    $objectory = new Objectory();
                    $objectory->set_field_value("DIRPROJPKID", $projectUser->get_field_value("DIRPROJPKID"));
                    $objectory->set_field_value("REPTYPEPKID", $component->get_field_value("REPTYPEPKID"));
                    if ($objectory->selectRow($datasource, FOREIGNKEY) == false) {
                        //
                        $this->m_errorSet[VIEW_OBJECT_ERROR] = true;
                        //
                        return (false);
                    }
                    //
                    $template->assign($objectory->fieldSet());
                    $template->assign($this->fieldSet());
                    $template->assign($this->BlockSet());
                    //
                    break;
                }
                //
                $template->output($mode);
                //
                return (true);
            }
        };
        //	Class
        //-------------------------------------------------------------------------
        
    }
    //	namespace
    //-----------------------------------------------------------------------------
    
?>
Return current item: Entier Studio