TemplateExtensionAction.class.php (1260B)
1 <?php 2 namespace cms\action\template; 3 use cms\action\Method; 4 use cms\action\TemplateAction; 5 use cms\model\Project; 6 use cms\model\TemplateModel; 7 use language\Messages; 8 9 10 class TemplateExtensionAction extends TemplateAction implements Method { 11 public function view() { 12 } 13 public function post() { 14 $project = new Project( $this->template->projectid ); 15 $models = $project->getModels(); 16 17 $extensions = array(); 18 foreach( $models as $modelId => $modelName ) { 19 20 $input = $this->getRequestVar( $modelName ); 21 22 // Validierung: Werte dürfen nicht doppelt vorkommen. 23 if ( in_array($input, $extensions) ) 24 { 25 $this->addErrorFor($this->template,Messages::DUPLICATE_INPUT); 26 throw new \util\exception\ValidationException( $modelName ); 27 } 28 29 $extensions[ $modelId ] = $input; 30 } 31 32 foreach( $models as $modelId => $modelName ) { 33 34 $templatemodel = new TemplateModel($this->template->templateid, $modelId); 35 $templatemodel->load(); 36 37 $templatemodel->extension = $extensions[ $modelId ]; 38 39 $templatemodel->persist(); 40 } 41 42 $this->addNoticeFor($this->template,Messages::SAVED); 43 } 44 }