### Eclipse Workspace Patch 1.0 #P annotate Index: annotate.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/annotate/annotate.module,v retrieving revision 1.11 diff -u -r1.11 annotate.module --- annotate.module 14 Mar 2009 17:05:05 -0000 1.11 +++ annotate.module 4 Sep 2009 12:38:18 -0000 @@ -147,21 +147,24 @@ ); } else { - // Get the annotations + $forms = array(); + // New annotation + $note= (object)array(); + $note->nid=$node->nid; + $forms[]= drupal_get_form('annotate_private_entry_form_new', $note); + + // Existing annotations $result = _annotate_list_by_node_by_user( $node->nid, $user->uid); - - // This could be better done with an annotation object - // Where is the last edit date? - $fields = db_fetch_array($result); - $node->annotation_note = $fields['note']; - $node->annotation_note_format = $fields['note_format']; - $node->annotation_visibility= $fields['visibility']; - - // Add our form as a content item. - $node->content['annotate_form'] = array( - '#value' => drupal_get_form('annotate_private_entry_form', $node), - '#weight' => 10, - ); + while ($note = db_fetch_object($result)) { + $forms[]= drupal_get_form('annotate_private_entry_form_' . $note->timestamp, $note); + } + // Make list + foreach($forms as $index => $form) { + $node->content['annotate_form_' . $index] = array( + '#value' => $form, + '#weight' => 10 + $index, + ); + } } break; @@ -195,34 +198,56 @@ } } +/* + * Implementation of hook_forms + */ +function annotate_forms($form_id) { + $forms = array(); + if (strpos($form_id, 'annotate_private_entry_form_') === 0) { + $forms[$form_id] = array( + 'callback' => 'annotate_private_entry_form', + ); + } + return $forms; +} + /** * Define the form for entering an annotation. * * The fieldset collapse if no annotation is made and allowed */ -function annotate_private_entry_form($form_state, $node) { - $args = func_get_args(); - - $form['annotate'] = array( +function annotate_private_entry_form($form_state, $note) { + drupal_set_message( "annotate_private_entry_form: " . print_r( $note, TRUE)); + $form['annotate'] = array( '#type' => 'fieldset', '#title' => t('Annotations'), '#collapsible' => TRUE, - '#collapsed' => !$node->annotation && !variable_get('annotate_show_expanded', '0'), + '#collapsed' => !$note->note && !variable_get('annotate_show_expanded', '0'), ); - + + $form['annotate']['timestamp'] = array( + '#type' => 'value', + '#value' => $note->timestamp + ); + + $form['annotate']['uid'] = array( + '#type' => 'value', + '#value' => $note->uid + ); + $form['annotate']['nid'] = array( '#type' => 'value', - '#value' => $node->nid + '#value' => $note->nid ); $form['annotate']['note_filter']['note'] = array( '#type' => 'textarea', '#title' => t('Notes'), - '#default_value' => $node->annotation_note, + '#default_value' => $note->note, '#description' => t('Make your personal annotations about this content here. When marked private only you (and the site administrator) will be able to see them.'), ); - $form['annotate']['note_filter']['format']= filter_form( $node->annotation_note_format); + $form['annotate']['note_filter']['format']= filter_form( $note->note_format); $options = array( ANNOTATE_ENUM_VISIBILITY_PRIVATE => t('Private'), @@ -233,7 +258,7 @@ $form['annotate']['visibility'] = array( '#type' => 'radios', '#title' => t('Visibility'), - '#default_value' => isset($node->annotation_visibility) ? $node->annotation_visibility : 0, + '#default_value' => isset($note->visibility) ? $note->visibility : 0, '#options' => $options, '#description' => t('Set the visibility of this annotation'), ); @@ -242,6 +267,10 @@ '#type' => 'submit', '#value' => t('Update') ); + + $form['#submit'] = array( + 'annotate_private_entry_form_submit', + ); return $form; } @@ -250,14 +279,15 @@ * implementation of hook_submit */ function annotate_private_entry_form_submit($form, &$form_state) { + drupal_set_message( "annotate_private_entry_form_submit: " . print_r( $form_state, TRUE)); global $user; - $nid = $form_state['values']['nid']; $note_format = trim( $form_state['values']['format']); $note = trim( $form_state['values']['note']); $visibility = $form_state['values']['visibility']; - - db_query("DELETE FROM {annotations} WHERE uid = %d and nid = %d", $user->uid, $nid); + $timestamp = $form_state['values']['timestamp']; + + db_query("DELETE FROM {annotations} WHERE uid = %d AND nid = %d AND timestamp = %d", $user->uid, $nid, $timestamp); if (isset($note) && strlen($note)) { db_query("INSERT INTO {annotations} (uid, nid, note_format, note, visibility, timestamp) VALUES (%d, %d, %d, '%s', %d, %d)" @@ -372,7 +402,7 @@ } function _annotate_list_by_node_by_user( $nid, $uid) { - $sql = "SELECT visibility, note_format, note, timestamp FROM {annotations} WHERE nid = %d AND uid = %d"; + $sql = "SELECT * FROM {annotations} WHERE nid = %d AND uid = %d"; $result = db_query( $sql, $nid, $uid); return $result; }