changeset 3:d52c1baec6fb

Implemented Scald CRUD triggers based on field value updates.
author Tom Wolf <tom@t-dub.net>
date Wed, 22 Apr 2009 23:32:15 -0500
parents 3d3d533f9eff
children e2bf7cf37972
files mee.module
diffstat 1 files changed, 23 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/mee.module	Tue Apr 07 11:19:03 2009 -0500
+++ b/mee.module	Wed Apr 22 23:32:15 2009 -0500
@@ -64,6 +64,7 @@
         '#default_value' => url($field['mee_dnd_callback_url']) ? $field['mee_dnd_callback_url'] : '',
         '#description' => t('The absolute URL or relative path of a callback URL that provides proper JSON to the drag and drop library.'),
       );
+      // @TODO: Add an "Editor Context" option on a per-field basis
       return $form;
 
     case 'save':
@@ -92,30 +93,41 @@
       break; // end 'submit'
 
     case 'insert':
-      // @@@TODO: register a new Atom based on this textarea
       foreach ($items as $delta => $item) {
-        $temp_atom = new stdClass;
-        $temp_atom->type = 'composite';
-        $temp_atom->provider = 'mee';
-        $temp_atom->base_id = $node->nid . ':' . $delta;
-        $temp_atom->uid = $node->uid;
-        $temp_atom->title = $node->title;
-        $temp_atom->authors = array(scald_uid_to_aid($node->uid));
-        $scald_included = scald_included($node->body);
+        $scald_included = scald_included($item);
+
+        $temp_atom                = new stdClass;
+        $temp_atom->type          = 'composite';
+        $temp_atom->provider      = 'mee';
+        $temp_atom->base_id       = $node->nid . ':' . $delta;
+        $temp_atom->publisher     = $node->uid;
+        $temp_atom->title         = $node->title;
+        $temp_atom->authors       = array(scald_uid_to_aid($node->uid));
         $temp_atom->relationships = empty($scald_included) ? array() : array('includes' => $scald_included);
+
         $sid = scald_register_atom($temp_atom);
       }
       break; // end 'insert'
 
     case 'update':
       foreach ($items as $delta => $item) {
+        $scald_included = scald_included($item);
 
+        // @@@TODO: Handle failure of fetch
+        $atom = scald_fetch(scald_search(array('base_id' => $node->nid . ':' . $delta), FALSE, TRUE));
+        $atom->publisher  = $node->uid;
+        $atom->title      = $node->title;
+        $atom->authors    = array(
+        $temp_atom->relationships = empty($scald_included) ? array() : array('includes' => $scald_included);
+
+        scald_update_atom($atom);
       }
-      // @@@TODO: Update the existing Atom
       break; // end 'update'
 
     case 'delete':
-      // @@@TODO: Remove the Atom based on this instance of the field
+      foreach ($items as $delta => $item) {
+        scald_unregister_atom(scald_search(array('base_id' => $node->nid . ':' . $delta), FALSE, TRUE));
+      }
       break; // end 'delete'
 
     case 'sanitize':