Example #1
0
 /**
  * Adds a reader to the group's security doc.
  * @return associative array of the Httpful response
  */
 public function add_reader(User $user = null, $reflexive = true)
 {
     if ($user == null) {
         throw new UnexpectedValueException("No user required.");
     }
     $user_name = $user->get_name();
     // Get original security doc
     $old_doc = $this->get_security_doc();
     // If they're already there, throw an exception
     if (in_array($user_name, $old_doc['members']['names'])) {
         throw new Exception($user_name . " is already a reader in " . $this->name . ".");
     }
     // add them
     array_push($old_doc['members']['names'], $user_name);
     $new_doc = $old_doc;
     // Send request
     $put_response = json_decode($this->set_security_doc($new_doc), true);
     // if there was no error, update the user as well
     if (!isset($put_response['error']) && $reflexive) {
         $user->add_group($this);
     }
     return $put_response;
 }