Skip to content

Commit

Permalink
Fixes help doc section selection/determination, section is deprecated…
Browse files Browse the repository at this point in the history
… and is secondary choice over item location_data->src [#515 state:resolved milestone:2.0.5 responsible:dleffler]
  • Loading branch information
dleffler committed Feb 14, 2012
1 parent b19f3ed commit b3d3980
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 31 deletions.
61 changes: 36 additions & 25 deletions framework/modules/help/controllers/helpController.php
Expand Up @@ -90,23 +90,30 @@ public function edit() {
}
if (empty($help->help_version_id)) $help->help_version_id = $version;

$sectionlist = array();
$sections = $db->selectObjectsIndexedArray('section',1);
$helpsections = $db->selectObjects('help',1);
foreach ($helpsections as $helpsection) {
if ($helpsection->location_data != null) {
$helpsrc = expUnserialize($helpsection->location_data);
if (!array_key_exists($helpsrc->src, $sectionlist) && $helpsection->section != 0) {
$sectionlist[$helpsrc->src] = $sections[$helpsection->section]->name;
if ($helpsection->section == $sectionObj->id) {
$sectionlist[$helpsrc->src] .= " (current section)";
}
}
}
}
$sectionlist[$this->loc->src] = $sectionObj->name." (current section)";
// assign_to_template(array('record'=>$help,"cursec"=>$sectionObj->id,"sections"=>$sectionlist));
assign_to_template(array('record'=>$help,"cursec"=>$this->loc->src,"sections"=>$sectionlist));
// $sectionlist = array();
// $sections = $db->selectObjectsIndexedArray('section',1);
// $helpsections = $db->selectObjects('help',1);
// foreach ($helpsections as $helpsection) {
// if ($helpsection->location_data != null) {
// $helpsrc = expUnserialize($helpsection->location_data);
// if (!array_key_exists($helpsrc->src, $sectionlist) && $helpsection->section != 0) {
// $sectionlist[$helpsrc->src] = $sections[$helpsection->section]->name;
// if ($helpsection->section == $sectionObj->id) {
// $sectionlist[$helpsrc->src] .= " (current section)";
// }
// }
// }
// }

$sectionlist = array();
foreach ($db->selectObjects('sectionref','module="helpController"') as $sectionref) {
if (!empty($sectionref->source) && empty($sectionlist[$sectionref->source])) {
$sectionlist[$sectionref->source] = $db->selectValue('section', 'name', 'id="' . $sectionref->section .'"');
}
}
$sectionlist[$this->loc->src] .= gt(" (current section)");

assign_to_template(array('record'=>$help,"current_section"=>$this->loc->src,"sections"=>$sectionlist));
}

/**
Expand All @@ -116,12 +123,7 @@ public function show() {
global $db;

expHistory::set('viewable', $this->params);

$help = new help();
// if (empty($this->params['title']) && !empty($this->params['version'])) {
// $this->params['title'] = $this->params['version'];
// $this->params['version'] = 'current';
// }
if (empty($this->params['version']) || $this->params['version'] == 'current') {
$version_id = $db->selectValue('help_version', 'id', 'is_current=1');
} else {
Expand Down Expand Up @@ -151,7 +153,13 @@ public function manage() {

// for now we'll display help by section, though location_data would be more accurate
// this helps find problems in older help docs
$sections = $db->selectObjectsIndexedArray('section',1);
// $sections = $db->selectObjectsIndexedArray('section',1);
$sections = array();
foreach ($db->selectObjects('sectionref','module="helpController"') as $sectionref) {
if (!empty($sectionref->source) && empty($sections[$sectionref->source])) {
$sections[$sectionref->source] = $db->selectValue('section', 'name', 'id="' . $sectionref->section .'"');
}
}

$where = empty($this->params['version']) ? 1 : 'help_version_id='.$this->params['version'];
$page = new expPaginator(array(
Expand Down Expand Up @@ -408,8 +416,11 @@ public static function getSection($params) {
$hv = $db->selectValue('help_version', 'id', 'version='.$params['version']);
}
$help = $h->find('first','help_version_id='.$hv.' and sef_url=\''.$params['title'].'\'');
$sessec = expSession::get('last_section') ? expSession::get('last_section') : 1 ;
$sid = ($help->section!=0)?$help->section:$sessec;
$session_section = expSession::get('last_section') ? expSession::get('last_section') : 1 ;
// $sid = ($help->section!=0)?$help->section:$session_section;
// default to finding help section by location_data & sectionref, else use help section field and then session section
$help_sectionref = $db->selectObject('sectionref','module="helpController" AND source="'. expUnserialize($help->location_data)->src.'"');
$sid = !empty($help_sectionref) ? $help_sectionref->section : (($help->section!=0) ? $help->section : $session_section);
if (!expSession::get('last_section')) {
expSession::set('last_section',$sid);
}
Expand Down
9 changes: 5 additions & 4 deletions framework/modules/help/models/help.php
Expand Up @@ -34,13 +34,14 @@ public function __construct($params=array()) {
public function save() {
global $db;

if (isset($_POST['section'])) {
if (isset($_POST['help_section'])) {
// manipulate section & location_data to correct values
$hlpsection = $db->selectObject('sectionref','module = "helpController" AND source = "'.$_POST['section'].'"');
$this->section = $hlpsection->section;
// $hlpsection = $db->selectObject('sectionref','module = "helpController" AND source = "'.$_POST['section'].'"');
// $hlpsection = $db->selectValue('sectionref', 'section', 'module = "helpController" AND source="' . $_POST['section'] .'"');
$this->section = $db->selectValue('sectionref', 'section', 'module = "helpController" AND source="' . $_POST['help_section'] .'"');
$loc = null;
$loc->mod = 'help';
$loc->src = $_POST['section'];
$loc->src = $_POST['help_section'];
$loc->int = '';
$this->location_data = serialize($loc);
}
Expand Down
2 changes: 1 addition & 1 deletion framework/modules/help/views/help/edit.tpl
Expand Up @@ -35,7 +35,7 @@
{control type="dropdown" name="help_version_id" label="Version"|gettext frommodel="help_version" key=id display=version order=version dir=DESC value=$record->help_version_id}
{*{control type=textarea name=summary label="Summary"|gettext value=$record->summary}*}
{control type=html name=body label="General Information"|gettext value=$record->body}
{control type="dropdown" name="section" label="Help Section"|gettext items=$sections value=$cursec}
{control type="dropdown" name="help_section" label="Help Section"|gettext items=$sections value=$record->loc->src default=$current_section}
</div>
<div id="tab2">
<h2>{'Actions and Views'|gettext}</h2>
Expand Down
2 changes: 1 addition & 1 deletion framework/modules/help/views/help/manage.tpl
Expand Up @@ -39,7 +39,7 @@
<tr class="{cycle values="odd,even"}">
<td><a href={link action=show version=$doc->help_version->version title=$doc->sef_url}>{$doc->title}</a></td>
<td><a href="{link action=manage version=$doc->help_version->id}">{$doc->help_version->version}</a></td>
<td>{$sections[$sec]->name}</td>
<td>{$sections[$doc->loc->src]}</td>
<td>
{permissions}
{if $permissions.edit == 1}
Expand Down

0 comments on commit b3d3980

Please sign in to comment.