| 1 |
<?php |
<?php |
| 2 |
// $Id: uts_path.module,v 1.18 2009/05/30 02:36:10 boombatower Exp $ |
// $Id: uts_path.module,v 1.19 2009/05/30 03:05:34 boombatower Exp $ |
| 3 |
/** |
/** |
| 4 |
* @file |
* @file |
| 5 |
* Collect the user path taken to complete a task and compare to defined ideal path. |
* Collect the user path taken to complete a task and compare to defined ideal path. |
| 117 |
*/ |
*/ |
| 118 |
function uts_path_init() { |
function uts_path_init() { |
| 119 |
$status = variable_get('uts_path_ideal_recorder', UTS_PATH_RECORDER_CLOSED); |
$status = variable_get('uts_path_ideal_recorder', UTS_PATH_RECORDER_CLOSED); |
|
if ($status != UTS_PATH_RECORDER_CLOSED) { |
|
|
drupal_add_css(drupal_get_path('module', 'uts_path') . '/uts-path.css'); |
|
|
drupal_add_css(drupal_get_path('module', 'uts_proctor') . '/uts-proctor.css'); |
|
| 120 |
|
|
| 121 |
$status_message = t('<b>Status</b>: @status', array('@status' => uts_path_get_recorder_status($status))); |
if ($status != UTS_PATH_RECORDER_CLOSED) { |
| 122 |
drupal_set_content('header', theme('uts_path_record', $status_message, drupal_get_form('uts_path_record_ideal_form'))); |
// Cause recorder to be closed before recoring is called, but allow status |
| 123 |
|
// message to be accurate since recording occurs before it is generated. |
| 124 |
|
$action_form = drupal_get_form('uts_path_record_ideal_form'); |
| 125 |
} |
} |
| 126 |
|
|
| 127 |
// Record the current page if in ideal recording mode or proctor data record. |
// Record the current page if in ideal recording mode or proctor data record. |
| 131 |
else if (module_exists('uts_proctor') && uts_proctor_data_record()) { |
else if (module_exists('uts_proctor') && uts_proctor_data_record()) { |
| 132 |
uts_path_record(FALSE); |
uts_path_record(FALSE); |
| 133 |
} |
} |
| 134 |
|
|
| 135 |
|
if ($status != UTS_PATH_RECORDER_CLOSED) { |
| 136 |
|
drupal_add_css(drupal_get_path('module', 'uts_path') . '/uts-path.css'); |
| 137 |
|
drupal_add_css(drupal_get_path('module', 'uts_proctor') . '/uts-proctor.css'); |
| 138 |
|
|
| 139 |
|
$status_message = t('<b>Status</b>: @status', array('@status' => uts_path_get_recorder_status($status))); |
| 140 |
|
|
| 141 |
|
if ($path = uts_path_ideal_get(variable_get('uts_path_ideal_recorder_task_nid', 0))) { |
| 142 |
|
$status_message .= ' (' . format_plural(count($path), '1 step', '@count steps') . ')'; |
| 143 |
|
} |
| 144 |
|
|
| 145 |
|
drupal_set_content('header', theme('uts_path_record', $status_message, $action_form)); |
| 146 |
|
} |
| 147 |
} |
} |
| 148 |
|
|
| 149 |
/** |
/** |
| 189 |
variable_set('uts_path_ideal_recorder', UTS_PATH_RECORDER_CLOSED); |
variable_set('uts_path_ideal_recorder', UTS_PATH_RECORDER_CLOSED); |
| 190 |
|
|
| 191 |
// Redirect to task page and display instructions. |
// Redirect to task page and display instructions. |
| 192 |
drupal_set_message(t('Please confirm that the ideal path is correct as it is automatically saved.')); |
drupal_set_message(t('Please confirm that the ideal path is correct. The path is automatically saved.')); |
| 193 |
$form_state['redirect'] = 'node/' . variable_get('uts_path_ideal_recorder_task_nid', 0) . '/edit'; |
$form_state['redirect'] = 'node/' . variable_get('uts_path_ideal_recorder_task_nid', 0) . '/edit'; |
| 194 |
break; |
break; |
| 195 |
case t('Clear'): |
case t('Clear'): |
| 266 |
} |
} |
| 267 |
|
|
| 268 |
/** |
/** |
| 269 |
* Render the ideal path for the current task node. |
* Get the ideal path for the specified task node. |
| 270 |
* |
* |
| 271 |
* @param integer $task_nid The task NID to render ideal path for. |
* @param integer $task_nid The task NID to render ideal path for. |
| 272 |
* @return string HTML output. |
* @return array Ideal path. |
| 273 |
*/ |
*/ |
| 274 |
function uts_path_render_ideal($task_nid) { |
function uts_path_ideal_get($task_nid) { |
| 275 |
$rows = array(); |
$rows = array(); |
| 276 |
if ($task_nid) { |
if ($task_nid) { |
| 277 |
$result = db_query('SELECT path, breadcrumb, title |
$result = db_query('SELECT path, breadcrumb, title |
| 278 |
FROM {uts_path_ideal} |
FROM {uts_path_ideal} |
| 279 |
WHERE task_nid = %d |
WHERE task_nid = %d |
| 280 |
ORDER BY weight ASC', $task_nid); |
ORDER BY weight ASC', $task_nid); |
|
$header = array(t('Path'), t('Breadcrumb'), t('Title')); |
|
| 281 |
while ($record = db_fetch_array($result)) { |
while ($record = db_fetch_array($result)) { |
| 282 |
$rows[] = $record; |
$rows[] = $record; |
| 283 |
} |
} |
| 284 |
} |
} |
| 285 |
return (count($rows) > 0 ? theme('table', $header, $rows) : t('No path to display.')); |
return $rows; |
| 286 |
|
} |
| 287 |
|
|
| 288 |
|
/** |
| 289 |
|
* Render the ideal path for the specified task node. |
| 290 |
|
* |
| 291 |
|
* @param integer $task_nid The task NID to render ideal path for. |
| 292 |
|
* @return string HTML output. |
| 293 |
|
*/ |
| 294 |
|
function uts_path_render_ideal($task_nid) { |
| 295 |
|
$rows = array(); |
| 296 |
|
if ($task_nid) { |
| 297 |
|
$header = array(t('Path'), t('Breadcrumb'), t('Title')); |
| 298 |
|
$rows = uts_path_ideal_get($task_nid); |
| 299 |
|
} |
| 300 |
|
return ($rows ? theme('table', $header, $rows) : t('No path to display.')); |
| 301 |
} |
} |
| 302 |
|
|
| 303 |
/** |
/** |