openrat-cms

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

PreviewLink.class.php (3767B)


      1 <?php
      2 
      3 namespace cms\generator\link;
      4 
      5 use cms\action\RequestParams;
      6 use cms\generator\BaseContext;
      7 use cms\generator\PageContext;
      8 use cms\model\Alias;
      9 use cms\model\BaseObject;
     10 use cms\model\Link;
     11 use cms\model\Url;
     12 use util\exception\GeneratorException;
     13 
     14 /**
     15  * Linkformatter for Preview.
     16  */
     17 
     18 class PreviewLink implements LinkFormat
     19 {
     20 	private $context;
     21 
     22 	/**
     23 	 * PreviewLink constructor.
     24 	 * @param $context BaseContext
     25 	 */
     26 	public function __construct($context)
     27 	{
     28 		$this->context = $context;
     29 	}
     30 
     31 
     32 	/**
     33 	 * Calculates the Preview Link to an object.
     34 	 *
     35      * @param $from BaseObject unused in preview.
     36      * @param $to BaseObject the target where the link points to.
     37      */
     38     public function linkToObject( BaseObject $from, BaseObject $to )
     39     {
     40 
     41         $param = [
     42             'oid'                       => '__OID__'.$to->objectid.'__',
     43             RequestParams::PARAM_OUTPUT => 'preview',
     44 		];
     45 
     46         if   ( $this->context instanceof PageContext ) {
     47 			$param[ RequestParams::PARAM_MODEL_ID    ] = $this->context->modelId;
     48             $param[ RequestParams::PARAM_LANGUAGE_ID ] = $this->context->languageId;
     49 		}
     50 
     51         switch( $to->typeid )
     52         {
     53             case BaseObject::TYPEID_FOLDER:
     54 				$inhalt = \util\Html::url('folder','show',$to->objectid,$param);
     55 				break;
     56             case BaseObject::TYPEID_FILE:
     57             case BaseObject::TYPEID_IMAGE:
     58             case BaseObject::TYPEID_TEXT:
     59                 $inhalt = \util\Html::url('file','show',$to->objectid,$param);
     60                 break;
     61             case BaseObject::TYPEID_PAGE:
     62                 $inhalt = \util\Html::url('page','show',$to->objectid,$param);
     63                 break;
     64 
     65             case BaseObject::TYPEID_LINK:
     66                 $link = new Link( $to->objectid );
     67                 $link->load();
     68 
     69                 $linkedObject = new BaseObject( $link->linkedObjectId );
     70                 $linkedObject->objectLoad();
     71 
     72                 switch( $linkedObject->typeid )
     73                 {
     74                     case BaseObject::TYPEID_FILE:
     75                         $inhalt = \util\Html::url('file','show',$link->linkedObjectId,$param);
     76                         break;
     77 
     78                     case BaseObject::TYPEID_PAGE:
     79                         $inhalt = \util\Html::url('page','show',$link->linkedObjectId,$param);
     80                         break;
     81                     case BaseObject::TYPEID_URL:
     82                         $inhalt = \util\Html::url('url','show',$link->linkedObjectId,$param);
     83                         break;
     84 					default:
     85 						$inhalt = 'Unknown link type: '.$linkedObject->typeid;
     86                 }
     87                 break;
     88 
     89             case BaseObject::TYPEID_ALIAS:
     90                 $alias = new Alias( $to->objectid );
     91 				$alias->load();
     92                 $alias->linkedObjectId;
     93 
     94                 $linkedObject = new BaseObject( $alias->linkedObjectId );
     95                 $linkedObject->objectLoad();
     96 
     97                 switch( $linkedObject->typeid )
     98                 {
     99                     case BaseObject::TYPEID_FILE:
    100                         $inhalt = \util\Html::url('file','show',$alias->linkedObjectId,$param);
    101                         break;
    102 
    103                     case BaseObject::TYPEID_PAGE:
    104                         $inhalt = \util\Html::url('page','show',$alias->linkedObjectId,$param);
    105                         break;
    106 					default:
    107 						$inhalt = 'Unknown link type: '.$linkedObject->typeid;
    108                 }
    109                 break;
    110 
    111             case BaseObject::TYPEID_URL:
    112                 $url = new Url( $to->objectid );
    113                 $url->load();
    114                 $inhalt = $url->url;
    115 
    116                 break;
    117 			default:
    118 				throw new GeneratorException('Unknown type '.$to->typeid.' in target '.$to->__toString() );
    119 
    120 		}
    121 
    122         return $inhalt;
    123 
    124     }
    125 
    126 }