Location: PHPKode > projects > Entier Studio > entierstudio/studio/classes/views/view.RepositoryModelElementExplorer.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.RepositoryModelElementExplorer.php 89 2008-01-28 20:25:53Z yannromefort $
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefRepositoryModelElementExplorer")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefRepositoryModelElementExplorer", "1");
    define(ROOTVIEW, 10);
    //-------------------------------------------------------------------------
    //	Include
    @require_once (FRAMEWORK_DIR . VIEWHELPER);
    //-------------------------------------------------------------------------
    //	Class
    class RepositoryModelElementExplorer extends ViewObject {
        //---------------------------------------------------------------------
        //	Constructor
        
        /**
         *
         */
        function RepositoryModelElementExplorer() {
            //
            
        }
        //---------------------------------------------------------------------
        //	Methods
        
        /**
         *
         * @access	private
         *
         * @param	object	DataSource object
         * @param	object	ViewTemplate object
         * @param	string	block name in layout
         * @param	integer	foreign key value
         * @return	boolean
         */
        function RenderBaseList(&$datasource, &$template, $block, $handle, $value) {
            //
            $elementSet = new RepositoryModelElementSet($value);
            if ($elementSet->selectSet($datasource, REFLECTKEY, NATURALKEY) == true) {
                //
                for ($i = 0;$i < $elementSet->rowCount();$i++) {
                    //	select next row
                    if ($elementSet->fetchCursorRow($datasource) == false) return (false);
                    //
                    $template->select($block[2], $handle);
                    $template->assign($elementSet->fieldSet() , NULL, $handle);
                    $template->render($block[2], $handle);
                }
            }
            //
            return (true);
        }
        /**
         *
         * @access	private
         *
         * @param	object	DataSource object
         * @param	object	ViewTemplate object
         * @param	string	block name in layout
         * @param	integer	foreign key value
         * @return	boolean
         */
        function RenderBaseTree(&$datasource, &$template, $block, $parent, $value) {
            //
            $elementSet = new RepositoryModelElementSet($value);
            if ($elementSet->selectSet($datasource, REFLECTKEY, NATURALKEY) == true) {
                //
                $handle = $template->import("RepositoryModelElement-base.html");
                if ($handle == -1) return (false);
                //
                for ($i = 0;$i < $elementSet->rowCount();$i++) {
                    //	select next row
                    if ($elementSet->fetchCursorRow($datasource) == false) return (false);
                    //
                    $template->select($block[1] . "-" . $block[2], $handle);
                    $template->assign($elementSet->fieldSet() , NULL, $handle);
                    //	select base element
                    if ($this->RenderBase($datasource, $template, $block, $handle, $elementSet->fieldSet()) == false) return (false);
                    //	select  dependent rows
                    if ($this->RenderBaseList($datasource, $template, $block, $handle, $elementSet->get_field_value("REPMELEPKID")) == false) return (false);
                    //
                    $template->render($block[1] . "-" . $block[2], $handle);
                }
                //
                $template->render(".", $handle);
                $template->insert("REPBASETREE", $handle, $parent);
            } else {
                // template quirk!!!
                $template->assign("REPBASETREE", "//emply list", $parent);
            }
            //
            return (true);
        }
        /**
         *
         * @access	private
         *
         * @param	object	DataSource object
         * @param	object	ViewTemplate object
         * @param	string	block name in layout
         * @param	integer	parent display
         * @param	array	element fields set
         * @return	boolean
         */
        function RenderBase(&$datasource, &$template, $block, $handle, $model) {
            //
            $elementType = new RepositoryModelElementType($model["REPMELTPKID"]);
            $elementType->selectRow($datasource);
            if ($elementType->get_field_value("REPMELTTYPE") == MODEL_ENABLED) {
                //
                $element = new RepositoryModelElement();
                $element->set_field_value("REPCELEPKID", $model["REPCELEPKID"]);
                if ($element->selectRow($datasource, FOREIGNKEY) == true) {
                    //
                    $element->set_field_value("REPMELEROOT", $model["REPMELEPKID"]);
                    //
                    $template->select($block[1], $handle);
                    $template->assign($element->fieldSet() , NULL, $handle);
                    //	select dependent rows
                    if ($this->RenderBaseTree($datasource, $template, $block, $handle, $element->get_field_value("REPMELEPKID")) == false) return (false);
                    //
                    $template->render($block[1], $handle);
                }
            }
            //
            return (true);
        }
        /**
         *
         * @access	private
         *
         * @param	object	DataSource object
         * @param	object	ViewTemplate object
         * @param	string	block name in layout
         * @param	integer	foreign key value
         * @return	boolean
         */
        function renderTree(&$datasource, &$template, $block, $handle, $value) {
            //
            $elementSet = new RepositoryModelElementSet($value);
            if ($elementSet->selectSet($datasource, REFLECTKEY, NATURALKEY) == true) {
                //
                for ($i = 0;$i < $elementSet->rowCount();$i++) {
                    //	select next row
                    if ($elementSet->fetchCursorRow($datasource) == false) return (false);
                    //
                    $template->select($block[0], $handle);
                    $template->assign($elementSet->fieldSet() , NULL, $handle);
                    //	select base element
                    if ($this->RenderBase($datasource, $template, $block, $handle, $elementSet->fieldSet()) == false) return (false);
                    $template->render($block[0], $handle);
                    //	select dependent rows
                    if ($this->renderTree($datasource, $template, $block, $handle, $elementSet->get_field_value("REPMELEPKID")) == 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);
            }
            //
            /*
            * *- 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);
                }
            }
            //
            @include_once (COMPONENTS_DATA . "data.RepositoryModelElement.php");
            //
            switch ($view) {
                case FORMVIEW:
                    /*
                    * @see handler RepositoryModelElement-form.php
                    */
                    //
                    /*
                    *
                    * 1- RepositoryModelElement
                    * 2- RepositoryModelElementType
                    * 3- RepositoryCoreElementSet
                    * 4- ApplicationCodificationSet
                    *
                    */
                    //
                    /*
                    * 1- RepositoryModelElement
                    *
                    */
                    //
                    $element = new RepositoryModelElement($this->m_fieldSet["REPMELEPKID"]);
                    if ($element->selectRow($datasource) == false) {
                        //
                        $this->m_errorSet[VIEW_OBJECT_ERROR] = true;
                        //
                        return (false);
                    }
                    //
                    $template->assign($element->fieldSet());
                    //
                    /*
                    * 2- RepositoryModelElementType
                    *
                    */
                    //
                    @include_once (COMPONENTS_DATA . "data.RepositoryModelElementType.php");
                    //
                    $elementType = new RepositoryModelElementType($this->m_fieldSet["REPMELTPKID"]);
                    if ($elementType->selectRow($datasource) == false) {
                        //
                        $this->m_errorSet[VIEW_OBJECT_ERROR] = true;
                        //
                        return (false);
                    }
                    //
                    $template->assign($elementType->fieldSet());
                    //
                    /*
                    * 3- RepositoryCoreElementSet Dropdownlist
                    */
                    //
                    @include_once (COMPONENTS_DATA . "data.RepositoryCoreElementSet.php");
                    //
                    $elementSet = new RepositoryCoreElementSet($element->get_field_value("REPOSITPKID") , $elementType->get_field_value("REPCELTPKID"));
                    if ($elementSet->selectSet($datasource, FOREIGNKEY) == false) {
                        //
                        $this->m_errorSet[HTML_OBJECT_ERROR] = true;
                        //
                        return (false);
                    }
                    //
                    @include_once (FRAMEWORK_DIR . "htmldropdownlist.php");
                    //
                    $elementTypeDDL = new HTMLDropdownList("fkid", "formInput");
                    $this->m_blockSet["REPCELELIST"] = $elementTypeDDL->renderObject($datasource, $elementSet, $element->get_field_value("REPMELTPKID"));
                    //
                    /*
                    * 4- 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 RepositoryModelElement-view.php
                    */
                    //
                    /*
                    * 1- RepositoryModelElement
                    * 2- RepositoryModelElement parent
                    * 3- ApplicationCodificationSet
                    * 4- RepositoryCoreElementSet
                    * 5- RepositoryModelElementTypeSet
                    * 6- RepositoryModelElementPropertyList
                    */
                    //
                    /*
                    * 1- RepositoryModelElement
                    */
                    //
                    $element = new RepositoryModelElement($this->m_fieldSet["REPMELEPKID"]);
                    if ($element->selectRow($datasource) == false) {
                        //
                        $this->m_errorSet[VIEW_OBJECT_ERROR] = true;
                        //
                        return (false);
                    }
                    //
                    $template->assign($element->fieldSet());
                    //
                    /*
                    * 2- RepositoryModelElement Parent
                    */
                    //
                    $parent = new RepositoryModelElement($element->get_field_value("REPMELELINK"));
                    if ($parent->selectRow($datasource) == false) {
                        //
                        $this->m_errorSet[VIEW_OBJECT_ERROR] = true;
                        //
                        return (false);
                    }
                    //
                    if ($parent->get_field_value("REPMELELINK") == NULL) $this->m_blockSet["REPLINKVIEW"] = "root";
                    else $this->m_blockSet["REPLINKVIEW"] = "view";
                    //
                    /*
                    * 3- ApplicationCodificationSet
                    */
                    //
                    @include_once (COMPONENTS_HTML . "html.ApplicationCodificationDDL.php");
                    //
                    $codificationSet = NULL;
                    $codificationSetDDL = new ApplicationCodificationDDL("stat", "formInput", 1);
                    $this->m_blockSet["REPSTATLIST"] = $codificationSetDDL->renderObject($datasource, $codificationSet, $element->get_field_value("REPMELESTAT"));
                    //
                    unset($codificationSetDDL);
                    unset($codificationSet);
                    //
                    /*
                    * 4- RepositoryCoreElementSet Dropdownlist
                    */
                    //
                    @include_once (COMPONENTS_DATA . "data.RepositoryCoreElementSet.php");
                    //
                    $elementSet = new RepositoryCoreElementSet($element->get_field_value("REPOSITPKID") , $element->get_field_value("REPCELTPKID"));
                    if ($elementSet->selectSet($datasource, FOREIGNKEY, PRIMARYKEY) == false) {
                        //
                        $this->m_errorSet[HTML_OBJECT_ERROR] = true;
                        //
                        return (false);
                    }
                    //
                    $elementTypeDDL = new HTMLDropdownList("fkid", "formInput", false);
                    $this->m_blockSet["REPCELELIST"] = $elementTypeDDL->renderObject($datasource, $elementSet, $element->get_field_value("REPCELEPKID"));
                    //
                    unset($elementTypeDDL);
                    unset($elementSet);
                    //
                    $template->assign($this->m_blockSet);
                    //
                    /*
                    * 5- RepositoryModelElementTypeMap
                    * Add Types menu
                    */
                    //
                    @include_once (COMPONENTS_DATA . "data.RepositoryModelElementTypeMap.php");
                    //
                    $memberTypeSet = new RepositoryModelElementTypeMap($element->get_field_value("REPMELTPKID"));
                    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");
                    }
                    //
                    /*
                    * 6- RepositoryModelElementPropertyList
                    */
                    //
                    @include_once (COMPONENTS_VIEW . "view.RepositoryModelElementPropertyList.php");
                    //
                    $propertyList = new RepositoryModelElementPropertyList();
                    $propertyList->set_field_value("REPMELTPKID", $element->get_field_value("REPMELTPKID"));
                    $propertyList->set_field_value("REPMELEPKID", $element->get_field_value("REPMELEPKID"));
                    if ($propertyList->renderView($datasource, $template, "prop", "prop", LISTVIEW, RENDER) == false) {
                        //
                        $this->m_errorSet[VIEW_RENDER_ERROR] = true;
                        //
                        return (false);
                    }
                    //
                    break;
                case LISTVIEW:
                    /*
                    * @see handler RepositoryModelElement-list.php
                    */
                    //
                    /*
                    * 1- RepositoryModelElementSet List
                    */
                    //
                    @include_once (COMPONENTS_DATA . "data.RepositoryModelElementSet.php");
                    //
                    $elementSet = new RepositoryModelElementSet($this->m_fieldSet["REPMELEPKID"], $this->m_fieldSet["REPMELTPKID"]);
                    if ($elementSet->selectSet($datasource, FOREIGNKEY, NATURALKEY) == true) {
                        //
                        for ($i = 0;$i < $elementSet->rowCount();$i++) {
                            //	select next row
                            if ($elementSet->fetchCursorRow($datasource) == false) return (false);
                            //
                            $template->select($block);
                            $template->assign($elementSet->fieldSet());
                            $template->render($block);
                            //	select dependent rows
                            if ($this->renderTree($datasource, $template, $block, $elementSet->get_field_value("REPMELEPKID")) == false) return (false);
                        }
                    }
                    //
                    break;
                case TREEVIEW:
                    /*
                    * @see handler RepositoryModelElement-side.php
                    */
                    //
                    /*
                    *
                    * 1- RepositoryModelElement
                    * 2- RepositoryModelElementSet
                    *
                    */
                    //
                    /* 1- RepositoryModelElement Root
                    */
                    //
                    $element = new RepositoryModelElement($this->m_fieldSet["REPMELEPKID"]);
                    if ($element->selectRow($datasource) == false) {
                        //
                        $this->m_errorSet[VIEW_OBJECT_ERROR] = true;
                        //
                        return (false);
                    }
                    //
                    $template->assign($element->fieldSet());
                    //
                    /*
                    * 2- RepositoryModelElementSet Tree
                    */
                    //
                    @include_once (COMPONENTS_DATA . "data.RepositoryModelElementSet.php");
                    //
                    $elementSet = new RepositoryModelElementSet($this->m_fieldSet["REPMELEPKID"]);
                    if ($elementSet->selectSet($datasource, REFLECTKEY, NATURALKEY) == true) {
                        //
                        @include_once (COMPONENTS_DATA . "data.RepositoryModelElementType.php");
                        //
                        for ($i = 0;$i < $elementSet->rowCount();$i++) {
                            //	select next row
                            if ($elementSet->fetchCursorRow($datasource) == false) return (false);
                            //
                            $template->select($block[0]);
                            $template->assign($elementSet->fieldSet());
                            //	select base element
                            if ($this->RenderBase($datasource, $template, $block, 0, $elementSet->fieldSet()) == false) return (false);
                            //
                            $template->render($block[0]);
                            //	select dependent rows
                            if ($this->renderTree($datasource, $template, $block, 0, $elementSet->get_field_value("REPMELEPKID")) == false) return (false);
                        }
                    }
                    //
                    break;
                case FRAMEVIEW:
                    /*
                    * * @see handler RepositoryModelElement-frame.php
                    */
                    /*
                    * 1- RepositoryModelElement
                    */
                    /* select RepositoryModelElement on foreign key ( REPCELEPKID )
                    */
                    $element = new RepositoryModelElement();
                    $element->set_field_value("REPCELEPKID", $this->m_fieldSet["REPCELEPKID"]);
                    if ($element->selectRow($datasource, FOREIGNKEY) == false) {
                        /* select RepositoryCoreElementModelType on primary key ( REPCELEPKID )
                        */
                        @include_once (COMPONENTS_DATA . "data.RepositoryCoreElementModelType.php");
                        //
                        $coreElementModel = new RepositoryCoreElementModelType($this->m_fieldSet["REPCELEPKID"]);
                        if ($coreElementModel->selectRow($datasource) == false) {
                            //
                            $this->m_errorSet[VIEW_OBJECT_ERROR] = true;
                            //
                            return (false);
                        }
                        //
                        /* Insert a RepositoryModelElement based on the RepositoryCoreElementModelType
                        */
                        $element->set_field_value("REPMELTPKID", $coreElementModel->get_field_value("REPMELTPKID"));
                        $element->set_field_value("REPCELEPKID", $coreElementModel->get_field_value("REPCELEPKID"));
                        $element->set_field_value("REPMELENAME", $coreElementModel->get_field_value("REPCELENAME"));
                        $element->set_field_value("REPMELECODE", $coreElementModel->get_field_value("REPCELECODE"));
                        //
                        if ($element->insertRow($datasource) == false) {
                            //
                            $this->m_errorSet[VIEW_OBJECT_ERROR] = true;
                            //
                            return (false);
                        }
                    }
                    //
                    $template->assign($element->fieldSet());
                    //
                    break;
                case ROOTVIEW:
                    /*
                    * @see handler RepositoryModelElement-root.php
                    */
                    //
                    /*
                    * 1- RepositoryModelElement
                    * 2- ApplicationCodificationSet
                    * 3- RepositoryModelElementTypeSet
                    */
                    //
                    /*
                    * 1- RepositoryModelElement
                    */
                    // select ModelElement on primary key ( REPMELEPKID )
                    $element = new RepositoryModelElement($this->m_fieldSet["REPMELEPKID"]);
                    if ($element->selectRow($datasource) == false) {
                        //
                        $this->m_errorSet[VIEW_OBJECT_ERROR] = true;
                        //
                        return (false);
                    }
                    //
                    $template->assign($element->fieldSet());
                    //
                    /*
                    * 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, $element->get_field_value("REPMELESTAT"));
                    //
                    $template->assign($this->m_blockSet);
                    /*
                    * 3- RepositoryModelElementTypeMap
                    * Add Types menu
                    */
                    //
                    @include_once (COMPONENTS_DATA . "data.RepositoryModelElementTypeMap.php");
                    //
                    $memberTypeSet = new RepositoryModelElementTypeMap($element->get_field_value("REPMELTPKID"));
                    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;
                }
                //
                $template->output($mode);
                //
                return (true);
            }
        };
        //	Class
        //-------------------------------------------------------------------------
        
    }
    //	namespace
    //-----------------------------------------------------------------------------
    
?>
Return current item: Entier Studio