当前位置: 首页>>代码示例>>PHP>>正文


PHP factory::model方法代码示例

本文整理汇总了PHP中factory::model方法的典型用法代码示例。如果您正苦于以下问题:PHP factory::model方法的具体用法?PHP factory::model怎么用?PHP factory::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在factory的用法示例。


在下文中一共展示了factory::model方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: init

 /**
  * Initializing i18n
  *
  * @param array $options
  */
 public static function init($options = [])
 {
     $i18n = application::get('flag.global.i18n') ?? [];
     $i18n = array_merge_hard($i18n, $options ?? []);
     // determine final language
     $languages = factory::model('numbers_backend_i18n_languages_model_languages')->get();
     $final_language = application::get('flag.global.__language_code') ?? session::get('numbers.entity.format.language_code') ?? $i18n['language_code'] ?? 'sys';
     if (empty($languages[$final_language])) {
         $final_language = 'sys';
         $i18n['rtl'] = 0;
     }
     // put settings into system
     if (!empty($languages[$final_language])) {
         foreach ($languages[$final_language] as $k => $v) {
             $k = str_replace('lc_language_', '', $k);
             if (in_array($k, ['code', 'inactive'])) {
                 continue;
             }
             if (empty($v)) {
                 continue;
             }
             $i18n[$k] = $v;
         }
     }
     $i18n['language_code'] = $final_language;
     self::$options = $i18n;
     session::set('numbers.entity.format.language_code', $final_language);
     application::set('flag.global.i18n', $i18n);
     self::$initialized = true;
     // initialize the module
     return factory::submodule('flag.global.i18n.submodule')->init($i18n);
 }
开发者ID:volodymyr-volynets,项目名称:framework,代码行数:37,代码来源:i18n.php

示例2: can

 /**
  * Whether we can perform certain action
  *
  * @param mixed $action_code_or_id
  * @return boolean
  */
 public static function can($action_code_or_id)
 {
     if (self::$cache_actions === null) {
         self::$cache_actions = factory::model('numbers_backend_system_controller_model_actions')->get();
     }
     if (is_string($action_code_or_id)) {
         foreach (self::$cache_actions as $k => $v) {
             if ($v['sm_cntractn_code'] == $action_code_or_id) {
                 $action_code_or_id = $k;
                 break;
             }
         }
     }
     if (!isset(self::$cache_actions[$action_code_or_id])) {
         throw new Exception('Unknown action!');
     }
     $permissions = application::get(['controller', 'acl', 'permissions']);
     $start = $action_code_or_id;
     do {
         // see if we have permission
         if (empty($permissions[$start])) {
             break;
         }
         // we need to check permission on a parent
         if (!empty(self::$cache_actions[$start]['sm_cntractn_parent_id'])) {
             $start = self::$cache_actions[$start]['sm_cntractn_parent_id'];
         } else {
             // exit if there's no parent
             return true;
         }
     } while (1);
     return false;
 }
开发者ID:volodymyr-volynets,项目名称:framework,代码行数:39,代码来源:controller.php

示例3: process_options

 /**
  * Process options
  *
  * @param string $model_and_method - model::method
  * @param object $existing_object
  * @param array $where
  * @param array $existing_values
  * @param array $skip_values
  * @param array $options
  * @return array
  */
 public static function process_options($model_and_method, $existing_object = null, $where = [], $existing_values = [], $skip_values = [], $options = [])
 {
     // put changes into options
     $options['where'] = array_merge_hard($options['where'] ?? [], $where);
     $options['existing_values'] = $existing_values;
     $options['skip_values'] = $skip_values;
     // see if we have cached version
     $hash = sha1($model_and_method . serialize($options));
     if (isset(self::$cached_options[$hash])) {
         return self::$cached_options[$hash];
     } else {
         $temp = explode('::', $model_and_method);
         if (count($temp) == 1) {
             $model = $temp[0];
             $method = 'options';
         } else {
             $model = $temp[0];
             $method = $temp[1];
         }
         if ($model == 'this' && !empty($existing_object)) {
             $object = $existing_object;
         } else {
             $object = factory::model($model, true);
         }
         self::$cached_options[$hash] = $object->{$method}($options);
         return self::$cached_options[$hash];
     }
 }
开发者ID:volodymyr-volynets,项目名称:framework,代码行数:39,代码来源:common.php

