public function displaysnippetsAction() { if (!$this->strategy->canUseSnippets()) { throw new Am_Exception_AccessDenied(); } $ticket = $this->getDi()->helpdeskTicketTable->load($this->getParam('ticket'), false); $tpl = null; if ($ticket) { $tpl = new Am_SimpleTemplate(); $tpl->assign('user', $ticket->getUser()); } $ds = new Am_Query($this->getDi()->helpdeskSnippetTable); $grid = new Am_Grid_Editable('_snippet', ___('Snippets'), $ds, $this->getRequest(), $this->view, $this->getDi()); $grid->addField('title', ___('Title'))->setRenderFunction(function ($record, $fieldName, $grid) use($tpl) { $c = $record->content; if ($tpl) { $c = $tpl->render($c); } return sprintf('<td><a href="javascript:;" class="local am-helpdesk-insert-snippet" data-snippet-content="%s">%s</a></td>', Am_Controller::escape($c), Am_Controller::escape($record->title)); }); $grid->setForm(array($this, 'createForm')); $grid->actionGet('insert')->setTarget(null); $grid->setPermissionId(Bootstrap_Helpdesk::ADMIN_PERM_ID); $grid->isAjax($this->isAjax() && $this->isGridRequest('_snippet')); echo $grid->run(); }