uc_catalog.admin.inc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * @file
  4. * Catalog administration menu items.
  5. */
  6. /**
  7. * Catalog settings form.
  8. *
  9. * Configures the display of the catalog breadcrumb.
  10. *
  11. * @ingroup forms
  12. */
  13. function uc_catalog_settings_form($form, &$form_state) {
  14. $view = views_get_view('uc_catalog');
  15. $displays = array();
  16. foreach ($view->display as $display) {
  17. if ($display->display_plugin == 'page') {
  18. $displays[$display->id] = $display->display_title;
  19. }
  20. }
  21. $form['catalog-top-level']['uc_catalog_display'] = array(
  22. '#type' => 'select',
  23. '#title' => t('Catalog display'),
  24. '#default_value' => variable_get('uc_catalog_display', 'catalog'),
  25. '#options' => $displays,
  26. );
  27. $vid = variable_get('uc_catalog_vid', NULL);
  28. if ($vid) {
  29. $catalog = taxonomy_vocabulary_load($vid);
  30. $form['catalog_vid'] = array(
  31. '#markup' => '<p>' . t('The taxonomy vocabulary <a href="!edit-url">%name</a> is set as the product catalog.', array('!edit-url' => url('admin/structure/taxonomy/' . $catalog->machine_name), '%name' => $catalog->name)) . '</p>',
  32. );
  33. }
  34. $vocabs = array();
  35. $vocabularies = taxonomy_vocabulary_load_multiple(FALSE);
  36. foreach ($vocabularies as $vid => $vocabulary) {
  37. $vocabs[$vid] = $vocabulary->name;
  38. }
  39. $form['catalog-top-level']['uc_catalog_vid'] = array(
  40. '#type' => 'select',
  41. '#title' => t('Catalog vocabulary'),
  42. '#default_value' => variable_get('uc_catalog_vid', 0),
  43. '#options' => $vocabs,
  44. );
  45. $form['catalog-top-level']['uc_catalog_breadcrumb'] = array(
  46. '#type' => 'checkbox',
  47. '#title' => t('Display the catalog breadcrumb'),
  48. '#default_value' => variable_get('uc_catalog_breadcrumb', TRUE),
  49. );
  50. return system_settings_form($form);
  51. }
  52. /**
  53. * Displays links to all products that have not been categorized.
  54. */
  55. function uc_catalog_orphaned_products() {
  56. $build = array();
  57. if (variable_get('taxonomy_maintain_index_table', TRUE)) {
  58. $vid = variable_get('uc_catalog_vid', 0);
  59. $product_types = uc_product_types();
  60. $field = field_info_field('taxonomy_catalog');
  61. $types = array_intersect($product_types, $field['bundles']['node']);
  62. $result = db_query("SELECT DISTINCT n.nid, n.title FROM {node} n LEFT JOIN (SELECT ti.nid, td.vid FROM {taxonomy_index} ti LEFT JOIN {taxonomy_term_data} td ON ti.tid = td.tid WHERE td.vid = :vid) txnome ON n.nid = txnome.nid WHERE n.type IN (:types) AND txnome.vid IS NULL", array(':vid' => $vid, ':types' => $types));
  63. $rows = array();
  64. while ($node = $result->fetchObject()) {
  65. $rows[] = l($node->title, 'node/' . $node->nid . '/edit', array('query' => array('destination' => 'admin/store/products/orphans')));
  66. }
  67. if (count($rows) > 0) {
  68. $build['orphans'] = array(
  69. '#theme' => 'item_list',
  70. '#items' => $rows,
  71. );
  72. }
  73. else {
  74. $build['orphans'] = array(
  75. '#markup' => t('All products are currently listed in the catalog.'),
  76. '#prefix' => '<p>',
  77. '#suffix' => '</p>',
  78. );
  79. }
  80. }
  81. else {
  82. $build['orphans'] = array(
  83. '#markup' => t('The node terms index is not being maintained, so Ubercart can not determine which products are not entered into the catalog.'),
  84. '#prefix' => '<p>',
  85. '#suffix' => '</p>',
  86. );
  87. }
  88. return $build;
  89. }
  90. /**
  91. * Repairs the catalog taxonomy field if it is lost or deleted.
  92. */
  93. function uc_catalog_repair_field() {
  94. foreach (uc_product_types() as $type) {
  95. uc_catalog_add_node_type($type);
  96. }
  97. uc_catalog_add_image_field();
  98. drupal_set_message(t('The catalog taxonomy reference field has been repaired.'));
  99. drupal_goto('admin/structure/types/manage/product/fields');
  100. }