Commit 8516e64f authored by TravisCarden's avatar TravisCarden

By TravisCarden: Made various low level code improvements.

parent 5caef3a3
......@@ -12,7 +12,7 @@ INTRODUCTION
Current Maintainer: Travis Carden <http://drupal.org/user/236758>
Checklist API Provides a simple interface for modules to create fillable,
Checklist API provides a simple interface for modules to create fillable,
persistent checklists that track progress with completion times and users. See
checklistapi_example.module for an example implementation.
......
......@@ -13,6 +13,7 @@
* @ingroup forms
*/
function checklistapi_report_form() {
// Define table header.
$header = array(
t('Checklist'),
t('Progress'),
......@@ -20,31 +21,36 @@ function checklistapi_report_form() {
t('Last updated by'),
t('Operations'),
);
// Build table rows.
$rows = array();
$definitions = checklistapi_get_checklist_info();
if (count($definitions)) {
$rows = array();
foreach ($definitions as $id => $definition) {
$checklist = checklistapi_checklist_load($id);
$row = array();
$row[] = array(
'data' => ($checklist->userHasAccess()) ? l($checklist->title, $checklist->path) : drupal_placeholder($checklist->title),
'title' => (!empty($checklist->description)) ? $checklist->description : '',
);
$row[] = t('@completed of @total (@percent%)', array(
'@completed' => $checklist->getNumberCompleted(),
'@total' => $checklist->getNumberOfItems(),
'@percent' => round($checklist->getPercentComplete()),
));
$row[] = $checklist->getLastUpdatedDate();
$row[] = $checklist->getLastUpdatedUser();
$row[] = ($checklist->userHasAccess('edit') && $checklist->hasSavedProgress()) ? l(t('clear saved progress'), $checklist->path . '/clear', array(
'query' => array('destination' => 'admin/reports/checklistapi'),
)) : '';
$rows[] = $row;
}
}
else {
$rows[][] = array('data' => t('No checklists available.'), 'colspan' => 5);
foreach ($definitions as $id => $definition) {
$checklist = checklistapi_checklist_load($id);
$row = array();
$row[] = array(
'data' => ($checklist->userHasAccess()) ? l($checklist->title, $checklist->path) : drupal_placeholder($checklist->title),
'title' => (!empty($checklist->description)) ? $checklist->description : '',
);
$row[] = t('@completed of @total (@percent%)', array(
'@completed' => $checklist->getNumberCompleted(),
'@total' => $checklist->getNumberOfItems(),
'@percent' => round($checklist->getPercentComplete()),
));
$row[] = $checklist->getLastUpdatedDate();
$row[] = $checklist->getLastUpdatedUser();
$row[] = ($checklist->userHasAccess('edit') && $checklist->hasSavedProgress()) ? l(t('clear saved progress'), $checklist->path . '/clear', array(
'query' => array('destination' => 'admin/reports/checklistapi'),
)) : '';
$rows[] = $row;
}
return theme('table', array('header' => $header, 'rows' => $rows));
// Compile table.
$table = array(
'header' => $header,
'rows' => $rows,
'empty' => t('No checklists available.'),
);
return theme('table', $table);
}
......@@ -9,30 +9,30 @@
*/
/**
* Access callback: Checks the current user's access to a checklist.
* Access callback: Checks the current user's access to a given checklist.
*
* @param string $id
* The checklist ID.
* @param string $operation
* The operation to test access for. Possible values are "view", "edit", and
* "any". Defaults to "any".
* (optional) The operation to test access for. Accepted values are "view",
* "edit", and "any". Defaults to "any".
*
* @return bool
* Returns TRUE if the current user has access to perform a given operation on
* the specified checklist, or FALSE if not.
*/
function checklistapi_checklist_access($id, $operation = 'any') {
$access['view'] = user_access('view any checklistapi checklist') || user_access('view ' . $id . ' checklistapi checklist');
$access['edit'] = user_access('edit any checklistapi checklist') || user_access('edit ' . $id . ' checklistapi checklist');
$access['any'] = $access['view'] || $access['edit'];
if (isset($access[$operation])) {
return $access[$operation];
}
else {
$all_operations = array('view', 'edit', 'any');
if (!in_array($operation, $all_operations)) {
throw new Exception(t('No such operation "@operation"', array(
'@operation' => $operation,
)));
}
$access['view'] = user_access('view any checklistapi checklist') || user_access('view ' . $id . ' checklistapi checklist');
$access['edit'] = user_access('edit any checklistapi checklist') || user_access('edit ' . $id . ' checklistapi checklist');
$access['any'] = $access['view'] || $access['edit'];
return $access[$operation];
}
/**
......
......@@ -18,25 +18,25 @@
function checklistapi_checklist_clear_confirm($form, &$form_state, $id) {
$checklist = checklistapi_checklist_load($id);
$form['#checklist'] = $checklist;
return confirm_form(
$form,
t('Are you sure you want to clear %title saved progress?', array(
'%title' => $checklist->title,
)),
$checklist->path,
t('All progress details will be erased. This action cannot be undone.'),
t('Clear'),
t('Cancel')
);
$question = t('Are you sure you want to clear %title saved progress?', array(
'%title' => $checklist->title,
));
$description = t('All progress details will be erased. This action cannot be undone.');
$yes = t('Clear');
$no = t('Cancel');
return confirm_form($form, $question, $checklist->path, $description, $yes, $no);
}
/**
* Form submission handler for checklistapi_checklist_clear_confirm().
*/
function checklistapi_checklist_clear_confirm_submit($form, &$form_state) {
// If user confirmed, clear saved progress.
if ($form_state['values']['confirm']) {
$form['#checklist']->clearSavedProgress();
}
// Redirect back to checklist.
$form_state['redirect'] = $form['#checklist']->path;
}
......@@ -203,7 +203,7 @@ function checklistapi_checklist_form_submit($form, &$form_state) {
* can be set in the settings.php file.
*
* @return bool
* TRUE when in compact mode, FALSE when in expanded mode.
* TRUE when in compact mode, or FALSE when in expanded mode.
*/
function checklistapi_compact_mode() {
return isset($_COOKIE['Drupal_visitor_checklistapi_compact_mode']) ? $_COOKIE['Drupal_visitor_checklistapi_compact_mode'] : variable_get('checklistapi_compact_mode', FALSE);
......@@ -213,7 +213,8 @@ function checklistapi_compact_mode() {
* Menu callback: Sets whether the admin menu is in compact mode or not.
*
* @param string $mode
* Valid values are 'on' and 'off'.
* (optional) The mode to set compact mode to. Accepted values are "on" and
* "off". Defaults to "off".
*/
function checklistapi_compact_page($mode = 'off') {
user_cookie_save(array('checklistapi_compact_mode' => ($mode == 'on')));
......
......@@ -179,7 +179,7 @@ class ChecklistapiChecklist {
* The Drupal variable name.
*/
public function getSavedProgressVariableName() {
return 'checklistapi_checklist_' . $this->id;
return "checklistapi_checklist_{$this->id}";
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment