Location: PHPKode > projects > Entier Studio > entierstudio/studio/classes/views/view.ObjectoryResourceExplorer.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.ObjectoryResourceExplorer.php 81 2008-01-17 23:08:21Z yannromefort $
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefObjectoryResourceExplorer")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefObjectoryResourceExplorer", "1");
    //
    DEFINE(DATARESOURCE, 1);
    DEFINE(HOSTRESOURCE, 2);
    //-------------------------------------------------------------------------
    //	Include
    @require_once (FRAMEWORK_DIR . VIEWHELPER);
    //-------------------------------------------------------------------------
    //	Class
    class ObjectoryResourceExplorer extends ViewObject {
        //---------------------------------------------------------------------
        //	Constructor
        
        /**
         *
         * @param
         *
         */
        function ObjectoryResourceExplorer() {
            //
            
        }
        //---------------------------------------------------------------------
        //	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 ObjectoryElementSet($this->m_fieldSet["DIRPROJPKID"], $value);
            if ($elementSet->selectSet($datasource, REFLECTKEY) == true) {
                //
                for ($i = 0;$i < $elementSet->rowCount();$i++) {
                    //	select next ObjectoryElementSet row
                    if ($elementSet->fetchCursorRow($datasource) == false) return (false);
                    //
                    $template->select($block);
                    $template->assign($elementSet->fieldSet());
                    $template->render($block);
                    //	select ObjectoryElementSet dependent rows
                    if ($this->renderTree($datasource, $template, $block, $elementSet->get_field_value("OBJELEMPKID")) == 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	{ FORMVIEW, ITEMVIEW, LISTVIEW, TREEVIEW... }
         * @param	integer	outputmode
         * @return	boolean
         */
        function renderView(&$datasource, &$template, $layout, $block, $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);
                }
            }
            //
            $template->assign($this->m_fieldSet);
            //
            switch ($view) {
                case FORMVIEW:
                    /*
                    * * @see handler ObjectoryResource-form.php
                    */
                    //
                    /*
                    * 1- DirectoryProjectInfo
                    * 2- DirectoryResourceSet
                    * 3- ApplicationCodificationSet
                    */
                    //
                    //
                    @include_once (COMPONENTS_DATA . "data.DirectoryProjectInfo.php");
                    //
                    $project = new DirectoryProjectInfo($this->m_fieldSet["DIRPUSRPKID"]);
                    if ($project->selectRow($datasource) == false) {
                        //
                        $this->m_errorSet[VIEW_OBJECT_ERROR] = true;
                        return (false);
                    }
                    //
                    $template->assign($project->fieldSet());
                    //
                    /*
                    * 2- DirectoryResourceSet
                    */
                    //
                    @include_once (COMPONENTS_DATA . "data.DirectoryResourceSet.php");
                    $resourceSet = new DirectoryResourceSet($project->get_field_value("DIRECTOPKID") , $this->m_fieldSet["DIRRESTPKID"]);
                    if ($resourceSet->selectSet($datasource, FOREIGNKEY) == false) {
                        //
                        $this->m_errorSet[VIEW_OBJECT_ERROR] = true;
                        return (false);
                    }
                    //
                    @include_once (FRAMEWORK_DIR . "htmldropdownlist.php");
                    //
                    $resourceSetDDL = new HTMLDropdownList("list", "formInput");
                    $this->m_blockSet["DIRRESOLIST"] = $resourceSetDDL->renderObject($datasource, $resourceSet);
                    //
                    unset($resourceSetDDL);
                    unset($resourceSet);
                    //
                    /*
                    * 3- ApplicationCodificationSet Dropdownlist
                    */
                    //
                    @include_once (COMPONENTS_HTML . "html.ApplicationCodificationDDL.php");
                    //
                    $codificationSet = NULL;
                    $codificationSetDDL = new ApplicationCodificationDDL("stat", "formInput", 1);
                    $this->m_blockSet["OBJSTATLIST"] = $codificationSetDDL->renderObject($datasource, $codificationSet, $this->m_fieldSet["DIRRESTPKID"], 1);
                    //
                    unset($codificationSetDDL);
                    unset($codificationSet);
                    //
                    $template->assign($this->m_blockSet);
                    //
                    
                break;
                case ITEMVIEW:
                    /*
                    * * @see handler ObjectoryResource-view.php
                    */
                    //
                    /*
                    * 1- ObjectoryResource
                    * 2- ApplicationCodificationSet
                    * 3- RepositorySet
                    * 4- Connection test
                    */
                    //
                    /*
                    * 1- ObjectoryResource
                    */
                    //
                    @include_once (COMPONENTS_DATA . "data.ObjectoryResource.php");
                    //
                    $resource = new ObjectoryResource($this->m_fieldSet["OBJRESOPKID"]);
                    if ($resource->selectRow($datasource) == false) {
                        //
                        $this->m_errorSet[VIEW_OBJECT_ERROR] = true;
                        //
                        return (false);
                    }
                    //
                    $template->assign($resource->fieldSet());
                    //
                    /*
                    * 2- ApplicationCodificationSet Dropdownlist
                    */
                    //
                    @include_once (COMPONENTS_HTML . "html.ApplicationCodificationDDL.php");
                    //
                    $codificationSet = NULL;
                    $codificationSetDDL = new ApplicationCodificationDDL("stat", "formInput", 1);
                    $this->m_blockSet["OBJSTATLIST"] = $codificationSetDDL->renderObject($datasource, $codificationSet, $resource->get_field_value("OBJRESOSTAT"));
                    //
                    unset($codificationSetDDL);
                    unset($codificationSet);
                    //
                    /*
                    * 4- Connection test
                    */
                    //
                    $OBJRESOTEST = $this->get_field_value("OBJRESOTEST");
                    if (1 == $OBJRESOTEST) {
                        //
                        $OBJRURLHOST = $resource->get_field_value("OBJRURLHOST");
                        $OBJRURLPORT = $resource->get_field_value("OBJRURLPORT");
                        $OBJRURLUSER = $resource->get_field_value("OBJRURLUSER");
                        $OBJRURLPASS = $resource->get_field_value("OBJRDECPASS");
                        $OBJRURLNAME = $resource->get_field_value("OBJRURLNAME");
                        $DIRRACCCODE = $resource->get_field_value("DIRRACCCODE");
                        //
                        $className = $DIRRACCCODE . "DataSource";
                        $classFile = @strtolower($DIRRACCCODE) . ".datasource.php";
                        //
                        @include_once (FRAMEWORK_DIR . $classFile);
                        if (class_exists($className) == false) return (false);
                        //
                        @set_time_limit(180);
                        //
                        $database = new $className($OBJRURLHOST, $OBJRURLPORT, $OBJRURLUSER, $OBJRURLPASS, $OBJRURLNAME);
                        //
                        $connected = $database->openConnection();
                        // templateView bug!!!!
                        if ($connected) $this->m_blockSet["OBJRURLTEST"] = "ok";
                        else $this->m_blockSet["OBJRURLTEST"] = $database->errorString();
                        $database->closeConnection();
                        // @quirk see below else case
                        $template->assign($this->m_blockSet);
                        //
                        if ($connected) {
                            //
                            $template->select("online");
                            //
                            /*
                            * 4-1- Resource query if browser IE
                            */
                            //
                            $userBrowser = new UserBrowser();
                            $template->toggle("query", ($userBrowser->Browser() == "IE"));
                            //
                            /*
                            * 4-2- Resource mapping
                            */
                            //
                            switch ($resource->get_field_value("DIRRESTPKID")) {
                                case DATARESOURCE:
                                    //
                                    /*
                                    * 3- RepositorySet
                                    */
                                    //
                                    @include_once (COMPONENTS_DATA . "data.RepositorySet.php");
                                    //
                                    $repositorySet = new RepositorySet($resource->get_field_value("DIRECTOPKID"));
                                    if ($repositorySet->selectSet($datasource, FOREIGNKEY) == true) {
                                        //
                                        for ($i = 0;$i < $repositorySet->rowCount();$i++) {
                                            //	select next item
                                            if ($repositorySet->fetchCursorRow($datasource) == false) return (false);
                                            //
                                            //	render item
                                            $template->select("menu1");
                                            $template->assign($repositorySet->fieldSet());
                                            $template->render("menu1");
                                        }
                                    }
                                    //
                                    break;
                                }
                                //
                                $template->render("online");
                        }
                    } else {
                        // @quirk see above previous if case
                        $template->assign($this->m_blockSet);
                    }
                    //
                    break;
                case LISTVIEW:
                    /*
                    * * @see handler ObjectoryResource-list.php
                    */
                    //
                    break;
                case TREEVIEW:
                    /*
                    * * @see class ProjectsExplorer
                    */
                    /*
                    * 1- ObjectoryResourceSet
                    */
                    //
                    // select ObjectoryResourceSet on foreign key DIRPROJPKID + DIRRESTPKID
                    @include_once (COMPONENTS_DATA . "data.ObjectoryResourceSet.php");
                    //
                    $resourceSet = new ObjectoryResourceSet($this->m_fieldSet["DIRPROJPKID"], $this->m_fieldSet["DIRRESTPKID"]);
                    if ($resourceSet->selectSet($datasource, FOREIGNKEY) == true) {
                        //
                        for ($i = 0;$i < $resourceSet->rowCount();$i++) {
                            //	select next row
                            if ($resourceSet->fetchCursorRow($datasource) == false) return (false);
                            //
                            $template->select($block);
                            $template->assign($resourceSet->fieldSet());
                            $template->render($block);
                        }
                    }
                    //
                    break;
                case GRIDVIEW:
                    /*
                    * * @see handler ObjectoryResource-grid.php
                    */
                    //
                    //
                    break;
                }
                //
                $template->output($mode);
                //
                return (true);
            }
        };
        //	Class
        //-------------------------------------------------------------------------
        
    }
    //	namespace
    //-----------------------------------------------------------------------------
    
?>
Return current item: Entier Studio