Пример #1
0
 /**
  * Get one level of navigation
  *
  * @return Array containing navigation data
  */
 public static function get_product_group_navigation($id)
 {
     // Initialize the array
     $leaves = array();
     if (mgd_is_guid($id)) {
         try {
             $group = org_openpsa_products_product_group_dba::get_cached($id);
         } catch (midcom_error $e) {
             // Stop silently
             return $leaves;
         }
         $id = $group->id;
     }
     // Initialize the query builder
     $qb = org_openpsa_products_product_group_dba::new_query_builder();
     $qb->add_constraint('up', '=', $id);
     $qb->add_order('metadata.score', 'DESC');
     $qb->add_order('title');
     $qb->add_order('code');
     $groups = $qb->execute();
     // Get the properties of each group
     foreach ($groups as $group) {
         $leaves[$group->id] = array(MIDCOM_NAV_URL => $group->code ? "{$group->code}/" : "{$group->guid}/", MIDCOM_NAV_NAME => $group->title, MIDCOM_NAV_GUID => $group->guid, MIDCOM_NAV_OBJECT => $group, MIDCOM_NAV_NOENTRY => (bool) $group->metadata->navnoentry);
     }
     return $leaves;
 }
Пример #2
0
 public function get_path()
 {
     $path = $this->guid;
     if ($this->code) {
         $path = $this->code;
         try {
             $parent = org_openpsa_products_product_group_dba::get_cached($this->productGroup);
             $path = $parent->code . '/' . $path;
         } catch (midcom_error $e) {
             $e->log();
         }
     }
     return $path;
 }
Пример #3
0
 function _load_schemadb($handler_id, &$args, &$data)
 {
     $data['session'] = new midcom_services_session('org_openpsa_products_csvexport');
     if (!empty($_POST)) {
         $data['session']->set('POST_data', $_POST);
     }
     $root_group_guid = $this->_config->get('root_group');
     $group_name_to_filename = '';
     if ($root_group_guid) {
         $root_group = org_openpsa_products_product_group_dba::get_cached($root_group_guid);
         $group_name_to_filename = strtolower(str_replace(' ', '_', $root_group->code)) . '_';
     }
     if (isset($args[0])) {
         $data['schemadb_to_use'] = str_replace('.csv', '', $args[0]);
         $data['filename'] = $group_name_to_filename . $data['schemadb_to_use'] . '_' . date('Y-m-d') . '.csv';
     } else {
         if (isset($_POST) && array_key_exists('org_openpsa_products_export_schema', $_POST)) {
             //We do not have filename in URL, generate one and redirect
             $schemaname = $_POST['org_openpsa_products_export_schema'];
             if (strpos(midcom_connection::get_url('uri'), '/', strlen(midcom_connection::get_url('uri')) - 2)) {
                 midcom::get()->relocate(midcom_connection::get_url('uri') . "{$schemaname}");
             } else {
                 midcom::get()->relocate(midcom_connection::get_url('uri') . "/{$schemaname}");
             }
             // This will exit
         } else {
             $this->_request_data['schemadb_to_use'] = $this->_config->get('csv_export_schema');
         }
     }
     $this->_schema = $this->_config->get('csv_export_schema');
     if (isset($this->_request_data['schemadb_product'][$this->_request_data['schemadb_to_use']])) {
         $this->_schema = $this->_request_data['schemadb_to_use'];
     }
     $this->_schema_fields_to_skip = explode(',', $this->_config->get('export_skip_fields'));
     return $this->_request_data['schemadb_product'];
 }
Пример #4
0
 /**
  * Can-Handle check against the current group GUID. We have to do this explicitly
  * in can_handle already, otherwise we would hide all subtopics as the request switch
  * accepts all argument count matches unconditionally.
  *
  * @param mixed $handler_id The ID of the handler.
  * @param Array $args The argument list.
  * @param Array &$data The local request data.
  * @return boolean True if the request can be handled, false otherwise.
  */
 public function _can_handle_list($handler_id, array $args, array &$data)
 {
     if ($handler_id == 'index') {
         // We're in root-level product index
         if ($data['root_group']) {
             $data['group'] = org_openpsa_products_product_group_dba::get_cached($data['root_group']);
             $data['view_title'] = $data['group']->title;
         } else {
             $data['group'] = null;
             $data['view_title'] = $this->_l10n->get('product database');
         }
         $data['parent_group'] = $data['root_group'];
     } else {
         // We're in some level of groups
         $qb = org_openpsa_products_product_group_dba::new_query_builder();
         if ($handler_id == 'list_intree' || $handler_id == 'listall') {
             $parentgroup_qb = org_openpsa_products_product_group_dba::new_query_builder();
             $parentgroup_qb->add_constraint('code', '=', $args[0]);
             $groups = $parentgroup_qb->execute();
             if (empty($groups)) {
                 // No such parent group found
                 return false;
             }
             if (!empty($groups[0]->id)) {
                 $qb->add_constraint('up', '=', $groups[0]->id);
                 if ($handler_id == 'listall') {
                     $qb->add_constraint('code', '=', $args[1]);
                 }
             }
         } else {
             $qb->add_constraint('code', '=', $args[0]);
         }
         $results = $qb->execute();
         if (count($results) == 0) {
             try {
                 $data['group'] = new org_openpsa_products_product_group_dba($args[0]);
             } catch (midcom_error $e) {
                 return false;
             }
         } else {
             $data['group'] = $results[0];
         }
         $data['parent_group'] = $data['group']->id;
         if ($handler_id == 'listall') {
             try {
                 $group_up = new org_openpsa_products_product_group_dba($data['group']->up);
                 if (isset($group_up->title)) {
                     $data['group'] = $group_up;
                 }
             } catch (midcom_error $e) {
             }
         }
         if ($this->_config->get('code_in_title')) {
             $data['view_title'] = "{$data['group']->code} {$data['group']->title}";
         } else {
             $data['view_title'] = $data['group']->title;
         }
         if ($handler_id == 'listall') {
             $data['view_title'] = sprintf($this->_l10n_midcom->get('All %s'), $data['view_title']);
         }
         $data['acl_object'] = $data['group'];
     }
     return true;
 }
