File modules/cms/action/template/TemplateAddelAction.class.php
Last commit: Wed Mar 9 13:28:52 2022 +0100 dankert Refactoring: Checkbox values are always sent to the server. In the actions we must test the value with 'isTrue()'
1 <?php 2 namespace cms\action\template; 3 use cms\action\Action; 4 use cms\action\Method; 5 use cms\action\RequestParams; 6 use cms\action\TemplateAction; 7 use cms\model\Element; 8 use cms\model\Project; 9 use cms\model\Template; 10 use language\Messages; 11 12 13 class TemplateAddelAction extends TemplateAction implements Method { 14 public function view() { 15 // Die verschiedenen Element-Typen 16 $types = array(); 17 18 foreach( Element::getAvailableTypes() as $typeid => $t ) 19 { 20 $types[ $typeid ] = 'EL_'.$t; 21 } 22 23 // Code-Element nur fuer Administratoren (da voller Systemzugriff!) 24 if ( !$this->userIsAdmin() ) 25 unset( $types[Element::ELEMENT_TYPE_CODE] ); 26 27 // Auswahlmoeglichkeiten: 28 $this->setTemplateVar('types',$types); 29 30 // Vorbelegung: 31 $this->setTemplateVar('typeid',Element::ELEMENT_TYPE_TEXT); 32 } 33 public function post() { 34 35 $name = $this->request->getAlphanum('name'); 36 37 if ( empty($name) ) 38 throw new \util\exception\ValidationException('name'); 39 40 $newElement = $this->template->addElement( $name,$this->request->getText('description'),$this->request->getText('typeid') ); 41 42 if ( $this->request->isTrue('addtotemplate') ) 43 { 44 $project = new Project( $this->template->projectid); 45 $modelIds = $project->getModelIds(); 46 47 foreach( $modelIds as $modelId ) 48 { 49 $template = new Template( $this->template->templateid ); 50 $templateModel = $template->loadTemplateModelFor( $modelId ); 51 $templateModel->load(); 52 $templateModel->src .= "\n".'{{'.$newElement->name.'}}'; 53 $templateModel->persist(); 54 } 55 56 } 57 58 $this->addNoticeFor($this->template,Messages::SAVED); 59 } 60 }
Downloadmodules/cms/action/template/TemplateAddelAction.class.php
History Wed, 9 Mar 2022 13:28:52 +0100 dankert Refactoring: Checkbox values are always sent to the server. In the actions we must test the value with 'isTrue()' Wed, 10 Mar 2021 23:51:22 +0100 Jan Dankert Refactoring: Cleaned the Request params. Fri, 26 Feb 2021 01:06:01 +0100 Jan Dankert Refactoring accessing the request parameter values. Thu, 19 Nov 2020 14:49:58 +0100 Jan Dankert Fix: Action::addNotice() is replaced by Action::addNoticeFor() Wed, 18 Nov 2020 01:46:36 +0100 Jan Dankert Refactoring of model classes: New method persist() and some other cleanups. Tue, 17 Nov 2020 23:51:00 +0100 Jan Dankert Refactoring: Every Actionmethod has now its own class.