cvs diff: Diffing modules/project
Index: modules/project/project.css
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project/project.css,v
retrieving revision 1.28
diff -u -F^f -r1.28 project.css
--- modules/project/project.css	19 May 2006 10:09:20 -0000	1.28
+++ modules/project/project.css	26 May 2006 04:57:56 -0000
@@ -123,7 +123,7 @@
   margin: 0.05em 0.1em;
 }
 
-.node-form .project .options fieldset:after {
+.node-form .project fieldset:after {
   content: ".";
   display: block;
   height: 0;
@@ -133,6 +133,11 @@
 
 .node-form .project .options fieldset {display: inline-table;}
 
+.node-form .project .project-taxonomy-element {
+  float: left;
+  padding-right: 2em;
+}
+
 ul.project-terms {
   padding-left: 1.5em;
 }
Index: modules/project/project.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project/project.inc,v
retrieving revision 1.78
diff -u -F^f -r1.78 project.inc
--- modules/project/project.inc	23 May 2006 20:10:17 -0000	1.78
+++ modules/project/project.inc	26 May 2006 04:57:57 -0000
@@ -24,6 +24,62 @@ function project_project_form(&$node) {
 
   $form['#prefix'] = '<div class="project">';
 
+  /* Project taxonomy */
+  if (project_use_taxonomy()) {
+    $tree = taxonomy_get_tree(_project_get_vid());
+    $top_level = array();
+    $options = array();
+    foreach ($tree as $i => $term) {
+      if ($term->parents[0] == 0) {
+        $last_top = $term->tid;
+        $top_level[$term->tid] = $term->name;
+      }
+      else {
+        $options[$last_top][$term->tid] = $term->name;
+      }
+    }
+    // See if there are any project specific taxonomy terms already
+    // saved in this node (i.e. we're editing an existing project) and
+    // if so, extract the right default values for our custom form
+    // elements... 
+    if ($node->taxonomy) {
+      foreach ($node->taxonomy as $tid => $obj) {
+        if ($top_level[$tid]) {
+          $current_top = $tid;
+        }
+        else {
+          $current_options[$tid] = $tid;
+        }
+      }
+    } 
+    $form['project_taxonomy'] = array(
+      '#type' => 'fieldset',
+      '#weight' => '-30',
+      '#title' => t('Project categories'),
+      '#collapsible' => TRUE,
+    );
+    $form['project_taxonomy']['project_type'] = array(
+      '#title' => t('Project type'),
+      '#type' => 'radios',
+      '#prefix' => '<div class="project-taxonomy-element">',
+      '#suffix' => '</div>',
+      '#options' => $top_level,
+      '#default_value' => $current_top,
+      '#required' => TRUE,
+    );
+    foreach ($options as $tid => $values) {
+      $form['project_taxonomy'][$tid] = array(
+        '#title' => t('%type categories', array('%type' => $top_level[$tid])),
+        '#type' => 'select',
+        '#multiple' => TRUE,
+        '#options' => $values,
+        '#default_value' => $current_options,
+        '#prefix' => '<div class="project-taxonomy-element">',
+        '#suffix' => '</div>',
+      );
+    }
+  }
+
   /* Project properties */
   $form['project'] = array(
     '#type' => 'fieldset',
@@ -235,6 +291,25 @@ function project_project_form(&$node) {
   return $form;
 }
 
+/**
+ * Implementation of form_alter. This removes the work of
+ * taxonomy.module's form_alter() so we can do our own taxonomy
+ * selection. 
+ */
+function project_form_alter($form_id, &$form) {
+  if ($form_id == 'project_project_node_form') {
+    $vid = _project_get_vid();
+    if (isset($form['taxonomy'][$vid])) {
+      unset($form['taxonomy'][$vid]);
+    }
+    // If there are no children elements, we should unset the entire
+    // thing so we don't end up with an empty fieldset.
+    if (!element_children($form['taxonomy'])) {
+      unset($form['taxonomy']);
+    }
+  }
+}
+
 function project_project_cleanup($input) {
   return $input;
 }
@@ -304,6 +379,24 @@ function project_project_validate(&$node
       form_set_error($uri, t('%field is not a valid URL.', array('%field' => t(ucfirst($uri)))));
     }
   }
+
+  // Validate the project-specific sub-categories, if any...
+  if (project_use_taxonomy() && $node->project_type) {
+    $tree = taxonomy_get_tree(_project_get_vid());
+    $top_level = array();
+    foreach ($tree as $i => $term) {
+      if ($term->parents[0] == 0) {
+        $top_level[$term->tid] = $term->name;
+      }
+    }  
+    foreach ($top_level as $tid => $name) {
+      if ($node->project_type != $tid) {
+        if (!empty($node->$tid)) {
+          form_set_error($tid, t('Project type %project_type was selected, you can not use values from %invalid_type categories', array('%project_type' => theme('placeholder', $top_level[$node->project_type]), '%invalid_type' => theme('placeholder', $top_level[$tid]))));
+        }
+      }
+    }
+  }
 }
 
 /**
@@ -458,6 +551,21 @@ function project_project_load($node) {
   return $project;
 }
 
+function project_nodeapi(&$node, $op, $arg) {
+  switch ($op) {
+    case 'insert':
+      if ($node->type == 'project_project') {
+        _project_save_taxonomy($node);
+      }
+      break;
+    case 'update':
+      if ($node->type == 'project_project') {
+        _project_save_taxonomy($node);
+      }
+      break;
+  }
+}
+
 function project_project_insert($node) {
   project_project_convert_components($node);
   $node->components = serialize($node->components);
@@ -557,3 +665,30 @@ function project_cvs($nid = 0) {
     drupal_not_found();
   }
 }
+
+function _project_save_taxonomy(&$node) {
+  if (project_use_taxonomy() && $node->project_type) {
+    // First, clear out all terms from the project-specific taxonomy
+    // in this node. We'll re-add the right ones based on what's saved.
+    // This way, we're sure to clear out things that have been changed.
+    $vid = _project_get_vid();
+    $result = db_query('SELECT tid FROM {term_data} WHERE vid = %d', $vid);
+    $items = array();
+    while ($item = db_fetch_object($result)) {
+      $items[] = "tid = $item->tid";
+    }
+    if ($items) {
+      $sql = 'DELETE FROM {term_node} WHERE nid = %d AND ('. implode(' OR ', $items) . ')';
+      db_query($sql, $node->nid);
+    }
+    $tid = $node->project_type;
+    _project_db_save_taxonomy($node->nid, $tid);
+    foreach ($node->$tid as $tid) {
+      _project_db_save_taxonomy($node->nid, $tid);
+    }
+  }
+}
+
+function _project_db_save_taxonomy($nid, $tid) {
+  db_query('INSERT INTO {term_node} (nid, tid) VALUES (%d, %d)', $nid, $tid);
+}
Index: modules/project/project.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project/project.install,v
retrieving revision 1.2
diff -u -F^f -r1.2 project.install
--- modules/project/project.install	2 Mar 2006 23:26:59 -0000	1.2
+++ modules/project/project.install	26 May 2006 04:57:57 -0000
@@ -190,4 +190,10 @@ function project_install() {
 
 function project_update_1() {
   return _system_update_utf8(array('project_projects', 'project_releases', 'project_issues', 'project_comments', 'project_subscriptions', 'project_issue_state'));
-}
\ No newline at end of file
+}
+
+function project_update_2() {
+  $ret = array();
+  $ret[] = update_sql("UPDATE {system} SET weight = 2 WHERE name = 'project'");
+  return $ret;
+}
Index: modules/project/project.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project/project.module,v
retrieving revision 1.240
diff -u -F^f -r1.240 project.module
--- modules/project/project.module	20 May 2006 14:25:37 -0000	1.240
+++ modules/project/project.module	26 May 2006 04:57:58 -0000
@@ -297,7 +297,7 @@ function _project_get_vid() {
     // Check to see if a project module vocabulary exists.
     $vid = db_result(db_query("SELECT vid FROM {vocabulary} WHERE module='%s'", 'project'));
     if (!$vid) {
-      $edit = array('name' => t('Projects'), 'multiple' => 1, 'required' => 1, 'hierarchy' => 1, 'relations' => 0, 'module' => 'project', 'nodes' => array('project_project' => 1));
+      $edit = array('name' => t('Projects'), 'multiple' => 1, 'hierarchy' => 1, 'relations' => 0, 'module' => 'project', 'nodes' => array('project_project' => 1));
       // If there is already a vocabulary assigned to 'project_project' nodes, use it.
       $vocabularies = taxonomy_get_vocabularies('project_project');
       if (count($vocabularies)) {
@@ -1067,3 +1067,11 @@ function project_autocomplete($string) {
     exit();
   }
 }
+
+/**
+ * Returns whether or not the project module should use
+ * taxonomy-specific functionality.
+ */
+function project_use_taxonomy() {
+  return module_exist('taxonomy') && taxonomy_get_tree(_project_get_vid());
+}
cvs diff: Diffing modules/project/po
cvs diff: Diffing modules/project/po/ar
