File modules/cms/action/object/ObjectSettingsAction.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\object; 3 use cms\action\Action; 4 use cms\action\Method; 5 use cms\action\ObjectAction; 6 use cms\model\Permission; 7 use language\Messages; 8 use template_engine\components\html\component_else\ElseComponent; 9 use util\exception\ValidationException; 10 11 12 class ObjectSettingsAction extends ObjectAction implements Method { 13 public function view() { 14 $this->setTemplateVar('settings',$this->baseObject->settings); 15 16 $this->setTemplateVar( 'valid_from_date' ,$this->baseObject->validFromDate==null?'':date('Y-m-d',$this->baseObject->validFromDate) ); 17 $this->setTemplateVar( 'valid_from_time' ,$this->baseObject->validFromDate==null?'':date('H:i' ,$this->baseObject->validFromDate) ); 18 $this->setTemplateVar( 'valid_until_date',$this->baseObject->validToDate ==null?'':date('Y-m-d',$this->baseObject->validToDate ) ); 19 $this->setTemplateVar( 'valid_until_time',$this->baseObject->validToDate ==null?'':date('H:i' ,$this->baseObject->validToDate ) ); 20 } 21 22 23 public function post() { 24 $this->baseObject->settings = $this->request->getText( 'settings'); 25 26 // Validate YAML-Settings 27 try { 28 \util\YAML::parse( $this->baseObject->settings); 29 } 30 catch( \Exception $e ) 31 { 32 $this->addWarningFor( $this->baseObject,"Invalid YAML"); 33 throw new ValidationException( 'settings' ); 34 } 35 36 // Gültigkeitszeiträume speichern. 37 $this->baseObject->validFromDate = $this->toTimestamp( 38 $this->request->getText( 'valid_from_date' ), 39 $this->request->getText( 'valid_from_time' ) 40 ); 41 42 $this->baseObject->validToDate = $this->toTimestamp( 43 $this->request->getText( 'valid_until_date'), 44 $this->request->getText( 'valid_until_time') 45 ); 46 47 48 $this->baseObject->save(); 49 50 $this->addNoticeFor( $this->baseObject,Messages::SAVED); 51 } 52 53 54 protected function toTimestamp( $date, $time ) { 55 if ( $date && $time ) 56 return strtotime( $date.' '.$time ); 57 if ( $date ) 58 return strtotime( $date ); 59 else 60 return null; 61 } 62 63 64 /** 65 * @return int Permission-flag. 66 */ 67 public function getRequiredPermission() { 68 return Permission::ACL_PROP; 69 } 70 71 72 }
Download modules/cms/action/object/ObjectSettingsAction.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()' Fri, 3 Dec 2021 23:27:44 +0100 dankert New: Only allowed methods are shown in the dropdown menu; Some security enhancements. 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() Tue, 17 Nov 2020 23:51:00 +0100 Jan Dankert Refactoring: Every Actionmethod has now its own class.