public function find_parent($args) { $this->_request_data['up'] = 0; //Check if args[0] is a product group code. if ((int) $args[0] == 0 && strlen($args[0]) > 1) { $qb2 = org_openpsa_products_product_group_dba::new_query_builder(); $qb2->add_constraint('code', '=', $args[0]); $qb2->add_order('code'); $up_group = $qb2->execute(); if (count($up_group) == 1) { //We just pick the first category here $qb = org_openpsa_products_product_group_dba::new_query_builder(); $qb->add_constraint('up', '=', $up_group[0]->id); $qb->add_order('code', 'ASC'); $qb->set_limit(1); $up_group = $qb->execute(); if (count($up_group) == 1) { $this->_request_data['up'] = $up_group[0]->id; } } } else { $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_dba'); } else { try { $parent = new org_openpsa_products_product_group_dba($this->_request_data['up']); } catch (midcom_error $e) { return false; } $parent->require_do('midgard:create'); if ($parent->orgOpenpsaObtype == org_openpsa_products_product_group_dba::TYPE_SMART) { return false; } $this->_request_data['parent'] = $parent; } }
/** * 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(); }