openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

UserMembershipsAction.class.php (1309B)


      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 }