text changes to registration mail content
[namibia] / module / PriceGuide / src / PriceGuide / Service / Offer.php
1 <?php
2 namespace PriceGuide\Service;
3
4
5
6 /**
7  * Manage Offer data.
8  * @author andre.fourie
9  */
10 class Offer extends \PriceGuide\DataBin\Offer
11 {
12
13
14         /**
15          * ExecuteAfter: Create, Update.
16          * Change job status if needed and update stock entry with offer data.
17          * @param array $meta
18          * @param object|null $jobRecord
19          * @param object|null $record
20          * @param \Workspace\Utility\ServiceInputParams $contract
21          * @return array
22          */
23         public function updateStatusAndStock($meta, $jobRecord, $record, \Workspace\Utility\ServiceInputParams $contract)
24         {
25                 #-> State change on first offer received.
26                 ('Open4Offers' == $jobRecord->jobState)
27                         && $this->workflowNode->changeState('This.UpdateableOffers');
28
29                 #-> Get offer statistics.
30                 $stats = $this->em->createQuery(
31                                  'SELECT COUNT(offer.id) AS numOffres, MAX(offer.amount) AS maxOffer '
32                                 .'FROM \PriceGuide\Entity\Offer offer '
33                                 .'WHERE IDENTITY(offer.priceGuideStock) = :jobId'
34                                 )
35                                 ->setParameter('jobId', $jobRecord->id)
36                                 ->getSingleResult();
37
38                 #-> Update stock item with statistics.
39                 $stockService = new \Stock\Service\Stock();
40                 $stockService->setWorkflow(new \Stock\Workflow());
41                 $stockService->update($jobRecord->stock->id, array(
42                                 'numberOfOffers' => $stats['numOffres'],
43                                 'highestOffer'   => $stats['maxOffer']
44                 ));
45         }
46
47         /**
48          * ExecuteAfter: Archive.
49          * Change status to Archived.
50          * @param array $meta
51          * @param object|null $jobRecord
52          * @param object|null $record
53          * @param \Workspace\Utility\ServiceInputParams $contract
54          * @return array
55          */
56         public function archive($meta, $jobRecord, $record, \Workspace\Utility\ServiceInputParams $contract)
57         {
58                 #-> Change status of offer.
59                 $record->previousStatus = $record->status;
60                 $record->status = 'Archived';
61                 $this->em->flush();
62         }
63
64         /**
65          * ExecuteAfter: Unarchive.
66          * Change status to previous status.
67          * @param array $meta
68          * @param object|null $jobRecord
69          * @param object|null $record
70          * @param \Workspace\Utility\ServiceInputParams $contract
71          * @return array
72          */
73         public function unarchive($meta, $jobRecord, $record, \Workspace\Utility\ServiceInputParams $contract)
74         {
75                 #-> Change status of offer.
76                 $record->status = $record->previousStatus;
77                 $record->previousStatus = 'Archived';
78                 $this->em->flush();
79         }
80
81
82
83 }