Browse Source

- Three query-related Job 5.x settings now imported to QBF 6.x settings, including hook_update_N
- removed remaining "job" references in QBF module

Frederic G. Marand 15 years ago
parent
commit
a3927f46c4
2 changed files with 132 additions and 13 deletions
  1. 6 1
      qbf.install
  2. 126 12
      qbf.module

+ 6 - 1
qbf.install

@@ -1,5 +1,5 @@
 <?php
-// $Id: qbf.install,v 1.1.4.5 2009-03-22 14:31:27 marand Exp $
+// $Id: qbf.install,v 1.1.4.6 2009-03-22 15:15:19 marand Exp $
 /**
  * @file
  * QBF module - installer
@@ -196,6 +196,11 @@ function qbf_update_6000()
   {
   $ret = array();
 
+  variable_set(QBF_VAR_MAX_QUERIES,      variable_get('job_max_queries',      QBF_DEF_MAX_QUERIES));
+  variable_set(QBF_VAR_PROFILE_CATEGORY, variable_get('job_profile_category', QBF_DEF_PROFILE_CATEGORY));
+  variable_set(QBF_VAR_QUERY_MODE,       variable_get('job_query_mode',       Qbf_Query_Mode::CONTAINS));
+  drupal_set_message('Migrated QBF-related settings from Job 5.x to QBF 6.x settings');
+
   db_drop_primary_key($ret, QBF_TABLE_NAME);
   db_drop_index($ret, QBF_TABLE_NAME, 'query_updated');
   db_drop_index($ret, QBF_TABLE_NAME, 'query_created');

+ 126 - 12
qbf.module

@@ -12,7 +12,7 @@
  * @package QBF
  */
 
-// $Id: qbf.module,v 1.9.4.11 2009-03-22 14:30:41 marand Exp $
+// $Id: qbf.module,v 1.9.4.12 2009-03-22 15:15:19 marand Exp $
 
 /**
  * Saved error reporting level.
@@ -79,6 +79,13 @@ define('QBF_PERM_ADMIN',             'administer QBF');
  */
 define('QBF_TABLE_NAME',             'qbf_queries');
 
+/**
+ * Maximum number of queries a user may save
+ *
+ * @ingroup vars
+ */
+define('QBF_VAR_MAX_QUERIES',        'qbf_max_queries');
+
 /**
  * Notify owner about saved query deletions, variable name.
  *
@@ -96,6 +103,22 @@ define('QBF_VAR_NOTIFY_DELETE',      'qbf_notify_delete');
  */
 define('QBF_VAR_PROFILE_CATEGORY',   'qbf_profile_category');
 
+/**
+ * Querying mode: contains, starts, or equals
+ *
+ * @ingroup vars
+ */
+define('QBF_VAR_QUERY_MODE',         'qbf_query_mode');
+
+/**
+ * Default value for the max number of saved queries per user
+ *
+ * @ingroup vars
+ *
+ * See QBF_VAR_MAX_QUERIES
+ */
+define('QBF_DEF_MAX_QUERIES',          5);
+
 /**
  * Notify owner about saved query deletions, default value.
  *
@@ -112,6 +135,63 @@ define('QBF_DEF_NOTIFY_DELETE',      FALSE);
  */
 define('QBF_DEF_PROFILE_CATEGORY',     'Saved queries');
 
+/**
+ * Return #options properties.
+ *
+ * It has not been implemented as an abstract class with a values array, from
+ * which all descendant class could reuse the getter method
+ * get_options(), although this would be much cleaner, because the current
+ * translation interface (potx.module) relies on t(), and it is impossible for
+ * static properties to be initialized to values which are the result of a
+ * function, like:
+ * <code>protected $arOptions = array('foo' => t('foo'));</code>
+ * which would be necessary in this case. The alternative solution of only
+ * declaring the array keys and returning their translated version as a value
+ * with t($key) in get_options() would also fail because the translation
+ * template extractor would not be able to generate the declaration from a
+ * t() call with variable content.
+ *
+ * @link http://drupal.org/project/potx
+ */
+Interface Qbf_Optioned_Interface
+  {
+  static function get_options();
+  }
+
+/**
+ * Querying modes for QBF
+ */
+class Qbf_Query_Mode implements Qbf_Optioned_Interface
+  {
+  /**
+   * Query mode: contains
+   */
+  const CONTAINS = 'contains';
+  /**
+   * Query mode: starts with
+   */
+  const STARTS   = 'starts';
+  /**
+   * Query mode: equals
+   */
+  const EQUALS   = 'equals';
+
+  /**
+   * Returns the list of querying modes
+   *
+   * @ingroup classmethods
+   * @return array
+   */
+  static function get_options() {
+    return array
+      (
+      self::CONTAINS => t('Contains'),
+      self::STARTS   => t('Starts with'),
+      self::EQUALS   => t('Equals'),
+      );
+  }
+}
+
 /**
  * A class wrapper for saved QBF queries
  */
