Example #1
0
File: menu.php Project: ratiw/petro
 public static function _init()
 {
     \Lang::load('menu');
     \Config::load('petro', true);
     static::$table = \Config::get('petro.menu.table', 'menu');
     static::$template = \Config::get('petro.template.menu');
 }
Example #2
0
 public static function table()
 {
     if (!static::$table) {
         static::$table = lcfirst(get_called_class()) . 's';
     }
     return static::$table;
 }
Example #3
0
    /**
     * @static
     * @return void
     */
    public static function _init()
    {
        \Config::load('dbroutes', true);

        static::$table = \Config::get('dbroutes.db.table', 'dbroutes');
        static::$cache_id = \Config::get('dbroutes.cache.cacheid', 'routes');
    }
Example #4
0
 /**
  * Return instance of table for active record, if DfTable don't exist create instance and save
  * @return DfTable
  */
 private static function table()
 {
     if (static::$table === null) {
         static::$table = new DfTable(static::getDb(), static::getName());
     }
     return static::$table;
 }
Example #5
0
 /**
  * Gets all the group info.
  *
  * @param   string|int  Group id or name
  * @return  void
  */
 public function __construct($id = null, $check_exists = false)
 {
     static::$table = strtolower(Config::get('sentry::sentry.table.groups'));
     static::$join_table = strtolower(Config::get('sentry::sentry.table.users_groups'));
     $db_instance = trim(Config::get('sentry::sentry.db_instance'));
     static::$group_identifier = strtolower(Config::get('sentry::sentry.identifiers.group_id'));
     // db_instance check
     if (!empty($db_instance)) {
         static::$db_instance = $db_instance;
     }
     if ($id === null) {
         return;
     }
     if (is_numeric($id)) {
         if ($id <= 0) {
             throw new SentryGroupException(__('sentry::sentry.invalid_group_id'));
         }
         $field = 'id';
     } else {
         $field = 'name';
     }
     $group = DB::connection(static::$db_instance)->table(static::$table)->where($field, '=', $id)->first();
     // if there was a result - update user
     if ($group !== null) {
         if ($check_exists) {
             return true;
         }
         $this->group = get_object_vars($group);
     } else {
         throw new SentryGroupNotFoundException(__('sentry::sentry.group_not_found', array('group' => $id)));
     }
 }
Example #6
0
 static function new_with($name, $settings)
 {
     $me = new static();
     $me->name = $name;
     $me->containee = ref($settings['db']);
     $me->base_table = ref($me->table($settings['base_table']->name));
     return $me;
 }
Example #7
0
 /**
  * Table name getter/setter
  */
 public static function table($tableName = null)
 {
     if (null !== $tableName) {
         static::$table = $tableName;
         return $this;
     }
     return static::$table;
 }
Example #8
0
 private static function Create($operation, $table = null)
 {
     $q = new static();
     $q->operation($operation);
     if (!is_null($table)) {
         $q->table($table);
     }
     return $q;
 }
Example #9
0
 /**
  * Gets the table names
  */
 public static function _init()
 {
     static::$table = strtolower(Config::get('sentry.table.groups'));
     static::$join_table = strtolower(Config::get('sentry.table.users_groups'));
     $_db_instance = trim(Config::get('sentry.db_instance'));
     // db_instance check
     if (!empty($_db_instance)) {
         static::$db_instance = $_db_instance;
     }
 }
 public static function table()
 {
     if (!static::$table) {
         static::$table = strtolower(str_replace(chr(92), '_', get_class_name(static::class)));
         // Инициализация таблицы
         if (static::table()[0] !== '`') {
             static::$table = '`' . static::table() . '`';
         }
     }
     return static::$table;
 }
