type = "album"; $album->title = $title; $album->description = $description; $album->name = $name; while (ORM::Factory("item") ->where("parent_id", $parent_id) ->where("name", $album->name) ->find()->id) { $album->name = "{$name}-" . rand(); } $album = $album->add_to_parent($parent_id); mkdir($album->file_path()); $thumbnail_dir = dirname($album->thumbnail_path()); if (!file_exists($thumbnail_dir)) { mkdir($thumbnail_dir); } return $album; } static function set_thumbnail($id, $filename) { $album = ORM::factory("item", $id); /** @todo: parameterize these dimensions */ $image = Image::factory($filename); $image->resize(200, 140, Image::WIDTH)->save($album->thumbnail_path()); $dims = getimagesize($album->thumbnail_path()); $album->thumbnail_width = $dims[0]; $album->thumbnail_height = $dims[1]; return $album->save(); } }