private function _process($form, $certificate, $document)
 {
     $form->setupInputFilter();
     $tempFile = null;
     $prg = $this->fileprg($form);
     if ($document) {
         $form->bind($document);
     } else {
         $document = new Document();
     }
     if ($prg instanceof \Zend\Http\PhpEnvironment\Response) {
         return $prg;
         // Return PRG redirect response
     } elseif (is_array($prg)) {
         if ($form->isValid()) {
             // Form is valid, save the form!
             $data = $form->getData();
             $tempFile = $form->get('url')->getValue();
             $data['url'] = '/data/docs/' . basename($tempFile['tmp_name']);
             $document->exchangeArray($data);
             $this->getDocumentsTable()->save($certificate->ISIN, $document);
             return $this->redirect()->toRoute('home', array('action' => 'view', 'type' => $certificate->getType(), 'ISIN' => $certificate->ISIN));
         } else {
             // Form not valid, but file uploads might be valid...
             // Get the temporary file information to show the user in the view
             $fileErrors = $form->get('url')->getMessages();
             if (empty($fileErrors)) {
                 $tempFile = $form->get('url')->getValue();
             }
         }
     }
     return array('form' => $form, 'ISIN' => $certificate->ISIN, 'tempFile' => $tempFile);
 }
 public function save($ISIN, Document $document)
 {
     $data = $document->getArrayCopy();
     $data['ISIN'] = $ISIN;
     if (!$document->id) {
         $this->tableGateway->insert($data);
     } elseif ($this->getDocument($document->id)) {
         $this->tableGateway->update($data, array('id' => $document->id));
     } else {
         throw new \Exception('Document id does not exist');
     }
 }
 /**
  * 
  */
 public function testTrackDocuments()
 {
     $oDocument = new Document();
     $oDocument->setTitle('Foobar');
     $oDocument2 = new Document();
     $oDocument2->setTitle('Foobar2');
     $oDocument3 = new Document();
     $oDocument3->setTitle('Foobar3');
     $this->object->add($oDocument);
     $this->object->add($oDocument2);
     $this->object->add($oDocument3);
     $aTrackedDocuments = $this->object->getTrackedDocuments();
     $this->assertEquals(3, count($aTrackedDocuments));
 }
 public function testDisplayAsXml()
 {
     $certificate = new BonusCertificate();
     $document = new Document();
     $priceHistory = new PriceHistory();
     $raw = array('ISIN' => 'mc5B4ac9', 'trading_market' => 'Frankfurt', 'currency' => 'EUR', 'issuer' => 'Microsoft', 'issuing_price' => 20.0, 'current_price' => 25.0, 'type' => 2, 'bonus_barrier_level' => 40.0);
     $docRaw = array('id' => 1, 'name' => 'ddr23', 'type' => 'pdf', 'url' => '/ssds/wwd.pdf');
     $priceHistoryRaw = array('time_stampt' => date('Y-m-d h:i:s'), 'price' => 25.0);
     $document->exchangeArray($docRaw);
     $priceHistory->exchangeArray($priceHistoryRaw);
     $certificate->exchangeArray($raw);
     $certificate->setDocuments(array($document));
     $certificate->setPriceHistory(array($priceHistory));
     $doc = new \DOMDocument();
     $doc->loadXml($certificate->displayAsXml());
     foreach ($raw as $key => $item) {
         if ($key == 'type') {
             continue;
         }
         if ($key == 'bonus_barrier_level') {
             $tagName = 'barrier-level';
         } else {
             $tagName = str_replace('_', '-', $key);
         }
         $this->assertTagOnce($doc, $tagName, $item);
     }
     $this->assertTagOnce($doc, $tagName, null);
     foreach ($docRaw as $key => $item) {
         if ($key == 'id') {
             continue;
         }
         $this->assertTagOnce($doc, $key, $item);
     }
     $this->assertTagOnce($doc, 'price-record', null);
     $actualVal = new \DateTime($priceHistoryRaw['time_stampt']);
     $this->assertTagOnce($doc, 'time-stampt', $actualVal->format('c'));
     $this->assertTagOnce($doc, 'price', $priceHistoryRaw['price']);
 }
Example #5
0
 /**
  * Remove a document from the tracker array.
  * 
  * @param \Application\Model\Document $oDocument
  */
 public function remove(Document $oDocument)
 {
     if (isset($this->aDocuments[$oDocument->getTitle()])) {
         unset($this->aDocuments[$oDocument->getTitle()]);
     }
 }
Example #6
0
 /**
  * Attach the purchased document record to the purchase record.
  * 
  * @return \Application\Model\Document
  * @throws \InvalidArgumentException
  */
 public function setDocument(Document $oDocument)
 {
     if (\is_null($oDocument->getId())) {
         throw new \InvalidArgumentException('Not a valid document record.  Document has no record id.  Id is null.');
     }
     $this->oDocument = $oDocument;
     $this->documentId = $oDocument->getId();
 }
Example #7
0
 /**
  * Delete a document record from the database for the given Document object.
  * 
  * @param \Application\Model\Document $oDocument
  */
 public function delete(Document $oDocument)
 {
     $this->oTableGateway->delete(array(Document::ID => $oDocument->getId()));
 }
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testAttachUnPersistedDocument()
 {
     $oDocument = new Document();
     $oDocument->setTitle('Foobar');
     $oDocument->setInfo('Foobar, Foobar, Foobar');
     $oPurchase = new Purchase();
     $oPurchase->setEmail('*****@*****.**');
     $oPurchase->setDocument($oDocument);
 }
Example #9
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;
 }
 /**
  * Method tests adding a duplicate title.
  */
 public function testDuplicateTitle()
 {
     $oDocument = new Document();
     $oDocument->setTitle('Foobar');
     $oDocument->setInfo('Foobar, Foobar, Foobar');
     $iID = $this->oDao->insert($oDocument);
     $this->assertNotNull($iID);
     $this->assertGreaterThan(1, $iID);
     $oPersistDoc = $this->oDao->find($iID);
     $this->assertInstanceOf('\\Application\\Model\\Document', $oPersistDoc);
     $oDocument2 = new Document();
     $oDocument2->setTitle('Foobar');
     $oDocument2->setInfo('Foobar, Foobar, Foobar');
     try {
         $this->oDao->insert($oDocument2);
     } catch (InvalidQueryException $oEx) {
         $this->assertContains(' Duplicate entry', $oEx->getMessage());
     } finally {
         //Clean up the db after testing
         $this->oDao->delete($oPersistDoc);
     }
 }