Example #11
0
 /**
  * Constructor.
  * @param array $databaseConfiguration
  * @param Table $table Log table
  * @param bool|int $level The minimum logging level at which this handler will be triggered
  * @param boolean $bubble
  */
 public function __construct(array $databaseConfiguration, Table $table, $level = Logger::DEBUG, $bubble = true)
 {
     DatabaseConnectionFactory::create(static::DATABASE, $databaseConfiguration);
     static::$table = $table;
     /* @todo Check if the table exists, otherwise create
             if (!$table->exists()) {
     
             }
             */
     parent::__construct($level, $bubble);
 }
Example #12
0
 public function stor($id, $data, $date, $table)
 {
     static::$table = $table;
     $load = new Load();
     $load->server_id = $id;
     $load->load_one = $data->one;
     $load->load_five = $data->five;
     $load->load_fifteen = $data->fifteen;
     $load->load_uptime = $data->uptime;
     $load->load_user = $data->user;
     $load->load_date = $date;
     $load->save();
 }
Example #13
0
 /**
  * Initialise the class
  *
  * @param
  * @return	
  */
 public static function _init()
 {
     \Config::load('dbpage', true);
     static::$table = \Config::get('dbpage.db.table', 'pages');
     $installed = \Config::get('dbpage.db.installed', false);
     if (!$installed) {
         if (!static::_install_db()) {
             throw new \Exception('Could not create db pages table.');
         }
         \Config::set('dbpage.db', array('table' => static::$table, 'installed' => true));
         \Config::save('dbpage', \Config::get('dbpage'));
     }
 }
Example #14
0
 /**
  * Loads in the migrations config file, checks to see if the migrations
  * table is set in the database (if not, create it), and reads in all of
  * the versions from the DB.
  *
  * @return  void
  */
 public static function _init()
 {
     logger(Fuel::L_DEBUG, 'Migrate class initialized');
     \Config::load('migrations', true);
     static::$table = \Config::get('migrations.table', static::$table);
     // installs or upgrades table
     static::table_check();
     //get all versions from db
     $migrations = \DB::select()->from(static::$table)->execute()->as_array();
     foreach ($migrations as $migration) {
         static::$version[$migration['type']][$migration['name']] = (int) $migration['version'];
     }
 }
Example #15
0
 public static function _init()
 {
     logger(Fuel::L_DEBUG, 'Migrate class initialized');
     \Config::load('migrations', true);
     static::$table = \Config::get('migrations.table', static::$table);
     \DBUtil::create_table(static::$table, array('current' => array('type' => 'int', 'constraint' => 11, 'null' => false, 'default' => 0)));
     // Check if there is a version
     $current = \DB::select('current')->from(static::$table)->execute()->get('current');
     // Not set, so we are on 0
     if ($current === null) {
         \DB::insert(static::$table)->set(array('current' => '0'))->execute();
     } else {
         static::$version = (int) $current;
     }
 }
Example #16
0
 /**
  * loads in the migrations config file, checks to see if the migrations
  * table is set in the database (if not, create it), and reads in all of
  * the versions from the DB.
  *
  * @return  void
  */
 public static function _init()
 {
     logger(\Fuel::L_DEBUG, 'Migrate class initialized');
     // load the migrations config
     \Config::load('migrations', true);
     // set the name of the table containing the installed migrations
     static::$table = \Config::get('migrations.table', static::$table);
     // installs or upgrades the migration table to the current schema
     static::table_version_check();
     //get all installed migrations from db
     $migrations = \DB::select()->from(static::$table)->order_by('type', 'ASC')->order_by('name', 'ASC')->order_by('migration', 'ASC')->execute()->as_array();
     // convert the db migrations to match the config file structure
     foreach ($migrations as $migration) {
         isset(static::$migrations[$migration['type']]) or static::$migrations[$migration['type']] = array();
         static::$migrations[$migration['type']][$migration['name']][] = $migration['migration'];
     }
 }
