From 99dd3aa1d65b11d8c8127bea6a2c457be2dec32f Mon Sep 17 00:00:00 2001 From: Loic d'Anterroches Date: Sun, 23 Nov 2008 11:20:08 +0100 Subject: [PATCH] Remove the corresponding information from the timeline on deletion. --- src/IDF/Timeline.php | 26 ++++++++++++++++++++++++++ src/IDF/Upload.php | 8 ++++++++ 2 files changed, 34 insertions(+) diff --git a/src/IDF/Timeline.php b/src/IDF/Timeline.php index e85868d..68900ea 100644 --- a/src/IDF/Timeline.php +++ b/src/IDF/Timeline.php @@ -130,4 +130,30 @@ class IDF_Timeline extends Pluf_Model $t->create(); return true; } + + /** + * Remove an item from the timeline. + * + * You must call this function when you delete items wich are + * tracked in the timeline. Just add the call: + * + * IDF_Timeline::remove($this); + * + * in the preDelete() method of your object. + * + * @param mixed Item to be removed + * @return bool Success + */ + public static function insert($item) + { + if ($item->id > 0) { + $sql = new Pluf_SQL('model_id=%s AND model_class=%s', + array($item->id, $item->_model)); + $items = Pluf::factory('IDF_Timeline')->getList(array('filter'=>$sql->gen())); + foreach ($items as $tl) { + $tl->delete(); + } + } + return true; + } } diff --git a/src/IDF/Upload.php b/src/IDF/Upload.php index 25715b7..6b302fe 100644 --- a/src/IDF/Upload.php +++ b/src/IDF/Upload.php @@ -154,6 +154,14 @@ class IDF_Upload extends Pluf_Model return Pluf::f('url_media').'/upload/'.$project->shortname.'/files/'.$this->file; } + /** + * We drop the information from the timeline. + */ + function preDelete() + { + IDF_Timeline::remove($this); + } + /** * Returns the timeline fragment for the file. *