src/Controller/AppBundle/Connector/FasterForward/EntityFasterForward.php

Open in your IDE?
  1. <?php
  2. namespace App\Controller\AppBundle\Connector\FasterForward;
  3. use App\Controller\AppBundle\Connector\Assu\AFD\AFDMapping;
  4. use App\Controller\AppBundle\Connector\Awacs\ResponseField;
  5. use App\Controller\AppBundle\Connector\Entity;
  6. class EntityFasterForward extends Entity
  7. {
  8.     public function __construct($fields$type)
  9.     {
  10.         $this->fields json_decode(json_encode($fields), true);
  11.         $this->type $type;
  12.         $this->processDates();
  13.     }
  14.     public function hasAnvaPoliciesEntity()
  15.     {
  16.         $polissen $this->collection('polissen');
  17.         foreach ($polissen as $polis) {
  18.             if (substr($polis->view('polisnummer'), 05) == "8056-") {
  19.                 return substr($polis->view('polisnummer'), 0strpos($polis->view('polisnummer'), "-"5));
  20.             }
  21.         }
  22.         return false;
  23.     }
  24.     private function processDates() {
  25.         foreach ($this->fields as $key => $field) {
  26.             if (is_string($field)) {
  27.                 $r \DateTime::createFromFormat(\DateTime::ATOM$field);
  28.                 if ($r) {
  29.                     $this->fields[$key] = $r->format('Ymd');
  30.                 }
  31.             }
  32.         }
  33.     }
  34.     /**
  35.      * @param string $name name of field
  36.      */
  37.     public function field($name)
  38.     {
  39.         $field = new FasterForwardField();
  40.         $field->portaalName $name;
  41.         if (FasterForwardMapping::fieldExists($name$this->type)) {
  42.             $f FasterForwardMapping::getField($name$this->type);
  43.             if (isset($f['level']) && $f['level'] == 'bezitting') {
  44.                 $field->value $this->collections['bezittingen'][0]->fields[$f['name']];
  45.             } else {
  46.                 $field->value $this->fields[$f['name']];
  47.             }
  48.         } else {
  49.             $field->value $this->fields[$name] ?? '';
  50.         }
  51.         $field->type $this->type;
  52.         //$field->codelist = isset(AssuMapping::$adnMap[$name . ' ']['codelist']) ? AssuMapping::$adnMap[$name . ' ']['codelist'] : '';
  53.         return $field;
  54.     }
  55.     /**
  56.      * @param string $name name of field
  57.      * @return bool
  58.      */
  59.     public function fieldExists($name)
  60.     {
  61. //        if (!AssuMapping::fieldExists($name, $this->type)) return false;
  62. //        return $this->fieldByNumberExists(AssuMapping::getField($name, $this->type));
  63.         return true;
  64.     }
  65.     /**
  66.      * @param string $number Field number
  67.      * @return ResponseField Response Field
  68.      * @throws \Exception when field does not exist
  69.      */
  70.     public function fieldByNumber($number)
  71.     {
  72.         if (!$this->fieldByNumberExists($number)) throw new \Exception('Field does not exist ' $number);
  73.         return $this->fields[$number];
  74.     }
  75.     /**
  76.      * @param string $number Field number
  77.      * @return bool
  78.      */
  79.     public function fieldByNumberExists($number)
  80.     {
  81.         return (isset($this->fields[$number]));
  82.     }
  83.     /**
  84.      * Updates field to be changed on persist.
  85.      * @param $name string Name of field to update
  86.      * @param $value mixed New value of field
  87.      */
  88.     public function updateField($name$value)
  89.     {
  90.         $this->updatedFields[FasterForwardMapping::getField($name$this->type)] = $value;
  91.     }
  92.     /**
  93.      * Updates field to be changed on persist if the value is different than the current value.
  94.      * @param $name string Name of field to update
  95.      * @param $value mixed New value of field
  96.      */
  97.     public function updateIfChanged($name$value)
  98.     {
  99.         if ($this->field($name)->value() != $value) {
  100.             $this->updateField($name$value);
  101.         }
  102.     }
  103.     /**
  104.      * Updates field to be changed on persist.
  105.      * @param $number string Number of field to update
  106.      * @param $value mixed New value of field
  107.      */
  108.     public function updateFieldByNumber($number$value)
  109.     {
  110.         $this->updatedFields[$number] = $value;
  111.     }
  112.     /**
  113.      * @return array Array of updated fields. The key is the number of the field, the value is the new value.
  114.      */
  115.     public function getUpdatedFields()
  116.     {
  117.         return $this->updatedFields;
  118.     }
  119.     /**
  120.      * @return bool True iff there are fields changed
  121.      */
  122.     public function isUpdated()
  123.     {
  124.         return !empty($this->updatedFields);
  125.     }
  126.     /**
  127.      * @return string Primary key of object
  128.      */
  129.     public function getKey()
  130.     {
  131.         return $this->key;
  132.     }
  133.     /**
  134.      * @return string Type of entity (singular)
  135.      */
  136.     public function getType()
  137.     {
  138.         return $this->type;
  139.     }
  140.     /**
  141.      * @return array of fields
  142.      */
  143.     public function fieldsAsArray()
  144.     {
  145.         return $this->fields;
  146.     }
  147.     /**
  148.      * @return string Key of entity
  149.      */
  150.     public function key()
  151.     {
  152.         return $this->key;
  153.     }
  154.     /**
  155.      * @param string $name Name of index
  156.      * @return mixed Content of index
  157.      * @throws \Exception When index does not exist
  158.      */
  159.     public function index($name)
  160.     {
  161.         if (!$this->indexExists($name)) throw new \Exception('Unknown index ' $name);
  162.         return $this->indices[$name];
  163.     }
  164.     /**
  165.      * @param string $name Name of index
  166.      * @return bool
  167.      */
  168.     public function indexExists($name)
  169.     {
  170.         return isset($this->indices[$name]);
  171.     }
  172.     /**
  173.      * @param string $type Collection type
  174.      * @return Entity[] List of collections of type $type
  175.      */
  176.     public function collection($type)
  177.     {
  178.         if (empty($this->collections[$type])) {
  179.             return [];
  180.         } else {
  181.             return $this->collections[$type];
  182.         }
  183.     }
  184.     public function view($portaalNaam$raw false)
  185.     {
  186.         return $this->field($portaalNaam)->view();
  187. //        if ($this->type == 'relatie') {
  188. //        if (isset(FasterForwardMapping::$map[$this->type][$portaalNaam]) && isset($this->fields[FasterForwardMapping::$map[$this->type][$portaalNaam]['name']])) {
  189. //            $block = FasterForwardMapping::$map[$this->type][$portaalNaam];
  190. //            $return = $this->fields[$block['name']];
  191. //            if (isset($block['function'])) {
  192. //                return FasterForwardMapping::executeFunction($block['function'], $return);
  193. //            }
  194. //            if (isset($block['type'])) {
  195. //                switch ($block['type']) {
  196. //                    case 'date':
  197. //                        $dt = new \DateTime($return);
  198. //                    default:
  199. //                        break;
  200. //                }
  201. //            }
  202. //            return $return;
  203. //        } elseif (isset($this->fields[$portaalNaam])) {
  204. //            return $this->fields[$portaalNaam];
  205. //        }
  206. //        } else {
  207. //            $portaalNaam = $portaalNaam . ' ';
  208. //            if (isset(AssuMapping::$adnMap[$portaalNaam])) {
  209. //                foreach (AssuMapping::$adnMap[$portaalNaam]['codes'] as $code) {
  210. //                    if ($code != '') {
  211. //                        $sh = $code[0] . $code[1];
  212. //                        if (isset($this->fields['MESSAGE'][$sh][$code])) {
  213. //                            if (
  214. //                                isset(AssuMapping::$adnMap[$portaalNaam]['codelist']) &&
  215. //                                AFDMapping::getView(AssuMapping::$adnMap[$portaalNaam]['codelist'], $this->fields['MESSAGE'][$sh][$code]) !== null &&
  216. //                                AFDMapping::getView(AssuMapping::$adnMap[$portaalNaam]['codelist'], $this->fields['MESSAGE'][$sh][$code]) != '' &&
  217. //                                !$raw
  218. //                            ) {
  219. //                                $res = AFDMapping::getView(AssuMapping::$adnMap[$portaalNaam]['codelist'], $this->fields['MESSAGE'][$sh][$code]);
  220. //                                if (\DateTime::createFromFormat('Y-m-d', $res) != false) {
  221. //                                    return \DateTime::createFromFormat('Y-m-d', $res)->format('Ymd');
  222. //                                }
  223. //                                return AFDMapping::getView(AssuMapping::$adnMap[$portaalNaam]['codelist'], $this->fields['MESSAGE'][$sh][$code]);
  224. //                            }
  225. //                            return $this->fields['MESSAGE'][$sh][$code];
  226. //                        }
  227. //                    }
  228. //                }
  229. //            }
  230. //        }
  231.         return '';
  232.     }
  233.     /**
  234.      * Check if entity is wachtpolis
  235.      * @return bool true iff entity is wachtpolis
  236.      */
  237.     public function isWachtpolis()
  238.     {
  239.         return $this->isWachtpolis;
  240.     }
  241.     /**
  242.      * Check if entity is a business entity
  243.      * @return bool true iff entity is business
  244.      */
  245.     public function isBusiness()
  246.     {
  247.         if (empty($this->view('soort_relatie'))) {
  248.             return false;
  249.         }
  250.         return $this->view('soort_relatie') != 'Prive';
  251.     }
  252.     public function serialize()
  253.     {
  254.         return serialize([
  255.             $this->type,
  256.             $this->key,
  257.             $this->indices,
  258.             $this->fields,
  259.             $this->collections,
  260.             $this->isWachtpolis
  261.         ]);
  262.     }
  263.     public function unserialize($serialized)
  264.     {
  265.         list(
  266.             $this->type,
  267.             $this->key,
  268.             $this->indices,
  269.             $this->fields,
  270.             $this->collections,
  271.             $this->isWachtpolis
  272.             ) = unserialize($serialized);
  273.     }
  274. }