admin/controllers/Logs.php
public function event()
    {
        if (!userHasPermission('admin:admin:logs:event:browse')) {
            unauthorised();
        }

        // --------------------------------------------------------------------------

        //  Set method info
        $this->data['page']->title = 'Browse Events';

        // --------------------------------------------------------------------------

        $sTableAlias = $this->event->getTableAlias();

        // --------------------------------------------------------------------------

        //  Get pagination and search/sort variables
        $oInput     = Factory::service('Input');
        $iPage      = (int) $oInput->get('page') ?: 0;
        $iPerPage   = (int) $oInput->get('perPage') ?: 50;
        $sSortOn    = $oInput->get('sortOn') ?: $sTableAlias . '.created';
        $sSortOrder = $oInput->get('sortOrder') ?: 'desc';
        $sKeywords  = $oInput->get('keywords') ?: '';

        // --------------------------------------------------------------------------

        //  Define the sortable columns
        $aSortColumns = [
            $sTableAlias . '.created' => 'Created',
            $sTableAlias . '.type'    => 'Type',
        ];

        // --------------------------------------------------------------------------

        //  Define the $aData variable for the queries
        $aData = [
            'sort'     => [
                [$sSortOn, $sSortOrder],
            ],
            'keywords' => $sKeywords,
        ];

        //  Are we downloading? Or viewing?
        if ($oInput->get('dl') && userHasPermission('admin:admin:logs:event:download')) {

            //  Get all items for the search, the view will iterate over the resultset
            $oEvents = $this->event->getAllRawQuery(null, null, $aData);

            Helper::loadCsv($oEvents, 'export-events-' . toUserDatetime(null, 'Y-m-d_h-i-s') . '.csv');

        } else {

            //  Get the items for the page
            $iTotalRows           = $this->event->countAll($aData);
            $this->data['events'] = $this->event->getAll($iPage, $iPerPage, $aData);

            //  Set Search and Pagination objects for the view
            $this->data['search']     = Helper::searchObject(true, $aSortColumns, $sSortOn, $sSortOrder, $iPerPage, $sKeywords);
            $this->data['pagination'] = Helper::paginationObject($iPage, $iPerPage, $iTotalRows);

            //  Add the header button for downloading
            if (userHasPermission('admin:admin:logs:event:download')) {

                //  Build the query string, so that the same search is applies
                $oInput               = Factory::service('Input');
                $aParams              = [];
                $aParams['dl']        = true;
                $aParams['sortOn']    = $oInput->get('sortOn');
                $aParams['sortOrder'] = $oInput->get('sortOrder');
                $aParams['keywords']  = $oInput->get('keywords');

                $aParams = array_filter($aParams);
                $aParams = http_build_query($aParams);

                Helper::addHeaderButton('admin/admin/logs/event?' . $aParams, 'Download As CSV');
            }

            Helper::loadView('event/index');
        }
    }
public function event()
    {
        if (!userHasPermission('admin:admin:logs:event:browse')) {
            unauthorised();
        }

        // --------------------------------------------------------------------------

        //  Set method info
        $this->data['page']->title = 'Browse Events';

        // --------------------------------------------------------------------------

        $sTableAlias = $this->event->getTableAlias();

        // --------------------------------------------------------------------------

        //  Get pagination and search/sort variables
        $oInput     = Factory::service('Input');
        $iPage      = (int) $oInput->get('page') ?: 0;
        $iPerPage   = (int) $oInput->get('perPage') ?: 50;
        $sSortOn    = $oInput->get('sortOn') ?: $sTableAlias . '.created';
        $sSortOrder = $oInput->get('sortOrder') ?: 'desc';
        $sKeywords  = $oInput->get('keywords') ?: '';

        // --------------------------------------------------------------------------

        //  Define the sortable columns
        $aSortColumns = [
            $sTableAlias . '.created' => 'Created',
            $sTableAlias . '.type'    => 'Type',
        ];

        // --------------------------------------------------------------------------

        //  Define the $aData variable for the queries
        $aData = [
            'sort'     => [
                [$sSortOn, $sSortOrder],
            ],
            'keywords' => $sKeywords,
        ];

        //  Are we downloading? Or viewing?
        if ($oInput->get('dl') && userHasPermission('admin:admin:logs:event:download')) {

            //  Get all items for the search, the view will iterate over the resultset
            $oEvents = $this->event->getAllRawQuery(null, null, $aData);

            Helper::loadCsv($oEvents, 'export-events-' . toUserDatetime(null, 'Y-m-d_h-i-s') . '.csv');

        } else {

            //  Get the items for the page
            $iTotalRows           = $this->event->countAll($aData);
            $this->data['events'] = $this->event->getAll($iPage, $iPerPage, $aData);

            //  Set Search and Pagination objects for the view
            $this->data['search']     = Helper::searchObject(true, $aSortColumns, $sSortOn, $sSortOrder, $iPerPage, $sKeywords);
            $this->data['pagination'] = Helper::paginationObject($iPage, $iPerPage, $iTotalRows);

            //  Add the header button for downloading
            if (userHasPermission('admin:admin:logs:event:download')) {

                //  Build the query string, so that the same search is applies
                $oInput               = Factory::service('Input');
                $aParams              = [];
                $aParams['dl']        = true;
                $aParams['sortOn']    = $oInput->get('sortOn');
                $aParams['sortOrder'] = $oInput->get('sortOrder');
                $aParams['keywords']  = $oInput->get('keywords');

                $aParams = array_filter($aParams);
                $aParams = http_build_query($aParams);

                Helper::addHeaderButton('admin/admin/logs/event?' . $aParams, 'Download As CSV');
            }

            Helper::loadView('event/index');
        }
    }
Browse Site Events
@return void