diff --git a/3.0/modules/date_tag/README.md b/3.0/modules/date_tag/README.md new file mode 100644 index 00000000..eaa29571 --- /dev/null +++ b/3.0/modules/date_tag/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/3.0/modules/date_tag/helpers/date_tag.php b/3.0/modules/date_tag/helpers/date_tag.php new file mode 100644 index 00000000..424cdf15 --- /dev/null +++ b/3.0/modules/date_tag/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/3.0/modules/date_tag/helpers/date_tag_event.php b/3.0/modules/date_tag/helpers/date_tag_event.php new file mode 100644 index 00000000..cca9ab76 --- /dev/null +++ b/3.0/modules/date_tag/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")->where("type", "=", "photo")->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/3.0/modules/date_tag/module.info b/3.0/modules/date_tag/module.info new file mode 100644 index 00000000..abd68be0 --- /dev/null +++ b/3.0/modules/date_tag/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"