src/Controller/IRMS/IrmsController.php line 45

Open in your IDE?
  1. <?php
  2. namespace App\Controller\IRMS;
  3. use App\Controller\BaseController;
  4. use App\Controller\SecurePageInterface;
  5. use DateTime;
  6. use Empire\Access\Access;
  7. use Empire\Access\Key;
  8. use Empire\Content\Category;
  9. use Empire\Content\Content;
  10. use Empire\Core\Approval;
  11. use Empire\Core\Branch;
  12. use Empire\Core\Core;
  13. use Empire\Core\Event;
  14. use Empire\Core\MeetingTime;
  15. use Empire\Core\News;
  16. use Empire\Core\Password;
  17. use Empire\Core\Page;
  18. use Empire\Core\PageCategory;
  19. use Empire\Core\Position;
  20. use Empire\Core\Rank;
  21. use Empire\Core\Unit;
  22. use Empire\Core\User;
  23. use Empire\Legacy\members;
  24. use Exception;
  25. use Symfony\Component\HttpFoundation\Request;
  26. use Symfony\Component\HttpFoundation\Response;
  27. use Symfony\Component\Routing\Annotation\Route;
  28. /**
  29.  * Class IrmsController
  30.  * @package App\Controller
  31.  * @Route("/irms")
  32.  */
  33. class IrmsController extends BaseController implements SecurePageInterface
  34. {
  35.     /**
  36.      * @Route("", name="irms")
  37.      * @param Request $request
  38.      * @return Response
  39.      * @throws Exception
  40.      */
  41.     public function portal(Request $request): Response
  42.     {
  43.         $eventNumber 15;
  44.         $page $request->query->get('e'0);
  45.         $offset $page $eventNumber;
  46.         return $this->render('irms/portal.twig', [
  47.             'gejs' => ['ajax''inplace''events''award'],
  48.             'news' => News::getLatestNews(News::NEWS_TYPE_DEV),
  49.             'events' => Event::getUnitEvents(Core::user(), true$offset$eventNumber),
  50.             'page' => $page,
  51.             'ranks' => Rank::getLatest(Core::user()),
  52.             'awards' => members::getLatestAwards(5),
  53.             'meeting' => new MeetingTime(),
  54.         ]);
  55.     }
  56.     /**
  57.      * @return Response
  58.      * @throws Exception
  59.      * @Route("/menu")
  60.      */
  61.     public function menu(): Response
  62.     {
  63.         $irms PageCategory::loadAll(Page::PAGE_TYPE_SECURE);
  64.         $ing PageCategory::loadAll(Page::PAGE_TYPE_PUBLIC);
  65.         return $this->render('irms/menu.twig', [
  66.             'gejs' => ['ajax''switcher'],
  67.             'irms' => $irms,
  68.             'ing' => $ing,
  69.         ]);
  70.     }
  71.     /**
  72.      * @return Response
  73.      * @throws Exception
  74.      * @Route("/content", methods={"GET"})
  75.      */
  76.     public function content(): Response
  77.     {
  78.         $ccats Category::loadAll();
  79.         $clist = [];
  80.         foreach ($ccats as $category) {
  81.             $clist[] = ['id' => $category->getID(), 'name' => $category->getName()];
  82.         }
  83.         return $this->render('irms/content.twig', [
  84.             'gejs' => ['ajax''switcher'],
  85.             'ccats' => $ccats,
  86.             'clist' => json_encode($clist),
  87.             'admin' => Core::user()->hasAccess(['content' => 2]),
  88.             'title' => 'Content Management',
  89.         ]);
  90.     }
  91.     /**
  92.      * @param Request $request
  93.      * @return string
  94.      * @throws
  95.      * @Route("/content", methods={"POST"})
  96.      */
  97.     public function content_post(Request $request): string
  98.     {
  99.         if ($request->get('mode') === 'page-edit') {
  100.             $page Content::load([$request->get('id')]);
  101.             if (Content::isValidPageSlug($request->get('url'))) {
  102.                 $page->updateFields([
  103.                     'CCAT_ID' => $request->get('category'),
  104.                     'CONT_PAGE' => Content::sanitiseUrl($request->get('url')),
  105.                     'CONT_UPDATED' => (new DateTime())->format('Y-m-d H:i:s')]);
  106.             } else {
  107.                 $this->addFlash('error''While attempting to update page <b>' $page->getName() . '</b> the following error occured:<br>Invalid characters for the url slug. Allowed characters are <code>a-z A-Z 0-9 . _ -</code>.');
  108.             }
  109.         } elseif ($request->get('mode') === 'add-page') {
  110.             try {
  111.                 Content::addPage($request->get('title'), $request->get('url'), $request->get('category'));
  112.             } catch (Exception $e) {
  113.                 $this->addFlash('error''Trying to add page <b>' $request->get('title') . '</b>, but an error occurred.<br><pre>' $e->getMessage() . '</pre>');
  114.             }
  115.         } elseif ($request->get('mode') === 'add-category') {
  116.             Category::addCategory($request->get('name'));
  117.         } elseif ($request->get('mode') === 'add-position') {
  118.             Access::setPositionKeys(Position::load([$request->get('position')]), [['!content'$request->get('category')]], false);
  119.         } elseif ($request->get('mode') === 'delete-position') {
  120.             Access::unsetPositionKeys(Position::load([$request->get('position')]), [['!content'$request->get('category')]]);
  121.         } else {
  122.             var_dump($_REQUEST);
  123.             return "";
  124.         }
  125.         return $this->redirect("content");
  126.     }
  127.     /**
  128.      * @return Response
  129.      * @Route("/relations")
  130.      */
  131.     public function relations(): Response
  132.     {
  133.         return $this->render('irms/relations.twig', [
  134.             'gejs' => ['ajax'],
  135.             'title' => "Manage Diplomatic Relations"
  136.         ]);
  137.     }
  138.     /**
  139.      * @return Response
  140.      * @Route("/structure")
  141.      */
  142.     public function structure(): Response
  143.     {
  144.         $branches Branch::loadAll();
  145.         $tree Unit::treeify(Unit::loadEditable(Core::user()));
  146.         if (Access::isDev(Core::user())) {
  147.             $keys Key::loadAll(Key::ORDER_BY_CAT);
  148.         } else {
  149.             $keys Access::userKeys(Core::user());
  150.         }
  151.         return $this->render('irms/structure.twig', [
  152.             'gejs' => ['ajax'],
  153.             'title' => 'Organisational Structure Management',
  154.             'branches' => $branches,
  155.             'tree' => $tree,
  156.             'tiers' => Position::POSITION_TIER_NAMES,
  157.             'keys' => $keys,
  158.             'regions' => Unit::REGIONS,
  159.         ]);
  160.     }
  161.     /**
  162.      * @return Response
  163.      * @Route("/units")
  164.      */
  165.     public function units(): Response
  166.     {
  167.         $branches Branch::loadAll();
  168.         $tree Unit::treeify(Unit::loadEditable(Core::user()));
  169.         if (Access::isDev(Core::user())) {
  170.             $keys Key::loadAll(Key::ORDER_BY_CAT);
  171.         } else {
  172.             $keys Access::userKeys(Core::user());
  173.         }
  174.         return $this->render('irms/units.twig', [
  175.             'gejs' => ['ajax'],
  176.             'title' => 'Units',
  177.             'branches' => $branches,
  178.             'tree' => $tree,
  179.             'tiers' => Position::POSITION_TIER_NAMES,
  180.             'keys' => $keys,
  181.             'regions' => Unit::REGIONS,
  182.         ]);
  183.     }
  184.     /**
  185.      * @return Response
  186.      * @Route("/units/addMember", methods={"GET"})
  187.      */
  188.     public function unitsAddMember(): Response
  189.     {
  190.         $branches Branch::loadAll();
  191.         $tree Unit::treeify(Unit::loadEditable(Core::user()));
  192.         return $this->render('irms/unitadd.twig', [
  193.             'gejs' => ['ajax'],
  194.             'title' => 'Add Member to Unit',
  195.             'branches' => $branches,
  196.             'tree' => $tree
  197.         ]);
  198.     }
  199.     /**
  200.      * @param Request $request
  201.      * @return Response
  202.      * @throws Exception
  203.      * @Route("/units/addMember", methods={"POST"})
  204.      */
  205.     public function unitsAddMember_post(Request $request): Response
  206.     {
  207.         $name $request->request->get('name');
  208.         if(User::exists($name)){
  209.             $position $request->request->get('position');
  210.             $user User::loadByName($name);
  211.             $uid $user->getID();
  212.             $user->addPosition(intval($position));
  213.             $this->addFlash('success''Added to position!');
  214.             return $this->redirect("/irms/profile~$uid");
  215.         } else {
  216.             $this->addFlash('error''User does not exist!');
  217.             return $this->redirect("/irms/units/addMember");
  218.         }
  219.     }
  220.     
  221.     /**
  222.      * @param Request $request
  223.      * @return Response
  224.      * @throws Exception
  225.      * @Route("/adminevents", methods={"GET"})
  226.      */
  227.     public function adminevents(Request $request): Response
  228.     {
  229.         $type $request->get('type') ? $request->get('type') : Event::EVENTTYPES['ADMIN'];
  230.         $min $request->get('min') ? $request->get('min') : 0;
  231.         $max $request->get('max') ? $request->get('max') : 100;
  232.         $events Event::getByType(intval($type), intval($min), intval($max));
  233.         return $this->render('irms/events.twig', [
  234.             'gejs' => ['ajax'],
  235.             'title' => "Admin Events",
  236.             'events' => $events,
  237.             'types' => Event::EVENTTYPES,
  238.         ]);
  239.     }
  240.     /**
  241.      * @return Response
  242.      * @Route("/library")
  243.      * @throws Exception
  244.      */
  245.     public function library(): Response
  246.     {
  247.         $branches = [
  248.             Branch::loadByName("Imperial Throne"),
  249.             Branch::loadByName("COMPNOR"),
  250.             Branch::loadByName("Imperial Army"),
  251.             Branch::loadByName("Imperial Navy"),
  252.             Branch::loadByName("Regional Government"),
  253.             Branch::loadByName("Ministry of Industry")
  254.         ];
  255.         $branches[0]->name "Empire";
  256.         return $this->render('irms/doclib.twig', [
  257.             'gejs' => ['ajax'],
  258.             'title' => "Document Library Management",
  259.             'branches' => $branches
  260.         ]);
  261.     }
  262.     /**
  263.      * @return Response
  264.      * @Route("/forum")
  265.      */
  266.     public function forum(): Response
  267.     {
  268.         return $this->render('irms/forum.twig', [
  269.             'gejs' => ['ajax'],
  270.             'title' => 'Forum Access Management'
  271.         ]);
  272.     }
  273.     /**
  274.      * @param int $member
  275.      * @return Response
  276.      * @Route("/adminresetpassword~{id}")
  277.      */
  278.     public function adminResetPassword(int $id)
  279.     {        
  280.         if(!Core::user()->hasAccess('dev')) {
  281.             $this->addFlash('error''Unauthorised access!');
  282.             return $this->render('irms/403.twig', ['gejs' => ['ajax']]);
  283.         }
  284.         $user User::load([$id]);
  285.         Password::forceResetPassword($user$this);
  286.         return $this->redirect('/irms');
  287.     }
  288.     /**
  289.      * @return Response
  290.      * @Route("/notifications", methods={"GET"}, name="notifications")
  291.      * @throws Exception
  292.      */
  293.     public function notifications(): Response
  294.     {
  295.         return $this->render('irms/notifications.twig', [
  296.             'gejs' => ['ajax'],
  297.             'title' => "Notifications",
  298.             'notifications' => Core::user()->getNotifications(),
  299.             'oldNotifications' => Core::user()->getOldNotifications(),
  300.         ]);
  301.     }
  302.     /**
  303.      * @return Response
  304.      * @Route("/approvals", methods={"GET"}, name="approvals")
  305.      * @throws Exception
  306.      */
  307.     public function approvals(): Response
  308.     {
  309.         return $this->render('irms/approvals.twig', [
  310.             'gejs' => ['ajax'],
  311.             'title' => "Approvals",
  312.             'approvals' => Core::user()->getApprovals(),
  313.             'oldApprovals' => Core::user()->getOldApprovals(),
  314.         ]);
  315.     }
  316. }