<?php

namespace App\Reports\Sources\UsersAccess;

class PopulateQuickColumns extends \App\Reports\Sources\PopulateAbstract
{

	public function populate() :void
	{

		// INITS ----------------------------------------------------------------------------------

		global $DBTOffices, $DBTDepartments, $DBTUserProfiles;

		$reportTable = $this->tableManager->getTableName();

		$activeColumns = array_keys( $this->columnsManager->getStdColumns() );

		// UPDATE USER DETAILS/////////////////////////////////////////////////////////////////////
		$this->reportGenerationStatusUpdate('extractMainDataFromDb', 'updateUserDetails', 0);

		// update the office name
		$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $activeColumns);
		$reportCopyInfo->populateSimple($DBTOffices, 'officeName', 'idOffice', 'name');

		// update the department name
		$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $activeColumns);
		$reportCopyInfo->populateSimple($DBTDepartments, 'departmentName', 'idDepartment', 'name');


		// UPDATE ACCESS DETAILS///////////////////////////////////////////////////////////////////
		$this->reportGenerationStatusUpdate('extractMainDataFromDb', 'updateAccessDetails', 0);

		// update the profile name
		$reportCopyInfo = new \App\Reports\Db\ManageRecords\UpdateSimple($reportTable, $activeColumns);
		$reportCopyInfo->populateSimple($DBTUserProfiles, 'profileName', 'idProfile', 'name');

		// load some extra langs
		if (in_array('sectionName', $activeColumns)) {
			\App\Loader_Lang::getInstance()->loadAppFile("_customLoad/usersAccess/options.lang.php");
			$_LANG = \App\Loader_Lang::getInstance()->getAll();
		}

		// update the section name (option)
		$reportCopyInfo = new \App\Reports\Db\ManageRecords\Update($reportTable, 'rep', $activeColumns);
		$reportCopyInfo->addCaseStructureColumn("sectionName",   "idSection",   (Array)$_LANG['usersAccess']['options']);
		$reportCopyInfo->addFilter("rep.type", "=", "option");
		$reportCopyInfo->populate();

		// update the section name (section)
		$reportCopyInfo = new \App\Reports\Db\ManageRecords\Update($reportTable, 'rep', $activeColumns);
		$reportCopyInfo->addCaseStructureColumn("sectionName",   "idSection",   (Array)$_LANG['menu']);
		$reportCopyInfo->addFilter("rep.type", "=", "section");
		$reportCopyInfo->populate();

	}

}

