Skip to content

Commit

Permalink
Add help version selector view to change 'active' help version while …
Browse files Browse the repository at this point in the history
…leaving current help version set...comes in handy when checking docs site with a pre-release version. [#430 state:resolved owner:dleffler milestone:2.0.3]
  • Loading branch information
dleffler committed Dec 15, 2011
1 parent e25df7c commit 496b5d8
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 10 deletions.
87 changes: 77 additions & 10 deletions framework/modules/help/controllers/helpController.php
Expand Up @@ -18,7 +18,7 @@
##################################################

class helpController extends expController {
public $useractions = array('showall'=>'Show all');
public $useractions = array('showall'=>'Show all','select_version'=>'Select Help Version');
public $codequality = 'beta';

function displayname() { return "Help"; }
Expand All @@ -37,7 +37,10 @@ function __construct($src=null, $params=array()) {

$this->help_version = expSession::get('help-version');
}


/**
* Display list of help documents
*/
public function showall() {
expHistory::set('viewable', $this->params);
$hv = new help_version();
Expand Down Expand Up @@ -66,7 +69,10 @@ public function showall() {

assign_to_template(array('current_version'=>$ref_version, 'page'=>$page, 'rank'=>($order==='rank')?1:0));
}


/**
* Create or Edit a help document
*/
public function edit() {
global $db, $sectionObj;
expHistory::set('editable', $this->params);
Expand Down Expand Up @@ -95,7 +101,10 @@ public function edit() {
// assign_to_template(array('record'=>$help,"cursec"=>$sectionObj->id,"sections"=>$sectionlist));
assign_to_template(array('record'=>$help,"cursec"=>$this->loc->src,"sections"=>$sectionlist));
}


/**
* Display a help document
*/
public function show() {
global $db;

Expand All @@ -111,7 +120,10 @@ public function show() {
$doc = $help->find('first', 'help_version_id='.$version_id.' AND sef_url="'.$this->params['title'].'"');
assign_to_template(array('doc'=>$doc,"hv"=>$this->help_version));
}


/**
* Manage help documents
*/
public function manage() {
expHistory::set('manageable', $this->params);
global $db;
Expand Down Expand Up @@ -142,7 +154,14 @@ public function manage() {

assign_to_template(array('current_version'=>$current_version, 'page'=>$page, 'sections'=>$sections));
}


/**
* Routine to copy all existing help docs from a version to the new version
* @static
* @param $from
* @param $to
* @return bool
*/
private static function copydocs($from, $to) {
global $db;

Expand Down Expand Up @@ -178,7 +197,10 @@ private static function copydocs($from, $to) {
flash('message', gt('Copied all docs from version').' '.$oldvers.' '.gt('to new version').' '.$newvers);
return true;
}


/**
* Manage help versions
*/
public function manage_versions() {
expHistory::set('manageable', $this->params);

Expand All @@ -200,14 +222,20 @@ public function manage_versions() {

assign_to_template(array('current_version'=>$current_version, 'page'=>$page));
}


/**
* Create or Edit details about a help version
*/
public function edit_version() {
expHistory::set('editable', $this->params);
$id = empty($this->params['id']) ? null : $this->params['id'];
$version = new help_version($id);
assign_to_template(array('record'=>$version));
}


/**
* Delete a help version and all assoc docs
*/
public function delete_version() {
if (empty($this->params['id'])) {
flash('error', gt('The version you are trying to delete could not be found'));
Expand Down Expand Up @@ -237,7 +265,10 @@ public function delete_version() {
flash('message', gt('Deleted version').' '.$version->version.' '.gt('and').' '.$num_docs.' '.gt('documents that were in that version.'));
expHistory::back();
}


/**
* Creates a new help version, possibly based on existing help version
*/
public function update_version() {
global $db;

Expand Down Expand Up @@ -268,6 +299,9 @@ public function update_version() {
expHistory::back();
}

/**
* Switches current help version globally
*/
public function activate_version() {
global $db;

Expand All @@ -284,6 +318,39 @@ public function activate_version() {
expHistory::back();
}

/**
* Displays available help versions
*/
public function select_version() {
global $db;

$hv = expSession::get('help-version');
$selected = $db->selectValue('help_version', 'id', 'version="'.$hv.'"');
$versions = $db->selectDropdown('help_version','version',1,'version');
assign_to_template(array('current_version'=>$hv, 'selected'=>$selected, 'versions'=>$versions));
}

/**
* Switches current help version temporarily
*/
public function switch_version() {
global $db;

// unset the current version.
expSession::un_set('help-version');
// set the requested version.
$version = $db->selectValue('help_version','version','id="'.$this->params['version'].'"');
expSession::set('help-version',$version);
flash('message', gt('Now displaying Help version').' '.$version);
expHistory::back();
}

/**
* Hack to try and determine page which help doc is assoc with
* @static
* @param $params
* @return null|void
*/
public static function getSection($params) {
global $db;
$h = new help();
Expand Down
39 changes: 39 additions & 0 deletions framework/modules/help/views/help/select_version.tpl
@@ -0,0 +1,39 @@
{*
* Copyright (c) 2007-2008 OIC Group, Inc.
* Written and Designed by Adam Kessler
*
* This file is part of Exponent
*
* Exponent is free software; you can redistribute
* it and/or modify it under the terms of the GNU
* General Public License as published by the Free
* Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* GPL: http://www.gnu.org/licenses/gpl.txt
*
*}

{literal}
<style type="text/css">
.control .label {
display: inline;
font-size: 100%;
font-weight: bold;
}
</style>
{/literal}

<div class="module help select-version">
<form>
{control type="dropdown" name="version" label="Help Version: "|gettext items=$versions default=$selected onchange="switch_ver(this.value)"}
</form>
</div>

{literal}
<script type="text/javascript">
function switch_ver(id){
location.href="index.php?module=help&action=switch_version&version=" + id
}
</script>
{/literal}

0 comments on commit 496b5d8

Please sign in to comment.