예제 #1
0
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testAttachUnPersistedDocument()
 {
     $oDocument = new Document();
     $oDocument->setTitle('Foobar');
     $oDocument->setInfo('Foobar, Foobar, Foobar');
     $oPurchase = new Purchase();
     $oPurchase->setEmail('*****@*****.**');
     $oPurchase->setDocument($oDocument);
 }
예제 #2
0
 /**
  * Private method inserts the purchase record and clears the tracking cookie.
  * 
  * The method will cancel the purchase operation if the email address is not valid and will write a 
  * notice message to the application log.
  *  
  * @param \Application\Controller\Document $oDocument
  * @param string $mEmail
  * @return bool
  */
 private function doPurchase(Document $oDocument, $mEmail)
 {
     //Grab componenets from the DI contained
     $oPurchaseDao = $this->getServiceLocator()->get('PurchaseTable');
     $oTracker = $this->getServiceLocator()->get('DocumentTracker');
     $oLog = $this->getServiceLocator()->get('AppLog');
     $oEmailFilter = $this->getServiceLocator()->get('EmailFilter');
     $oValidator = $this->getServiceLocator()->get('EmailValidator');
     //Filter the email address received from the form input.
     $sEmail = $oEmailFilter->filter($mEmail);
     //Check if the email is of a valid format
     if ($oValidator->isValid($sEmail)) {
         $oPurchase = new Purchase();
         $oPurchase->setEmail($sEmail);
         $oPurchase->setDocument($oDocument);
         //Store the purchase record in the database.
         $oPurchaseDao->insert($oPurchase);
         $oLog->info('Document purchased');
         //clear the tracking cookie
         $oTracker->deleteCookie();
         return true;
     } else {
         //Add a message to the application log if an invalid email is found.
         $oLog->log(Logger::NOTICE, 'Invalid email detected during purchase');
     }
     return false;
 }
예제 #3
0
 /**
  * This method instantites the Purchase object and its associated document object from values 
  * returned from an SQL SELECT JOIN statement.
  * 
  * Method does not affect state and can be made static.
  * 
  * @param array $aData
  * @return Purchase
  */
 private static function build(array $aData)
 {
     $oDocument = new Document();
     $oDocument->exchangeArray($aData);
     //Review, appended table purchase name name to returned columns in the join
     //to avoid ambiguous column name.
     //Reassigning to expected key names for hydrating the Purchase object.
     $aData[Purchase::ID] = $aData['purchase.' . Purchase::ID];
     $aData[Purchase::CREATED_ON] = $aData['purchase.' . Purchase::CREATED_ON];
     $aData[Purchase::EMAIL] = $aData['purchase.' . Purchase::EMAIL];
     $oPurchase = new Purchase();
     $oPurchase->exchangeArray($aData);
     $oPurchase->setDocument($oDocument);
     return $oPurchase;
 }