File modules/cms/action/group/GroupMembershipsAction.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\group; 3 use cms\action\GroupAction; 4 use cms\action\Method; 5 use cms\model\User; 6 use language\Messages; 7 8 class GroupMembershipsAction extends GroupAction implements Method { 9 10 public function view() { 11 // Mitgliedschaften ermitteln 12 // 13 $userliste = array(); 14 15 $allUsers = User::listAll(); 16 17 $actualGroupUsers = $this->group->getUsers(); 18 19 foreach( $allUsers as $id=>$name ) 20 { 21 $hasUser = array_key_exists($id,$actualGroupUsers); 22 $varName = 'user'.$id; 23 $userliste[$id] = array('name' => $name, 24 'id' => $id, 25 'var' => $varName, 26 'member' => $hasUser 27 ); 28 $this->setTemplateVar($varName,$hasUser); 29 } 30 $this->setTemplateVar('memberships',$userliste); 31 } 32 33 public function post() { 34 35 $allUsers = User::listAll(); 36 $groupUsers = $this->group->getUsers(); 37 38 foreach( $allUsers as $id=>$name ) 39 { 40 $hasUser = array_key_exists($id,$groupUsers); 41 42 if ( !$hasUser && $this->request->isTrue('user'.$id) ) 43 $this->group->addUser($id); 44 45 if ( $hasUser && !$this->request->isTrue('user'.$id) ) 46 $this->group->delUser($id); 47 } 48 49 $this->addNoticeFor($this->group, Messages::USER_ADDED_TO_GROUP); 50 } 51 }
Download modules/cms/action/group/GroupMembershipsAction.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.