|
@@ -12,7 +12,7 @@
|
|
* @package QBF
|
|
* @package QBF
|
|
*/
|
|
*/
|
|
|
|
|
|
-// $Id: qbf.module,v 1.9.4.10 2009-03-22 11:26:54 marand Exp $
|
|
|
|
|
|
+// $Id: qbf.module,v 1.9.4.11 2009-03-22 14:30:41 marand Exp $
|
|
|
|
|
|
/**
|
|
/**
|
|
* Saved error reporting level.
|
|
* Saved error reporting level.
|
|
@@ -227,10 +227,10 @@ function _qbf_form_perform_submit($form, &$form_state)
|
|
* @param array $form
|
|
* @param array $form
|
|
* @param array $form_state
|
|
* @param array $form_state
|
|
*/
|
|
*/
|
|
-function _qbf_form_perform_validate($form, &$form_state)
|
|
|
|
- {
|
|
|
|
- // @todo validate searches: checkboxes sets needs at least one value checked, otherwise there won't be any result
|
|
|
|
- }
|
|
|
|
|
|
+//function _qbf_form_perform_validate($form, &$form_state)
|
|
|
|
+// {
|
|
|
|
+// // @todo validate searches: checkboxes sets needs at least one value checked, otherwise there won't be any result
|
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
/**
|
|
* Submit handler for qbf_form, Save search button.
|
|
* Submit handler for qbf_form, Save search button.
|
|
@@ -250,16 +250,40 @@ function _qbf_form_save_submit($form, &$form_state)
|
|
return $qid;
|
|
return $qid;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Validate handler for qbf_form, Save search button.
|
|
* Validate handler for qbf_form, Save search button.
|
|
*
|
|
*
|
|
* @param array $form
|
|
* @param array $form
|
|
* @param array $form_state
|
|
* @param array $form_state
|
|
*/
|
|
*/
|
|
-function _qbf_form_save_validate($form, &$form_state)
|
|
|
|
|
|
+//function _qbf_form_save_validate($form, &$form_state)
|
|
|
|
+// {
|
|
|
|
+// // @todo validate saves. Check whether any validation is necessary.
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Return the human-readable for a query type.
|
|
|
|
+ *
|
|
|
|
+ * @param string $query_type
|
|
|
|
+ * @return string
|
|
|
|
+ */
|
|
|
|
+function _qbf_get_name_from_type($query_type)
|
|
{
|
|
{
|
|
- // @todo validate saves. Check whether any validation is necessary.
|
|
|
|
|
|
+ static $labels = array();
|
|
|
|
+
|
|
|
|
+ if (empty($labels) || empty($labels[$query_type]))
|
|
|
|
+ {
|
|
|
|
+ $ar_forms = qbf_forms();
|
|
|
|
+ foreach ($ar_forms as /* $qbf_form_id => */ $form_info)
|
|
|
|
+ {
|
|
|
|
+ if ($query_type == $form_info['callback arguments'][0]['form'])
|
|
|
|
+ {
|
|
|
|
+ $labels[$query_type] = $form_info['callback arguments'][0]['label'];
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return $labels[$query_type];
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -287,7 +311,7 @@ function _qbf_query_delete($query)
|
|
{
|
|
{
|
|
$qid = $query->qid;
|
|
$qid = $query->qid;
|
|
$sq = 'DELETE FROM %s WHERE qid = %d ';
|
|
$sq = 'DELETE FROM %s WHERE qid = %d ';
|
|
- $q = db_query($sq, QBF_TABLE_NAME, $qid);
|
|
|
|
|
|
+ db_query($sq, QBF_TABLE_NAME, $qid);
|
|
$message = t('Query @id "@name" has been deleted.', array
|
|
$message = t('Query @id "@name" has been deleted.', array
|
|
(
|
|
(
|
|
'@id' => $qid,
|
|
'@id' => $qid,
|
|
@@ -303,6 +327,7 @@ function _qbf_query_delete($query)
|
|
if ($notify /* && $query->uid != $user->uid */)
|
|
if ($notify /* && $query->uid != $user->uid */)
|
|
{
|
|
{
|
|
$owner = user_load(array('uid' => $query->uid));
|
|
$owner = user_load(array('uid' => $query->uid));
|
|
|
|
+ $account = user_load(array('uid' => $query->uid));
|
|
$language = user_preferred_language($account);
|
|
$language = user_preferred_language($account);
|
|
$params = array
|
|
$params = array
|
|
(
|
|
(
|
|
@@ -311,7 +336,7 @@ function _qbf_query_delete($query)
|
|
'deletor' => $user,
|
|
'deletor' => $user,
|
|
'language' => $language,
|
|
'language' => $language,
|
|
);
|
|
);
|
|
- $ret = drupal_mail('qbf', __FUNCTION__, $user->mail, $language, $params, $user->mail);
|
|
|
|
|
|
+ /* $ret = */ drupal_mail('qbf', __FUNCTION__, $user->mail, $language, $params, $user->mail);
|
|
drupal_set_message(t('User !link has been informed', array
|
|
drupal_set_message(t('User !link has been informed', array
|
|
(
|
|
(
|
|
'!link' => l($account->name, 'user/'. $query->uid),
|
|
'!link' => l($account->name, 'user/'. $query->uid),
|
|
@@ -606,6 +631,15 @@ function qbf_admin_settings()
|
|
'#default_value' => variable_get(QBF_VAR_NOTIFY_DELETE, QBF_DEF_NOTIFY_DELETE),
|
|
'#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'),
|
|
'#title' => t('Notify users when one of their saved searches has been deleted'),
|
|
);
|
|
);
|
|
|
|
+
|
|
|
|
+ $form['queries'][QBF_VAR_PROFILE_CATEGORY] = array
|
|
|
|
+ (
|
|
|
|
+ '#type' => 'textfield',
|
|
|
|
+ '#title' => t('Name of profile category'),
|
|
|
|
+ '#description' => t('Choose a title for the section of the user profiles where the list of search queries will be displayed. It may match an existing profile category.'),
|
|
|
|
+ '#default_value' => variable_get(QBF_VAR_PROFILE_CATEGORY, QBF_DEF_PROFILE_CATEGORY),
|
|
|
|
+ );
|
|
|
|
+
|
|
return system_settings_form($form);
|
|
return system_settings_form($form);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -732,7 +766,7 @@ function qbf_form(&$form_state, $query_info, $qbf_form_id, $query = NULL)
|
|
* @param array $args
|
|
* @param array $args
|
|
* @return array
|
|
* @return array
|
|
*/
|
|
*/
|
|
-function qbf_forms($args = NULL)
|
|
|
|
|
|
+function qbf_forms(/* $args = NULL */)
|
|
{
|
|
{
|
|
static $forms = array();
|
|
static $forms = array();
|
|
|
|
|
|
@@ -775,15 +809,15 @@ function qbf_get_queries_by_user($uid = NULL)
|
|
$uid = $user->uid;
|
|
$uid = $user->uid;
|
|
}
|
|
}
|
|
|
|
|
|
- $sq = 'SELECT qq.qid, qq.uid, qq.name, qq.query, qq.updated '
|
|
|
|
|
|
+ $sq = 'SELECT qq.qid, qq.uid, qq.type, qq.name, qq.query, qq.updated '
|
|
. 'FROM {%s} qq '
|
|
. 'FROM {%s} qq '
|
|
. 'WHERE qq.uid = %d '
|
|
. 'WHERE qq.uid = %d '
|
|
- . 'ORDER BY qq.name ';
|
|
|
|
|
|
+ . 'ORDER BY qq.type, qq.name ';
|
|
// no db_rewrite_sql: this function is not in a menu callback, so it is up to
|
|
// no db_rewrite_sql: this function is not in a menu callback, so it is up to
|
|
// the caller to check access
|
|
// the caller to check access
|
|
$q = db_query($sq, QBF_TABLE_NAME, $uid);
|
|
$q = db_query($sq, QBF_TABLE_NAME, $uid);
|
|
$ret = array();
|
|
$ret = array();
|
|
- while ($o = db_fetch_object($q))
|
|
|
|
|
|
+ while (is_object($o = db_fetch_object($q)))
|
|
{
|
|
{
|
|
$ret[$o->qid] = $o; // qid is the PK, so it is present and unique
|
|
$ret[$o->qid] = $o; // qid is the PK, so it is present and unique
|
|
}
|
|
}
|
|
@@ -905,7 +939,7 @@ function qbf_query_load($us_qid)
|
|
if ($qid === 0)
|
|
if ($qid === 0)
|
|
{
|
|
{
|
|
$ar_forms = qbf_forms();
|
|
$ar_forms = qbf_forms();
|
|
- foreach ($ar_forms as $qbf_form_id => $form_info)
|
|
|
|
|
|
+ foreach ($ar_forms as /* $qbf_form_id => */ $form_info)
|
|
{
|
|
{
|
|
if ($us_qid === $form_info['callback arguments'][0]['form'])
|
|
if ($us_qid === $form_info['callback arguments'][0]['form'])
|
|
{
|
|
{
|
|
@@ -977,65 +1011,140 @@ function qbf_query_mapper($ar_query_map = array(), $ar_defaults = array())
|
|
return $ret;
|
|
return $ret;
|
|
}
|
|
}
|
|
|
|
|
|
-error_reporting($_qbf_er);
|
|
|
|
-
|
|
|
|
-function qbf___________________________________________________(){}
|
|
|
|
-
|
|
|
|
-// ======== D6 LIMIT ==================================================================================================
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
- * Implement hook_profile_alter().
|
|
|
|
|
|
+ * Implement hook_user().
|
|
|
|
+ *
|
|
|
|
+ * Display job searchs as an account form category
|
|
*
|
|
*
|
|
- * Add saved queries to the profile rendering
|
|
|
|
|
|
+ * Edit and account could be passed by reference, but are currently not modified.
|
|
*
|
|
*
|
|
* @ingroup hooks
|
|
* @ingroup hooks
|
|
- * @param object $account
|
|
|
|
- * @return void
|
|
|
|
|
|
+ *
|
|
|
|
+ * @param string $op
|
|
|
|
+ * @param array &$edit
|
|
|
|
+ * @param array $account
|
|
|
|
+ * @param string $category
|
|
|
|
+ * @return array|void
|
|
*/
|
|
*/
|
|
-function qbf_profile_alter(&$account)
|
|
|
|
|
|
+function qbf_user($op, $edit, $account, $category = NULL)
|
|
{
|
|
{
|
|
- // @TODO D6 use $account->content instead of $fields: check whether this is sufficient
|
|
|
|
- global $user;
|
|
|
|
|
|
+ $qbf_category = variable_get(QBF_VAR_PROFILE_CATEGORY, QBF_DEF_PROFILE_CATEGORY);
|
|
|
|
|
|
- // Only allow field to QBF admins and own user
|
|
|
|
- if ($user->uid != $account->uid && !user_access(QBF_PERM_ADMIN))
|
|
|
|
- {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ // dsm("hook user($op, edit, $account->uid = $account->name, $category)");
|
|
|
|
|
|
- $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))
|
|
|
|
|
|
+ switch ($op)
|
|
{
|
|
{
|
|
- $account->content[$cat_name] = array();
|
|
|
|
|
|
+ case 'categories':
|
|
|
|
+ // dsm("hook user($op)");
|
|
|
|
+ $ret = array();
|
|
|
|
+ $ret[] = array
|
|
|
|
+ (
|
|
|
|
+ 'name' => 'qbf',
|
|
|
|
+ 'title' => $qbf_category,
|
|
|
|
+ 'weight' => 2,
|
|
|
|
+ );
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+// case 'view':
|
|
|
|
+// // Only allow field to QBF admins and own user
|
|
|
|
+// if ($user->uid != $account->uid && !user_access(QBF_PERM_ADMIN))
|
|
|
|
+// {
|
|
|
|
+// return;
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// $account->content['queries'] = array
|
|
|
|
+// (
|
|
|
|
+// '#type' => 'user_profile_category',
|
|
|
|
+// '#title' => t('Saved job/internship queries'),
|
|
|
|
+// // '#class' => "job-user-$category",
|
|
|
|
+// );
|
|
|
|
+// $account->content['queries']['list'] = array
|
|
|
|
+// (
|
|
|
|
+// '#type' => 'user_profile_item',
|
|
|
|
+// '#title' => t('List of searches'),
|
|
|
|
+// '#value' => '<p>Would appear here</p>',
|
|
|
|
+// );
|
|
|
|
+// $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;
|
|
|
|
+// dsm($account->content);
|
|
|
|
+// break;
|
|
|
|
+
|
|
|
|
+ case 'form':
|
|
|
|
+ // dsm("hook user($op, $account->uid = $account->name, $category)");
|
|
|
|
+ if ($category != 'qbf')
|
|
|
|
+ {
|
|
|
|
+ $ret = NULL;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // No access control: it is already controlled by the
|
|
|
|
+ // "administer users" permission in user.module
|
|
|
|
+ $ar_queries = qbf_get_queries_by_user($account->uid);
|
|
|
|
+ $count = count($ar_queries);
|
|
|
|
+
|
|
|
|
+ $ar_header = array
|
|
|
|
+ (
|
|
|
|
+ t('Query type'),
|
|
|
|
+ t('Query title'),
|
|
|
|
+ t('Saved on'),
|
|
|
|
+ // t('# results'),
|
|
|
|
+ t('Actions'),
|
|
|
|
+ );
|
|
|
|
+ $ar_data = array();
|
|
|
|
+ foreach ($ar_queries as $query)
|
|
|
|
+ {
|
|
|
|
+ $ar_data[] = array
|
|
|
|
+ (
|
|
|
|
+ _qbf_get_name_from_type($query->type),
|
|
|
|
+ l($query->name, QBF_PATH_MAIN . "/$query->qid"),
|
|
|
|
+ format_date($query->updated, 'small'),
|
|
|
|
+ // t('n.a.'),
|
|
|
|
+ l(t('Delete'), QBF_PATH_MAIN ."/$query->qid/delete", array('query' => "destination=user/$account->uid/edit/qbf")),
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ $data = theme('table', $ar_header, $ar_data);
|
|
|
|
+
|
|
|
|
+ $max_count = variable_get(JOB_VAR_MAX_QUERIES, JOB_DEF_MAX_QUERIES);
|
|
|
|
+ if ($count < $max_count)
|
|
|
|
+ {
|
|
|
|
+ $new_query_link = l(t('Create new query'), QBF_PATH_MAIN);
|
|
|
|
+ $data .= format_plural($max_count - $count,
|
|
|
|
+ '<p>You may still save one more query.',
|
|
|
|
+ '<p>You may still save @count more queries.');
|
|
|
|
+ $data .= " $new_query_link.</p>";
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ $data .= t("<p>You have reached the maximum number of saved queries (@count).</p>",
|
|
|
|
+ array('@count' => $count));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * A first-level form element is needed by contrib module profile_privacy,
|
|
|
|
+ * at least in version 5.x-1.2 and 6.x-1-2. This mimics the
|
|
|
|
+ * user_profile_category/user_profile_item scheme provided by profile.module.
|
|
|
|
+ * We do not use these types, in order to use the full display area width
|
|
|
|
+ * for the queries table.
|
|
|
|
+ */
|
|
|
|
+ $ret['job'] = array
|
|
|
|
+ (
|
|
|
|
+ '#type' => 'markup', // in profile, usually user_profile_category
|
|
|
|
+ '#title' => NULL,
|
|
|
|
+ );
|
|
|
|
+ $ret['job']['queries'] = array
|
|
|
|
+ (
|
|
|
|
+ '#type' => 'markup', // in profile, usually user_profile_item
|
|
|
|
+ '#value' => $data,
|
|
|
|
+ );
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
|
|
|
|
- // @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));
|
|
|
|
|
|
+ return $ret;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+error_reporting($_qbf_er);
|