PDA

View Full Version : Image Gallery - using Section Sort Order in Admin page


Tobias
10-05-2006, 07:54 PM
Hello,

this post is a solution to a request made over at SD.com for the Image Gallery (p17).

The Imager Gallery (p17) plugin has a Setting to specify the "Section Sort Order" to order the top menu and the dropdown list on the end-user page. This setting, however, is not used on the Admin page itself (which sorts alphabetically).

IF you would like to have the dropdowns in the Admin page also be sorted the way the Settings configured, below code change is a solution to it.

Version of Subdreamer: 2.3.5.

FIND in file "p17_settings.php" below code, starting around line 813:

function PrintSectionChildren($parentid, $selected, $exclude, $indent, $displaycounts = 0)
{
global $DB;

$getsections = $DB->query("SELECT sectionid, name FROM " . TABLE_PREFIX . "p17_sections WHERE parentid = $parentid ORDER BY name");


while($sections = $DB->fetch_array($getsections))
{
if($exclude != $sections['sectionid'])
{
$name = $indent . ' ' . $sections['name'] .iif($sections['sectionid'] == 1," (root)","");

if($displaycounts)
{
$getimagecount = $DB->query_first("SELECT COUNT(*) FROM " . TABLE_PREFIX . "p17_images WHERE activated = '1' AND sectionid = " . $sections['sectionid']);
$name .= ' ('.$getimagecount[0].')';
}

echo "<option value=\"$sections[sectionid]\" ".iif($selected == $sections['sectionid'],"selected","").">$name</option>";
}

PrintSectionChildren($sections['sectionid'], $selected, $exclude, $indent . '- - ', $displaycounts);
}
}


REPLACE above (whole implementation of "PrintSectionChildren") with below code block.
It includes my markers for code changes for you to see what has changed:



// ############################ GET SECTION SORT ORDER ##########################
// CONDEV 20060817 Added - adapted from "p17_GetSectionSort" of "imagegallery.php"
function GetSectionSort($sortoption)
{
switch($sortoption)
{
case '0': //'Newest First':
$order = 'datecreated DESC';
break;

case '1': //'Oldest First':
$order = 'datecreated ASC';
break;

case '2': //'Alphabetically A-Z'
$order = 'name ASC';
break;

case '3': //'Alphabetically Z-A':
$order = 'name DESC';
break;

default:
$order = 'name ASC';
break;
}

return $order;
}


//CONDEV 20060817 added "$sortoption"
function PrintSectionChildren($parentid, $selected, $exclude, $indent, $displaycounts = 0, $sortoption = null)
{
global $DB;

// CONDEV 20060817 get sort order only the first time this is called (== null)
if(!$sortoption)
{
// get specific plugin setting for "Section Sort Order"
$sortoption = $DB->query_first("SELECT title, value FROM " . TABLE_PREFIX .
"pluginsettings WHERE pluginid = '17' and title = 'Section Sort Order'");
$sortoption = (isset($sortoption)&&isset($sortoption[1]))?$sortoption[1]:'';
}

// CONDEV 20060817 changed sort order
$getsections = $DB->query("SELECT sectionid, name FROM " . TABLE_PREFIX . "p17_sections WHERE parentid = $parentid ORDER BY " . GetSectionSort($sortoption));

while($sections = $DB->fetch_array($getsections))
{
if($exclude != $sections['sectionid'])
{
$name = $indent . ' ' . $sections['name'] .iif($sections['sectionid'] == 1," (root)","");

if($displaycounts)
{
$getimagecount = $DB->query_first("SELECT COUNT(*) FROM " . TABLE_PREFIX . "p17_images WHERE activated = '1' AND sectionid = " . $sections['sectionid']);
$name .= ' ('.$getimagecount[0].')';
}

echo "<option value=\"$sections[sectionid]\" ".iif($selected == $sections['sectionid'],"selected","").">$name</option>";
}

//CONDEV 20060817 added sort option
PrintSectionChildren($sections['sectionid'], $selected, $exclude, $indent . '- - ', $displaycounts, $sortoption);
}
}


Mass Media Pro Plugin - Live Demo : Mass Media Pro (http://www.sddepot.com/mass_media/)
My SDDepot Blog (http://www.sddepot.com/community/blog/tobias/) - SDDepot - Skins and Plugins (http://www.sddepot.com/)