public function handleUpdateMsgs() { $vnames = array('updateMessage', 'readflag', 'messageId'); $this->copyToSession($vnames); if (!isset($_SESSION['updateMessage'])) { return; } try { $isUnread = $_SESSION['readflag'] == 'unread' ? true : false; $msgIds = $_SESSION['messageId']; $msgIds = explode(',', $msgIds); $immnSrvc = new IMMNService($this->apiFQDN, $this->getSessionToken()); $this->clearSession(array('updateMessage')); if (count($msgIds) > 1) { $deltaChanges = array(); foreach ($msgIds as $msgId) { $deltaChanges[] = new IMMNDeltaChange($msgId, null, $isUnread); } $immnSrvc->updateMessages($deltaChanges); } else { /* one message id */ $msgId = $msgIds[0]; $immnSrvc->updateMessage($msgId, $isUnread); } $this->results[C_UPDATE_MSGS] = true; } catch (Exception $e) { $this->errors[C_UPDATE_MSGS] = $e->getMessage(); $this->clearSession(array('updateMessage')); } }
/** * Update the messages * * @method updateMessages * * @param {json} immnDeltaChanges - Array containing information about which changes are requested * * @return {Response} Returns Response object * @throws ServiceException if API request was not successful. */ public function updateMessages($immnDeltaJson) { $token = $this->getSessionConsentToken('MIM'); $immnSrvc = new IMMNService($this->base_url, $token); $immnDeltaChanges = array(); foreach ($immnDeltaJson['messages'] as $message) { if (isset($message['id'])) { $id = $message['id']; $isUnread = isset($message['isUnread']) ? $message['isUnread'] : null; $isFavorite = isset($message['isFavorite']) ? $message['isFavorite'] : null; array_push($immnDeltaChanges, new IMMNDeltaChange($id, $isFavorite, $isUnread)); } } return $immnSrvc->updateMessages($immnDeltaChanges, true); }
} catch (ServiceException $se) { echo $se->getErrorResponse(); } /* This try/catch block tests the updateMessages method. */ try { // Specify the id of the message to update. $msgId = 'ENTER VALUE'; // Update the message's Favorite status to true. $favorite = true; // Update the message's Unread status to true. $unread = true; // Create an array that contains an IMMNDeltaChange object to pass to the // IMMNService object. $immnDeltaChange = array(new IMMNDeltaChange($msgId, $favorite, $unread)); // Send the request to update the messages. $immnSrvc->updateMessages($immnDeltaChange); echo "Successfully updated messages.\n"; } catch (ServiceException $se) { echo $se->getErrorResponse(); } /* This try/catch block tests the updateMessage method. */ try { $msgId = 'ENTER VALUE'; // Update the message's Favorite status to true. $favorite = true; // Update the message's Unread status to true. $unread = true; // Send the request to update the message. $immnSrvc->updateMessage($msgId, $unread, $favorite); echo "Successfully updated message.\n"; } catch (ServiceException $se) {