# PartViewer.class.php

Go to the documentation of this file.

    00001 <?php
    00002 /***************************************************************************
    00003  *   Copyright (C) 2006-2007 by Anton E. Lebedevich                        *
    00004  *                                                                         *
    00005  *   This program is free software; you can redistribute it and/or modify  *
    00006  *   it under the terms of the GNU Lesser General Public License as        *
    00007  *   published by the Free Software Foundation; either version 3 of the    *
    00008  *   License, or (at your option) any later version.                       *
    00009  *                                                                         *
    00010  ***************************************************************************/
    00011
    00015     class PartViewer
    00016     {
    00017         protected $viewResolver     = null;
    00018         protected $model            = null;
    00019
    00020         public function __construct(ViewResolver $resolver, $model = null)
    00021         {
    00022             $this->viewResolver = $resolver;
    00023             $this->model = $model;
    00024         }
    00025
    00029         public function view($partName, $model = null)
    00030         {
    00031             Assert::isTrue($model === null || $model instanceof Model);
    00032
    00033             // use model from outer template if none specified
    00034             if ($model === null) {
    00035                 $model = $this->model;
    00036
    00037                 $parentModel = $this->model->has('parentModel')
    00038                     ? $this->model->get('parentModel')
    00039                     : null;
    00040
    00041             } else
    00042                 $parentModel = $this->model;
    00043
    00044             $model->set('parentModel', $parentModel);
    00045
    00046             $rootModel = $this->model->has('rootModel')
    00047                 ? $this->model->get('rootModel')
    00048                 : $this->model;
    00049
    00050             $model->set('rootModel', $rootModel);
    00051
    00052             if ($partName instanceof View)
    00053                 $partName->render($model);
    00054             else
    00055                 $this->viewResolver->resolveViewName($partName)->render($model);
    00056
    00057             return $this;
    00058         }
    00059
    00060         public function partExists($partName)
    00061         {
    00062             return $this->viewResolver->viewExists($partName);
    00063         }
    00064
    00068         public function getModel()
    00069         {
    00070             return $this->model;
    00071         }
    00072     }
    00073 ?>