public function testAssocLists() { $o_config = new Configuration(__CA_BASE_DIR__ . '/tests/lib/core/data/test.conf'); $va_assoc = $o_config->getAssoc('an_associative_list'); $this->assertEquals(sizeof(array_keys($va_assoc)), 1); $this->assertEquals(sizeof(array_keys($va_assoc['key 1'])), 5); $this->assertEquals($va_assoc['key 1']['subkey1'], 1); $this->assertEquals($va_assoc['key 1']['subkey2'], 2); $this->assertTrue(is_array($va_assoc['key 1']['subkey3'])); $this->assertEquals($va_assoc['key 1']['subkey3']['subsubkey1'], 'at the bottom of the hole'); $this->assertEquals($va_assoc['key 1']['subkey3']['subsubkey2'], 'this is a quoted string'); $this->assertTrue(is_array($va_assoc['key 1']['subkey4'])); $this->assertEquals($va_assoc['key 1']['subkey4'][0], 'Providence'); $this->assertEquals($va_assoc['key 1']['subkey4'][1], 'Pawtucket'); $this->assertEquals($va_assoc['key 1']['subkey4'][2], 'Woonsocket'); $this->assertEquals($va_assoc['key 1']['subkey4'][3], 'Narragansett'); $this->assertEquals($va_assoc['key 1']['subkey5'], '/usr/local/fish'); $va_assoc = $o_config->getAssoc('macro_assoc'); $this->assertEquals(sizeof(array_keys($va_assoc)), 3); $this->assertEquals(sizeof(array_keys($va_assoc['fish'])), 3); $this->assertEquals(sizeof(array_keys($va_assoc['shellfish'])), 3); $this->assertEquals(sizeof(array_keys($va_assoc['other'])), 3); $this->assertEquals($va_assoc['fish'][0], 'flounder'); $this->assertEquals($va_assoc['shellfish'][0], 'scallop'); $this->assertEquals($va_assoc['other'][0], 'chicken'); $va_assoc = $o_config->getAssoc('an_assoc_list_with_embedded_brackets'); $this->assertEquals($va_assoc['test'], 'Hello {there}'); }
/** * Main processing method, both hooks (insert and update) delegate to this. * * @param $pa_params array As given to the hook method. */ protected function _process(&$pa_params) { /** @var BundlableLabelableBaseModelWithAttributes $vo_instance */ $vo_instance = $pa_params['instance']; // Configuration items used multiple times $vb_add_matched = $this->opo_config->getBoolean('add_matched'); $vb_remove_unmatched = $this->opo_config->getBoolean('remove_unmatched'); // Process each rule in order specified foreach ($this->opo_config->getAssoc('rules') as $va_rule) { $vs_related_table = $va_rule['related_table']; $vm_related_record = $va_rule['related_record']; $vs_relationship_type = $va_rule['relationship_type']; // Ensure the related model record exists /** @var BundlableLabelableBaseModelWithAttributes $vo_related_model */ $vo_related_model = new $vs_related_table(is_string($vm_related_record) && !is_numeric($vm_related_record) ? array('idno' => $vm_related_record) : $vm_related_record); if (sizeof($vo_related_model->getFieldValuesArray()) > 0) { // Determine whether a relationship already exists, and whether the rule matches the source object $vn_relationship_id = self::_getRelationshipId($pa_params['instance'], $vs_related_table, $vm_related_record, $vs_relationship_type); $vb_matches = $this->_hasMatch($pa_params, $va_rule); // Add relationship where one does not already exist, and the rule matches if ($vb_add_matched && $vb_matches && is_null($vn_relationship_id)) { $vo_instance->addRelationship($vs_related_table, $vm_related_record, $vs_relationship_type); if ($this->opo_config->getBoolean('notify')) { $this->_notifications()->addNotification(_t(isset($va_rule['add_relationship_notification']) ? $va_rule['add_relationship_notification'] : $this->opo_config->get('default_add_relationship_notification'), $vo_related_model->getTypeName(), $vo_related_model->getListName()), __NOTIFICATION_TYPE_INFO__); } } // Remove relationship where one exists, and the rule does not match if ($vb_remove_unmatched && !$vb_matches && !is_null($vn_relationship_id)) { $vo_instance->removeRelationship($vs_related_table, $vn_relationship_id); if ($this->opo_config->getBoolean('notify')) { $this->_notifications()->addNotification(_t(isset($va_rule['remove_relationship_notification']) ? $va_rule['remove_relationship_notification'] : $this->opo_config->get('default_remove_relationship_notification'), $vo_related_model->getTypeName(), $vo_related_model->getListName()), __NOTIFICATION_TYPE_INFO__); } } } } }