diff --git a/3.0/modules/editcaptured/css/editcaptured.css b/3.0/modules/editcaptured/css/editcaptured.css new file mode 100644 index 00000000..84e8853c --- /dev/null +++ b/3.0/modules/editcaptured/css/editcaptured.css @@ -0,0 +1,9 @@ +#g-dialog select { + display: inline; +} +.g-editcaptured-usedate { + display: inline; +} +.g-editcaptured-setsubitems { + display: inline; +} diff --git a/3.0/modules/editcaptured/helpers/editcaptured_event.php b/3.0/modules/editcaptured/helpers/editcaptured_event.php new file mode 100644 index 00000000..00b5735b --- /dev/null +++ b/3.0/modules/editcaptured/helpers/editcaptured_event.php @@ -0,0 +1,154 @@ +id == 1) + return; + + // Search if there are at least some child items containing a captured date + $model = ORM::factory("item") + ->where("parent_id", "=", $item->id) + ->where("captured", "IS NOT", null) + ->order_by("captured", "ASC"); + $first_child = $model->find(); + if (!$first_child->id) $first_child = null; + + // Chose preselected option, depending on wheather item already has captured date or not + if ($item->captured) { + $dateoptions_preselect = "selected"; + } else { + $dateoptions_preselect = "remove"; + } + + // Depending on wheather there are child items or not, we generate the dropdown options + if ($first_child) { + $dateoptions = array("selected" => t("Selected Date"), + "oldest" => t("Date of oldest Child"), + "youngest" => t("Date of youngest Child"), + "now" => t("Current Date"), + "remove" => t("Remove Date")); + + // If there are child items with captured date, we preset the date field with the oldest item + if (!$item->captured && $first_child) { + $item->captured = $first_child->captured; + $dateoptions_preselect = "oldest"; + } + } else { + $dateoptions = array("selected" => t("Selected Date"), + "now" => t("Current Date"), + "remove" => t("Remove Date")); + } + + // Add captured date field to the form + $form->edit_item->dateselect("capturedate") + ->label(t("Captured")) + ->minutes(1) + ->years(1970, date('Y')+1) + ->value($item->captured); + + // Add dropdown menu for options to the form + $form->edit_item->dropdown("capturedate_usedate") + ->options($dateoptions) + ->id("g-editcaptured-usedate") + ->selected($dateoptions_preselect); + + // Add checkbox for users who want to change the captured date of subitems, too + if ($item->is_album()) { + $form->edit_item->checkbox("capturedate_setsubitems") + ->label(t("Set also subitems's date")) + ->id("g-editcaptured-setsubitems"); + } + } + + static function item_edit_form_completed($item, $form) { + // Change the item's captured field to the specified value. + + // We don't want to change the root element, so check for that + if ($item->id == 1) { + return; + } + + // Depending on the dropdown option, we set the date + switch ($form->edit_item->capturedate_usedate->value) { + + // Just use the date selected in the form + case "selected": + $item->captured = $form->edit_item->capturedate->value; + break; + + // Use the date of the oldest child (we check again if there is such a child) + case "oldest": + $model = ORM::factory("item") + ->where("parent_id", "=", $item->id) + ->where("captured", "IS NOT", null) + ->order_by("captured", "ASC"); + $first_child = $model->find(); + if ($first_child->id) { + $item->captured = $first_child->captured; + } else { + $item->captured = null; + } + break; + + // Use the date of the youngest child (we check again if there is such a child) + case "youngest": + $model = ORM::factory("item") + ->where("parent_id", "=", $item->id) + ->where("captured", "IS NOT", null) + ->order_by("captured", "DESC"); + $first_child = $model->find(); + if ($first_child->id) { + $item->captured = $first_child->captured; + } else { + $item->captured = null; + } + break; + + // Use the current date + case "now": + $item->captured = time(); + break; + + // Remove the date + case "remove": + $item->captured = null; + } + + $item->save(); + + // Set the date also for all subitems (at the moment only direct subitems are supported + if ($item->is_album() && $form->edit_item->capturedate_setsubitems->checked) { + foreach (ORM::factory("item")->where("parent_id", "=", $item->id)->find_all() as $subitem) { + if ($subitem->loaded() && access::can("edit", $subitem)) { + $subitem->captured = $item->captured; + $subitem->save(); + } + } + //message::success(t("Changed captured date of subitems")); + } + + } + +} + diff --git a/3.0/modules/editcaptured/helpers/editcaptured_theme.php b/3.0/modules/editcaptured/helpers/editcaptured_theme.php new file mode 100644 index 00000000..7458860c --- /dev/null +++ b/3.0/modules/editcaptured/helpers/editcaptured_theme.php @@ -0,0 +1,31 @@ +item()) { + return; + } + $item = $theme->item(); + if ( $item && access::can("edit", $item) ) { + $theme->css("editcaptured.css"); + } + } +} diff --git a/3.0/modules/editcaptured/module.info b/3.0/modules/editcaptured/module.info new file mode 100644 index 00000000..9a76e495 --- /dev/null +++ b/3.0/modules/editcaptured/module.info @@ -0,0 +1,3 @@ +name = "Edit Captured Date" +description = "Edit the capture date of an element manually or semiautomatically based on date of subitems." +version = 2