method __construct documentation in bbn\Appui\Statistic

Constructor.

function(bbn\Db $db, string $code, array $cfg = []) { // Parent constructors parent::__construct($db); self::optionalInit(); // Db ok if (!$this->db->check()) { throw new Exception(X::_("The database is in error mode")); } // History ok if (!History::isInit()) { throw new Exception(X::_("History is disabled")); } // Option found if (!($this->id_option = self::getOptionId($code, 'active'))) { throw new Exception(X::_("No id option corresponding to code in active statistics")); } // Cfg retrieved if (!($this->ocfg = self::getOption($this->id_option))) { throw new Exception(X::_("No cfg option corresponding to id in active statistics")); } $cfg = array_merge($cfg, $this->ocfg); // Params ok if (!X::hasProps($cfg, ['type', 'table'], true) || !X::is_string($cfg['type'], $cfg['table'])) { X::log($cfg); throw new Exception(X::_("Invalid configuration")); } // Correcting case $cfg['type'] = strtolower($cfg['type']); // Type accepted if (X::indexOf(self::$types, $cfg['type']) === -1) { throw new Exception(X::_("Invalid type in configuration")); } // History config retrieved if ($this->hcfg = History::getTableCfg($cfg['table'])) { // For sum and avg types field is mandatory if ((X::indexOf(['sum', 'avg'], $cfg['type']) > -1) && !isset($cfg['field'])) { throw new Exception(X::_("The field parameter is mandatory for sum and avg types")); } $this->code = $code; $this->dbo = new \bbn\Appui\Database($this->db); if (isset($cfg['field'])) { if (!($this->_id_field = $this->dbo->columnId($cfg['field'], $cfg['table']))) { throw new Exception(X::_("The field parameter must be a known field of the table (asked %s in %s)", $cfg['field'], $cfg['table'])); } } if (($cfg['type'] === 'update') && empty($this->_id_field)) { throw new Exception(X::_("The field parameter is mandatory for statistics of type update")); } $this->type = $cfg['type']; $this->cfg = $cfg; if (!empty($cfg['inserter']) && bbn\Str::isUid($cfg['inserter'])) { $this->inserter = $cfg['inserter']; } if (!empty($cfg['updater']) && bbn\Str::isUid($cfg['updater'])) { $this->updater = $cfg['updater']; } if (!empty($cfg['deleter']) && bbn\Str::isUid($cfg['deleter'])) { $this->deleter = $cfg['deleter']; } // Creating the configuration $req = $this->_set_request_cfg(); X::log([$cfg, $req], 'stat'); $this->db_cfg = $this->db->processCfg($req); } // Right props in cfg }

Constructor. BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way

This website uses cookies to ensure you get the best experience on our website.