Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 15 |
| HistoryController | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 15 |
| getNodeReadTimestamps | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 9 |
|||
| readNode | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 6 |
|||
| <?php | |
| /** | |
| * @file | |
| * Contains \Drupal\history\Controller\HistoryController. | |
| */ | |
| namespace Drupal\history\Controller; | |
| use Symfony\Component\HttpFoundation\Request; | |
| use Symfony\Component\HttpFoundation\JsonResponse; | |
| use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; | |
| use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | |
| use Drupal\Core\Controller\ControllerBase; | |
| use Drupal\node\NodeInterface; | |
| /** | |
| * Returns responses for History module routes. | |
| */ | |
| class HistoryController extends ControllerBase { | |
| /** | |
| * Returns a set of nodes' last read timestamps. | |
| * | |
| * @param \Symfony\Component\HttpFoundation\Request $request | |
| * The request of the page. | |
| * | |
| * @return Symfony\Component\HttpFoundation\JsonResponse | |
| * The JSON response. | |
| */ | |
| public function getNodeReadTimestamps(Request $request) { | |
| if ($this->currentUser()->isAnonymous()) { | |
| throw new AccessDeniedHttpException(); | |
| } | |
| $nids = $request->request->get('node_ids'); | |
| if (!isset($nids)) { | |
| throw new NotFoundHttpException(); | |
| } | |
| return new JsonResponse(history_read_multiple($nids)); | |
| } | |
| /** | |
| * Marks a node as read by the current user right now. | |
| * | |
| * @param \Symfony\Component\HttpFoundation\Request $request | |
| * The request of the page. | |
| * @param \Drupal\node\NodeInterface $node | |
| * The node whose "last read" timestamp should be updated. | |
| */ | |
| public function readNode(Request $request, NodeInterface $node) { | |
| if ($this->currentUser()->isAnonymous()) { | |
| throw new AccessDeniedHttpException(); | |
| } | |
| // Update the history table, stating that this user viewed this node. | |
| history_write($node->id()); | |
| return new JsonResponse((int)history_read($node->id())); | |
| } | |
| } |