src/Controller/AppBundle/Connector/Assu/EntityAssu.php line 9

Open in your IDE?
  1. <?php
  2. namespace App\Controller\AppBundle\Connector\Assu;
  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 EntityAssu extends Entity {
  7.     public function __construct($fields$type) {
  8.         if ($type == 'relatie') {
  9.             $this->fields $fields;
  10.         } else {
  11.             $this->fields json_decode(json_encode((array)$fields), 1);
  12.         }
  13.         $this->type $type;
  14.         if ($this->type == 'relatie') {
  15.             $this->key $this->view('relatienummer');
  16.         } else {
  17.             $this->key $this->view('polisnummer');
  18.         }
  19.     }
  20.     /**
  21.      * @param string $name name of field
  22.      */
  23.     public function field($name) {
  24.         $field = new AssuField();
  25.         $field->value $this->view($nametrue);
  26.         $field->portaalName $name;
  27.         $field->codelist = isset(AssuMapping::$adnMap[$name ' ']['codelist']) ? AssuMapping::$adnMap[$name ' ']['codelist'] : '';
  28.         return $field;
  29.     }
  30.     /**
  31.      * @param string $name name of field
  32.      * @return bool
  33.      */
  34.     public function fieldExists($name) {
  35.         if (!AssuMapping::fieldExists($name$this->type)) return false;
  36.         return $this->fieldByNumberExists(AssuMapping::getField($name$this->type));
  37.     }
  38.     /**
  39.      * @param string $number Field number
  40.      * @return ResponseField Response Field
  41.      * @throws \Exception when field does not exist
  42.      */
  43.     public function fieldByNumber($number) {
  44.         if (!$this->fieldByNumberExists($number)) throw new \Exception('Field does not exist ' $number);
  45.         return $this->fields[$number];
  46.     }
  47.     /**
  48.      * @param string $number Field number
  49.      * @return bool
  50.      */
  51.     public function fieldByNumberExists($number) {
  52.         return (isset($this->fields[$number]));
  53.     }
  54.     /**
  55.      * Updates field to be changed on persist.
  56.      * @param $name string Name of field to update
  57.      * @param $value mixed New value of field
  58.      */
  59.     public function updateField($name$value) {
  60.         $this->updatedFields[AssuMapping::getField($name$this->type)] = $value;
  61.     }
  62.     /**
  63.      * Updates field to be changed on persist if the value is different than the current value.
  64.      * @param $name string Name of field to update
  65.      * @param $value mixed New value of field
  66.      */
  67.     public function updateIfChanged($name$value) {
  68.         if ($this->field($name)->value() != $value) {
  69.             $this->updateField($name$value);
  70.         }
  71.     }
  72.     /**
  73.      * Updates field to be changed on persist.
  74.      * @param $number string Number of field to update
  75.      * @param $value mixed New value of field
  76.      */
  77.     public function updateFieldByNumber($number$value) {
  78.         $this->updatedFields[$number] = $value;
  79.     }
  80.     /**
  81.      * @return array Array of updated fields. The key is the number of the field, the value is the new value.
  82.      */
  83.     public function getUpdatedFields() {
  84.         return $this->updatedFields;
  85.     }
  86.     /**
  87.      * @return bool True iff there are fields changed
  88.      */
  89.     public function isUpdated() {
  90.         return !empty($this->updatedFields);
  91.     }
  92.     /**
  93.      * @return string Primary key of object
  94.      */
  95.     public function getKey()
  96.     {
  97.         return $this->key;
  98.     }
  99.     /**
  100.      * @return string Type of entity (singular)
  101.      */
  102.     public function getType()
  103.     {
  104.         return $this->type;
  105.     }
  106.     /**
  107.      * @return array of fields
  108.      */
  109.     public function fieldsAsArray() {
  110.         return $this->fields;
  111.     }
  112.     /**
  113.      * @return string Key of entity
  114.      */
  115.     public function key() {
  116.         return $this->key;
  117.     }
  118.     /**
  119.      * @param string $name Name of index
  120.      * @return mixed Content of index
  121.      * @throws \Exception When index does not exist
  122.      */
  123.     public function index($name) {
  124.         if (!$this->indexExists($name)) throw new \Exception('Unknown index ' $name);
  125.         return $this->indices[$name];
  126.     }
  127.     /**
  128.      * @param string $name Name of index
  129.      * @return bool
  130.      */
  131.     public function indexExists($name) {
  132.         return isset($this->indices[$name]);
  133.     }
  134.     /**
  135.      * @param string $type Collection type
  136.      * @return Entity[] List of collections of type $type
  137.      */
  138.     public function collection($type) {
  139.         if (empty($this->collections[$type])) {
  140.             return [];
  141.         } else {
  142.             return $this->collections[$type];
  143.         }
  144.     }
  145.     public function view($portaalNaam$raw false) {
  146.         if ($this->type == 'relatie') {
  147.             if (isset(AssuMapping::$map[$portaalNaam]) && isset($this->fields[AssuMapping::$map[$portaalNaam]])) {
  148.                 $return $this->fields[AssuMapping::$map[$portaalNaam]];
  149.                 if ($portaalNaam == 'geboortedatum') {
  150.                     $return str_replace('-'''$return);
  151.                 }
  152.                 return $return;
  153.             }
  154.         } else {
  155.             $portaalNaam $portaalNaam ' ';
  156.             if (isset(AssuMapping::$adnMap[$portaalNaam])) {
  157.                 foreach (AssuMapping::$adnMap[$portaalNaam]['codes'] as $code) {
  158.                     if ($code != '') {
  159.                         $sh $code[0] . $code[1];
  160.                         if (isset($this->fields['MESSAGE'][$sh][$code])) {
  161.                             if (
  162.                                 isset(AssuMapping::$adnMap[$portaalNaam]['codelist']) &&
  163.                                 AFDMapping::getView(AssuMapping::$adnMap[$portaalNaam]['codelist'], $this->fields['MESSAGE'][$sh][$code]) !== null &&
  164.                                 AFDMapping::getView(AssuMapping::$adnMap[$portaalNaam]['codelist'], $this->fields['MESSAGE'][$sh][$code]) != '' &&
  165.                                 !$raw
  166.                             ) {
  167.                                 $res AFDMapping::getView(AssuMapping::$adnMap[$portaalNaam]['codelist'], $this->fields['MESSAGE'][$sh][$code]);
  168.                                 if (\DateTime::createFromFormat('Y-m-d'$res) != false) {
  169.                                     return \DateTime::createFromFormat('Y-m-d'$res)->format('Ymd');
  170.                                 }
  171.                                 return AFDMapping::getView(AssuMapping::$adnMap[$portaalNaam]['codelist'], $this->fields['MESSAGE'][$sh][$code]);
  172.                             }
  173.                             return $this->fields['MESSAGE'][$sh][$code];
  174.                         }
  175.                     }
  176.                 }
  177.             }
  178.         }
  179.         return '';
  180.     }
  181.     /**
  182.      * Check if entity is wachtpolis
  183.      * @return bool true iff entity is wachtpolis
  184.      */
  185.     public function isWachtpolis()
  186.     {
  187.         return $this->isWachtpolis;
  188.     }
  189.     /**
  190.      * Check if entity is a business entity
  191.      * @return bool true iff entity is business
  192.      */
  193.     public function isBusiness() {
  194.         if (empty($this->view('soort_relatie'))) {
  195.             return false;
  196.         }
  197.         return $this->view('soort_relatie') != 'Prive';
  198.     }
  199.     public function serialize()
  200.     {
  201.         return serialize([
  202.             $this->type,
  203.             $this->key,
  204.             $this->indices,
  205.             $this->fields,
  206.             $this->collections,
  207.             $this->isWachtpolis
  208.         ]);
  209.     }
  210.     public function unserialize($serialized)
  211.     {
  212.         list(
  213.             $this->type,
  214.             $this->key,
  215.             $this->indices,
  216.             $this->fields,
  217.             $this->collections,
  218.             $this->isWachtpolis
  219.         ) = unserialize($serialized);
  220.     }
  221. }