*/
class syntax_plugin_acknowledge_listing extends SyntaxPlugin
{
/** @inheritDoc */
public function getType()
{
return 'substition';
}
/** @inheritDoc */
public function getPType()
{
return 'block';
}
/** @inheritDoc */
public function getSort()
{
return 155;
}
/** @inheritDoc */
public function connectTo($mode)
{
$this->Lexer->addSpecialPattern('~~ACKNOWLEDGE.*?~~', $mode, 'plugin_acknowledge_listing');
}
/** @inheritDoc */
public function handle($match, $state, $pos, Doku_Handler $handler)
{
// check for 'all' parameter
$includeDone = strtolower(substr($match, strlen('~~ACKNOWLEDGE '), -2)) === 'all';
return ['includeDone' => $includeDone];
}
/** @inheritDoc */
public function render($mode, Doku_Renderer $renderer, $data)
{
if ($mode !== 'xhtml') {
return false;
}
$renderer->info['cache'] = false;
$renderer->doc .= '
';
$renderer->doc .= $this->getListing($data['includeDone']);
$renderer->doc .= '
';
return true;
}
/**
* Returns the list of pages to be acknowledged by the user,
* optionally including past acknowledgments.
*
* @param bool $includeDone
*
* @return string
*/
protected function getListing($includeDone)
{
global $INPUT;
global $USERINFO;
$user = $INPUT->server->str('REMOTE_USER');
if ($user === '') return '';
$groups = $USERINFO['grps'];
/** @var helper_plugin_acknowledge $helper */
$helper = plugin_load('helper', 'acknowledge');
$items = $helper->getUserAssignments($user, $groups, $includeDone);
$html = $this->getLang('ackNotFound');
if (!empty($items)) {
$html = '';
foreach ($items as $item) {
$done = $item['ack'] ?
' ✔'
: '';
$html .= '- ' . html_wikilink(':' . $item['page']) . $done . '
';
}
$html .= '
';
}
return $html;
}
}