Files
wevads-platform/app/controllers/Plannings.php
2026-02-26 03:06:17 +01:00

151 lines
4.1 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>');
/**
* @framework iResponse Framework
* @version 1.0
* @author Amine Idrissi <contact@iresponse.tech>
* @date 2019
* @name Plannings.php
*/
# core
use IR\Core\Application as Application;
# mvc
use IR\Mvc\Controller as Controller;
# models
use IR\App\Models\Admin\User as User;
use IR\App\Models\Production\Team as Team;
# http
use IR\Http\Request as Request;
# helpers
use IR\App\Helpers\Authentication as Authentication;
use IR\App\Helpers\Page as Page;
use IR\App\Helpers\DataTable as DataTable;
use IR\App\Helpers\Permissions as Permissions;
# exceptions
use IR\Exceptions\Types\PageException as PageException;
/**
* @name Auth
* @description Plannings Controller
*/
class Plannings 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()
{
# set the current application to a local variable
$this->app = Application::getCurrent();
# connect to the database
$this->app->database('system')->connect();
# check for authentication
if(!Authentication::isUserAuthenticated())
{
Page::redirect($this->app->http->request->getBaseURL() . RDS . 'auth' . RDS . 'login.' . DEFAULT_EXTENSION);
}
# check users roles
Authentication::checkUserRoles();
# get the authenticated user
$this->authenticatedUser = Authentication::getAuthenticatedUser();
}
/**
* @name main
* @description the main action
* @before init
* @after closeConnections
*/
public function main()
{
# check for permissions
$access = Permissions::checkForAuthorization($this->authenticatedUser,__CLASS__,__FUNCTION__);
if($access == false)
{
throw new PageException('Access Denied !',403);
}
$teams = Team::all(Team::FETCH_ARRAY,['status = ?',['Activated']],['id','name', 'team_members_ids'],'naturalsort(name)','ASC');
$users = $teams ? User::all(User::FETCH_ARRAY,['id IN ?',[explode(',',$teams[0]['team_members_ids'])]],['id','first_name','last_name', 'production_id'], 'id', 'ASC') : [];
$weeks = [];
$dd = "01-01-".date("Y");
for($i = 1; $i <= 52; $i++) {
$weeks[] = $i;
}
//get actual week number
$this->pageView->set([
'users' => $users,
'weeks' => $weeks,
'teams' => $teams,
'actual_week' => intval(date("W")),
'day_number' => date("N"),
'update_access' => Permissions::isMenuiTemAuthorized($this->authenticatedUser,'add-plannings')
]);
}
public function getTeamMembers($team_id)
{
# check for permissions
$access = Permissions::checkForAuthorization($this->authenticatedUser,__CLASS__,__FUNCTION__);
if($access == false)
{
throw new PageException('Access Denied !',403);
}
$users = [];
$this->pageView->set([
'users' => $users,
]);
}
/**
* @name closeConnections
* @description close all connections
* @once
* @protected
*/
public function closeConnections()
{
# connect to the database
$this->app->database('system')->disconnect();
$this->app->database('clients')->disconnect();
}
/**
* @name checkForMessage
* @description checks for session messages
* @once
* @protected
*/
public function checkForMessage()
{
# check for message
Page::checkForMessage($this);
}
}