/** * Converts a fully fledged data bean into a basic * object for the Moodle DB layer * @param TxttoolsAccount $txttoolsAccount Account to convert * @param object $existingRecord Existing DB record * @return object Converted object * @version 2015062901 * @since 2011042601 */ private function convertBeanToStandardClass(TxttoolsAccount $txttoolsAccount, $existingRecord = null) { if ($existingRecord == null) { $existingRecord = new object(); } // Map fields in $existingRecord->username = $txttoolsAccount->getUsername(); $existingRecord->password = $txttoolsAccount->getEncryptedPassword(); $existingRecord->description = $txttoolsAccount->getDescription(); $existingRecord->defaultuser = $txttoolsAccount->getDefaultUser()->getId(); $existingRecord->creditsused = $txttoolsAccount->getCreditsUsed(); $existingRecord->creditsremaining = $txttoolsAccount->getCreditsRemaining(); $existingRecord->outboundenabled = $txttoolsAccount->isOutboundEnabled() ? 1 : 0; $existingRecord->inboundenabled = $txttoolsAccount->isInboundEnabled() ? 1 : 0; $existingRecord->accounttype = $txttoolsAccount->getBillingType(); $existingRecord->lastupdate = $txttoolsAccount->getLastUpdate(); $existingRecord->url = $txttoolsAccount->getUrl(); $existingRecord->location = $txttoolsAccount->getLocation(); return $existingRecord; }
/** * Build JSON response structure for an updated account * @param TxttoolsAccount $txttoolsAccount Account to build from * @return string Constructed JSON * @version 2012100801 * @since 2011061301 */ private function buildResponse(TxttoolsAccount $txttoolsAccount) { // Copy template down $response = $this->responseTemplate; $response['accountID'] = $txttoolsAccount->getId(); $response['username'] = $txttoolsAccount->getUsername(); $response['description'] = $txttoolsAccount->getDescription(); $response['creditsUsed'] = $txttoolsAccount->getCreditsUsed(); $response['creditsRemaining'] = $txttoolsAccount->getCreditsRemaining(); $response['updateTimeString'] = $txttoolsAccount->getLastUpdateFormatted(); $response['allowOutbound'] = $txttoolsAccount->isOutboundEnabled() ? 1 : 0; $response['allowInbound'] = $txttoolsAccount->isInboundEnabled() ? 1 : 0; $response['billingType'] = $txttoolsAccount->getBillingType(); // Include account restrictions if specified foreach ($txttoolsAccount->getAllowedUsers() as $allowedUser) { $response['allowedUsers'][$allowedUser->getId()] = array('firstName' => $allowedUser->getFirstName(), 'lastName' => $allowedUser->getLastName(), 'username' => $allowedUser->getUsername()); } // Include inbound filters if specified foreach ($txttoolsAccount->getInboundFilters() as $inboundFilter) { $response['inboundFilters'][$inboundFilter->getId()] = array('type' => $inboundFilter->getFilterType(), 'operand' => (string) $inboundFilter->getOperand(), 'inboxes' => array()); foreach ($inboundFilter->getDestinationUsers() as $biteSizedUser) { // No I'm not kidding. Fortunately these won't be included often $response['inboundFilters'][$inboundFilter->getId()]['users'][$biteSizedUser->getId()] = array('firstName' => $biteSizedUser->getFirstName(), 'lastName' => $biteSizedUser->getLastName(), 'username' => $biteSizedUser->getUsername()); } } return json_encode($response); }