122 lines
3.0 KiB
PHP
Executable File
122 lines
3.0 KiB
PHP
Executable File
<?php declare(strict_types=1); namespace IR\App\Controllers; if (!defined('IR_START')) exit('<pre>No direct script access allowed</pre>');
|
|
|
|
use IR\App\Helpers\Authentication;
|
|
use IR\App\Helpers\DataTable;
|
|
use IR\App\Helpers\Page;
|
|
use IR\App\Helpers\Permissions;
|
|
use IR\App\Models\Specials\Subscriber;
|
|
use IR\Core\Application;
|
|
use IR\Exceptions\Types\PageException;
|
|
use IR\Http\Request;
|
|
use IR\Mvc\Controller;
|
|
|
|
/**
|
|
* @name Subscribes
|
|
* @description Teams Controller
|
|
*/
|
|
class Subscribers extends Controller {
|
|
|
|
/**
|
|
* @app
|
|
* @readwrite
|
|
*/
|
|
protected $app;
|
|
|
|
/**
|
|
* @app
|
|
* @readwrite
|
|
*/
|
|
protected $authenticatedUser;
|
|
|
|
/**
|
|
* @name init
|
|
* @description initializing process before the action method executed
|
|
* @once
|
|
* @protected
|
|
*/
|
|
public function init() {
|
|
$this->app = Application::getCurrent();
|
|
$this->app->database('clients')->connect();
|
|
$this->app->database('system')->connect();
|
|
if(!Authentication::isUserAuthenticated()) {
|
|
Page::redirect($this->app->http->request->getBaseURL() . RDS . 'auth' . RDS . 'login.' . DEFAULT_EXTENSION);
|
|
}
|
|
Authentication::checkUserRoles();
|
|
$this->authenticatedUser = Authentication::getAuthenticatedUser();
|
|
}
|
|
|
|
/**
|
|
* @name main
|
|
* @description the main action
|
|
* @before init
|
|
* @after closeConnections,checkForMessage
|
|
*/
|
|
public function main() {
|
|
$access = Permissions::checkForAuthorization($this->authenticatedUser,__CLASS__,__FUNCTION__);
|
|
if($access == false) {
|
|
throw new PageException('Access Denied !',403);
|
|
}
|
|
$columnsArray = [
|
|
'id',
|
|
'email',
|
|
'created_date',
|
|
];
|
|
$columns = Page::createTableHeader($columnsArray);
|
|
$filters = Page::createTableFilters($columnsArray);
|
|
$this->masterView->set([
|
|
'listSubscribeEmails' => 'true',
|
|
'tools' => 'true'
|
|
]);
|
|
$this->pageView->set([
|
|
'columns' => $columns,
|
|
'filters' => $filters
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @name get
|
|
* @description the get action
|
|
* @before init
|
|
* @after closeConnections
|
|
*/
|
|
public function get() {
|
|
$access = Permissions::checkForAuthorization($this->authenticatedUser,__CLASS__,'main');
|
|
if($access == false) {
|
|
throw new PageException('Access Denied !',403);
|
|
}
|
|
$data = $this->app->http->request->retrieve(Request::ALL,Request::POST);
|
|
if(count($data)) {
|
|
$columns = [
|
|
'id',
|
|
'email',
|
|
'created_date'
|
|
];
|
|
die(
|
|
json_encode(
|
|
DataTable::init($data,'specials.subscribers',$columns,new Subscriber(),'subscribers','DESC', null, false, false, 'clients')
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @name closeConnections
|
|
* @description close all connections
|
|
* @once
|
|
* @protected
|
|
*/
|
|
public function closeConnections() {
|
|
$this->app->database('clients')->disconnect();
|
|
$this->app->database('system')->disconnect();
|
|
}
|
|
|
|
/**
|
|
* @name checkForMessage
|
|
* @description checks for session messages
|
|
* @once
|
|
* @protected
|
|
*/
|
|
public function checkForMessage() {
|
|
Page::checkForMessage($this);
|
|
}
|
|
} |