Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* Move the captured field into the exif module where it is created an…

…d populated.

* Create a new API event get_sort_fields that allows modules to contribute new sort fields that they manage. the only condition is that the module needs to add it to the item table.
* Changed g2_import to call this api to get the allowable sort fields
* Changed album::get_edit_form to call this new api to get the available sort fields
Partial fix for ticket #627, as the Capture date is not available until the exif module is installed.
  • Loading branch information...
commit a00619b812393cf73d1c188af7961af820d36185 1 parent 09f998e
@talmdal talmdal authored
View
4 modules/exif/helpers/exif_event.php
@@ -27,4 +27,8 @@ static function item_created($item) {
static function item_deleted($item) {
Database::instance()->delete("exif_records", array("item_id" => $item->id));
}
+
+ static function get_sort_fields($sort_order) {
+ $sort_order->fields["captured"] = t("Date captured");
+ }
}
View
10 modules/exif/helpers/exif_installer.php
@@ -29,6 +29,12 @@ static function install() {
PRIMARY KEY (`id`),
KEY(`item_id`))
DEFAULT CHARSET=utf8;");
+
+
+ $item_fields = $db->list_fields("items");
+ if (empty($item_fields["captured"])) {
+ $db->query("ALTER TABLE {items} ADD COLUMN `captured` int(9) default NULL");
+ }
module::set_version("exif", 1);
}
@@ -41,6 +47,8 @@ static function deactivate() {
}
static function uninstall() {
- Database::instance()->query("DROP TABLE IF EXISTS {exif_records};");
+ $db = Database::instance();
+ $db->query("DROP TABLE IF EXISTS {exif_records};");
+ $db->query("ALTER TABLE {items} DROP COLUMN `captured`");
}
}
View
32 modules/g2_import/helpers/g2_import.php
@@ -23,6 +23,7 @@ class g2_import_Core {
public static $map = array();
private static $current_g2_item = null;
+ private static $order_map = false;
static function is_configured() {
return module::get_var("g2_import", "embed_path");
@@ -313,7 +314,6 @@ static function import_user(&$queue) {
return $message;
}
-
/**
* Import a single album.
*/
@@ -357,16 +357,26 @@ static function import_album(&$queue) {
$album->view_count = g2(GalleryCoreApi::fetchItemViewCount($g2_album_id));
$album->created = $g2_album->getCreationTimestamp();
- $order_map = array(
- "originationTimestamp" => "captured",
- "creationTimestamp" => "created",
- "description" => "description",
- "modificationTimestamp" => "updated",
- "orderWeight" => "weight",
- "pathComponent" => "name",
- "summary" => "description",
- "title" => "title",
- "viewCount" => "view_count");
+ if (self::$order_map === false) {
+ self::$order_map = array(
+ "originationTimestamp" => "captured",
+ "creationTimestamp" => "created",
+ "description" => "description",
+ "modificationTimestamp" => "updated",
+ "orderWeight" => "weight",
+ "pathComponent" => "name",
+ "summary" => "description",
+ "title" => "title",
+ "viewCount" => "view_count");
+ $sort_order = (object)array("fields" => array());
+ module::event("get_sort_fields", $sort_order);
+ foreach (self::$order_map as $g2_sort_key => $g3_sort_key) {
+ if (empty($sort_order->fields[$g3_sort_key])) {
+ unset(self::$order_map[$g2_sort_key]);
+ }
+ }
+ }
+
$direction_map = array(
ORDER_ASCENDING => "asc",
ORDER_DESCENDING => "desc");
View
12 modules/gallery/helpers/album.php
@@ -166,12 +166,10 @@ static function get_edit_form($parent) {
* Return a structured set of all the possible sort orders.
*/
static function get_sort_order_options() {
- return array("weight" => t("Manual"),
- "captured" => t("Date captured"),
- "created" => t("Date uploaded"),
- "title" => t("Title"),
- "updated" => t("Date modified"),
- "view_count" => t("Number of views"),
- "rand_key" => t("Random"));
+ $sort_order = (object)array("fields" => array());
+ module::event("get_sort_fields", $sort_order);
+ asort($sort_order->fields);
+
+ return $sort_order->fields;
}
}
View
10 modules/gallery/helpers/gallery_event.php
@@ -53,4 +53,14 @@ static function item_index_data($item, $data) {
$data[] = $item->name;
$data[] = $item->title;
}
+
+ static function get_sort_fields($sort_order) {
+ $sort_order->fields = array_merge($sort_order->fields,
+ array("weight" => t("Manual"),
+ "created" => t("Date uploaded"),
+ "title" => t("Title"),
+ "updated" => t("Date modified"),
+ "view_count" => t("Number of views"),
+ "rand_key" => t("Random")));
+ }
}
View
17 modules/gallery/helpers/gallery_installer.php
@@ -68,7 +68,6 @@ static function install() {
$db->query("CREATE TABLE {items} (
`id` int(9) NOT NULL auto_increment,
`album_cover_item_id` int(9) default NULL,
- `captured` int(9) default NULL,
`created` int(9) default NULL,
`description` varchar(2048) default NULL,
`height` int(9) default NULL,
@@ -268,7 +267,7 @@ static function install() {
module::set_var("gallery", "show_credits", 1);
// @todo this string needs to be picked up by l10n_scanner
module::set_var("gallery", "credits", "Powered by <a href=\"%url\">Gallery %version</a>");
- module::set_version("gallery", 12);
+ module::set_version("gallery", 13);
}
static function upgrade($version) {
@@ -364,6 +363,20 @@ static function upgrade($version) {
$db->query("UPDATE {items} SET `relative_url_cache` = NULL, `relative_path_cache` = NULL");
module::set_version("gallery", $version = 12);
}
+
+ if ($version == 12) {
+ // remove the capture field if exif is not installed and it has no data
+ if (!module::is_active("exif")) {
+ $total_records = $db->query("SELECT COUNT(id) as total_records FROM {items}")
+ ->current()->total_records;
+ $count_null = $db->query("SELECT COUNT(id) as count_null FROM {items} where `captured`is NULL")
+ ->current()->count_null;
+ if ($total_records == $count_null) {
+ $db->query("ALTER TABLE {items} DROP COLUMN `captured`");
+ }
+ }
+ module::set_version("gallery", $version = 13);
+ }
}
static function uninstall() {
View
2  modules/gallery/module.info
@@ -1,3 +1,3 @@
name = "Gallery 3"
description = "Gallery core application"
-version = 12
+version = 13
View
2  modules/info/views/info_block.html.php
@@ -16,7 +16,7 @@
<?= html::clean($item->name) ?>
</li>
<? endif ?>
- <? if ($item->captured): ?>
+ <? if (module::is_active("exif") && $item->captured): ?>
<li>
<strong class="caption"><?= t("Captured:") ?></strong>
<?= date("M j, Y H:i:s", $item->captured)?>
Please sign in to comment.
Something went wrong with that request. Please try again.