Пример #5
0
 /**
  * The handle callback populates root group information
  */
 public function _on_can_handle($argc, $argv)
 {
     if ($this->_config->get('root_group') === 0) {
         $this->_request_data['root_group'] = 0;
     } else {
         $root_group = org_openpsa_products_product_group_dba::get_cached($this->_config->get('root_group'));
         $this->_request_data['root_group'] = $root_group->id;
     }
     if ($argc >= 1) {
         $mc = midcom_db_topic::new_collector('up', $this->_topic->id);
         $mc->add_constraint('name', '=', $argv[0]);
         $mc->execute();
         $keys = $mc->list_keys();
         if (count($keys) > 0) {
             // the values are dummy...
             return false;
         }
     }
     return true;
 }
Пример #6
0
 /**
  * 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);
 }
Пример #7
0
?>
    </p>

    <form enctype="multipart/form-data" action="&(prefix);api/product/csv/" method="post" class="datamanager">
        <label for="org_openpsa_products_export_schema">
            <span class="field_text"><?php 
echo $data['l10n']->get('schema');
?>
</span>
            <select class="dropdown" name="org_openpsa_products_export_schema" id="org_openpsa_products_export_schema">
                <?php 
// FIXME: this schema counting is *really* inefficient
$root_group_guid = $data['config']->get('root_group');
if (!empty($root_group_guid)) {
    try {
        $root_group = org_openpsa_products_product_group_dba::get_cached($root_group_guid);
        $qb_groups = org_openpsa_products_product_group_dba::new_query_builder();
        $qb_groups->add_constraint('up', 'INTREE', $root_group->id);
        $groups = $qb_groups->execute();
    } catch (midcom_error $e) {
        $root_group = null;
    }
}
foreach (array_keys($data['schemadb_product']) as $name) {
    $count_by_schema = 0;
    if ($root_group) {
        $qb = org_openpsa_products_product_dba::new_query_builder();
        $qb->add_constraint('code', '<>', '');
        $qb->begin_group('OR');
        $qb->add_constraint('productGroup', '=', $root_group->id);
        foreach ($groups as $group) {
Пример #8
0
 /**
  * @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_csv_select($handler_id, array $args, array &$data)
 {
     $this->_prepare_handler($args);
     $data['product_groups'] = array();
     $up = 0;
     if ($this->_config->get('root_group') != 0) {
         $root_group_guid = $this->_config->get('root_group');
         $root_group_obj = org_openpsa_products_product_group_dba::get_cached($root_group_guid);
         $up = $root_group_obj->up;
     }
     $data['product_groups'] = $this->_get_product_group_tree($up);
     if (isset($_POST['org_openpsa_products_import_schema'])) {
         $data['schema'] = $_POST['org_openpsa_products_import_schema'];
     } else {
         $data['schema'] = 'default';
     }
     $this->_datamanager->set_schema($data['schema']);
     if (array_key_exists('org_openpsa_products_import_separator', $_POST)) {
         $data['time_start'] = time();
         $data['rows'] = array();
         switch ($_POST['org_openpsa_products_import_separator']) {
             case ';':
                 $data['separator'] = ';';
                 break;
             case ',':
             default:
                 $data['separator'] = ',';
                 break;
         }
         $data['new_products_product_group'] = $_POST['org_openpsa_products_import_new_products_product_group'];
         if (is_uploaded_file($_FILES['org_openpsa_products_import_upload']['tmp_name'])) {
             // Copy the file for later processing
             $data['tmp_file'] = tempnam($GLOBALS['midcom_config']['midcom_tempdir'], 'org_openpsa_products_import_csv');
             $src = fopen($_FILES['org_openpsa_products_import_upload']['tmp_name'], 'r');
             $dst = fopen($data['tmp_file'], 'w+');
             while (!feof($src)) {
                 $buffer = fread($src, 131072);
                 /* 128 kB */
                 fwrite($dst, $buffer, 131072);
             }
             fclose($src);
             fclose($dst);
             // Read cell headers from the file
             $read_rows = 0;
             $handle = fopen($_FILES['org_openpsa_products_import_upload']['tmp_name'], 'r');
             $separator = $data['separator'];
             $total_columns = 0;
             while ($read_rows < 2 && ($csv_line = fgetcsv($handle, 3000, $separator))) {
                 if ($total_columns == 0) {
                     $total_columns = count($csv_line);
                 }
                 $columns_with_content = 0;
                 foreach ($csv_line as $value) {
                     if ($value != '') {
                         $columns_with_content++;
                     }
                 }
                 $percentage = round(100 / $total_columns * $columns_with_content);
                 if ($percentage >= $this->_config->get('import_csv_data_percentage')) {
                     $data['rows'][] = $csv_line;
                     $read_rows++;
                 }
             }
         }
         $data['time_end'] = time();
     }
 }