diff --git a/modules/batchtag/controllers/batchtag.php b/modules/batchtag/controllers/batchtag.php new file mode 100644 index 00000000..fc17f594 --- /dev/null +++ b/modules/batchtag/controllers/batchtag.php @@ -0,0 +1,54 @@ +where("parent_id", $this->input->post("item_id")) + ->where("type !=", "album") + ->find_all(); + + // Loop through each item in the album and make sure the user has + // access to view and edit it. + foreach ($children as $child) { + if (access::can("view", $child) && access::can("edit", $child)) { + + // Assuming the user can view/edit the current item, loop + // through each tag that was submitted and apply it to + // the current item. + foreach (split(",", $this->input->post("name")) as $tag_name) { + $tag_name = trim($tag_name); + if ($tag_name) { + tag::add($child, $tag_name); + } + } + } + } + + // Redirect back to the album. + $item = ORM::factory("item", $this->input->post("item_id")); + url::redirect(url::abs_site("{$item->type}s/{$item->id}")); + } +} diff --git a/modules/batchtag/helpers/batchtag_installer.php b/modules/batchtag/helpers/batchtag_installer.php new file mode 100644 index 00000000..0a24b58c --- /dev/null +++ b/modules/batchtag/helpers/batchtag_installer.php @@ -0,0 +1,27 @@ +item(); + + // Only display the form in albums that the user has edit permission in. + if ($item->is_album() && access::can("edit", $item)) { + + // Make a new sidebar block. + $block = new Block(); + $block->css_id = "gBatchTag"; + $block->title = t("Batch Tag"); + $block->content = new View("batchtag_block.html"); + + // Make a new form to place in the sidebar block. + $form = new Forge("batchtag/tagitems", "", "post", + array("id" => "gBatchTagForm")); + $label = t("Tag everything in this album:"); + $group = $form->group("add_tag")->label("Add Tag"); + $group->input("name")->label($label)->rules("required|length[1,64]"); + $group->hidden("item_id")->value($item->id); + $group->submit("")->value(t("Add Tag")); + $block->content->form = $form; + + // Display the block. + return $block; + } + } +} \ No newline at end of file diff --git a/modules/batchtag/module.info b/modules/batchtag/module.info new file mode 100644 index 00000000..398147ac --- /dev/null +++ b/modules/batchtag/module.info @@ -0,0 +1,3 @@ +name = BatchTag +description = Automatically apply a tag to the entire contents of an album. +version = 1 diff --git a/modules/batchtag/views/batchtag_block.html.php b/modules/batchtag/views/batchtag_block.html.php new file mode 100644 index 00000000..4993189e --- /dev/null +++ b/modules/batchtag/views/batchtag_block.html.php @@ -0,0 +1,2 @@ + + \ No newline at end of file