openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

TemplateAction.class.php (3070B)


      1 <?php
      2 
      3 namespace cms\action;
      4 
      5 namespace cms\action;
      6 use cms\model\Content;
      7 use cms\model\Folder;
      8 use cms\model\Permission;
      9 use cms\model\Element;
     10 use cms\model\Page;
     11 use cms\model\Project;
     12 use cms\model\Template;
     13 use cms\model\TemplateModel;
     14 use cms\model\Value;
     15 use language\Messages;
     16 use util\exception\SecurityException;
     17 use util\exception\ValidationException;
     18 use util\Html;
     19 use util\Session;
     20 
     21 
     22 // OpenRat Content Management System
     23 // Copyright (C) 2002-2009 Jan Dankert
     24 //
     25 // This program is free software; you can redistribute it and/or
     26 // modify it under the terms of the GNU General Public License
     27 // as published by the Free Software Foundation; either version 2
     28 // of the License, or (at your option) any later version.
     29 //
     30 // This program is distributed in the hope that it will be useful,
     31 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     32 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     33 // GNU General Public License for more details.
     34 //
     35 // You should have received a copy of the GNU General Public License
     36 // along with this program; if not, write to the Free Software
     37 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
     38 
     39 /**
     40  * Action-Klasse zum Bearbeiten einer Seitenvorlage.
     41  * 
     42  * @author Jan Dankert
     43  * @package openrat.actions
     44  */
     45 
     46 class TemplateAction extends BaseAction
     47 {
     48     /**
     49      * @var Template
     50      */
     51 	protected $template;
     52 	private $element;
     53 
     54 
     55 	function __construct()
     56 	{
     57         parent::__construct();
     58 
     59     }
     60 
     61 
     62     public function init()
     63     {
     64 		$this->template = new Template( $this->request->getId() );
     65 
     66 		$this->template->load();
     67 
     68 		$this->setTemplateVar( 'templateid',$this->template->templateid );
     69 
     70 		if	( intval($this->request->getText('elementid')) != 0 )
     71 		{
     72 			$this->element = new Element( $this->request->getText('elementid') );
     73 			$this->element->load();
     74 			$this->setTemplateVar( 'elementid',$this->element->elementid );
     75 		}
     76 	}
     77 
     78 
     79 
     80 
     81 	/**
     82 	 * User must be an project administrator.
     83 	 */
     84 	public function checkAccess() {
     85 		$project      = new Project( $this->template->projectid );
     86 		$rootFolderId = $project->getRootObjectId();
     87 
     88 		$rootFolder = new Folder( $rootFolderId );
     89 		$rootFolder->load();
     90 
     91 		if   ( ! $rootFolder->hasRight( Permission::ACL_PROP )  )
     92 			throw new SecurityException();
     93 	}
     94 
     95 
     96 	protected function getTemplateModels()
     97 	{
     98 		$project = new Project($this->template->projectid);
     99 		$versions = [];
    100 
    101 		$templatemodels = [];
    102 		foreach ($project->getModels() as $modelId => $modelName) {
    103 			$templatemodels[] = new TemplateModel($this->template->templateid, $modelId);
    104 		}
    105 
    106 		return $templatemodels;
    107 	}
    108 
    109 
    110 
    111 	protected function ensureValueIdIsInAnyTemplate( $valueId ) {
    112 
    113 		$versions = [];
    114 
    115 		foreach( $this->getTemplateModels() as $templateModel )
    116 		{
    117 			$templateModel->load();
    118 
    119 			$content = new Content( $templateModel->getContentid() );
    120 
    121 			$versions = array_merge( $versions, $content->getVersionList() );
    122 		}
    123 
    124 		if   ( ! in_array( $valueId, $versions ))
    125 			throw new SecurityException( 'value-id is not contained in the version list of this file' );
    126 	}
    127 }