Example #17
0
 /**
  * Fonction de creation d'une nouvelle table dans la base de donnée.
  *
  * @param string $table
  * @param callable $cb
  * @param bool $displaySql
  */
 public static function create($table, callable $cb, $displaySql = false)
 {
     static::$table = $table;
     $fields = new Fields($table);
     call_user_func_array($cb, [$fields]);
     $sql = (new StatementMaker($fields))->toCreateTableStatement();
     if ($sql == null) {
         die("Please check your 'up' method.\n");
     }
     if ($displaySql) {
         echo $sql . "\n";
     }
     static::$data = $fields->getBindData();
     if (Database::statement($sql)) {
         echo "{$table} table created.\n";
     }
 }
 public static function prepare()
 {
     if (static::$adapter !== null) {
         return;
     }
     $dbSettings = \Phramework\Phramework::getSetting('query-log', 'database');
     if (!$dbSettings) {
         throw new \Phramework\Exceptions\ServerException('query-log.database is not configured');
     }
     if (is_array($dbSettings)) {
         $dbSettings = (object) $dbSettings;
     }
     $adapterNamespace = $dbSettings->adapter;
     $adapter = new $adapterNamespace((array) $dbSettings);
     if (!$adapter instanceof \Phramework\Database\IAdapter) {
         throw new \Exception(sprintf('Class "%s" is not implementing Phramework\\Database\\IAdapter', $adapterNamespace));
     }
     if (isset($dbSettings->schema)) {
         static::$schema = $dbSettings->schema;
     }
     static::$table = isset($dbSettings->table) ? $dbSettings->table : 'query_log';
     static::setAdapter($adapter);
 }
