public function execute(CommandContext $context) { if (!Current_User::allow('hms', 'edit_role_members')) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException('You do not have permission to edit role members.'); } $username = $context->get('username'); $rolename = $context->get('role'); $class = $context->get('className'); $instance = $context->get('instance'); if (is_null($username) || is_null($rolename)) { echo json_encode(false); exit; } $db = new PHPWS_DB('hms_role'); $db->addWhere('name', $rolename); $result = $db->select('row'); if (PHPWS_Error::logIfError($result) || is_null($result['id'])) { echo json_encode(false); exit; } $role_id = $result['id']; $role = new HMS_Role(); $role->id = $role_id; if ($role->load()) { echo json_encode($role->removeUser($username, $class, $instance)); exit; } echo json_encode(false); exit; }
public function execute(CommandContext $context) { if (!Current_User::allow('hms', 'edit_role_members')) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException('You do not have permission to edit role members.'); } $username = $context->get('username'); $role_id = $context->get('role'); $classname = $context->get('class'); $instance = $context->get('instance'); if (is_null($username) || is_null($role_id)) { echo json_encode(false); exit; } $role = new HMS_Role(); $role->id = $role_id; if ($role->load()) { try { $role->addUser($username, $classname, $instance); echo json_encode('true'); exit; } catch (Exception $e) { echo json_encode($e->getMessage()); exit; } } }
public function execute(CommandContext $context) { $role_id = $context->get('role'); $perm_id = $context->get('permission'); if (is_null($role_id) || is_null($perm_id)) { echo json_encode(false); exit; } $role = new HMS_Role(); $role->id = $role_id; $perm = new HMS_Permission(); $perm->id = $perm_id; if ($role->load() && $perm->load()) { echo json_encode($role->addPermission($perm)); exit; } echo json_encode(false); exit; }
/** * Copies this floor object to a new term, then calls copy on all * 'this' floor's rooms * * Setting $assignments to 'true' causes the copy public function to copy * the assignments as well as the hall structure. * * @return bool False if unsuccessful. */ public function copy($to_term, $hall_id, $assignments = false, $roles = false) { if (!$this->id) { return false; } //echo "in hms_floor, copying this floor id: $this->id <br>"; // Create a clone of the current floor object // Set id to 0, set term, and save $new_floor = clone $this; $new_floor->reset(); $new_floor->term = $to_term; $new_floor->residence_hall_id = $hall_id; $new_floor->f_movein_time_id = null; $new_floor->t_movein_time_id = null; $new_floor->rt_movein_time_id = null; try { $new_floor->save(); } catch (Exception $e) { throw $e; } // Copy any roles related to this floor. if ($roles) { PHPWS_Core::initModClass("hms", "HMS_Permission.php"); PHPWS_Core::initModClass("hms", "HMS_Role.php"); // Get memberships by object instance. $membs = HMS_Permission::getUserRolesForInstance($this); // Add each user to new floor foreach ($membs as $m) { // Lookup the username $user = new PHPWS_User($m['user_id']); // Load role and add user to new instance $role = new HMS_Role(); $role->id = $m['role']; $role->load(); $role->addUser($user->getUsername(), get_class($new_floor), $new_floor->id); } } // Load all the rooms for this floor if (empty($this->_rooms)) { try { $this->loadRooms(); } catch (Exception $e) { throw $e; } } /** * Rooms exist. Start making copies. * Further copying is needed at the room level. */ if (!empty($this->_rooms)) { foreach ($this->_rooms as $room) { try { $room->copy($to_term, $new_floor->id, null, $assignments); } catch (Exception $e) { throw $e; } } } }
public function copy($to_term, $assignments = FALSE, $roles = FALSE) { if (!$this->id) { return false; } // echo "In hms_residence_hall, copying this hall: $this->id <br>"; // Create clone of current room object // Set id to 0, set term, and save $new_hall = clone $this; $new_hall->reset(); $new_hall->id = 0; $new_hall->term = $to_term; try { $new_hall->save(); } catch (Exception $e) { // rethrow it to the top level throw $e; } // Copy any roles related to this residence hall. if ($roles) { PHPWS_Core::initModClass("hms", "HMS_Permission.php"); PHPWS_Core::initModClass("hms", "HMS_Role.php"); // Get memberships by object instance. $membs = HMS_Permission::getUserRolesForInstance($this); // test($membs,1); // Add each user to new hall foreach ($membs as $m) { // Lookup the username $user = new PHPWS_User($m['user_id']); // Load role and add user to new instance $role = new HMS_Role(); $role->id = $m['role']; $role->load(); $role->addUser($user->getUsername(), get_class($new_hall), $new_hall->id); } } // Save successful, create new floors // Load all floors for this hall if (empty($this->_floors)) { try { $this->loadFloors(); } catch (Exception $e) { throw $e; } } // Floors exist, start making copies if (!empty($this->_floors)) { foreach ($this->_floors as $floor) { try { $floor->copy($to_term, $new_hall->id, $assignments, $roles); } catch (Exception $e) { throw $e; } } } }