openrat-cms

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

Macro.class.php (3844B)


      1 <?php
      2 // OpenRat Content Management System
      3 // Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de
      4 //
      5 // This program is free software; you can redistribute it and/or
      6 // modify it under the terms of the GNU General Public License
      7 // as published by the Free Software Foundation; either version 2
      8 // of the License, or (at your option) any later version.
      9 //
     10 // This program is distributed in the hope that it will be useful,
     11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 // GNU General Public License for more details.
     14 //
     15 // You should have received a copy of the GNU General Public License
     16 // along with this program; if not, write to the Free Software
     17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
     18 namespace util;
     19 
     20 use cms\base\DB;
     21 use cms\generator\PageContext;
     22 use cms\model\BaseObject;
     23 use cms\model\Page;
     24 use cms\model\Project;
     25 use util\Session;
     26 
     27 
     28 /**
     29  * Service-Klasse fuer allgemeine Interface-Methoden. Insbesondere
     30  * in Code-Elementen kann und soll auf diese Methoden zurueckgegriffen
     31  * werden.
     32  *
     33  * @author Jan Dankert
     34  */
     35 class Macro
     36 {
     37 	/**
     38 	 * @var PageContext
     39 	 */
     40 	protected $pageContext;
     41 
     42 	/**
     43 	 * @var Page
     44 	 * @deprecated use getPage()
     45 	 */
     46 	protected $page;
     47 
     48 	/**
     49 	 * @param $pageContext PageContext
     50 	 */
     51 	public function setPageContext( $pageContext) {
     52 		$this->pageContext = $pageContext;
     53 		$this->page = new Page( $pageContext->objectId );
     54 	}
     55 
     56 	/**
     57 	 * Ausführen des Makros. Diese Methode sollte durch die Unterklasse überschrieben werden.
     58 	 */
     59 	public function execute()
     60 	{
     61 		// overwrite this in subclasses
     62 	}
     63 
     64 
     65 	/**
     66 	 * Holt die aktuellen Datenbankverbindung.
     67 	 */
     68 	protected function db()
     69 	{
     70 		return DB::get();
     71 	}
     72 
     73 
     74 	/**
     75 	 * Holt die aktuelle Objekt-Id.
     76 	 * @return number
     77 	 */
     78 	protected function getObjectId()
     79 	{
     80 		return $this->pageContext->objectId;
     81 	}
     82 
     83 
     84 	/**
     85 	 * Holt die aktuelle Seite.
     86 	 * @return \cms\model\Page
     87 	 */
     88 	protected function getPage()
     89 	{
     90 		$page = new Page($this->pageContext->objectId);
     91 		$page->load();
     92 
     93 		return $page;
     94 	}
     95 
     96 
     97 	protected function getPageName() {
     98 		return $this->getPage()->getNameForLanguage( $this->pageContext->languageId )->name;
     99 	}
    100 
    101 	/**
    102 	 * Holt das aktuelle Objekt.
    103 	 * @return Object
    104 	 */
    105 	protected function &getObject()
    106 	{
    107 		return new Page( $this->pageContext->objectId );
    108 	}
    109 
    110 
    111 	/**
    112 	 * Ermittelt die Id des Wurzelordners im aktuellen Projekt.
    113 	 */
    114 	protected function getRootObjectId()
    115 	{
    116 		$page = new Page( $this->pageContext->objectId );
    117 		$page->load();
    118 		$project = $page->getProject();
    119 ;
    120 		return $project->getRootObjectId();
    121 	}
    122 
    123 
    124 	/**
    125 	 * Löscht die bisher erzeugte Ausgabe.
    126 	 * @deprecated useless
    127 	 */
    128 	public function delOutput()
    129 	{
    130 	}
    131 
    132 	/**
    133 	 * Ergänzt die Standardausgabe um den gewünschten Wert.
    134 	 * @deprecated use echo()
    135 	 */
    136 	public function output($text)
    137 	{
    138 		echo $text;
    139 	}
    140 
    141 
    142 	/**
    143 	 * Ergänzt die Standardausgabe um den gewünschten Wert. Es wird ein Zeilenendezeichen ergänzt.
    144 	 * @deprecated use echo()
    145 	 */
    146 	public function outputLn($text)
    147 	{
    148 		echo $text . "\n";
    149 	}
    150 
    151 
    152 	/**
    153 	 * Setzt eine Sitzungsvariable.
    154 	 *
    155 	 * @param String $var
    156 	 * @param Object $value
    157 	 */
    158 	public function setSessionVar($var, $value)
    159 	{
    160 		Session::set($var, $value);
    161 	}
    162 
    163 
    164 	/**
    165 	 * Ermittelt eine Sitzungsvariable.
    166 	 *
    167 	 * @param String $var
    168 	 * @return string
    169 	 */
    170 	public function getSessionVar($var)
    171 	{
    172 		return Session::get($var);
    173 	}
    174 
    175 
    176 	/**
    177 	 * Ermittelt den Pfad auf ein Objekt.
    178 	 * @param Object
    179 	 * @return string
    180 	 */
    181 	public function pathToObject($targetObject)
    182 	{
    183 		if (is_numeric($targetObject))
    184 			$targetObject = new BaseObject( $targetObject );
    185 
    186 		$targetObject->load();
    187 		$linkFormat = $this->pageContext->getLinkScheme();
    188 
    189 		return $linkFormat->linkToObject( new Page( $this->pageContext->sourceObjectId), $targetObject );
    190 	}
    191 
    192 }