? enabledisable.patch Index: fivestar.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/fivestar/fivestar.install,v retrieving revision 1.5.2.13 diff -u -p -r1.5.2.13 fivestar.install --- fivestar.install 22 Oct 2009 00:23:29 -0000 1.5.2.13 +++ fivestar.install 11 Jan 2010 21:56:47 -0000 @@ -7,7 +7,17 @@ */ function fivestar_schema() { - return array(); + $schema['fivestar_node'] = array( + 'fields' => array( + 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'enabled' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + ), + 'indexes' => array( + 'nid' => array('nid'), + ), + ); + + return $schema; } function fivestar_install() { Index: fivestar.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/fivestar/fivestar.module,v retrieving revision 1.13.2.73 diff -u -p -r1.13.2.73 fivestar.module --- fivestar.module 20 Dec 2009 00:36:23 -0000 1.13.2.73 +++ fivestar.module 11 Jan 2010 21:56:48 -0000 @@ -330,6 +330,25 @@ function fivestar_form_alter(&$form, &$f $form['#submit'][] = 'fivestar_node_type_form_submit'; } + + if (preg_match('/_node_form$/', $form_id)) { + if (variable_get('fivestar_'. $form['type']['#value'], 0)) { + + $form['fivestar'] = array( + '#title' => 'Fivestar', + '#type' => 'fieldset', + '#tree' => TRUE, + '#collapsible' => TRUE, + '#collapsed' => TRUE, + ); + + $form['fivestar']['enable'] = array( + '#title' => 'Enable fivestar', + '#type' => 'checkbox', + '#default_value' => fivestar_node_enabled($form['#node']), + ); + } + } } /** @@ -906,6 +925,30 @@ function fivestar_fivestar_widgets() { return $widgets; } +function fivestar_node_enabled(&$node) { + $result = db_fetch_object(db_query(db_rewrite_sql("SELECT f.nid, f.enabled FROM {fivestar_node} f WHERE nid = %d", 'f', 'nid'), $node->nid)); + if ((int)$result->enabled === 1) { + return 1; + } else { + return 0; + } +} + +function fivestar_node_save(&$node, $fivestar, $update = array()) { + if (isset($fivestar['enable'])) { + //fivestar_node_delete($node); + + // prepare an array for drupal_write_record + $node_fivestar['nid'] = $node->nid; + $node_fivestar['enabled'] = $fivestar['enable']; + $result = drupal_write_record('fivestar_node', $node_fivestar, $update); // todo : check this out!! + } +} + +function fivestar_node_delete($node) { + db_query('DELETE FROM {fivestar_node} WHERE nid = %d', $node->nid); +} + /** * Implementation of hook_nodeapi(). * @@ -913,6 +956,22 @@ function fivestar_fivestar_widgets() { */ function fivestar_nodeapi(&$node, $op, $teaser, $page) { switch ($op) { + case 'insert': + if (!empty($node->fivestar)) { + fivestar_node_save($node, $node->fivestar); + } + break; + + case 'update': + if (!empty($node->fivestar)) { + fivestar_node_save($node, $node->fivestar, 'nid'); + } + break; + + case 'delete': + fivestar_node_delete($node); + break; + case 'view': $exclude_modes = array( NODE_BUILD_PREVIEW, @@ -920,7 +979,7 @@ function fivestar_nodeapi(&$node, $op, $ NODE_BUILD_SEARCH_RESULT, NODE_BUILD_RSS, ); - if (!in_array($node->build_mode, $exclude_modes) && !isset($node->modr8_form_teaser) && variable_get('fivestar_'. $node->type, 0)) { + if (!in_array($node->build_mode, $exclude_modes) && !isset($node->modr8_form_teaser) && variable_get('fivestar_'. $node->type, 0) && (fivestar_node_enabled($node) == 1)) { if ($teaser) { $position = variable_get('fivestar_position_teaser_'. $node->type, 'above'); } Index: fivestar_field.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/fivestar/Attic/fivestar_field.inc,v retrieving revision 1.3.2.20 diff -u -p -r1.3.2.20 fivestar_field.inc --- fivestar_field.inc 5 Oct 2009 01:06:26 -0000 1.3.2.20 +++ fivestar_field.inc 11 Jan 2010 21:56:49 -0000 @@ -99,6 +99,7 @@ function fivestar_field_settings($op, $f return array( 'rating' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'sortable' => TRUE), 'target' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE), + 'enable' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), ); } } @@ -129,6 +130,9 @@ function fivestar_field($op, &$node, $fi break; case 'sanitize': $items[0]['stars'] = $field['stars']; + if ($items[0]['enable'] == 0) { + unset($items[0]); + } break; } } @@ -209,7 +213,16 @@ function fivestar_widget_settings($op, $ */ function fivestar_widget(&$form, &$form_state, $field, $items) { $element = array('#tree' => TRUE); - $element['rating'] = array( + + $element['fivestar'] = array( + '#type' => 'fieldset', + '#title' => t('Fivestar'), + '#collapsed' => TRUE, + '#collapsible' => TRUE, + '#tree' => TRUE, + ); + + $element['fivestar']['rating'] = array( '#type' => 'fivestar', '#title' => t($field['widget']['label']), '#default_value' => isset($items[0]['rating']) ? $items[0]['rating'] : NULL, @@ -223,11 +236,19 @@ function fivestar_widget(&$form, &$form_ '#labels_enable' => FALSE, ); - $element['target'] = array( + $element['fivestar']['enable'] = array( + '#type' => 'checkbox', + '#title' => t('Enable fivestar'), + '#description' => t('Uncheck this box if you don\'t want to display the fivestar on this node.'), + '#default_value' => (isset($items[0]['enable'])) ? $items[0]['enable'] : TRUE, + ); + + $element['fivestar']['target'] = array( '#type' => 'value', '#value' => $field['target'], ); - $element['axis'] = array( + + $element['fivestar']['axis'] = array( '#type' => 'value', '#value' => $field['axis'], );