Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Module to set default sort order on new Albums.
- Loading branch information
Showing
6 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
3.0/modules/default_sort/controllers/admin_default_sort.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php defined("SYSPATH") or die("No direct script access.") ?><?php | ||
|
||
class Admin_Default_Sort_Controller extends Admin_Controller { | ||
public function index() { | ||
$form = $this->_get_form(); | ||
|
||
if (request::method() == "post") { | ||
access::verify_csrf(); | ||
|
||
if ($form->validate()) { | ||
module::set_var("default_sort", "default_sort_column", $_POST['sort_column']); | ||
module::set_var("default_sort", "default_sort_direction", $_POST['sort_direction']); | ||
|
||
message::success(t("Settings have been saved")); | ||
url::redirect("admin/default_sort"); | ||
} else { | ||
message::error(t("There was a problem with the submitted form. Please check your values and try again.")); | ||
} | ||
} | ||
|
||
print $this->_get_view(); | ||
} | ||
|
||
private function _get_view($form = null) { | ||
$v = new Admin_View("admin.html"); | ||
$v->page_title = t("Gallery 3 :: Set Default Sort Order for New Albums"); | ||
|
||
$v->content = new View("admin_default_sort.html"); | ||
$v->content->form = empty($form) ? $this->_get_form() : $form; | ||
|
||
return $v; | ||
} | ||
|
||
private function _get_form() { | ||
$form = new Forge("admin/default_sort", "", "post", array("id" => "g-admin-default_sort-form")); | ||
|
||
$group = $form->group("sort_order")->label(t("Sort Order")); | ||
|
||
$group ->dropdown("sort_column") | ||
->id(t("sort_column")) | ||
->label(t("Sort by")) | ||
->options(array_merge(array("none" => t("None")), album::get_sort_order_options())) | ||
->selected(module::get_var("default_sort", "default_sort_column", "none")); | ||
|
||
$group ->dropdown("sort_direction") | ||
->id(t("sort_direction")) | ||
->label(t("Sort by")) | ||
->options(array("none" => t("None"), "ASC" => t("Ascending"), "DESC" => t("Descending"))) | ||
->selected(module::get_var("default_sort", "default_sort_direction", "none")); | ||
|
||
$form->submit("submit")->value(t("Save")); | ||
return $form; | ||
} | ||
} | ||
|
||
# vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php defined("SYSPATH") or die("No direct script access."); | ||
|
||
class default_sort_Core { | ||
} | ||
|
||
# vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php defined("SYSPATH") or die("No direct script access."); | ||
|
||
class default_sort_event_Core { | ||
static function admin_menu($menu, $theme) { | ||
$menu | ||
->get("settings_menu") | ||
->append(Menu::factory("link") | ||
->id("default_sort_menu") | ||
->label(t("Default Sort Order")) | ||
->url(url::site("admin/default_sort"))); | ||
} | ||
|
||
static function item_created($item) { | ||
if ($item->is_album()) { | ||
if (($s = module::get_var("default_sort", "default_sort_column", ""))) | ||
$item->sort_column = $s; | ||
|
||
if (($s = module::get_var("default_sort", "default_sort_direction", ""))) | ||
$item->sort_order = $s; | ||
|
||
$item->save(); | ||
} | ||
} | ||
} | ||
|
||
# vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab: |
29 changes: 29 additions & 0 deletions
29
3.0/modules/default_sort/helpers/default_sort_installer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php defined("SYSPATH") or die("No direct script access."); | ||
|
||
class default_sort_installer { | ||
private static function getversion() { return 1; } | ||
private static function setversion() { module::set_version("default_sort", self::getversion()); } | ||
|
||
static function install() { | ||
self::setversion(); | ||
} | ||
|
||
static function upgrade($version) { | ||
if ($version < self::getversion()) | ||
self::setversion(); | ||
} | ||
|
||
static function can_activate() { | ||
} | ||
|
||
static function activate() { | ||
} | ||
|
||
static function deactivate() { | ||
} | ||
|
||
static function uninstall() { | ||
} | ||
} | ||
|
||
# vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name = "Default Sort Order" | ||
description = "Set default sort order for newly-created albums." | ||
version = 1 | ||
author_name = "jingai" | ||
author_url = "" | ||
info_url = "http://codex.gallery2.org/Gallery3:Modules:default_sort" | ||
discuss_url = "http://gallery.menalto.com/forum_module_default_sort" |
11 changes: 11 additions & 0 deletions
11
3.0/modules/default_sort/views/admin_default_sort.html.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php defined("SYSPATH") or die("No direct script access.") ?> | ||
|
||
<div id="g-admin-code-block"> | ||
<h2><?= t("Default Sort Order") ?></h2> | ||
|
||
<p><?= t("Set default sort order and column for newly-created albums."); ?></p> | ||
|
||
<div class="g-block-content"> | ||
<?php echo $form; ?> | ||
</div> | ||
</div> |