/** * 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}."); } }
/** * Internal helper, loads the datamanager for the current wikipage. Any error triggers a 500. */ private function _load_datamanager() { if ($GLOBALS['midcom_config']['enable_ajax_editing']) { $this->_controller = midcom_helper_datamanager2_controller::create('ajax'); $this->_controller->schemadb =& $this->_request_data['schemadb']; $this->_controller->set_storage($this->_page); $this->_controller->process_ajax(); $this->_datamanager =& $this->_controller->datamanager; } else { $this->_datamanager = new midcom_helper_datamanager2_datamanager($this->_request_data['schemadb']); if (!$this->_datamanager->autoset_storage($this->_page)) { throw new midcom_error("Failed to create a DM2 instance for wiki page {$this->_page->guid}."); } } }
/** * 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}."); } }