setResponse($response); } if ($message) { $this->setMessage($message); } } /** * Get Message * * @return Zend_Mobile_Push_Message_Gcm */ public function getMessage() { return $this->_message; } /** * Set Message * * @param Zend_Mobile_Push_Message_Gcm $message * @return Zend_Mobile_Push_Response_Gcm */ public function setMessage(Zend_Mobile_Push_Message_Gcm $message) { $this->_message = $message; return $this; } /** * Get Response * * @return array */ public function getResponse() { return $this->_response; } /** * Set Response * * @param array $response * @return Zend_Mobile_Push_Response_Gcm */ public function setResponse(array $response) { if (!isset($response['results']) || !isset($response['success']) || !isset($response['failure']) || !isset($response['canonical_ids']) || !isset($response['multicast_id'])) { throw new Zend_Mobile_Push_Exception('Response did not contain the proper fields'); } $this->_response = $response; $this->_results = $response['results']; $this->_successCnt = (int) $response['success']; $this->_failureCnt = (int) $response['failure']; $this->_canonicalCnt = (int) $response['canonical_ids']; $this->_id = (int) $response['multicast_id']; return $this; } /** * Get Success Count * * @return int */ public function getSuccessCount() { return $this->_successCnt; } /** * Get Failure Count * * @return int */ public function getFailureCount() { return $this->_failureCnt; } /** * Get Canonical Count * * @return int */ public function getCanonicalCount() { return $this->_canonicalCnt; } /** * Get Results * * @return array multi dimensional array of: * NOTE: key is registration_id if the message is passed. * 'registration_id' => array( * 'message_id' => 'id', * 'error' => 'error', * 'registration_id' => 'id' * ) */ public function getResults() { return $this->_correlate(); } /** * Get Singular Result * * @param int $flag one of the RESULT_* flags * @return array singular array with keys being registration id * value is the type of result */ public function getResult($flag) { $ret = array(); foreach ($this->_correlate() as $k => $v) { if (isset($v[$flag])) { $ret[$k] = $v[$flag]; } } return $ret; } /** * Correlate Message and Result * * @return array */ protected function _correlate() { $results = $this->_results; if ($this->_message && $results) { $tokens = $this->_message->getToken(); while($token = array_shift($tokens)) { $results[$token] = array_shift($results); } } return $results; } }