/** * Load either a create controller or an edit (simple) controller or trigger an error message */ private function _load_controller() { // Get the configured schemas $schemadbs = $this->_config->get('schemadbs_folder'); // Check if a custom schema exists if (array_key_exists($this->_topic->component, $schemadbs)) { $schemadb = $schemadbs[$this->_topic->component]; } else { if (!array_key_exists('default', $schemadbs)) { throw new midcom_error('Configuration error. No default schema for topic has been defined!'); } $schemadb = $schemadbs['default']; } $GLOBALS['midcom_admin_folder_mode'] = $this->_handler_id; // Create the schema instance $this->_schemadb = midcom_helper_datamanager2_schema::load_database($schemadb); switch ($this->_handler_id) { case 'edit': $this->_controller = midcom_helper_datamanager2_controller::create('simple'); $this->_controller->schemadb =& $this->_schemadb; $this->_controller->set_storage($this->_topic); break; case 'create': foreach ($this->_schemadb as $schema) { if (isset($schema->fields['name'])) { $schema->fields['name']['required'] = 0; } } $this->_controller = midcom_helper_datamanager2_controller::create('create'); $this->_controller->schemadb =& $this->_schemadb; $this->_controller->schemaname = 'default'; $this->_controller->callback_object =& $this; // Suggest to create the same type of a folder as the parent is $component_suggestion = $this->_topic->component; //Unless config told us otherwise if ($this->_config->get('default_component')) { $component_suggestion = $this->_config->get('default_component'); } $this->_controller->defaults = array('component' => $component_suggestion); break; case 'createlink': if (!array_key_exists('link', $schemadbs)) { throw new midcom_error('Configuration error. No link schema for topic has been defined!'); } $schemadb = $schemadbs['link']; // Create the schema instance $this->_schemadb = midcom_helper_datamanager2_schema::load_database($schemadb); $this->_schemadb->default->fields['name']['required'] = 0; $this->_controller = midcom_helper_datamanager2_controller::create('create'); $this->_controller->schemadb =& $this->_schemadb; $this->_controller->schemaname = 'link'; $this->_controller->callback_object =& $this; break; default: throw new midcom_error('Unable to process the request, unknown handler id'); } if (!$this->_controller->initialize()) { throw new midcom_error("Failed to initialize a DM2 controller instance for article {$this->_event->id}."); } }
/** * loads the controller instance */ private function _prepare_datamanager() { $this->_controller = $this->get_controller('create'); // adjust cost per unit label // we have a percentage here? if ($this->_product->costType != "m") { $cost_per_unit_title = "cost per unit (percentage)"; $this->_controller->schemadb["default"]->fields['costPerUnit']['title'] = $this->_l10n->get($cost_per_unit_title); } $this->_controller->initialize(); }
/** * Check if a schema has been set * * @param string $identifier The form identifier * @return boolean Indicating success. */ function initialize($identifier = null) { parent::initialize($identifier); if (count($this->schemadb) == 0) { throw new midcom_error('You must set a schema database before initializing midcom_helper_datamanager2_controller_simple.'); } if ($this->datamanager === null) { throw new midcom_error('You must set the datamanager member before initializing midcom_helper_datamanager2_controller_simple.'); } $this->formmanager = new midcom_helper_datamanager2_formmanager($this->datamanager->schema, $this->datamanager->types); return $this->formmanager->initialize($identifier); }
/** * AJAX controller initialization. Loads required Javascript libraries and connects to the parent class initialization. * * @param string $identifier The form identifier * @return boolean Indicating success. */ function initialize($identifier = null) { parent::initialize(); if (count($this->schemadb) == 0) { throw new midcom_error('You must set a schema database before initializing midcom_helper_datamanager2_controller_ajax.'); } if ($this->datamanager === null) { throw new midcom_error('You must set the datamanager member before initializing midcom_helper_datamanager2_controller_ajax.'); } $this->form_identifier .= $identifier; return true; }
/** * Load the DM2 edit controller instance * * @return boolean Indicating success of DM2 edit controller instance */ private function _load_datamanager() { $this->_schemadb = midcom_helper_datamanager2_schema::load_database($GLOBALS['midcom_config']['metadata_schema']); $this->_controller = midcom_helper_datamanager2_controller::create('simple'); $this->_controller->schemadb =& $this->_schemadb; // Check if we have metadata schema defined in the schemadb specific for the object's schema or component $object_schema = $this->_object->get_parameter('midcom.helper.datamanager2', 'schema_name'); $component_schema = str_replace('.', '_', midcom_core_context::get()->get_key(MIDCOM_CONTEXT_COMPONENT)); if ($object_schema == '' || !isset($this->_schemadb[$object_schema])) { if (isset($this->_schemadb[$component_schema])) { // No specific metadata schema for object, fall back to component-specific metadata schema $object_schema = $component_schema; } else { // No metadata schema for component, fall back to default $object_schema = 'metadata'; } } $this->_controller->set_storage($this->_object, $object_schema); if (!$this->_controller->initialize()) { throw new midcom_error("Failed to initialize a DM2 controller instance for article {$this->_article->id}."); } }