Please enable JavaScript to view this site.

The manual for the JobRouter developer

The dashboard API provides the widget class under namespace \JobRouter\Api\Dashboard\v1, which must be expanded for your own widgets. A new widget must select the namespace to match the folder hierarchy.
For example, if a widget is defined in <Jobrouter>/dashboard/MyWidgets/ActiveUsers/ActiveUsers.php the namespace must be dashboard\MyWidgets\ActiveUsers and the class name must beActiveUsers that the widget can be integrated correctly.

In addition, at least the method getTitle has to be implemented, which determines the name for the collection.

 

<?php

namespace dashboard\MyWidgets\ActiveUsers;

 

use JobRouter\Api\Dashboard\v1\Widget;

 

class ActiveUsers extends Widget

{

    public function getTitle()

    {

        return CONST_MY_WIDGETS_ACTIVE_USERS;

    }

 

    public function getCategory()

    {

        return 'administration';

    }

 

    public function getDimensions()

    {

        return ([

            'minHeight' => 2,

            'minWidth' => 2,

            'maxHeight' => 4,

            'maxWidth' => 4,

        ]);

    }

 

    public function getData()

    {

        return [

            'items' => $this->getActiveUsers(),

            'noEntries' => CONST_MY_WIDGETS_NO_ENTRIES,

        ];

    }

 

    private function getActiveUsers()

    {

        $jobDB = $this->getJobDB();

        $sql = 'SELECT username as label, last_action as value FROM JRSESSIONS';

 

        $result = $jobDB->query($sql);

 

        if ($result === false) {

            return [];

        }

 

        return $jobDB->fetchAll($result);

    }

 

    public function isAuthorized()

    {

        return $this->getUser()->getUsername() == 'admin' || $this->getUser()->isInJobFunction('development');

    }

}