public function readForDto($missingInfo = '') { // TODO This can be refactored to perform missing info based on the data type, rather than the property name. There is much repetition in the code below CP 2014-08 parent::read(); $entriesToReturn = array(); if ($missingInfo != '') { foreach ($this->entries as $entry) { $foundMissingInfo = false; if (!array_key_exists('senses', $entry) || count($entry['senses']) == 0) { $foundMissingInfo = true; } else { foreach ($entry['senses'] as $sense) { switch ($missingInfo) { case LexConfig::DEFINITION: if (!array_key_exists('definition', $sense) || count($sense['definition']) == 0) { $foundMissingInfo = true; } else { foreach ($sense['definition'] as $form) { if ($form['value'] == '') { $foundMissingInfo = true; } } } break; case LexConfig::POS: if (!array_key_exists('partOfSpeech', $sense) || !array_key_exists('value', $sense['partOfSpeech']) || $sense['partOfSpeech']['value'] == '') { $foundMissingInfo = true; } break; case LexConfig::EXAMPLE_SENTENCE: if (!array_key_exists('examples', $sense) || count($sense['examples']) == 0) { $foundMissingInfo = true; } else { foreach ($sense['examples'] as $example) { if (!array_key_exists('sentence', $example) || count($example['sentence']) == 0) { $foundMissingInfo = true; } else { foreach ($example['sentence'] as $form) { if ($form['value'] == '') { $foundMissingInfo = true; } } } } } break; case LexConfig::EXAMPLE_TRANSLATION: if (!array_key_exists('examples', $sense) || count($sense['examples']) == 0) { $foundMissingInfo = true; } else { foreach ($sense['examples'] as $example) { if (!array_key_exists('translation', $example) || count($example['translation']) == 0) { $foundMissingInfo = true; } else { foreach ($example['translation'] as $form) { if ($form['value'] == '') { $foundMissingInfo = true; } } } } } break; default: throw new \Exception("Unknown missingInfoType = " . $missingInfo); } if ($foundMissingInfo) { break; } } } if ($foundMissingInfo) { $entriesToReturn[] = $entry; } } // end of foreach $this->entries = $entriesToReturn; $this->count = count($this->entries); } }