diff options
author | Bharat Mediratta <bharat@menalto.com> | 2008-12-23 04:36:09 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2008-12-23 04:36:09 +0000 |
commit | 5713e3c66ed8bab3b86490d7b6e90f7947d53429 (patch) | |
tree | e6a4f5e93dd15406c655c7b51d455c5181d3334c /core/helpers | |
parent | 2502240ce4ad25e9fb60ee2468764e25346d2917 (diff) |
Change photo::create() and album::create() to take ORM instances
instead of ids.
Diffstat (limited to 'core/helpers')
-rw-r--r-- | core/helpers/album.php | 13 | ||||
-rw-r--r-- | core/helpers/photo.php | 15 |
2 files changed, 14 insertions, 14 deletions
diff --git a/core/helpers/album.php b/core/helpers/album.php index 53af0079..70b05006 100644 --- a/core/helpers/album.php +++ b/core/helpers/album.php @@ -32,7 +32,11 @@ class album_Core { * @param string $description (optional) the longer description of this album * @return Item_Model */ - static function create($parent_id, $name, $title, $description=null, $owner_id=null) { + static function create($parent, $name, $title, $description=null, $owner_id=null) { + if (!$parent->loaded || $parent->type != "album") { + throw new Exception("@todo INVALID_PARENT"); + } + $album = ORM::factory("item"); $album->type = "album"; $album->title = $title; @@ -43,17 +47,12 @@ class album_Core { $album->resize_dirty = 1; while (ORM::factory("item") - ->where("parent_id", $parent_id) + ->where("parent_id", $parent->id) ->where("name", $album->name) ->find()->id) { $album->name = "{$name}-" . rand(); } - $parent = ORM::factory("item", $parent_id); - if (!$parent->loaded) { - throw new Exception("@todo INVALID_PARENT_ID"); - } - $album = $album->add_to_parent($parent); mkdir($album->file_path()); mkdir(dirname($album->thumb_path())); diff --git a/core/helpers/photo.php b/core/helpers/photo.php index 8c826e1c..d8fc2595 100644 --- a/core/helpers/photo.php +++ b/core/helpers/photo.php @@ -33,7 +33,11 @@ class photo_Core { * @param string $description (optional) the longer description of this photo * @return Item_Model */ - static function create($parent_id, $filename, $name, $title, $description=null, $owner_id=null) { + static function create($parent, $filename, $name, $title, $description=null, $owner_id=null) { + if (!$parent->loaded || $parent->type != "album") { + throw new Exception("@todo INVALID_PARENT"); + } + if (!is_file($filename)) { throw new Exception("@todo MISSING_IMAGE_FILE"); } @@ -63,7 +67,7 @@ class photo_Core { // Randomize the name if there's a conflict while (ORM::Factory("item") - ->where("parent_id", $parent_id) + ->where("parent_id", $parent->id) ->where("name", $photo->name) ->find()->id) { // @todo Improve this. Random numbers are not user friendly @@ -71,11 +75,6 @@ class photo_Core { } // This saves the photo - $parent = ORM::factory("item", $parent_id); - if (!$parent->loaded) { - throw new Exception("@todo INVALID_PARENT_ID"); - } - $photo->add_to_parent($parent); copy($filename, $photo->file_path()); @@ -91,6 +90,8 @@ class photo_Core { $parent->save(); graphics::generate($parent); } + + return $photo; } static function get_add_form($parent) { |