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; } }
public static function break_cache($table) { if (in_array($table, static::$ignore_tables)) { return; } $res = db::select('_compiler_keys')->add_field_to_retrieve('file')->filter('`dependants` LIKE "%' . $table . '%"')->execute(); while ($row = db::fetch($res)) { switch (static::$mode) { case static::MODE_FILE: static::break_file($row->file); break; case static::MODE_REDIS: //$this->break_redis($row->file); throw new \Exception('Page caching method is not implemented - Redis'); break; case static::MODE_MEMCACHED: static::break_memcached($row->file); break; } } db::delete('_compiler_keys')->filter('`dependants` LIKE "%' . $table . '%"')->execute(); }
/** * @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; }