コード例 #1
0
 public function __construct(PDOStatement $statement, $param_values = array(), $param_data_types = array(), $fetch_style = moojon_db::FETCH_ASSOC)
 {
     $this->iterator = $this->getIterator();
     $query_string = $statement->queryString;
     $log = $query_string;
     if (ENVIRONMENT == 'development' || ENVIRONMENT == 'cli') {
         $values = 'Param values(';
         $parsed_query = $log;
         foreach ($param_values as $key => $value) {
             $values .= "{$key} = {$value}, ";
             $apos = array_key_exists($key, $param_data_types) && $param_data_types[$key] == moojon_db::PARAM_STR ? "'" : '';
             $parsed_query = str_replace($key, "{$apos}{$value}{$apos}", $parsed_query);
         }
         $parsed_query = "Parsed query: {$parsed_query}";
         if (count($param_values)) {
             $values = substr($values, 0, -2);
         }
         $values .= ')';
         $data_types = 'Param data types(';
         foreach ($param_data_types as $key => $value) {
             $data_types .= "{$key} = {$value}, ";
         }
         if (count($data_types)) {
             $data_types = substr($data_types, 0, -2);
         }
         $data_types .= ')';
         $log .= "\n\n{$parsed_query}\n\n{$values}\n\n{$data_types}";
         moojon_base::log($log);
     }
     foreach ($param_values as $key => $value) {
         if ($value !== null) {
             $data_type = array_key_exists($key, $param_data_types) ? $param_data_types[$key] : moojon_db::PARAM_STR;
             if (strpos($query_string, $key) !== false) {
                 $statement->bindValue($key, $value, $data_type);
             }
         }
     }
     $this->affected = $statement->execute();
     $this->non_query = $statement->columnCount() > 0;
     if ($this->non_query) {
         foreach ($statement->fetchAll($fetch_style) as $record) {
             $this[] = $record;
         }
     }
 }
コード例 #2
0
ファイル: model.tag.helper.php プロジェクト: steview/moojon
function time_tag(moojon_base_model $model, moojon_base_column $column, $attributes = array())
{
    $attributes = try_set_name_and_id_attributes($attributes, $model, $column);
    $attributes['class'] = 'time';
    return datetime_label_select_options($attributes, moojon_config::get('time_format'), moojon_base::get_time($column->get_value()));
}
コード例 #3
0
ファイル: rest.helper.php プロジェクト: steview/moojon
function model_from_symbol($symbol)
{
    $symbol_name = moojon_base::get_symbol_name($symbol);
    $class = moojon_primary_key::get_class($symbol_name);
    $id = moojon_primary_key::get_id_from_foreign_key($symbol);
    $model = new $class();
    $method_name = "read_by_{$id}";
    return $model->{$method_name}(moojon_request::get($symbol_name));
}
コード例 #4
0
ファイル: tag.helper.php プロジェクト: steview/moojon
function paginator_ul($records, $limit = null, $page_symbol_name = null, $limit_symbol_name = null, $attributes = array())
{
    if (!is_integer($records)) {
        $records = count($records);
    }
    $limit_symbol_name = $limit_symbol_name ? $limit_symbol_name : moojon_config::get('paginator_limit_symbol_name');
    if (!$limit) {
        $limit = moojon_request::has($limit_symbol_name) ? moojon_request::get($limit_symbol_name) : moojon_config::get('paginator_limit');
    }
    if ($records > $limit) {
        $page_symbol_name = $page_symbol_name ? $page_symbol_name : moojon_config::get('paginator_page_symbol_name');
        $page = moojon_request::has($page_symbol_name) ? moojon_request::get($page_symbol_name) : 1;
        $page = $page < 1 ? 1 : (int) $page;
        $children = array();
        $params = moojon_get::get_data();
        $get = $params;
        if (array_key_exists($limit_symbol_name, $get)) {
            $get[$limit_symbol_name] = $limit;
        }
        $get[$page_symbol_name] = ":{$page_symbol_name}";
        foreach ($get as $key => $value) {
            $get[$key] = "{$key}={$value}";
        }
        $querystring = moojon_uri::get_uri() . '?' . implode('&', $get);
        for ($i = 1; $i < ceil($records / $limit) + 1; $i++) {
            $params[$page_symbol_name] = $i;
            $attributes = $i == $page ? array('class' => 'selected') : array();
            $children[] = li_tag(a_tag($i, moojon_base::parse_symbols($querystring, $params), $attributes));
        }
        $return = ul_tag($children);
    } else {
        $return = '';
    }
    return $return;
}