/** * Looks up a product to display. * * @param mixed $handler_id The ID of the handler. * @param Array $args The argument list. * @param Array &$data The local request data. */ public function _handler_edit($handler_id, array $args, array &$data) { $this->_group = new org_openpsa_products_product_group_dba($args[0]); $this->_request_data['controller'] = midcom_helper_datamanager2_controller::create('simple'); $this->_request_data['controller']->schemadb =& $this->_request_data['schemadb_group']; $this->_request_data['controller']->set_storage($this->_group); if (!$this->_request_data['controller']->initialize()) { throw new midcom_error("Failed to initialize a DM2 controller instance for product {$this->_group->id}."); } switch ($this->_request_data['controller']->process_form()) { case 'save': if ($this->_config->get('index_groups')) { // Index the group $indexer = midcom::get('indexer'); org_openpsa_products_viewer::index($this->_request_data['controller']->datamanager, $indexer, $this->_topic); } midcom::get('cache')->invalidate($this->_topic->guid); case 'cancel': return new midcom_response_relocate("{$this->_group->guid}/"); } $this->_update_breadcrumb_line(); $this->_prepare_request_data(); // Add toolbar items org_openpsa_helpers::dm2_savecancel($this); $this->_view_toolbar->bind_to($this->_group); midcom::get('metadata')->set_request_metadata($this->_group->metadata->revised, $this->_group->guid); midcom::get('head')->set_pagetitle($this->_group->title); }
public function _update_breadcrumb($handler_id) { // Get common breadcrumb for the product $breadcrumb = org_openpsa_products_viewer::update_breadcrumb_line($this->_object); // Handler-based additions switch ($handler_id) { case 'edit_product': $breadcrumb[] = array(MIDCOM_NAV_URL => '', MIDCOM_NAV_NAME => sprintf($this->_l10n_midcom->get('edit %s'), $this->_l10n->get('product'))); break; case 'delete_product': $breadcrumb[] = array(MIDCOM_NAV_URL => '', MIDCOM_NAV_NAME => sprintf($this->_l10n_midcom->get('delete %s'), $this->_l10n->get('product'))); break; } midcom_core_context::get()->set_custom_key('midcom.helper.nav.breadcrumb', $breadcrumb); }
/** * Looks up a product to display. * * @param mixed $handler_id The ID of the handler. * @param Array $args The argument list. * @param Array &$data The local request data. */ public function _handler_view($handler_id, array $args, array &$data) { if (preg_match('/_raw$/', $handler_id)) { midcom::get()->skip_page_style = true; } $this->_productlink = new org_openpsa_products_product_link_dba($args[0]); $data['controller'] = null; $data['datamanager'] = new midcom_helper_datamanager2_datamanager($data['schemadb_productlink']); if (!$data['datamanager']->autoset_storage($this->_productlink)) { throw new midcom_error("Failed to create a DM2 instance for productlink {$this->_productlink->guid}."); } $this->_prepare_request_data(); $this->bind_view_to_object($this->_productlink, $data['datamanager']->schema->name); $breadcrumb = org_openpsa_products_viewer::update_breadcrumb_line($this->_productlink); midcom_core_context::get()->set_custom_key('midcom.helper.nav.breadcrumb', $breadcrumb); midcom::get('metadata')->set_request_metadata($this->_productlink->metadata->revised, $this->_productlink->guid); // midcom::get('head')->set_pagetitle($this->_request_data['view_title']); }
/** * Looks up a product to display. * * @param mixed $handler_id The ID of the handler. * @param Array $args The argument list. * @param Array &$data The local request data. */ public function _handler_view($handler_id, array $args, array &$data) { if (preg_match('/_raw$/', $handler_id)) { midcom::get()->skip_page_style = true; } $qb = org_openpsa_products_product_dba::new_query_builder(); if (preg_match('/^view_product_intree/', $handler_id)) { $group_qb = org_openpsa_products_product_group_dba::new_query_builder(); if (mgd_is_guid($args[0])) { $group_qb->add_constraint('guid', '=', $args[0]); } else { $group_qb->add_constraint('code', '=', $args[0]); } $groups = $group_qb->execute(); if (empty($groups)) { throw new midcom_error_notfound("Product group {$args[0]} not found"); } $categories_mc = org_openpsa_products_product_group_dba::new_collector('up', $groups[0]->id); $categories_in = $categories_mc->get_values('id'); if (count($categories_in) == 0) { /* No matching categories belonging to this group * So we can search for the application using only * this group id */ $qb->add_constraint('productGroup', 'INTREE', $groups[0]->id); } else { $categories_in[] = $groups[0]->id; $qb->add_constraint('productGroup', 'IN', $categories_in); } if (mgd_is_guid($args[1])) { $qb->add_constraint('guid', '=', $args[1]); } else { $qb->add_constraint('code', '=', $args[1]); } } else { if (mgd_is_guid($args[0])) { $qb->add_constraint('guid', '=', $args[0]); } else { $qb->add_constraint('code', '=', $args[0]); } } if ($this->_config->get('enable_scheduling')) { $qb->add_constraint('start', '<=', time()); $qb->begin_group('OR'); /* * List products that either have no defined end-of-market dates * or are still in market */ $qb->add_constraint('end', '=', 0); $qb->add_constraint('end', '>=', time()); $qb->end_group(); } $results = $qb->execute(); $this->_request_data['is_linked_from'] = ''; if (!empty($results)) { $this->_product = $results[0]; if ($this->_config->get('enable_productlinks') && $this->_product->productGroup != 0) { $root_group_guid = $this->_config->get('root_group'); if ($root_group_guid != '') { $root_group = org_openpsa_products_product_group_dba::get_cached($root_group_guid); } if ($root_group->id != $this->_product->productGroup) { $product_group = new org_openpsa_products_product_group_dba($this->_product->productGroup); $mc_intree = org_openpsa_products_product_group_dba::new_collector('id', $product_group->id); $mc_intree->add_constraint('up', 'INTREE', $root_group->id); $count = $mc_intree->count(); if ($count == 0) { $mc_intree = org_openpsa_products_product_link_dba::new_collector('product', $this->_product->id); $mc_intree->add_constraint('productGroup', 'INTREE', $root_group->id); $mc_intree->execute(); $results = $mc_intree->list_keys(); if (count($results) > 0) { foreach ($results as $guid => $array) { $this->_request_data['is_linked_from'] = $guid; } } } } } } else { if (preg_match('/^view_product_intree/', $handler_id)) { $this->_product = new org_openpsa_products_product_dba($args[1]); } else { $this->_product = new org_openpsa_products_product_dba($args[0]); } } if ($GLOBALS['midcom_config']['enable_ajax_editing']) { $data['controller'] = midcom_helper_datamanager2_controller::create('ajax'); $data['controller']->schemadb =& $data['schemadb_product']; $data['controller']->set_storage($this->_product); $data['controller']->process_ajax(); $data['datamanager'] =& $data['controller']->datamanager; } else { $data['controller'] = null; $data['datamanager'] = new midcom_helper_datamanager2_datamanager($data['schemadb_product']); if (!$data['datamanager']->autoset_storage($this->_product)) { throw new midcom_error("Failed to create a DM2 instance for product {$this->_product->guid}."); } } $this->_prepare_request_data(); $this->bind_view_to_object($this->_product, $data['datamanager']->schema->name); if (isset($product_group)) { unset($product_group); } $product_group = null; if ($this->_request_data['is_linked_from'] != '') { $linked_product = new org_openpsa_products_product_link_dba($data['is_linked_from']); if ($linked_product->productGroup != 0) { $product_group = new org_openpsa_products_product_group_dba($linked_product->productGroup); } } $breadcrumb = org_openpsa_products_viewer::update_breadcrumb_line($this->_product, $product_group); midcom_core_context::get()->set_custom_key('midcom.helper.nav.breadcrumb', $breadcrumb); midcom::get('metadata')->set_request_metadata($this->_product->metadata->revised, $this->_product->guid); $title = $this->_config->get('product_page_title'); if (strstr($title, '<PRODUCTGROUP')) { try { $productgroup = new org_openpsa_products_product_group_dba($this->_product->productGroup); $title = str_replace('<PRODUCTGROUP_TITLE>', $productgroup->title, $title); $title = str_replace('<PRODUCTGROUP_CODE>', $productgroup->code, $title); } catch (midcom_error $e) { $title = str_replace('<PRODUCTGROUP_TITLE>', '', $title); $title = str_replace('<PRODUCTGROUP_CODE>', '', $title); } } $title = str_replace('<PRODUCT_CODE>', $this->_product->code, $title); $title = str_replace('<PRODUCT_TITLE>', $this->_product->title, $title); $title = str_replace('<TOPIC_TITLE>', $this->_topic->extra, $title); midcom::get('head')->set_pagetitle($title); }
/** * Displays an article edit view. * * Note, that the article for non-index mode operation is automatically determined in the can_handle * phase. * * If create privileges apply, we relocate to the index creation article * * @param mixed $handler_id The ID of the handler. * @param Array $args The argument list. * @param Array &$data The local request data. */ public function _handler_create($handler_id, array $args, array &$data) { $this->_request_data['up'] = (int) $args[0]; if ($this->_request_data['up'] == 0) { midcom::get('auth')->require_user_do('midgard:create', null, 'org_openpsa_products_product_group_dba'); } else { $parent = new org_openpsa_products_product_group_dba($data['up']); $parent->require_do('midgard:create'); $data['parent'] = $parent; } $data['selected_schema'] = $args[1]; if (!array_key_exists($data['selected_schema'], $data['schemadb_group'])) { throw new midcom_error_notfound('Schema ' . $data['selected_schema'] . ' was not found it schemadb'); } $this->_schema =& $data['selected_schema']; $data['controller'] = $this->get_controller('create'); switch ($data['controller']->process_form()) { case 'save': if ($this->_config->get('index_groups')) { // Index the group $indexer = midcom::get('indexer'); org_openpsa_products_viewer::index($data['controller']->datamanager, $indexer, $this->_topic); } midcom::get('cache')->invalidate($this->_topic->guid); return new midcom_response_relocate("{$this->_group->guid}/"); case 'cancel': if ($this->_request_data['up'] == 0) { return new midcom_response_relocate(''); } else { return new midcom_response_relocate("{$this->_request_data['up']}/"); } } $this->_prepare_request_data(); // Add toolbar items org_openpsa_helpers::dm2_savecancel($this); $this->_request_data['view_title'] = sprintf($this->_l10n_midcom->get('create %s'), $this->_l10n->get($this->_schemadb[$this->_schema]->description)); midcom::get('head')->set_pagetitle($this->_request_data['view_title']); $this->_update_breadcrumb_line(); }
public function _on_reindex_tree_iterator(&$indexer, &$dms, &$topic, &$group, &$topic, &$config) { if ($dms['group']->autoset_storage($group)) { if ($config->get('index_groups')) { org_openpsa_products_viewer::index($dms['group'], $indexer, $topic, $config); } } else { debug_add("Warning, failed to initialize datamanager for product group {$group->id}. Skipping it.", MIDCOM_LOG_WARN); } if ($config->get('index_products')) { $qb_products = org_openpsa_products_product_dba::new_query_builder(); $qb_products->add_constraint('productGroup', '=', $group->id); $products = $qb_products->execute(); unset($qb_products); if (is_array($products)) { foreach ($products as $product) { if (!$dms['product']->autoset_storage($product)) { debug_add("Warning, failed to initialize datamanager for product {$product->id}. Skipping it.", MIDCOM_LOG_WARN); continue; } org_openpsa_products_viewer::index($dms['product'], $indexer, $topic, $config); unset($product); } } unset($products); } $subgroups = array(); $qb_groups = org_openpsa_products_product_group_dba::new_query_builder(); $qb_groups->add_constraint('up', '=', $group->id); $subgroups = $qb_groups->execute(); unset($qb_groups); if (!is_array($subgroups)) { return true; } foreach ($subgroups as $subgroup) { $this->_on_reindex_tree_iterator($indexer, $dms, $topic, $subgroup, $topic, $config); unset($subgroup); } unset($subgroups); return true; }