diff options
author | Silvio <s1lv10@uol.com.br> | 2010-08-04 14:36:20 -0300 |
---|---|---|
committer | Silvio <s1lv10@uol.com.br> | 2010-08-04 14:36:20 -0300 |
commit | d547587ac6c0f765a983a746adb03490a9e74502 (patch) | |
tree | c8a67e920fdf61ac05be616943b55f9acef0b367 /lib/sfIsisImporter.class.php | |
parent | a2f5132c5ad483422096449bdac9651f19d6080d (diff) | |
download | sf_isis_importer_plugin-d547587ac6c0f765a983a746adb03490a9e74502.tar.gz sf_isis_importer_plugin-d547587ac6c0f765a983a746adb03490a9e74502.tar.bz2 |
Checking for denied combinations
Diffstat (limited to 'lib/sfIsisImporter.class.php')
-rw-r--r-- | lib/sfIsisImporter.class.php | 101 |
1 files changed, 100 insertions, 1 deletions
diff --git a/lib/sfIsisImporter.class.php b/lib/sfIsisImporter.class.php index 32fde7d..4b46455 100644 --- a/lib/sfIsisImporter.class.php +++ b/lib/sfIsisImporter.class.php @@ -99,6 +99,7 @@ class sfIsisImporter extends IsisConnector * * @param string $base_model Model to use * @param int $entry Entry number + * @todo Audit: which field/subfields combination are denied? */ public function addEntry($base_model, $entry) { @@ -113,7 +114,10 @@ class sfIsisImporter extends IsisConnector // Dispatch to custom import procedures. foreach (new IsisMethodIterator($this) as $method => $field) { - $this->{$method}($model, $field); + if (!$this->hasDeniedCombinations($base_model, $field)) + { + $this->{$method}($model, $field); + } } $model->save(); @@ -431,4 +435,99 @@ class sfIsisImporter extends IsisConnector return $element; } + + /** + * Check denied combinations inside a field. + * + * @param string $model Model name + * @param array $field Field data from ISIS database schema + * @return boolean True if has a denied combination, false otherwise + * @todo Test + */ + public function hasDeniedCombinations($model, $field) + { + if (method_exists($this, 'getDeniedCombinations')) + { + foreach ($this->getDeniedCombinations($model, $field) as $combination) + { + $has = true; + + foreach ($combination as $item) + { + foreach (new IsisRowIterator($this, $field) as $row) + { + if (!$this->hasDeniedItem($field, $item, $row)) + { + $has = false; + break 2; + } + } + } + + if ($has) + { + $denied[$row] = $combination; + } + } + } + + if (isset($denied)) + { + foreach ($denied as $row => $combination) + { + $combination = implode(',', $combination); + $this->log("Found denied combination for row $row: $combination"); + } + + return true; + } + + return false; + } + + /** + * Check if a field has a denied item. + * + * @param array $field Field data from ISIS database schema + * @param string $item Item code + * @param int $row Row number + * @return boolean True if has a denied combination, false otherwise + * @todo Test + */ + public function hasDeniedItem($field, $item, $row) + { + // Default condition: presence requirement for an item. + $condition = true; + + // Check if item has the negation (absence) requirement for an item. + if (substr($item, 0, 1) == '!') + { + $item = substr($item, 1); + $condition = false; + } + + // Check if the item exists. + $has = $this->hasItem($field, $item, $row); + + if ($condition == true) + { + // If the condition is true, a denied combination won't be fulfilled if + // the item is not present. + if (!$has) + { + return false; + } + } + else + { + // If the condition is false, a denied combination won't be fulfilled if + // the item is present. + if ($has) + { + return false; + } + } + + return true; + } } |