示例4: query

    public function query($options = [])
    {
        $model = factory::model($options['model']);
        $db = $model->db_object();
        $where = '';
        if (!empty($options['where'])) {
            $where = 'AND ' . $db->prepare_condition($options['where']);
        }
        $ts = $db->full_text_search_query($options['fields'], $options['search_text'] . '');
        $fields = $options['fields'];
        $sql_pk = '';
        // we automatically include main pk into a query
        if (!in_array($options['pk'], $options['fields'])) {
            // in_array($options['pk'], $model->pk) &&
            $fields[] = $options['pk'];
            // we need to include integer types to the query
            $temp = intval($options['search_text']);
            if ($model->columns[$options['pk']]['php_type'] == 'integer' && $temp != 0) {
                $sql_pk .= " OR {$options['pk']} = " . (int) $options['search_text'];
            }
        }
        $fields[] = $ts['rank'];
        $fields = implode(', ', $fields);
        $tmp = <<<TTT
\t\t\tSELECT
\t\t\t\t{$fields}
\t\t\tFROM [table[{$options['model']}]] a
\t\t\tWHERE 1=1
\t\t\t\t\t{$where}
\t\t\t\t\tAND (({$ts['where']}){$sql_pk})
\t\t\tORDER BY {$ts['orderby']} DESC, {$options['fields'][0]}
\t\t\tLIMIT 11
TTT;
        return $tmp;
    }
开发者ID:volodymyr-volynets,项目名称:framework,代码行数:35,代码来源:datasource.php

示例5: method

 /**
  * Call validator method
  *
  * @param string $method
  * @param array $params
  * @param array $options
  * @param array $neighbouring_values
  * @return array
  */
 public static function method($method, $value, $params = [], $options = [], $neighbouring_values = [])
 {
     $method = factory::method($method);
     $params = $params ?? [];
     $params['options'] = $options;
     $params['neighbouring_values'] = $neighbouring_values;
     return factory::model($method[0], true)->{$method[1]}($value, $params);
 }
开发者ID:volodymyr-volynets,项目名称:framework,代码行数:17,代码来源:base.php

示例6: save

 public function save(&$form)
 {
     $model = factory::model($form->options['other']['model']);
     $save = [$model->column_prefix . 'important' => !empty($form->values['important']) ? 1 : 0, $model->column_prefix . 'comment_value' => $form->values['comment'] . '', $model->column_prefix . 'who_entity_id' => session::get('numbers.entity.em_entity_id'), $model->column_prefix . 'inserted' => format::now('timestamp')];
     foreach ($form->options['other']['map'] as $k => $v) {
         $save[$v] = $form->options['other']['pk'][$k];
     }
     $save_result = $model->save($save, ['ignore_not_set_fields' => true]);
     if ($save_result['success']) {
         $form->error('success', 'Comment has been added successfully!');
     } else {
         $form->error('danger', 'Could not add comment!');
     }
 }
开发者ID:volodymyr-volynets,项目名称:frontend,代码行数:14,代码来源:comment.php

示例7: query

 public function query($options = [])
 {
     $model = factory::model($options['model']);
     $db = $model->db_object();
     $where = null;
     if (!empty($options['where'])) {
         $where = 'AND ' . $db->prepare_condition($options['where']);
     }
     $columns = [];
     foreach ($model->columns as $k => $v) {
         $columns[] = 'a.' . $k . ' ' . str_replace($model->column_prefix, '', $k);
     }
     return "SELECT " . implode(', ', $columns) . ", b.em_entity_name FROM [table[{$options['model']}]] a LEFT JOIN [table[numbers_data_entities_entities_model_entities]] b ON a.{$model->column_prefix}who_entity_id = b.em_entity_id WHERE 1=1 {$where} ORDER BY {$model->column_prefix}inserted DESC";
 }
开发者ID:volodymyr-volynets,项目名称:frontend,代码行数:14,代码来源:comments.php

示例8: query

    public function query($options = [])
    {
        $where = null;
        if (!empty($options['where'])) {
            $model = factory::model($options['model']);
            $db = $model->db_object();
            $where = 'AND ' . $db->prepare_condition($options['where']);
        }
        return <<<TTT
\t\t\tSELECT
\t\t\t\tCOUNT(*) count
\t\t\tFROM [table[{$options['model']}]] a
\t\t\tWHERE 1=1
\t\t\t\t{$where}
TTT;
    }
