public static function unique_fn($table, $field, $str) { $base_fn = _get::fn($str); if (db::select($table)->add_field_to_retrieve($field)->filter($field . '=:fn', ['fn' => $base_fn])->execute()->rowCount()) { $cnt = 0; do { $fn = $base_fn . '_' . ++$cnt; } while (db::select($table)->add_field_to_retrieve($field)->filter($field . '=:fn', ['fn' => $fn])->execute()->rowCount()); return $fn; } else { return $base_fn; } }
/** * @param $object * @param array $fields_to_retrieve * @param $options * @return \db\select */ public static function get_query($object, array $fields_to_retrieve, $options) { $query = db::select(_get::__class_name($object)); $base_object = _get::__class_name($object); if (!empty($fields_to_retrieve)) { foreach ($fields_to_retrieve as $field) { if (strstr($field, '.') && !strstr($field, '.*') && !strstr($field, ' AS ')) { $query->add_field_to_retrieve($field . ' AS `' . str_replace('.', '@', $field) . '`'); } else { if (strstr($field, '(') === false && strstr($field, '.*') === false && strstr($field, '.') === false) { $query->add_field_to_retrieve($base_object . '.' . $field); } else { $query->add_field_to_retrieve($field); } } } } else { $query->add_field_to_retrieve($base_object . '.*'); } if (isset($options['parameters'])) { $query->filter('1', $options['parameters']); } if (isset($options['join'])) { foreach ($options['join'] as $key => $val) { $query->add_join($key, $val); } } if (isset($options['where'])) { $query->filter($options['where']); } if (isset($options['where_equals']) && $options['where_equals']) { foreach ($options['where_equals'] as $key => $val) { $query->filter_field($key, $val); } } if (isset($options['order'])) { $query->set_order($options['order']); } if (isset($options['limit'])) { $query->set_limit($options['limit']); } if (isset($options['group'])) { $query->add_grouping($options['group']); } return $query; }
public function get_total_count() { if (isset($this->options['limit'])) { $options = $this->options; unset($options['limit']); $query = db::get_query($this->class, ['COUNT(*)'], $options)->execute()->fetch(); return $query[0]; } return $this->count(); }
public static function break_cache($table) { if (in_array($table, static::$ignore_tables)) { return; } $time = microtime(true); db::replace('_cache_dependants')->add_value('key', $table)->add_value('hash', $time)->execute(); self::$dependants[$table] = $time; }
public function save($url, compiler_page $content, $parameters = []) { if (static::$disabled === 0) { $key = md5($url . serialize($parameters)); $dependents = implode(',', array_unique(self::$dependants)); db::insert('_compiler_keys')->add_value('file', $key)->add_value('dependants', $dependents)->execute(); switch (static::$mode) { case static::MODE_FILE: $this->save_file($key, $content); break; case static::MODE_REDIS: //$this->save_redis($file, $content); throw new \Exception('Page caching method is not implemented - Redis'); break; case static::MODE_MEMCACHED: $this->save_memcached($key, $content); break; } } }