File modules/cms/action/user/UserMembershipsAction.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\user; 3 use cms\action\Method; 4 use cms\action\UserAction; 5 use cms\model\Group; 6 use language\Messages; 7 8 9 class UserMembershipsAction extends UserAction implements Method { 10 public function view() { 11 $gruppenListe = array(); 12 13 $allGroups = Group::getAll(); 14 $userGroups = $this->user->getGroups(); 15 16 foreach( $allGroups as $id=>$name ) 17 { 18 19 $hasGroup = array_key_exists($id,$userGroups); 20 $varName = 'group'.$id; 21 $gruppenListe[$id] = array('name' =>$name, 22 'id' =>$id, 23 'var' =>$varName, 24 'member' =>$hasGroup 25 ); 26 $this->setTemplateVar($varName,$hasGroup); 27 } 28 $this->setTemplateVar('memberships',$gruppenListe); 29 } 30 31 public function post() { 32 $allGroups = Group::getAll(); 33 $userGroups = $this->user->getGroups(); 34 $aenderung = false; 35 36 foreach( $allGroups as $id=>$name ) 37 { 38 $hasGroup = array_key_exists($id,$userGroups); 39 40 if ( !$hasGroup && $this->request->isTrue('group'.$id) ) 41 $this->user->addGroup($id); 42 43 if ( $hasGroup && !$this->request->isTrue('group'.$id) ) 44 $this->user->delGroup($id); 45 } 46 47 $this->addNoticeFor($this->user,Messages::GROUP_MEMBERSHIPS_UPDATED); 48 } 49 }
Download modules/cms/action/user/UserMembershipsAction.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, 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.