/** * The handler for the group_list article. * * @param mixed $handler_id the array key from the request array * @param array $args the arguments given to the handler * @param Array &$data The local request data. */ public function _handler_list($handler_id, array $args, array &$data) { // Query for sub-objects if ($handler_id == 'list_intree') { $this->_handle_list_intree($args); } else { if ($handler_id == 'listall') { $this->_handle_listall($args); } else { if ($handler_id == 'list') { $this->_handle_list($args); } } } $group_qb = org_openpsa_products_product_group_dba::new_query_builder(); $group_qb->add_constraint('up', '=', $data['parent_group']); foreach ($this->_config->get('groups_listing_order') as $ordering) { $this->_add_ordering($group_qb, $ordering); } $this->_request_data['linked_products'] = array(); if ($this->_config->get('enable_productlinks')) { $mc_productlinks = org_openpsa_products_product_link_dba::new_collector('productGroup', $data['parent_group']); $this->_request_data['linked_products'] = $mc_productlinks->get_values('product'); } $data['groups'] = $group_qb->execute(); $data['products'] = array(); if ($this->_config->get('group_list_products')) { $this->_list_group_products(); } // Prepare datamanager $data['datamanager_group'] = new midcom_helper_datamanager2_datamanager($data['schemadb_group']); $data['datamanager_product'] = new midcom_helper_datamanager2_datamanager($data['schemadb_product']); $this->_populate_toolbar(); if ($data['group']) { if ($GLOBALS['midcom_config']['enable_ajax_editing']) { $data['controller'] = midcom_helper_datamanager2_controller::create('ajax'); $data['controller']->schemadb =& $data['schemadb_group']; $data['controller']->set_storage($data['group']); $data['controller']->process_ajax(); $data['datamanager_group'] =& $data['controller']->datamanager; } else { $data['controller'] = null; if (!$data['datamanager_group']->autoset_storage($data['group'])) { throw new midcom_error("Failed to create a DM2 instance for product group {$data['group']->guid}."); } } $this->bind_view_to_object($data['group'], $data['datamanager_group']->schema->name); } $this->_update_breadcrumb_line(); // Set the active leaf if ($this->_config->get('display_navigation') && $this->_request_data['group']) { $group = $this->_request_data['group']; // Loop as long as it is possible to get the parent group while ($group->guid) { // Break to the requested level (probably the root group of the products content topic) if ($group->id === $this->_config->get('root_group') || $group->guid === $this->_config->get('root_group')) { break; } $temp = $group->id; if ($group->up == 0) { break; } $group = new org_openpsa_products_product_group_dba($group->up); } if (isset($temp)) { // Active leaf of the topic $this->set_active_leaf($temp); } } 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); }