Skip to content

Commit

Permalink
Added config item to select album for background of logon page
Browse files Browse the repository at this point in the history
issue #27
  • Loading branch information
jeroenrnl committed Apr 13, 2016
1 parent e05b17e commit 512d81d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 7 deletions.
14 changes: 14 additions & 0 deletions php/classes/album.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,20 @@ public static function getCount() {
}
return $qry->getCount();
}

/**
* Get an array of id => name to build a non-hierarchical array
* this function always returns ALL albums and does NOT check user permissions
* @retrun array albums
*/
public static function getSelectArray() {
$albums=static::getRecords();
$selectArray=array(null => "");
foreach ($albums as $album) {
$selectArray[(string) $album->getId()] = $album->getName();
}
return $selectArray;
}
}

?>
12 changes: 12 additions & 0 deletions php/classes/confDefault.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ private static function getConfigInterface() {
$intSortDir->setDefault("asc");
$interface[]=$intSortDir;

$intLogonBgAlbum = new confItemSelect();
$intLogonBgAlbum->setName("interface.logon.background.album");
$intLogonBgAlbum->setLabel("Logon screen background album");
$intLogonBgAlbum->setDesc("Select an album from which a random photo is chosen as a " .
"background for the logon screen");
$intLogonBgAlbum->addOptions(album::getSelectArray());
$intLogonBgAlbum->setOptionsTranslate(false);
$intLogonBgAlbum->setDefault(null);

$interface[]=$intLogonBgAlbum;


return $interface;
}

Expand Down
28 changes: 22 additions & 6 deletions php/classes/confItemSelect.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class confItemSelect extends confItem {
/** @var array list of options */
private $options=array();

/** @var bool translate options */
private $translate=true;

/**
* Add an option
* @param string key
Expand Down Expand Up @@ -58,6 +61,14 @@ public function getOptions() {
return $this->options;
}

/**
* Set whether or not the options must be translated
* @param bool translate yes/no
*/
public function setOptionsTranslate($translate) {
$this->translate=$translate;
}

/**
* Check value
* check if a specific value is legal for this option
Expand All @@ -76,14 +87,19 @@ public function display() {
if ($this->internal) {
return;
}
$tpl=new block("confItemSelect", array(
"label" => e(translate($this->getLabel(),0)),
$params=array(
"label" => e(translate($this->getLabel(), 0)),
"name" => e($this->getName()),
"value" => e($this->getValue()),
"desc" => e(translate($this->getDesc(),0)),
"hint" => e(translate($this->getHint(),0)),
"options" => translate($this->getOptions(),0)
));
"desc" => e(translate($this->getDesc(), 0)),
"hint" => e(translate($this->getHint(), 0)),
);
if ($this->translate) {
$params["options"] = translate($this->getOptions(), 0);
} else {
$params["options"] = $this->getOptions();
}
$tpl=new block("confItemSelect", $params);
return $tpl;
}
}
2 changes: 1 addition & 1 deletion php/templates/default/blocks/confItemSelect.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<label for="<?php echo $tpl_name; ?>"><?php echo $tpl_label; ?></label>
<select name="<?php echo $tpl_name ?>">
<?php foreach ($tpl_options as $option=>$label): ?>
<?php if ($tpl_value===$option): ?>
<?php if ($tpl_value==$option): ?>
<?php $selected="selected"; ?>
<?php else: ?>
<?php $selected=""; ?>
Expand Down

0 comments on commit 512d81d

Please sign in to comment.