PageRenderTime 46ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/core/Collections/Controller/Collections.php

https://github.com/asdlfz/cockpit
PHP | 63 lines | 39 code | 24 blank | 0 comment | 5 complexity | 08f413dd730ad465970039f4aee0c40c MD5 | raw file
  1. <?php
  2. namespace Collections\Controller;
  3. class Collections extends \Cockpit\Controller {
  4. public function index() {
  5. return $this->render("collections:views/index.php");
  6. }
  7. public function collection($id = null) {
  8. if (!$this->app->module("auth")->hasaccess("Collections", 'manage.collections')) {
  9. return false;
  10. }
  11. $locales = $this->app->db->getKey("cockpit/settings", "cockpit.locales", []);
  12. return $this->render("collections:views/collection.php", compact('id', 'locales'));
  13. }
  14. public function entries($id) {
  15. $collection = $this->app->db->findOne("common/collections", ["_id" => $id]);
  16. if (!$collection) {
  17. return false;
  18. }
  19. $count = $this->app->module("collections")->collectionById($collection["_id"])->count();
  20. $collection["count"] = $count;
  21. return $this->render("collections:views/entries.php", compact('id', 'collection', 'count'));
  22. }
  23. public function entry($collectionId, $entryId=null) {
  24. $collection = $this->app->db->findOne("common/collections", ["_id" => $collectionId]);
  25. $entry = null;
  26. if (!$collection) {
  27. return false;
  28. }
  29. if ($entryId) {
  30. $col = "collection".$collection["_id"];
  31. $entry = $this->app->db->findOne("collections/{$col}", ["_id" => $entryId]);
  32. if (!$entry) {
  33. return false;
  34. }
  35. }
  36. $locales = $this->app->db->getKey("cockpit/settings", "cockpit.locales", []);
  37. return $this->render("collections:views/entry.php", compact('collection', 'entry', 'locales'));
  38. }
  39. }