function rest_breadcrumb($attributes = array()) { $attributes = try_set_attribute($attributes, 'class', 'breadcrumb'); $segments = explode('/', moojon_uri::get_match_pattern()); if ($segments[0] == APP) { array_shift($segments); } $count = count($segments); $ul = ul_tag(); $href = '/'; for ($i = 0; $i < $count; $i++) { $segment = $segments[$i]; $attributes = $i == $count - 1 ? array('class' => 'last') : array(); $link = true; if (moojon_base::is_symbol($segment)) { $symbol_name = moojon_base::get_symbol_name($segment); $href .= moojon_request::get($symbol_name) . '/'; if ($symbol_name != moojon_primary_key::NAME) { if (moojon_paths::get_model_path($segment)) { $content = model_from_symbol($segment); } } else { $content = model_from_id($segments[$i - 1]); } } else { if ($i == $count - 1) { $link = true; } $content = title_text($segment); $href .= $segment . '/'; } if ($content) { if ($i == $count - 1) { $ul->add_child(li_tag($content, $attributes)); } else { $ul->add_child(li_tag(a_tag($content, $href), $attributes)); } } } return div_tag($ul, $attributes); }
function table_for(moojon_model_collection $models, $column_names = array(), $attributes = array(), $no_records_message = null, $count = null) { $no_records_message = $no_records_message ? $no_records_message : moojon_config::get('no_records_message'); if ($models->count) { $attributes = try_set_attribute($attributes, 'cellpadding', '0'); $attributes = try_set_attribute($attributes, 'cellspacing', '0'); $model = $models->first; $model_class = get_class($model); $ths = array(th_tag(title_text($model->get_to_string_column()))); $column_names = $column_names ? $column_names : $model->get_ui_column_names(); foreach ($column_names as $column_name) { if ($model->to_string_column != $column_name) { $ths[] = th_tag(title_text($column_name)); } } $ths[] = th_tag('Edit'); $ths[] = th_tag('Delete'); $trs = array(); $primary_key = moojon_primary_key::NAME; $counter = 0; foreach ($models as $model) { $counter++; $tds = array(td_tag(member_tag($model))); foreach ($column_names as $column_name) { if ($model->to_string_column != $column_name) { if (method_exists($model, "get_{$column_name}") || method_exists($model, $column_name)) { $content = $model->{$column_name}; if (is_object($content) && is_subclass_of($content, 'moojon_base_column')) { $column = $content; $content = $column->get_value(); } else { $column = new moojon_string_column($column_name); $column->set_value($content); } } else { $column = $model->get_column($column_name); if ($relationship = find_has_one_relationship($model, $column_name)) { $name = $relationship->get_name(); $content = member_tag($model->{$name}); } else { if ($relationship = find_belongs_to_relationship($model, $column_name)) { $name = $relationship->get_name(); $content = member_tag($model->{$name}); } else { $content = $model->{$column_name}; } } } $tds[] = td_tag(format_content($model, $column, $content)); } } $tds[] = td_tag(edit_member_tag($model)); $tds[] = td_tag(delete_member_tag($model)); $trs[] = tr_tag($tds, array('class' => 'row' . $counter % 2)); } $children = array(thead_tag(tr_tag($ths)), tbody_tag($trs)); if ($count) { $ul = paginator_ul($count); $children[] = tfoot_tag(tr_tag(td_tag($ul, array('colspan' => count($column_names) + 2)))); } $child = table_tag($children, $attributes); } else { $child = p_tag($no_records_message); } return div_tag($child); }
function datetime_select_options($attributes = null, $format = null, $selected = null, $start = null, $end = null, $label = false) { if (!$format) { $format = moojon_config::get('datetime_format'); } $return = div_tag(null, array('class' => 'datetime')); $attributes = try_set_attribute($attributes, 'name', 'datetime_select'); $attributes = try_set_attribute($attributes, 'id', $attributes['name']); for ($i = 0; $i < strlen($format) + 1; $i++) { $select = null; $select_attributes = $attributes; $f = substr($format, $i, 1); $select_attributes['name'] = $attributes['name'] . "[{$f}]"; if ($i) { $select_attributes['id'] = $attributes['id'] . "_{$f}"; } else { $select_attributes['id'] = $attributes['id']; } switch ($f) { case 'Y': case 'y': $select = year_select_options($start, $end, $select_attributes, $selected, $f); $label_text = 'Year'; break; case 'm': case 'n': $select = month_select_options($select_attributes, $selected, $f); $label_text = 'Month'; break; case 'd': case 'j': $select = day_select_options($select_attributes, $selected, $f); $label_text = 'Day'; break; case 'G': case 'H': $select = hour_select_options($select_attributes, $selected, $f); $label_text = 'Hour'; break; case 'i': $select = minute_select_options($select_attributes, $selected); $label_text = 'Minute'; break; case 's': $select = second_select_options($select_attributes, $selected); $label_text = 'Second'; break; } if ($select) { if ($label) { $return->add_child(label_tag("{$label_text}:", $select_attributes['id'])); } $return->add_child($select); } } return $return; }