Просмотр исходного кода

- Can now perform, save, delete, and report on queries. In short, it works.
- imported QBF report on saved queries from job.module, no longer specific
- profile category is now within QBF and defaults to QBF

Frederic G. Marand 15 лет назад
Родитель
Сommit
4b4bffaceb
1 измененных файлов с 88 добавлено и 5 удалено
  1. 88 5
      qbf.module

+ 88 - 5
qbf.module

@@ -10,9 +10,11 @@
  * @author Frederic G. MARAND
  * @license Licensed under the CeCILL 2.0 and the General Public Licence version 2 or later
  * @package QBF
+ *
+ * @todo validate searches: checkboxes sets needs at least one value checked, otherwise there won't be any result
  */
 
-// $Id: qbf.module,v 1.9.4.7 2009-03-21 19:41:34 marand Exp $
+// $Id: qbf.module,v 1.9.4.8 2009-03-21 20:15:30 marand Exp $
 
 /**
  * Saved error reporting level.
@@ -81,13 +83,37 @@ define('QBF_TABLE_NAME',             'qbf_queries');
 
 /**
  * Notify owner about saved query deletions, variable name.
+ *
+ * @ingroup vars
  */
 define('QBF_VAR_NOTIFY_DELETE',      'qbf_notify_delete');
+
+/**
+ * Name of the profile category under which the list of saved queries will be
+ * displayed.
+ *
+ * @ingroup vars
+ *
+ * @see qbf_admin_settings(), qbf_profile_alter()
+ */
+define('QBF_VAR_PROFILE_CATEGORY',   'qbf_profile_category');
+
 /**
  * Notify owner about saved query deletions, default value.
+ *
+ * @ingroup vars
  */
 define('QBF_DEF_NOTIFY_DELETE',      FALSE);
 
+/**
+ * Default value for the profile category
+ *
+ * @ingroup vars
+ *
+ * See QBF_VAR_PROFILE_CATEGORY
+ */
+define('QBF_DEF_PROFILE_CATEGORY',     'Saved queries');
+
 /**
  * A class wrapper for saved QBF queries
  */
@@ -444,7 +470,7 @@ function qbf_form_save_submit($form, &$form_state)
   drupal_set_message(t('Your query was saved as "@name".',
     array('@name' => $form_state['values']['qbf_save_name'])));
   global $user;
-  $form_state['redirect'] = "user/$user->uid/qbf";
+  $form_state['redirect'] = "user/$user->uid/edit/qbf";
   return $qid;
   }
 
@@ -884,8 +910,8 @@ function _qbf_save($form_id, $form_state)
 function qbf_form(&$form_state, $query_info, $qbf_form_id, $query = NULL)
   {
   $form_id = $query_info['form'];
-  dsm(array("QBF_Form" => "Base = [$form_id], QBF ID = [$qbf_form_id]", 'query' => $query));
-  dsm($form_state);
+  // dsm(array("QBF_Form" => "Base = [$form_id], QBF ID = [$qbf_form_id]", 'query' => $query));
+  // dsm($form_state);
 
   // Fetch the basic form and rename it, passing it the previous values
   $node = new stdClass();
@@ -1000,4 +1026,61 @@ function qbf_query_form($query)
   $qbf_form_id = 'qbf_' . $query->type;
   $form = drupal_get_form($qbf_form_id, $query);
   return $form;
-  }
+  }
+
+/**
+ * Implement hook_profile_alter().
+ *
+ * Add saved queries to the profile rendering
+ *
+ * @ingroup hooks
+ * @param object $account
+ * @return void
+ */
+function qbf_profile_alter(&$account)
+  {
+  // @TODO D6 use $account->content instead of $fields: check whether this is sufficient
+  global $user;
+
+  // Only allow field to QBF admins and own user
+  if ($user->uid != $account->uid && !user_access(QBF_PERM_ADMIN))
+    {
+    return;
+    }
+
+  $ar_queries = qbf_get_queries_by_user($account->uid);
+  $count = count($ar_queries);
+  // @todo Create New link needs to use hook_qbf_register info
+  $new_query_link = l(t('Create new query'), JOB_PATH_MAIN);
+  $none_message = ($account->uid == $user->uid)
+    ? t('None yet. !newQuery', array('!newQuery' => $new_query_link))
+    : t('None yet.');
+
+  $saved = ($count > 0)
+    ? format_plural($count, 'One saved query. ', '@count saved queries. ')
+      . l(t('View/edit'), "user/$account->uid/edit/qbf")
+    : $none_message;
+
+  // @todo Support per-application/per-node profile categories
+  $cat_name = variable_get(QBF_VAR_PROFILE_CATEGORY, QBF_DEF_PROFILE_CATEGORY);
+  /*
+   * Due to the way profile.module works, existing categories are never empty,
+   * so any existing category name points to a non-empty array
+   */
+  if (!array_key_exists($cat_name, $account->content))
+    {
+    $account->content[$cat_name] = array();
+    }
+
+    // @FIXME: breaks drupal_render()
+//  $account->content[$cat_name] += array
+//      (
+//      'job-saved' => array
+//        (
+//        'title'        => t('Saved queries'),
+//        'value'        => $saved,
+//        'class'        => 'job-saved-queries',
+//        ),
+//      );
+  // dsm(array("jpa fields" => $account->content));
+  }