开发者ID:volodymyr-volynets,项目名称:frontend,代码行数:16,代码来源:count.php

示例9: query

 public function query($options = [])
 {
     $model = factory::model($options['model'], true);
     $this->db_object = $model->db_object;
     $column = $options['where']['column_name'];
     // adjust type based on value
     $where = null;
     if (empty($options['where']['column_value'])) {
         if ($options['type'] == 'previous') {
             $options['type'] = 'first';
         }
         if ($options['type'] == 'next') {
             $options['type'] = 'last';
         }
     } else {
         if ($options['type'] == 'previous') {
             $where = ' AND ' . $this->db_object->prepare_condition(["{$column},<" => $options['where']['column_value']]);
         } else {
             if ($options['type'] == 'next') {
                 $where = ' AND ' . $this->db_object->prepare_condition(["{$column},>" => $options['where']['column_value']]);
             } else {
                 if ($options['type'] == 'refresh') {
                     $where = ' AND ' . $this->db_object->prepare_condition(["{$column}" => $options['where']['column_value']]);
                 }
             }
         }
     }
     $depends = null;
     if (!empty($options['where']['depends'])) {
         $depends = ' AND (' . $this->db_object->prepare_condition($options['where']['depends']) . ')';
     }
     $pk = implode(', ', $options['pk']);
     // generate query based on type
     switch ($options['type']) {
         case 'first':
             return "SELECT {$pk} FROM {$model->name} WHERE {$column} = (SELECT MIN({$column}) new_value FROM {$model->name} WHERE {$column} IS NOT NULL {$depends}) {$depends}";
         case 'previous':
             return "SELECT {$pk} FROM {$model->name} WHERE 1=1 {$where} {$depends} ORDER BY {$column} DESC LIMIT 1";
         case 'next':
             return "SELECT {$pk} FROM {$model->name} WHERE 1=1 {$where} {$depends} ORDER BY {$column} ASC LIMIT 1";
         case 'last':
             return "SELECT {$pk} FROM {$model->name} WHERE {$column} = (SELECT MAX({$column}) new_value FROM {$model->name} WHERE {$column} IS NOT NULL {$depends}) {$depends}";
         case 'refresh':
         default:
             return "SELECT {$pk} FROM {$model->name} WHERE 1=1 {$where} {$depends}";
     }
 }
开发者ID:volodymyr-volynets,项目名称:frontend,代码行数:47,代码来源:navigation.php

示例10: query

    public function query($options = [])
    {
        $model = factory::model($options['model']);
        $db = $model->db_object();
        $where = '';
        if (!empty($options['where'])) {
            $where = 'AND ' . $db->prepare_condition($options['where']);
        }
        $fields = $options['fields'];
        if (!in_array($options['pk'], $options['fields'])) {
            $fields[] = $options['pk'];
        }
        $fields = implode(', ', $fields);
        return <<<TTT
\t\t\tSELECT
\t\t\t\t{$fields}
\t\t\tFROM [table[{$options['model']}]] a
\t\t\tWHERE 1=1
\t\t\t\t\t{$where}
TTT;
    }
开发者ID:volodymyr-volynets,项目名称:framework,代码行数:21,代码来源:values.php

示例11: destroy

    /**
     * Destroy
     */
    public static function destroy()
    {
        if (empty(self::$missing)) {
            return;
        }
        //if (!chance(10)) return;
        // we would create temp table
        $db = factory::model('numbers_backend_i18n_basic_model_missing')->db_object();
        $db->query("CREATE TEMPORARY TABLE temp_translations (sys text, counter integer, lang text)");
        // insert data
        $data = [];
        foreach (self::$missing as $k => $v) {
            $data[] = ['sys' => $k, 'counter' => $v, 'lang' => self::$language_code];
        }
        $db->insert('temp_translations', $data);
        // merge data
        $sql = <<<TTT
\t\t\tINSERT INTO lc_missing (
\t\t\t\tlc_missing_id,
\t\t\t\tlc_missing_language_code,
\t\t\t\tlc_missing_text_sys, 
\t\t\t\tlc_missing_counter
\t\t\t)
\t\t\tSELECT
\t\t\t\tnextval('lc_missing_lc_missing_id_seq'),
\t\t\t\tlang lc_missing_language_code,
\t\t\t\tsys lc_missing_text_sys,
\t\t\t\t0 lc_missing_counter
\t\t\tFROM temp_translations a
\t\t\tLEFT JOIN lc_translations b ON a.sys = b.lc_translation_text_sys AND a.lang = b.lc_translation_language_code
\t\t\tLEFT JOIN lc_missing c ON a.sys = c.lc_missing_text_sys AND a.lang = c.lc_missing_language_code
\t\t\tWHERE b.lc_translation_language_code IS NULL AND c.lc_missing_language_code IS NULL
TTT;
        $db->query($sql);
        // last step perform update
        $sql = "UPDATE lc_missing a SET lc_missing_counter = lc_missing_counter + coalesce((SELECT counter FROM temp_translations b WHERE b.sys = a.lc_missing_text_sys AND b.lang = a.lc_missing_language_code), 0)";
        $db->query($sql);
    }