Example #19
0
 /**
  * Return only ids
  * @param  string $queryLogId Foreign key
  * @return string[]
  */
 public static function getRelationshipByQueryLog($queryLogId)
 {
     //Access QueryLog object by this id to get the request_id
     $queryLogObject = QueryLog::getById($queryLogId);
     if (!$queryLogObject) {
         return [];
     }
     $requestId = $queryLogObject->attributes->request_id;
     SystemLogAdapter::prepare();
     $table = static::$table = SystemLogAdapter::getTable();
     $schema = SystemLogAdapter::getSchema();
     //Include schema if is set
     $schema = $schema ? sprintf('"%s".', $schema) : '';
     $ids = SystemLogAdapter::executeAndFetchAllArray(sprintf('SELECT "id"
             FROM %s"%s"
             WHERE "request_id" = ?', $schema, $table), [$requestId]);
     return array_map('strval', $ids);
 }
 /**
  * Initializes static fields, including a call to Columns() to get field types.
  */
 protected static function Init()
 {
     if (is_null(static::$table)) {
         static::$table = strtolower(get_called_class());
     }
     if (is_null(static::$conn) && isset($GLOBALS['conn'])) {
         static::$conn = $GLOBALS['conn'];
     }
     if (is_null(static::$cache) && isset($GLOBALS['cache'])) {
         static::$cache = $GLOBALS['cache'];
     }
     if (is_null(static::$columns)) {
         static::$columns = static::Columns();
     }
 }
Example #21
0
 /**
  * This method return a transliterated version of the specified string.
  *
  * @access public
  * @param mixed $string
  * @return Common\String                                    the newly transliterated string
  *
  * @see http://www.php.net/manual/en/transliterator.transliterate.php
  * @see http://stackoverflow.com/questions/4794647/php-dealing-special-characters-with-iconv
  * @see http://stackoverflow.com/questions/6837148/change-foreign-characters-to-normal-equivalent
  */
 public static function transliterate($string)
 {
     if (static::$table === NULL) {
         static::$table = array('á' => 'a', 'Á' => 'A', 'à' => 'a', 'À' => 'A', 'ă' => 'a', 'Ă' => 'A', 'â' => 'a', 'Â' => 'A', 'å' => 'a', 'Å' => 'A', 'ã' => 'a', 'Ã' => 'A', 'ą' => 'a', 'Ą' => 'A', 'ā' => 'a', 'Ā' => 'A', 'ä' => 'ae', 'Ä' => 'AE', 'æ' => 'ae', 'Æ' => 'AE', 'ḃ' => 'b', 'Ḃ' => 'B', 'ć' => 'c', 'Ć' => 'C', 'ĉ' => 'c', 'Ĉ' => 'C', 'č' => 'c', 'Č' => 'C', 'ċ' => 'c', 'Ċ' => 'C', 'ç' => 'c', 'Ç' => 'C', 'ď' => 'd', 'Ď' => 'D', 'ḋ' => 'd', 'Ḋ' => 'D', 'đ' => 'd', 'Đ' => 'D', 'ð' => 'dh', 'Ð' => 'Dh', 'é' => 'e', 'É' => 'E', 'è' => 'e', 'È' => 'E', 'ĕ' => 'e', 'Ĕ' => 'E', 'ê' => 'e', 'Ê' => 'E', 'ě' => 'e', 'Ě' => 'E', 'ë' => 'e', 'Ë' => 'E', 'ė' => 'e', 'Ė' => 'E', 'ę' => 'e', 'Ę' => 'E', 'ē' => 'e', 'Ē' => 'E', 'ḟ' => 'f', 'Ḟ' => 'F', 'ƒ' => 'f', 'Ƒ' => 'F', 'ğ' => 'g', 'Ğ' => 'G', 'ĝ' => 'g', 'Ĝ' => 'G', 'ġ' => 'g', 'Ġ' => 'G', 'ģ' => 'g', 'Ģ' => 'G', 'ĥ' => 'h', 'Ĥ' => 'H', 'ħ' => 'h', 'Ħ' => 'H', 'í' => 'i', 'Í' => 'I', 'ì' => 'i', 'Ì' => 'I', 'î' => 'i', 'Î' => 'I', 'ï' => 'i', 'Ï' => 'I', 'ĩ' => 'i', 'Ĩ' => 'I', 'į' => 'i', 'Į' => 'I', 'ī' => 'i', 'Ī' => 'I', 'ĵ' => 'j', 'Ĵ' => 'J', 'ķ' => 'k', 'Ķ' => 'K', 'ĺ' => 'l', 'Ĺ' => 'L', 'ľ' => 'l', 'Ľ' => 'L', 'ļ' => 'l', 'Ļ' => 'L', 'ł' => 'l', 'Ł' => 'L', 'ṁ' => 'm', 'Ṁ' => 'M', 'ń' => 'n', 'Ń' => 'N', 'ň' => 'n', 'Ň' => 'N', 'ñ' => 'n', 'Ñ' => 'N', 'ņ' => 'n', 'Ņ' => 'N', 'ó' => 'o', 'Ó' => 'O', 'ò' => 'o', 'Ò' => 'O', 'ô' => 'o', 'Ô' => 'O', 'ő' => 'o', 'Ő' => 'O', 'õ' => 'o', 'Õ' => 'O', 'œ' => 'oe', 'ø' => 'oe', 'Ø' => 'OE', 'ō' => 'o', 'Ō' => 'O', 'ơ' => 'o', 'Ơ' => 'O', 'ö' => 'oe', 'Ö' => 'OE', 'ṗ' => 'p', 'Ṗ' => 'P', 'ŕ' => 'r', 'Ŕ' => 'R', 'ř' => 'r', 'Ř' => 'R', 'ŗ' => 'r', 'Ŗ' => 'R', 'ś' => 's', 'Ś' => 'S', 'ŝ' => 's', 'Ŝ' => 'S', 'š' => 's', 'Š' => 'S', 'ṡ' => 's', 'Ṡ' => 'S', 'ş' => 's', 'Ş' => 'S', 'ș' => 's', 'Ș' => 'S', 'ß' => 'SS', 'ť' => 't', 'Ť' => 'T', 'ṫ' => 't', 'Ṫ' => 'T', 'ţ' => 't', 'Ţ' => 'T', 'ț' => 't', 'Ț' => 'T', 'ŧ' => 't', 'Ŧ' => 'T', 'ú' => 'u', 'Ú' => 'U', 'ù' => 'u', 'Ù' => 'U', 'ŭ' => 'u', 'Ŭ' => 'U', 'û' => 'u', 'Û' => 'U', 'ů' => 'u', 'Ů' => 'U', 'ű' => 'u', 'Ű' => 'U', 'ũ' => 'u', 'Ũ' => 'U', 'ų' => 'u', 'Ų' => 'U', 'ū' => 'u', 'Ū' => 'U', 'ư' => 'u', 'Ư' => 'U', 'ü' => 'ue', 'Ü' => 'UE', 'ẃ' => 'w', 'Ẃ' => 'W', 'ẁ' => 'w', 'Ẁ' => 'W', 'ŵ' => 'w', 'Ŵ' => 'W', 'ẅ' => 'w', 'Ẅ' => 'W', 'ý' => 'y', 'Ý' => 'Y', 'ỳ' => 'y', 'Ỳ' => 'Y', 'ŷ' => 'y', 'Ŷ' => 'Y', 'ÿ' => 'y', 'Ÿ' => 'Y', 'ź' => 'z', 'Ź' => 'Z', 'ž' => 'z', 'Ž' => 'Z', 'ż' => 'z', 'Ż' => 'Z', 'þ' => 'th', 'Þ' => 'Th', 'µ' => 'u', 'а' => 'a', 'А' => 'a', 'б' => 'b', 'Б' => 'b', 'в' => 'v', 'В' => 'v', 'г' => 'g', 'Г' => 'g', 'д' => 'd', 'Д' => 'd', 'е' => 'e', 'Е' => 'e', 'ё' => 'e', 'Ё' => 'e', 'ж' => 'zh', 'Ж' => 'zh', 'з' => 'z', 'З' => 'z', 'и' => 'i', 'И' => 'i', 'й' => 'j', 'Й' => 'j', 'к' => 'k', 'К' => 'k', 'л' => 'l', 'Л' => 'l', 'м' => 'm', 'М' => 'm', 'н' => 'n', 'Н' => 'n', 'о' => 'o', 'О' => 'o', 'п' => 'p', 'П' => 'p', 'р' => 'r', 'Р' => 'r', 'с' => 's', 'С' => 's', 'т' => 't', 'Т' => 't', 'у' => 'u', 'У' => 'u', 'ф' => 'f', 'Ф' => 'f', 'х' => 'h', 'Х' => 'h', 'ц' => 'c', 'Ц' => 'c', 'ч' => 'ch', 'Ч' => 'ch', 'ш' => 'sh', 'Ш' => 'sh', 'щ' => 'sch', 'Щ' => 'sch', 'ъ' => '', 'Ъ' => '', 'ы' => 'y', 'Ы' => 'y', 'ь' => '', 'Ь' => '', 'э' => 'e', 'Э' => 'e', 'ю' => 'ju', 'Ю' => 'ju', 'я' => 'ja', 'Я' => 'ja');
     }
     $buffer = static::valueOf($string)->__toString();
     //if (function_exists('transliterator_transliterate')) {
     //	$buffer = transliterator_transliterate('Any-Latin; Latin-ASCII; NFD; NFC', $buffer); // TODO need to verify flags
     //}
     //else if (function_exists('iconv')) {
     //	setlocale(LC_ALL, 'en_US.UTF8');
     //	$buffer = iconv(Core\Data\Charset::UTF_8_ENCODING, Core\Data\Charset::ISO_8859_1_ENCODING'//TRANSLIT//IGNORE', $buffer); // TODO need to find the correct flags
     //}
     //else {
     $buffer = str_replace(array_keys(static::$table), array_values(static::$table), $buffer);
     //}
     return new static($buffer);
 }
Example #22
0
 /**
  * Method to parse the table name from the class name
  *
  * @param string $class
  * @return string
  */
 protected static function parseTableName($class)
 {
     if ($class != 'Pop\\Db\\Record') {
         if (strpos($class, '_') !== false) {
             $cls = substr($class, strrpos($class, '_') + 1);
         } else {
             if (strpos($class, '\\') !== false) {
                 $cls = substr($class, strrpos($class, '\\') + 1);
             } else {
                 $cls = $class;
             }
         }
         $cls = static::camelCaseToUnderscore($cls);
         if (static::$prefix . $cls != static::$table) {
             static::$table = static::$prefix . $cls;
         }
     }
 }
Example #23
0
 /**
  * Create a collection of records from a SQL query.
  *
  * @param string $query
  * @param array $parameters
  * @return array
  */
 public static function fromQuery($query, $parameters)
 {
     $record = new static();
     $result = $record->table()->query($query, $parameters);
     return array_map(function ($r) {
         return static::fromArray($r);
     }, $result);
 }
Example #24
0
 public static function reset($sql = '')
 {
     // 保存最后的数据库操作语句
     if ($sql) {
         static::$lastSql = $sql;
     }
     static::$pdo = '';
     static::$pk = array('key' => 'id', 'value' => '');
     static::$table = '';
     // 默认是 AR 的调用模式, 获取当前 AR 类名,即为表名
     static::$where = '';
     static::$orWhere = '';
     static::$sqlSelect = array('fields' => '', 'group' => '', 'order' => '', 'limit' => '');
     static::$saveData = [];
     static::$bindValue = [];
 }
Example #25
0
 /** 
  * A customised setter to set the table name
  *
  * @param string table The name of the table
  */
 public static function setTableName($table)
 {
     static::$table = $table;
 }
Example #26
0
 /**
  * Retrieve the distinct values of the given attribute.
  * 
  * @param string $attribute
  * @param array  $filter    [optional]
  * @param array  $order     [optional]
  * @param int    $limit     [optional]
  * @param int    $offset    [optional]
  * @return array
  */
 public static function distinct($attribute, $filter = array(), $order = array(), $limit = null, $offset = 0)
 {
     $instance = new static();
     $storage = $instance->storage();
     if (!$storage instanceof Aggregational) {
         return array_values(array_unique(static::listing($attribute, $filter, $order)));
     }
     return $storage->distinct($instance->table(), $attribute, $filter, $order, $limit, $offset);
 }
Example #27
0
 /**
  * Gets the table names
  */
 public static function _init()
 {
     static::$table = strtolower(Config::get('sentry.table.groups'));
     static::$join_table = strtolower(Config::get('sentry.table.users_groups'));
 }
Example #28
0
 /**
  * Init, placé ici et pas dans le constructor pour l'utiliser dans __wakeup
  * @param array $params
  */
 public function init()
 {
     $this->db = _r('db');
     if (empty(static::$table)) {
         static::$table = strtolower(get_called_class());
     }
 }
Example #29
-1
 /**
  * Checks call to see if we can create a table from a magic call (for you wizards).
  * hover_striped, bordered_condensed, etc.
  *
  * @param string $method     Method name
  * @param array  $parameters Method parameters
  *
  * @return mixed
  */
 public static function __callStatic($method, $parameters)
 {
     // Opening a table
     if (str_contains($method, 'open') or $method == 'open') {
         $method = strtolower($method);
         $classes = explode('_', $method);
         $method = array_pop($classes);
         // Fallback to default type if defined
         if (sizeof($classes) == 0) {
             $classes = Config::get('table.classes');
         }
         // Filter table classes
         $classes = array_intersect($classes, static::$classes);
         $attributes = Helpers::set_multi_class_attributes($method, $classes, $parameters, 0, 'table-');
         $attributes = array_get($attributes, 0);
         static::$table = new static($attributes);
         return static::$table->open();
     }
     // Set default function
     if (!$method) {
         $method = 'table';
     }
     // Use cases
     switch ($method) {
         case 'close':
             $close = static::table()->close();
             static::$table = null;
             return $close;
             break;
         default:
             return call_user_func_array(array(static::table(), $method), $parameters);
             break;
     }
 }