コード例 #1
0
ファイル: RuleOrder.php プロジェクト: EdithF86/email-importer
 public function find(Message $message)
 {
     $corderCodes = array();
     foreach (array($message->getSubject(), $message->getBody()) as $mail) {
         $matches = NULL;
         if (preg_match_all('/\\d{4}\\/\\d{2}-\\d{4}\\/\\d{2}/m', $mail, $matches)) {
             $corderCodes = array_merge($corderCodes, $matches[0]);
         }
     }
     if (empty($corderCodes)) {
         return;
     }
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_oracle');
     $repo = $em->getRepository('Common\\Oracle\\Order');
     $orders = $repo->findByCode($corderCodes);
     foreach ($orders as $order) {
         // set order
         $metadata = new Metadata();
         $metadata->setMessage($message)->setType(Metadata::TYPE_ORDER)->setOracleId($order->getId())->setValue($order->getCode());
         if (!$this->metaExists($metadata, $message)) {
             $message->getMetadata()->add($metadata);
         }
         // take customer from order
         $metadata = new Metadata();
         $metadata->setMessage($message)->setType(Metadata::TYPE_CUSTOMER)->setOracleId($order->getCustomer()->getId())->setValue($order->getCustomer()->getEmail());
         if (!$this->metaExists($metadata, $message)) {
             $message->getMetadata()->add($metadata);
         }
     }
 }
コード例 #2
0
 protected function metaExists(Metadata $metadata, Message $message)
 {
     $exists = $message->getMetadata()->filter(function ($entry) use($metadata) {
         if ($entry->getMessage()->getId() == $metadata->getMessage()->getId() && $entry->getType() == $metadata->getType() && $entry->getOracleId() == $metadata->getOracleId() && $entry->getValue() == $metadata->getValue()) {
             return true;
         } else {
             return false;
         }
     })->count() > 0 ? true : false;
     if ($exists) {
         return true;
     } else {
         return false;
     }
 }
コード例 #3
0
 public function find(Message $message)
 {
     if ($message->getAddresses()->count() === 0) {
         return;
     }
     foreach ($message->getAddresses() as $address) {
         $from = strtolower(trim($address->getAddress()));
         $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_oracle');
         $repo = $em->getRepository('Common\\Oracle\\Customer');
         $customer = $repo->findByEmail($from);
         if (is_null($customer)) {
             return;
         }
         $metadata = new Metadata();
         $metadata->setMessage($message)->setType(Metadata::TYPE_CUSTOMER)->setOracleId($customer->getId())->setValue($customer->getEmail());
         if (!$this->metaExists($metadata, $message)) {
             $message->getMetadata()->add($metadata);
         }
     }
 }
コード例 #4
0
 private function articleUrl(Message $message)
 {
     $articleIds = array();
     foreach (array($message->getSubject(), $message->getBody()) as $mail) {
         if (preg_match_all('/article\\/([0-9]*)\\//mi', $mail, $matches)) {
             $articleIds = array_merge($articleIds, $matches[1]);
         }
     }
     $articleIds = array_values(array_unique($articleIds));
     $articleIds = array_map('trim', $articleIds);
     if (empty($articleIds)) {
         return;
     }
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_oracle');
     $qb = $em->createQueryBuilder();
     $qb->select('p')->from('Common\\Oracle\\Product', 'p')->where('p.id IN (:id)')->setParameter(':id', $articleIds);
     foreach ($qb->getQuery()->getResult() as $product) {
         $metadata = new Metadata();
         $metadata->setMessage($message)->setType(Metadata::TYPE_PRODUCT)->setOracleId($product->getId())->setValue($product->getName());
         if (!$this->metaExists($metadata, $message)) {
             $message->getMetadata()->add($metadata);
         }
     }
 }