开发者ID:volodymyr-volynets,项目名称:backend,代码行数:41,代码来源:base.php

示例12: init

 /**
  * Initialize
  * 
  * @param array $options
  */
 public static function init($options = [])
 {
     // default options
     self::$defaut_options = ['language_code' => 'sys', 'locale' => 'en_CA.UTF-8', 'timezone' => 'America/Toronto', 'server_timezone' => application::get('php.date.timezone'), 'date' => 'Y-m-d', 'time' => 'H:i:s', 'datetime' => 'Y-m-d H:i:s', 'timestamp' => 'Y-m-d H:i:s.u', 'amount_frm' => 20, 'amount_fs' => 40, 'settings' => ['currency_codes' => []], 'locale_locales' => [], 'locale_locale_js' => null, 'locale_set_name' => null, 'locale_options' => [], 'locale_override_class' => null];
     // settings from config files
     $config = application::get('flag.global.format');
     // settings from user account
     $entity = entity::groupped('format');
     // merge all of them together
     self::$options = array_merge_hard(self::$defaut_options, $config, i18n::$options, $entity, $options);
     // fix utf8
     self::$options['locale'] = str_replace(['utf8', 'utf-8'], 'UTF-8', self::$options['locale']);
     // generate a list of available locales
     $locale_settings = self::set_locale(self::$options['locale'], self::$defaut_options['locale']);
     self::$options = array_merge_hard(self::$options, $locale_settings);
     // fix values
     self::$options['amount_frm'] = (int) self::$options['amount_frm'];
     self::$options['amount_fs'] = (int) self::$options['amount_fs'];
     self::$options['locale_options']['mon_thousands_sep'] = self::$options['locale_options']['mon_thousands_sep'] ?? ',';
     self::$options['locale_options']['mon_decimal_point'] = self::$options['locale_options']['mon_decimal_point'] ?? '.';
     if (empty(self::$options['locale_options']['mon_grouping'])) {
         self::$options['locale_options']['mon_grouping'] = [3, 3];
     }
     // load data from models
     if (!empty(self::$options['model'])) {
         foreach (self::$options['model'] as $k => $v) {
             $method = factory::method($v, null);
             self::$options['settings'][$k] = factory::model($method[0], true)->{$method[1]}();
         }
         unset(self::$options['model']);
     }
     // push js format version to frontend
     if (!empty(self::$options['locale_override_class'])) {
         $locale_override_class = self::$options['locale_override_class'];
         $locale_override_class::js();
     }
 }
开发者ID:volodymyr-volynets,项目名称:framework,代码行数:42,代码来源:format.php

示例13: query

    public function query($options = [])
    {
        $where = null;
        if (!empty($options['where'])) {
            $model = factory::model($options['model']);
            $db = $model->db_object();
            $where = 'AND ' . $db->prepare_condition($options['where']);
        }
        if (!empty($options['orderby']['full_text_search']) && !empty($options['where']['full_text_search,fts'])) {
            $temp = [];
            foreach ($options['orderby'] as $k => $v) {
                if ($k != 'full_text_search') {
                    $temp[$k] = $v;
                } else {
                    $model = factory::model($options['model']);
                    $db = $model->db_object();
                    $temp2 = $db->full_text_search_query($options['where']['full_text_search,fts']['fields'], $options['where']['full_text_search,fts']['str']);
                    $temp[$temp2['orderby']] = $v;
                }
            }
            $options['orderby'] = $temp;
        } else {
            unset($options['orderby']['full_text_search']);
        }
        $options['orderby'] = !empty($options['orderby']) ? 'ORDER BY ' . array_key_sort_prepare_keys($options['orderby'], true) : '';
        return <<<TTT
\t\t\tSELECT
\t\t\t\t*
\t\t\tFROM [table[{$options['model']}]] a
\t\t\tWHERE 1=1
\t\t\t\t{$where}
\t\t\t{$options['orderby']}
\t\t\tLIMIT {$options['limit']}
\t\t\tOFFSET {$options['offset']}
TTT;
    }
