openrat-cms

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

DslObject.class.php (2057B)


      1 <?php
      2 
      3 namespace cms\generator\dsl;
      4 
      5 use cms\model\BaseObject;
      6 use cms\model\Folder;
      7 use cms\model\Page;
      8 use dsl\context\BaseScriptableObject;
      9 
     10 /**
     11  * Class DslObject
     12  * @package cms\generator\dsl
     13  */
     14 class DslObject extends BaseScriptableObject
     15 {
     16 	private $object;
     17 
     18 	public $id;
     19 	public $type;
     20 	public $name;
     21 
     22 	/**
     23 	 * DslPage constructor.
     24 	 * @param BaseObject $object
     25 	 */
     26 	public function __construct($object)
     27 	{
     28 		$this->object = $object;
     29 
     30 		$this->id   = $object->getId();
     31 		$this->type = $object->getType();
     32 		$this->name = $this->getDefaultName();
     33 	}
     34 
     35 
     36 	public function getTypeName() {
     37 
     38 		return $this->object->getType();
     39 	}
     40 
     41 	public function filename() {
     42 
     43 		return $this->object->filename();
     44 	}
     45 
     46 	public function getNameForLanguage( $languageid ) {
     47 
     48 		return $this->object->getNameForLanguage( $languageid )->getProperties();
     49 	}
     50 
     51 	public function getDefaultName() {
     52 
     53 		return $this->object->getDefaultName()->getName();
     54 	}
     55 
     56 	public function parent() {
     57 
     58 		if   ( $this->object->parentid == null )
     59 			return null;
     60 
     61 		return new DslObject( new Folder( $this->object->parentid ) );
     62 	}
     63 
     64 
     65 	public function children() {
     66 		if   ( $this->object->isFolder )
     67 		{
     68 			$folder = new Folder( $this->object->objectid );
     69 
     70 			return array_map( function($child) {
     71 				return new DslObject($child);
     72 			},
     73 				$folder->getObjects());
     74 		} else {
     75 			return [];
     76 		}
     77 	}
     78 
     79 
     80 
     81 	/**
     82 	 * @return DslTemplate
     83 	 * @throws \util\exception\ObjectNotFoundException
     84 	 */
     85 	public function getTemplate() {
     86 		if   ( $this->object->isPage )
     87 		{
     88 			$page = new Page( $this->object->objectid );
     89 			return new DslTemplate( $page->getTemplate() );
     90 		} else {
     91 			return null;
     92 		}
     93 	}
     94 
     95 
     96 	public function __toString()
     97 	{
     98 		return "CMS-Object:".$this->id;
     99 	}
    100 
    101 
    102 
    103 	public function getValue( $elementName ) {
    104 		// TODO
    105 		return ;
    106 	}
    107 
    108 
    109 
    110 	/**
    111 	 * @return array
    112 	 * @throws \util\exception\ObjectNotFoundException
    113 	 */
    114 	public function elements() {
    115 		if   ( $this->object->isPage )
    116 		{
    117 			$page = new Page( $this->object->objectid );
    118 			return $page->getElementIds();
    119 		} else {
    120 			return null;
    121 		}
    122 	}
    123 
    124 }