protected static function factory($class) { if (!self::$instance) { self::$instance = new $class(); } return self::$instance; }
public static function app_from_uri($uri) { $uri = moojon_uri::clean_uri($uri); $route_match = moojon_routes::map($uri); $data = $route_match->get_params(); foreach ($data as $key => $value) { moojon_request::set($key, $value); } $app = $data['app']; self::require_view_functions(); require_once moojon_paths::get_app_path($app); $app_class = self::get_app_class($app); return new $app_class($uri); }
public final function set_location($uri) { $uri = moojon_uri::clean_uri($uri); $route_match = moojon_routes::map($uri); $data = $route_match->get_params(); $this->app_name = $data['app']; $this->controller_name = $data['controller']; $this->action_name = $data['action']; if (self::get_app_class($this->app_name) != get_class($this)) { $location = moojon_config::get('index_file') . $uri; $this->redirect($location); } $this->set_controller(); }
function has_one_tag(moojon_model_collection $models = null, moojon_base_model $model, moojon_base_column $column, moojon_base_relationship $relationship, $attributes = array()) { $return = null; $name = $column->get_name(); $attributes = try_set_name_and_id_attributes($attributes, $model, $column); if ($value = moojon_request::get_or_null($name)) { $attributes['value'] = $value; $return = div_tag(array(hidden_input_tag($attributes), redirection_tag(moojon_server::redirection()))); } else { $foreign_key = $relationship->get_foreign_key(); $key = $relationship->get_key(); $relationship_name = $relationship->get_class($model); $relationship = new $relationship_name(); $models = $models ? $models : $relationship->read(); $options = array(); if ($column->get_null()) { $options['Please select...'] = 0; } foreach ($models as $option) { $options[(string) $option] = $option->{$key}; } $selected = $model->{$name} ? $model->{$name} : moojon_uri::get_or_null($foreign_key); $return = select_options($options, $selected, $attributes); } return $return; }
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); }
public static function get_actions() { $data = self::get_data(); require_once moojon_paths::get_controller_path($data['app'], $data['controller']); $actions = get_class_methods(self::get_controller_class($data['controller'])); $paths = array(moojon_paths::get_moojon_views_directory(), moojon_paths::get_moojon_views_app_directory(moojon_uri::get_app()), moojon_paths::get_moojon_views_app_controller_directory(moojon_uri::get_app(), moojon_uri::get_controller()), moojon_paths::get_project_views_directory(), moojon_paths::get_project_views_app_directory(moojon_uri::get_app()), moojon_paths::get_project_views_app_controller_directory(moojon_uri::get_app(), moojon_uri::get_controller())); foreach (self::colate_view($paths) as $view) { if (!in_array($actions, $view)) { $actions[] = $view; } } return $actions; }
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; }