/**
  * 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;
 }
 /**
  * Builds authentication block.
  * Method to build an <Authentication> block for authenticating a request with the API
  * @param TxttoolsAccount $txttoolsAccount txttools account to authenticate against
  * @version 2011041501
  * @since 2010090101
  */
 private function buildAuthentication($txttoolsAccount)
 {
     $outPass = $this->encrypter->decrypt(get_config('moodletxt', 'EK'), $txttoolsAccount->getEncryptedPassword());
     // Set authentication block
     // Code written this way so the output is all nice and formatted
     $this->currentAuthentication = '
 ' . MoodletxtXMLConstants::$REQUEST_AUTHENTICATION_BLOCK . '
     ' . MoodletxtXMLConstants::$REQUEST_AUTHENTICATION_USERNAME . $txttoolsAccount->getUsername() . MoodletxtXMLConstants::$_REQUEST_AUTHENTICATION_USERNAME . '
     ' . MoodletxtXMLConstants::$REQUEST_AUTHENTICATION_PASSWORD . $outPass . MoodletxtXMLConstants::$_REQUEST_AUTHENTICATION_PASSWORD . '
 ' . MoodletxtXMLConstants::$_REQUEST_AUTHENTICATION_BLOCK;
 }