From 5af4ce81e3bb64a1a7908d06e290997229e68ab7 Mon Sep 17 00:00:00 2001 From: Mike Miller Date: Fri, 25 Jan 2013 11:26:30 +0200 Subject: [PATCH 1/2] Squashed '3.0/modules/date_tag/' content from commit 0a94df7 git-subtree-dir: 3.0/modules/date_tag git-subtree-split: 0a94df70e809bc3d16cff0133ce06401f3fa83c4 --- README.md | 4 ++ helpers/date_tag.php | 29 +++++++++++ helpers/date_tag_event.php | 32 ++++++++++++ helpers/date_tag_installer.php | 42 ++++++++++++++++ helpers/date_tag_task.php | 89 ++++++++++++++++++++++++++++++++++ module.info | 7 +++ 6 files changed, 203 insertions(+) create mode 100644 README.md create mode 100644 helpers/date_tag.php create mode 100644 helpers/date_tag_event.php create mode 100644 helpers/date_tag_installer.php create mode 100644 helpers/date_tag_task.php create mode 100644 module.info diff --git a/README.md b/README.md new file mode 100644 index 00000000..eaa29571 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +date_tag +======== + +Gallery3 module to automatically add tags matching the image captured date \ No newline at end of file diff --git a/helpers/date_tag.php b/helpers/date_tag.php new file mode 100644 index 00000000..424cdf15 --- /dev/null +++ b/helpers/date_tag.php @@ -0,0 +1,29 @@ +is_photo() && $item->captured) { + tag::add($item, date("F", $item->captured)); + tag::add($item, date("Y", $item->captured)); + } + return; + } +} diff --git a/helpers/date_tag_event.php b/helpers/date_tag_event.php new file mode 100644 index 00000000..cca9ab76 --- /dev/null +++ b/helpers/date_tag_event.php @@ -0,0 +1,32 @@ +callback("date_tag_task::date_tag_all") + ->name(t("Add tags for dates")) + ->description(t("Add tags for dates of all images that have already been uploaded")) + ->severity(log::SUCCESS); + return $tasks; + } + + /** + * @param Task_Model the task + */ + static function date_tag_all($task) { + $errors = array(); + try { + $start = microtime(true); + $last_item_id= $task->get("last_item_id", null); + $current = 0; + $total = 0; + + switch ($task->get("mode", "init")) { + case "init": + $task->set("total", ORM::factory("item")->count_all()); + $task->set("mode", "date_tag_all"); + $task->set("completed", 0); + $task->set("last_item_id", 0); + + case "date_tag_all": + $completed = $task->get("completed"); + $total = $task->get("total"); + $last_item_id= $task->get("last_item_id"); + $items = ORM::factory("item") + ->where("id", ">", $last_item_id) + ->and_where("type", "=", "photo") + ->find_all(5); /* TODO: should we fetch more at a time? Less? */ + while ($current < $total && microtime(true) - $start < 1 && $item = $items->current()) { + $last_tem_id = $item->id; + $task->log("Looking at item {$item->name} (id: {$item->id})"); + date_tag::tag_item($item); + + $completed++; + $items->next(); + $task->percent_complete = $completed / $total * 100; + $task->set("completed", $completed); + $task->set("last_item_id", $item->id); + + + $task->status = t2("Examined %count items", "Examined %count items", $completed); + + if ($completed == $total) { + $task->done = true; + $task->state = "success"; + $task->percent_complete = 100; + } + } + } + } catch (Exception $e) { + Kohana_Log::add("error",(string)$e); + $task->done = true; + $task->state = "error"; + $task->status = $e->getMessage(); + $errors[] = (string)$e; + } + if ($errors) { + $task->log($errors); + } + } +} diff --git a/module.info b/module.info new file mode 100644 index 00000000..abd68be0 --- /dev/null +++ b/module.info @@ -0,0 +1,7 @@ +name = "Date Tag" +description = "Automatically add tags with the captured date" +version = 1 +author_name ="mikeage" +author_url = "http://mikeage.net" +info_url = "http://TODO" +discuss_url = "http://TODO" From ced903cad13117cea260eec3548747edf9feaf05 Mon Sep 17 00:00:00 2001 From: Mike Miller Date: Fri, 25 Jan 2013 15:06:47 +0200 Subject: [PATCH 2/2] Count the number of photo items only --- 3.0/modules/date_tag/helpers/date_tag_task.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3.0/modules/date_tag/helpers/date_tag_task.php b/3.0/modules/date_tag/helpers/date_tag_task.php index 2c57a83e..290b0e98 100644 --- a/3.0/modules/date_tag/helpers/date_tag_task.php +++ b/3.0/modules/date_tag/helpers/date_tag_task.php @@ -41,7 +41,7 @@ class date_tag_task_Core { switch ($task->get("mode", "init")) { case "init": - $task->set("total", ORM::factory("item")->count_all()); + $task->set("total", ORM::factory("item")->where("type", "=", "photo")->count_all()); $task->set("mode", "date_tag_all"); $task->set("completed", 0); $task->set("last_item_id", 0);