开发者ID:volodymyr-volynets,项目名称:frontend,代码行数:36,代码来源:data.php

示例14: human

 /**
  * Format filter string as human readable
  *
  * @param object $object
  * @return array
  */
 public static function human($object)
 {
     $input = $object->options['input'];
     $filter = $object->filter;
     $full_text_search = $filter['full_text_search'] ?? null;
     unset($filter['full_text_search']);
     // generate values
     $result = [];
     foreach ($filter as $k => $v) {
         if (!empty($v['range'])) {
             $start = object_table_columns::process_single_column($k, $v, $input['filter'] ?? [], ['process_domains' => true, 'ignore_defaults' => true, 'ignore_not_set_fields' => true]);
             $end = object_table_columns::process_single_column($k . '2', $v, $input['filter'] ?? [], ['process_domains' => true, 'ignore_defaults' => true, 'ignore_not_set_fields' => true]);
             $result[i18n(null, $v['name'])] = '(' . ($start[$k] ?? null) . ') - (' . ($end[$k . '2'] ?? null) . ')';
         } else {
             $start = object_table_columns::process_single_column($k, $v, $input['filter'] ?? [], ['process_domains' => true, 'ignore_defaults' => true, 'ignore_not_set_fields' => true]);
             // we need to process arrays
             if (isset($start[$k]) && is_array($start[$k])) {
                 if (!empty($v['options_model'])) {
                     $params = $v['options_params'] ?? [];
                     $start[$k] = array_options_to_string(factory::model($v['options_model'])->options(['where' => $params, 'i18n' => true]), $start[$k]);
                 } else {
                     $start[$k] = implode(', ', $start[$k]);
                 }
             }
             $result[i18n(null, $v['name'])] = $start[$k] ?? null;
         }
     }
     // full text search
     if (!empty($full_text_search)) {
         $names = [];
         foreach ($full_text_search as $v) {
             $names[] = i18n(null, $filter[$v]['name']);
         }
         $result[i18n(null, 'Text Search')] = ($input['filter']['full_text_search'] ?? null) . ' (' . implode(', ', $names) . ')';
     }
     return $result;
 }
开发者ID:volodymyr-volynets,项目名称:frontend,代码行数:43,代码来源:filter.php

示例15: create_temp_table

 /**
  * Create temporary table
  *
  * @param string $table
  * @param array $columns
  * @param array $pk
  * @param array $options
  *		skip_serials
  * @return array
  */
 public function create_temp_table($table, $columns, $pk = null, $options = [])
 {
     $ddl_object = factory::model(str_replace('_base_123', '_ddl', get_called_class() . '_123'));
     $columns_sql = [];
     foreach ($columns as $k => $v) {
         $temp = $ddl_object->is_column_type_supported($v, $table);
         // default
         $default = $temp['column']['default'] ?? null;
         if (is_string($default) && $default != 'now()') {
             $default = "'" . $default . "'";
         }
         // we need to cancel serial types
         if (!empty($options['skip_serials']) && strpos($temp['column']['type_original'] ?? $temp['column']['type'], 'serial') !== false) {
             $default = 0;
         }
         $columns_sql[] = $k . ' ' . $temp['column']['type'] . ($default !== null ? ' DEFAULT ' . $default : '') . (!($temp['column']['null'] ?? false) ? ' NOT NULL' : '');
     }
     // pk
     if ($pk) {
         $columns_sql[] = "PRIMARY KEY (" . implode(', ', $pk) . ")";
     }
     $columns_sql = implode(', ', $columns_sql);
     $sql = "CREATE TEMPORARY TABLE {$table} ({$columns_sql})";
     return $this->query($sql);
 }
开发者ID:volodymyr-volynets,项目名称:backend,代码行数:35,代码来源:base.php


注:本文中的factory::model方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。