public function grantBadge($badge, $users)
	{
		if (!$this->credentialsSet())
		{
			throw new Exception('You need to set the credentials first.');
		}

		if (!is_array($users))
		{
			$users = array($users);
		}

		$assertions = array();

		foreach ($users as $user)
		{
			$data = array();

			$data['BadgeId']      = $badge->id;
			$data['EvidenceUrl']  = $badge->evidenceUrl;
			$data['EmailAddress'] = $user;
			$data['ClientId']     = $this->credentials->clientId;

			$assertions[] = $data;
			unset($data);
		}

		$assertionsData = json_encode($assertions);

		if ($this->request_type == 'oauth' && is_a($this->request, 'oauth'))
		{
			$this->request->setAuthType(OAUTH_AUTH_TYPE_AUTHORIZATION);
			try
			{
				$this->request->fetch(self::PASSPORT_API_ENDPOINT . "assertions/", $assertionsData, OAUTH_HTTP_METHOD_POST, array('Content-Type' => 'application/json'));
			}
			catch (Exception $e)
			{
				throw new Exception('Badge grant request failed.');
			}

			$assertion = json_decode($this->request->getLastResponse());
		}
		else if ($this->request_type == 'curl' && get_resource_type($this->request) == 'curl')
		{
			curl_setopt($this->request, CURLOPT_URL, self::PASSPORT_API_ENDPOINT . "assertions/");
			curl_setopt($this->request, CURLOPT_POSTFIELDS, $assertionsData);
			curl_setopt($this->request, CURLOPT_RETURNTRANSFER, true);

			$response  = curl_exec($this->request);
			$assertion = json_decode($response);
		}
		else
		{
			throw new Exception('Unsupported request type');
		}

		foreach ($assertion as $ass)
		{
			if (empty($ass->Id) || !$ass->Id)
			{
				throw new Exception($ass->message);
			}
		}
	}
public function grantBadge($badge, $users)
	{
		if (!$this->credentialsSet())
		{
			throw new Exception('You need to set the credentials first.');
		}

		if (!is_array($users))
		{
			$users = array($users);
		}

		$assertions = array();

		foreach ($users as $user)
		{
			$data = array();

			$data['BadgeId']      = $badge->id;
			$data['EvidenceUrl']  = $badge->evidenceUrl;
			$data['EmailAddress'] = $user;
			$data['ClientId']     = $this->credentials->clientId;

			$assertions[] = $data;
			unset($data);
		}

		$assertionsData = json_encode($assertions);

		if ($this->request_type == 'oauth' && is_a($this->request, 'oauth'))
		{
			$this->request->setAuthType(OAUTH_AUTH_TYPE_AUTHORIZATION);
			try
			{
				$this->request->fetch(self::PASSPORT_API_ENDPOINT . "assertions/", $assertionsData, OAUTH_HTTP_METHOD_POST, array('Content-Type' => 'application/json'));
			}
			catch (Exception $e)
			{
				throw new Exception('Badge grant request failed.');
			}

			$assertion = json_decode($this->request->getLastResponse());
		}
		else if ($this->request_type == 'curl' && get_resource_type($this->request) == 'curl')
		{
			curl_setopt($this->request, CURLOPT_URL, self::PASSPORT_API_ENDPOINT . "assertions/");
			curl_setopt($this->request, CURLOPT_POSTFIELDS, $assertionsData);
			curl_setopt($this->request, CURLOPT_RETURNTRANSFER, true);

			$response  = curl_exec($this->request);
			$assertion = json_decode($response);
		}
		else
		{
			throw new Exception('Unsupported request type');
		}

		foreach ($assertion as $ass)
		{
			if (empty($ass->Id) || !$ass->Id)
			{
				throw new Exception($ass->message);
			}
		}
	}
public function grantBadge ( $ badge , $ users ) { if ( ! $ this -> credentialsSet ( ) ) { throw new Exception ( 'You need to set the credentials first.' ) ; } if ( ! is_array ( $ users ) ) { $ users = array ( $ users ) ; } $ assertions = array ( ) ; foreach ( $ users as $ user ) { $ data = array ( ) ; $ data [ 'BadgeId' ] = $ badge -> id ; $ data [ 'EvidenceUrl' ] = $ badge -> evidenceUrl ; $ data [ 'EmailAddress' ] = $ user ; $ data [ 'ClientId' ] = $ this -> credentials -> clientId ; $ assertions [ ] = $ data ; unset ( $ data ) ; } $ assertionsData = json_encode ( $ assertions ) ; if ( $ this -> request_type == 'oauth' && is_a ( $ this -> request , 'oauth' ) ) { $ this -> request -> setAuthType ( OAUTH_AUTH_TYPE_AUTHORIZATION ) ; try { $ this -> request -> fetch ( self :: PASSPORT_API_ENDPOINT . "assertions/" , $ assertionsData , OAUTH_HTTP_METHOD_POST , array ( 'Content-Type' => 'application/json' ) ) ; } catch ( Exception $ e ) { throw new Exception ( 'Badge grant request failed.' ) ; } $ assertion = json_decode ( $ this -> request -> getLastResponse ( ) ) ; } else if ( $ this -> request_type == 'curl' && get_resource_type ( $ this -> request ) == 'curl' ) { curl_setopt ( $ this -> request , CURLOPT_URL , self :: PASSPORT_API_ENDPOINT . "assertions/" ) ; curl_setopt ( $ this -> request , CURLOPT_POSTFIELDS , $ assertionsData ) ; curl_setopt ( $ this -> request , CURLOPT_RETURNTRANSFER , true ) ; $ response = curl_exec ( $ this -> request ) ; $ assertion = json_decode ( $ response ) ; } else { throw new Exception ( 'Unsupported request type' ) ; } foreach ( $ assertion as $ ass ) { if ( empty ( $ ass -> Id ) || ! $ ass -> Id ) { throw new Exception ( $ ass -> message ) ; } } }
Grant badges to users

@param   object  $badge  Badge info: ID, Evidence URL
@param   mixed   $users  String (for single user) or array (for multiple users) of user email addresses
@return  void
Grant badges to users