Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Help Editor] Fix array issues caused by super confusing code #2969

Merged
merged 5 commits into from
Oct 23, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 29 additions & 24 deletions modules/help_editor/php/NDB_Menu_Filter_help_editor.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file contains code for editing context help section
*
* PHP Version 5
* PHP Version 7
*
* @category Main
* @package Loris
Expand All @@ -14,7 +14,7 @@
/**
* This file contains code for editing context help section
*
* PHP Version 5
* PHP Version 7
*
* @category Main
* @package Loris
Expand Down Expand Up @@ -108,48 +108,53 @@ class NDB_Menu_Filter_Help_Editor extends NDB_Menu_Filter
{
$DB = Database::singleton();
//Get the default values
$help = $DB->pselect("SELECT helpID, topic from help", array());
foreach ($help as $row) {
$help_section[$row['helpID']] = $row['topic'];
// $result will contain an array of size n by 2.
// this must be transposed to create a dictionary of IDs to Topics
$result = $DB->pselect("SELECT helpID, topic from help", array());
foreach ($result as $row) {
$helpTopics[$row['helpID']] = $row['topic'];
}
$x = 0;

foreach ($this->list as $item) {
$this->tpl_data['items'][$x][0]['value'] = $x + $count;
$i = 1;
foreach ($item as $key => $val) {
// Check if key starts with $needle ("Topic")
$needle = "Topic";
if (substr($key, 0, strlen($needle)) === $needle) {
$this->tpl_data['items'][$x][$i]['helpID'] = array_search(
$val,
$help_section
);
$this->tpl_data['items'][$x][$i]['parentID'] = $item['Parent_Topic']; // @codingStandardsIgnoreLine
$item['Parent_Topic'] = $help_section[$item['Parent_Topic']];
// Set front-end values for child topics
$helpID = array_search($val, $helpTopics);
if ($key === 'Topic') {
// $helpID will be a string representing a number or false
// so this logic statement should not provide unexpected results
// should $helpID = "0", for example
if (!$helpID) {
error_log("Could not find helpID for value $val");
} else {
$this->tpl_data['items'][$x][$i]['helpID'] = $helpID;
}
// set frontend parentID to item's parent topic, if it exists
$this->tpl_data['items'][$x][$i]['parentID']
= $item['Parent_Topic'];
// set item's parent topic to backend parent, if it exists
if (array_key_exists($item['Parent_Topic'], $helpTopics)) {
$item['Parent_Topic'] = $helpTopics[$item['Parent_Topic']];
}
// this is to make sure sorting is done
// on the topic and not the ID
}
if ($key == "Parent_Topic") {
$this->tpl_data['items'][$x][$i]['parentID'] = "-1";
$this->tpl_data['items'][$x][$i]['helpID'] = $val;
if ($val == "-1") {
$val = "-";
} else {
$val = $help_section[$val];
}
// Set front-end values for parent topics
if ($key === 'Parent_Topic') {
$this->tpl_data['items'][$x][$i]['parentID'] = '-1';
$this->tpl_data['items'][$x][$i]['helpID'] = $helpID;
}
$this->tpl_data['items'][$x][$i]['name'] = $key;
$this->tpl_data['items'][$x][$i]['value'] = utf8_encode($val);

$i++;
}

$x++;
}
setCookie("LastUrl", "?test_name=help_editor");
return true;

}

/**
Expand Down