<?php

namespace App\Config;

class SystemVars extends DbUniAssocVarsAbstract
{

	/**
	 * The 'var' column name for this table.
	 * @var String
	 */
	protected $dbTablePkCol = 'var';

	/**
	 * The column that contains the actual value for this association.
	 * @var String
	 */
	protected $dbTableValueCol = 'value';

	/**
	 * The prefix for the system vars - not set.
	 * @var String
	 */
	protected $dbVarsPrefix = '';

	/**
	 * Indicates the table column name which stores the last update time for the current record;
	 * if nothing is set, the info is not saved in the db.
	 * @var String
	 */
	protected $dbTableLastUpdateTimeCol = 'lastUpdate';


	protected function getDbTableName()
	{
		global $DBTSystemVars;
		return $DBTSystemVars;
	}

	/**
	 * {@inheritDoc}
	 * @see \App\Config\BaseAbstract::save_check()
	 */
	protected function save_check()
	{
		// check parent validations - dbVarsList
		parent::save_check();

		// check fields length
		if ($this->itemsList) {
			foreach($this->itemsList as $var=>$value) {
				if (mb_strlen((string)$value)>10000) {
					$this->addErrorMessage("The var `{$var}` in SystemVars must not have a length greater than 10000 chars.");
				}
			}
		}

	}

}


