Index: modules/project/project.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project/project.module,v retrieving revision 1.243 diff -u -r1.243 project.module --- modules/project/project.module 1 Jun 2006 09:56:43 -0000 1.243 +++ modules/project/project.module 5 Jun 2006 14:37:24 -0000 @@ -134,7 +134,7 @@ } $versions = array(-1 => t('all')) + project_releases_list(); - $sort_methods = drupal_map_assoc(array_keys(module_invoke_all('project_sort_methods', 'methods'))); + $sort_methods = module_invoke_all('project_sort_methods', 'methods'); $form['releases'] = array('#type' => 'fieldset', '#title' => t('Releases'), @@ -388,16 +388,16 @@ // Only use the first-level terms. if ($term->depth == 0) { $items[] = array('path' => 'project/'. $term->name, - 'title' => $term->name, + 'title' => t('Browse %term', array('%term' => $term->name)), 'access' => $access, 'type' => MENU_NORMAL_ITEM, 'weight' => $term->weight, 'callback arguments' => array($term->name)); $j = 0; - $term_methods = array_filter(variable_get('project_sort_method_used_' . $term->tid, $sort_methods)); + $term_methods = array_filter(variable_get('project_sort_method_used_' . $term->tid, array_keys($sort_methods))); foreach ($term_methods as $sort_method) { $items[] = array('path' => 'project/' . $term->name . '/'. $sort_method, - 'title' => t('browse by %sort_method', array('%sort_method' => $sort_method)), + 'title' => t('by %sort_method', array('%sort_method' => $sort_methods[$sort_method])), 'access' => $access, 'type' => (($sort_method == variable_get('project_sort_method', 'category') || (($j == 0) && !in_array(variable_get('project_sort_method', 'category'), $term_methods))) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK), 'weight' => ($sort_method == variable_get('project_sort_method', 'category')) ? -10 : $j, @@ -540,8 +540,13 @@ if ($term->description) { $output .= '
' . filter_xss($term->description) . '
'; } + // Set the $module variable to the module that implements this method. + foreach (module_implements('project_sort_methods') as $module) { + if (in_array(module_invoke($module, 'project_sort_methods', 'methods'), $sort_methods)) { + break; + } + } - $module = $sort_methods[$sort_method]; if (module_invoke($module, 'project_sort_methods', 'set term', $sort_method)) { $tree = taxonomy_get_tree(_project_get_vid(), $term->tid); @@ -671,6 +676,7 @@ if (count($sql_elements['group_bys']['pieces'])) { $first_field = 'DISTINCT(' . $sql_elements['group_bys']['pieces'][0] . ')'; $sql_elements['group_bys']['pieces'] = array(); + $sql_elements['order_bys']['pieces'] = array(); } $sql_elements['fields']['pieces'] = array("COUNT($first_field)"); $count_query = project_build_query($sql_elements); @@ -844,13 +850,13 @@ function project_project_sort_methods($op, $method = NULL) { switch ($op) { // A listing of the available sorting methods. - // The array values are the name of the module (in this case, 'project'). case 'methods': - $methods = array(); - $methods['name'] = 'project'; - $methods['date'] = 'project'; + $methods = array('name' => t('name'), 'date' => t('date')); if (project_use_taxonomy()) { - $methods['category'] = 'project'; + $methods['category'] = t('category'); + } + if (project_use_drupal()) { + $methods['mostused'] = t('most used'); } return $methods; case 'sql_settings' : @@ -870,6 +876,13 @@ return array( 'order_bys' => array('n.title ASC', 'n.sticky DESC') ); + case 'mostused': + return array( + 'fields' => array('COUNT(cs.name) AS mostused'), + 'joins' => array('INNER JOIN {client_system} cs ON p.uri = cs.name'), + 'group_bys' => array('n.nid'), + 'order_bys' => array('mostused DESC', 'n.title ASC') + ); default: return; } @@ -889,6 +902,8 @@ return TRUE; case 'name': return FALSE; + case 'mostused': + return TRUE; } // Does this method group results by date? case 'group by date': @@ -898,6 +913,7 @@ case 'date': return TRUE; case 'name': + case 'mostused': return FALSE; default: return; @@ -1085,3 +1101,11 @@ function project_use_taxonomy() { return module_exist('taxonomy') && taxonomy_get_tree(_project_get_vid()); } + +/** + * Returns whether or not the project module should use + * drupal.module-specific functionality. + */ +function project_use_drupal() { + return module_exist('drupal') && db_num_rows(db_query("SELECT * FROM {client_system}")); +} \ No newline at end of file