Index: unitag.module
===================================================================
--- unitag.module (revision 2612)
+++ unitag.module (working copy)
@@ -42,12 +42,22 @@
'type' => MENU_DEFAULT_LOCAL_TASK
);
$items[] = array(
+ 'path' => 'admin/content/taxonomy/unitag/denials',
+ 'title' => t('Manage denials'),
+ 'callback' => 'drupal_get_form',
+ 'callback arguments' => array('unitag_manage_suggestions_form'),
+ 'access' => user_access('administer taxonomy'),
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => 1,
+ );
+ $items[] = array(
'path' => 'admin/content/taxonomy/unitag/settings',
'title' => t('Settings'),
'callback' => 'drupal_get_form',
'callback arguments' => array('unitag_settings_form'),
'access' => user_access('administer taxonomy'),
- 'type' => MENU_LOCAL_TASK
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => 3,
);
$items[] = array(
'path' => 'unitag/autocomplete',
@@ -232,6 +242,7 @@
* @return $form
*/
function unitag_manage_suggestions_form() {
+ $denials = arg(4) === 'denials';
// Display suggestions table.
$form['term_suggestions'] = array(
'#type' => 'fieldset',
@@ -242,7 +253,7 @@
);
// Grab available suggestions.
- $suggestions = unitag_suggestions_get();
+ $suggestions = unitag_suggestions_get($denials);
$utids = array();
foreach ($suggestions as $suggestion) {
$utids[$suggestion->utid] = '';
@@ -271,7 +282,8 @@
'new-term' => t('Approve as new terms'),
'new-synonym' => t('Approve as synonyms of the root term'),
'new-child' => t('Approve as children of the parent terms'),
- 'deny' => t('Deny and delete')
+ 'deny' => t('Deny'),
+ 'delete' => t('Delete'),
),
'#prefix' => '
'
);
@@ -376,6 +388,9 @@
unitag_suggestion_delete($suggestion, TRUE);
break;
case 'deny':
+ unitag_suggestion_deny($suggestion);
+ break;
+ case 'delete':
unitag_suggestion_delete($suggestion);
break;
}
@@ -679,8 +694,10 @@
// Perform the equivalent of a REPLACE. This ensures that case corrections
// go into the database correctly.
$basename = _unitag_get_basename($suggestion);
+ // check that this suggestion hasn't already been denied
+ $result = db_query("SELECT utid FROM {unitag} WHERE basename = '%s' AND deny = utid", $basename);
db_query("DELETE FROM {unitag} WHERE nid = %d AND vid = %d AND basename = '%s'", $nid, $vid, $basename);
- db_query("INSERT INTO {unitag} (nid, vid, name, basename) VALUES (%d, %d, '%s', '%s')", $nid, $vid, $suggestion, $basename);
+ db_query("INSERT INTO {unitag} (nid, vid, name, basename, deny) VALUES (%d, %d, '%s', '%s', %d)", $nid, $vid, $suggestion, $basename, db_result($result));
watchdog('taxonomy', t('Unitag: Added %name as a suggestion for node
%nid.', array('%name' => $suggestion, '!url' => url('node/'. $nid), '%nid' => $nid)), WATCHDOG_NOTICE);
}
@@ -716,6 +733,20 @@
}
/**
+ * Deny a suggestion. Marking a suggestion as denied will blacklist this
+ * suggestion from further additions.
+ *
+ * @param $suggestion
+ * The suggestion object which is to be denied.
+ */
+function unitag_suggestion_deny($suggestion) {
+ // Delete this entry.
+ db_query("UPDATE {unitag} SET deny = %d WHERE utid = %d", $suggestion->utid,$suggestion->utid);
+ watchdog('taxonomy', t('Unitag: denied suggestion %name.', array('%name' => $suggestion->name)), WATCHDOG_NOTICE);
+}
+
+
+/**
* Delete a suggestion.
*
* @param $suggestion
@@ -737,11 +768,14 @@
/**
* Retrieve all available suggestions.
*
+ * @param $denial
+ * boolean used to specify the retrival of denied terms
* @return Array
* An array of suggestions.
*/
-function unitag_suggestions_get() {
- $result = db_query("SELECT u.*, n.title FROM {unitag} u INNER JOIN {node} n USING (nid) ORDER BY u.vid, u.name, u.nid DESC");
+function unitag_suggestions_get($denial) {
+ $where = $denial ? 'WHERE u.deny != 0' : 'WHERE u.deny = 0';
+ $result = db_query("SELECT u.*, n.title FROM {unitag} u INNER JOIN {node} n USING (nid) $where ORDER BY u.vid, u.name, u.nid DESC");
$suggestions = array();
while ($suggestion = db_fetch_object($result)) {
$suggestions[$suggestion->utid] = $suggestion;
Index: unitag.install
===================================================================
--- unitag.install (revision 2612)
+++ unitag.install (working copy)
@@ -38,6 +38,26 @@
}
/**
+ * Implementation of hook_update_N()
+ */
+function unitag_update_1() {
+ $ret = array();
+
+ switch ($GLOBALS['db_type']) {
+ case 'pgsql':
+ db_add_column($ret, 'unitag', 'deny', 'int', array('default' => 0, 'not null' => TRUE));
+ break;
+
+ case 'mysql':
+ case 'mysqli':
+ $ret[] = update_sql("ALTER TABLE {unitag} ADD `deny` int unsigned NOT NULL default 0");
+ break;
+ }
+
+ return $ret;
+}
+
+/**
* Implementation of hook_uninstall().
*/
function unitag_uninstall() {