@@ -625,11 +705,31 @@ function _qbf_transform($key, $element, $form_state, $query)
 function qbf_admin_settings()
   {
   $form = array();
-  $form[QBF_VAR_NOTIFY_DELETE] = array
+  $form['queries'] = array
     (
-    '#type'          => 'checkbox',
-    '#default_value' => variable_get(QBF_VAR_NOTIFY_DELETE, QBF_DEF_NOTIFY_DELETE),
-    '#title'         => t('Notify users when one of their saved searches has been deleted'),
+    '#type'          => 'fieldset',
+    '#title'         => t('Queries'),
+    '#collapsible'   => TRUE,
+    '#collapsed'     => TRUE,
+    );
+
+  $form['queries'][QBF_VAR_MAX_QUERIES] = array
+    (
+    '#type'          => 'select',
+    '#title'         => t('Maximum number of saved queries'),
+    '#description'   => t('The maximum number of queries a user allowed to perform queries may save.'),
+    '#default_value' => variable_get(QBF_VAR_MAX_QUERIES, QBF_DEF_MAX_QUERIES),
+    '#options'       => array_combine($iota = range(1, 99), $iota),
+    );
+
+  $ar_options = Qbf_Query_Mode::get_options();
+  $form['queries'][QBF_VAR_QUERY_MODE] = array
+    (
+    '#type'          => 'radios',
+    '#title'         => t('Query mode'),
+    '#description'   => t('This defines the way QBF will search string fields. "Contains" returns more results and is slowest, "Equals" returns less results and is fastest, while "Starts with" balances results and speed. Even when using "Equals" mode, case is ignored.'),
+    '#options'       => $ar_options,
+    '#default_value' => variable_get(QBF_VAR_QUERY_MODE, Qbf_Query_Mode::CONTAINS),
     );
 
   $form['queries'][QBF_VAR_PROFILE_CATEGORY] = array
@@ -640,6 +740,21 @@ function qbf_admin_settings()
     '#default_value' => variable_get(QBF_VAR_PROFILE_CATEGORY, QBF_DEF_PROFILE_CATEGORY),
     );
 
+  $form['notifications'] = array
+    (
+    '#type'          => 'fieldset',
+    '#title'         => t('Notifications'),
+    '#collapsible'   => TRUE,
+    '#collapsed'     => TRUE,
+    );
+
+  $form['notifications'][QBF_VAR_NOTIFY_DELETE] = array
+    (
+    '#type'          => 'checkbox',
+    '#default_value' => variable_get(QBF_VAR_NOTIFY_DELETE, QBF_DEF_NOTIFY_DELETE),
+    '#title'         => t('Notify users when one of their saved searches has been deleted'),
+    );
+
   return system_settings_form($form);
   }
 
@@ -862,7 +977,6 @@ function qbf_menu()
     'access arguments' => array(QBF_PERM_ADMIN),
     'page callback'    => 'drupal_get_form',
     'page arguments'   => array('qbf_admin_settings'),
-    'type'             => MENU_NORMAL_ITEM,
     );
 
   $items[QBF_PATH_MAIN] = array
@@ -1014,7 +1128,7 @@ function qbf_query_mapper($ar_query_map = array(), $ar_defaults = array())
 /**
  * Implement hook_user().
  *
- * Display job searchs as an account form category
+ * Display saved QBF searches as an account form category
  *
  * Edit and account could be passed by reference, but are currently not modified.
  *
@@ -1055,8 +1169,8 @@ function qbf_user($op, $edit, $account, $category = NULL)
 //      $account->content['queries'] = array
 //        (
 //        '#type'    => 'user_profile_category',
-//        '#title'   => t('Saved job/internship queries'),
-//        // '#class'   => "job-user-$category",
+//        '#title'   => t('Saved queries'),
+//        // '#class'   => "qbf-user-$category",
 //        );
 //      $account->content['queries']['list'] = array
 //        (
@@ -1109,7 +1223,7 @@ function qbf_user($op, $edit, $account, $category = NULL)
         }
       $data = theme('table', $ar_header, $ar_data);
 
-      $max_count = variable_get(JOB_VAR_MAX_QUERIES, JOB_DEF_MAX_QUERIES);
+      $max_count = variable_get(QBF_VAR_MAX_QUERIES, QBF_DEF_MAX_QUERIES);
       if ($count < $max_count)
         {
         $new_query_link = l(t('Create new query'), QBF_PATH_MAIN);
@@ -1131,12 +1245,12 @@ function qbf_user($op, $edit, $account, $category = NULL)
        * We do not use these types, in order to use the full display area width
        * for the queries table.
        */
-      $ret['job'] = array
+      $ret['qbf'] = array
         (
         '#type' => 'markup', // in profile, usually user_profile_category
         '#title' => NULL,
         );
-      $ret['job']['queries'] = array
+      $ret['qbf']['queries'] = array
         (
         '#type'  => 'markup', // in profile, usually user_profile_item
         '#value' => $data,