芝麻web文件管理V1.00
编辑当前文件:/home/mgatv524/public_html/sommatv/lib/Controller/Help.php
. */ namespace Xibo\Controller; use Xibo\Exception\AccessDeniedException; use Xibo\Factory\HelpFactory; use Xibo\Service\ConfigServiceInterface; use Xibo\Service\DateServiceInterface; use Xibo\Service\LogServiceInterface; use Xibo\Service\SanitizerServiceInterface; /** * Class Help * @package Xibo\Controller */ class Help extends Base { /** * @var HelpFactory */ private $helpFactory; /** * Set common dependencies. * @param LogServiceInterface $log * @param SanitizerServiceInterface $sanitizerService * @param \Xibo\Helper\ApplicationState $state * @param \Xibo\Entity\User $user * @param \Xibo\Service\HelpServiceInterface $help * @param DateServiceInterface $date * @param ConfigServiceInterface $config * @param HelpFactory $helpFactory */ public function __construct($log, $sanitizerService, $state, $user, $help, $date, $config, $helpFactory) { $this->setCommonDependencies($log, $sanitizerService, $state, $user, $help, $date, $config); $this->helpFactory = $helpFactory; } /** * Help Page */ function displayPage() { $this->getState()->template = 'help-page'; } public function grid() { $helpLinks = $this->helpFactory->query($this->gridRenderSort(), $this->gridRenderFilter()); foreach ($helpLinks as $row) { /* @var \Xibo\Entity\Help $row */ // we only want to show certain buttons, depending on the user logged in if ($this->getUser()->userTypeId == 1) { // Edit $row->buttons[] = array( 'id' => 'help_button_edit', 'url' => $this->urlFor('help.edit.form', ['id' => $row->helpId]), 'text' => __('Edit') ); // Delete $row->buttons[] = array( 'id' => 'help_button_delete', 'url' => $this->urlFor('help.delete.form', ['id' => $row->helpId]), 'text' => __('Delete') ); // Test $row->buttons[] = array( 'id' => 'help_button_test', 'url' => $this->getHelp()->link($row->topic, $row->category), 'text' => __('Test') ); } } $this->getState()->template = 'grid'; $this->getState()->recordsTotal = $this->helpFactory->countLast(); $this->getState()->setData($helpLinks); } /** * Add Form */ public function addForm() { if ($this->getUser()->userTypeId != 1) throw new AccessDeniedException(); $this->getState()->template = 'help-form-add'; } /** * Help Edit form * @param int $helpId */ public function editForm($helpId) { if ($this->getUser()->userTypeId != 1) throw new AccessDeniedException(); $help = $this->helpFactory->getById($helpId); $this->getState()->template = 'help-form-edit'; $this->getState()->setData([ 'help' => $help ]); } /** * Delete Help Link Form * @param int $helpId */ public function deleteForm($helpId) { if ($this->getUser()->userTypeId != 1) throw new AccessDeniedException(); $help = $this->helpFactory->getById($helpId); $this->getState()->template = 'help-form-delete'; $this->getState()->setData([ 'help' => $help ]); } /** * Adds a help link */ public function add() { if ($this->getUser()->userTypeId != 1) throw new AccessDeniedException(); $help = $this->helpFactory->createEmpty(); $help->topic = $this->getSanitizer()->getString('topic'); $help->category = $this->getSanitizer()->getString('category'); $help->link = $this->getSanitizer()->getString('link'); $help->save(); // Return $this->getState()->hydrate([ 'message' => sprintf(__('Added %s'), $help->topic), 'id' => $help->helpId, 'data' => $help ]); } /** * Edits a help link * @param int $helpId */ public function edit($helpId) { if ($this->getUser()->userTypeId != 1) throw new AccessDeniedException(); $help = $this->helpFactory->getById($helpId); $help->topic = $this->getSanitizer()->getString('topic'); $help->category = $this->getSanitizer()->getString('category'); $help->link = $this->getSanitizer()->getString('link'); $help->save(); // Return $this->getState()->hydrate([ 'message' => sprintf(__('Edited %s'), $help->topic), 'id' => $help->helpId, 'data' => $help ]); } /** * Delete * @param int $helpId * @throws \Xibo\Exception\NotFoundException */ public function delete($helpId) { if ($this->getUser()->userTypeId != 1) throw new AccessDeniedException(); $help = $this->helpFactory->getById($helpId); $help->delete(); // Return $this->getState()->hydrate([ 'message' => sprintf(__('Deleted %s'), $help->topic) ]); } }