Example #1
0
 protected function _get_children($parent_id)
 {
     $mc = midgard_page::new_collector('up', $parent_id);
     $mc->set_key_property('id');
     $mc->add_value_property('id');
     $mc->add_value_property('name');
     $mc->add_value_property('title');
     $mc->add_value_property('component');
     $mc->execute();
     $child_ids = $mc->list_keys();
     $children = array();
     foreach ($child_ids as $cid => $data) {
         $children[] = $this->_prepare_page_data($mc->get_subkey($cid, 'id'), $mc->get_subkey($cid, 'name'), $mc->get_subkey($cid, 'title'), $mc->get_subkey($cid, 'component'));
     }
     return $children;
 }
Example #2
0
 /**
  * Call a route of a component with given arguments and return the data it generated
  *
  * Dynamic calls may be called for either a specific page that has a component assigned to it
  * by specifying a page GUID or path as the first argument, or to a static instance of a component
  * by specifying component name as the first argument.
  *
  * @param string $component_name Component name, page GUID or page path
  * @param string $route_id     Route identifier
  * @param array $arguments  Arguments to give to the route
  * @param boolean $switch_context Whether to run the route in a new context
  * @return $array data
  */
 public function dynamic_call($component_name, $route_id, array $arguments, $switch_context = true)
 {
     if (is_null($this->dispatcher)) {
         $this->dispatcher = new midcom_core_services_dispatcher_manual();
     }
     if ($switch_context) {
         $_MIDCOM->context->create();
     }
     $page = null;
     if (mgd_is_guid($component_name)) {
         $page = new midgard_page($component_name);
     } elseif (strpos($component_name, '/') !== false) {
         $page = new midgard_page();
         $page->get_by_path($component_name);
     }
     if ($page) {
         $component_name = $page->component;
         if (!$component_name) {
             throw new Exception("Page {$page->guid} has no component defined");
         }
         $this->dispatcher->set_page($page);
     }
     $this->dispatcher->populate_environment_data();
     $this->dispatcher->initialize($component_name);
     if (!$_MIDCOM->context->component_instance->configuration->exists('routes')) {
         throw new Exception("Component {$component_name} has no routes defined");
     }
     $routes = $_MIDCOM->context->component_instance->configuration->get('routes');
     if (!isset($routes[$route_id])) {
         throw new Exception("Component {$component_name} has no route {$route_id}");
     }
     $this->dispatcher->set_route($route_id, $arguments);
     $this->dispatcher->dispatch();
     $data = $_MIDCOM->context->{$component_name};
     if ($switch_context) {
         $_MIDCOM->context->delete();
     }
     return $data;
 }
Example #3
0
 private function get_page_prefix()
 {
     if (!$this->page) {
         throw new Exception("No page set for the manual dispatcher");
     }
     $prefix = "{$_MIDGARD['prefix']}/";
     $host_mc = midgard_host::new_collector('id', $_MIDGARD['host']);
     $host_mc->set_key_property('root');
     $host_mc->execute();
     $roots = $host_mc->list_keys();
     if (!$roots) {
         throw new Exception("Failed to load root page data for host {$_MIDGARD['host']}");
     }
     $root_id = null;
     foreach ($roots as $root => $array) {
         $root_id = $root;
         break;
     }
     if ($this->page->id == $root_id) {
         return $prefix;
     }
     $page_path = '';
     $page_id = $this->page->id;
     while ($page_id && $page_id != $root_id) {
         $parent_mc = midgard_page::new_collector('id', $page_id);
         $parent_mc->set_key_property('up');
         $parent_mc->add_value_property('name');
         $parent_mc->execute();
         $parents = $parent_mc->list_keys();
         foreach ($parents as $parent => $array) {
             $page_id = $parent;
             $page_path = $parent_mc->get_subkey($parent, 'name') . "/{$page_path}";
         }
     }
     return $prefix . $page_path;
 }
Example #4
0
 public function initialize($component)
 {
     if ($_MIDCOM->timer) {
         $_MIDCOM->timer->setMarker('MidCOM dispatcher::initialize');
     }
     // In main Midgard request we dispatch the component in connection to a page
     $page = new midgard_page();
     $page->get_by_id($_MIDGARD['page']);
     $this->component_name = $component;
     $_MIDCOM->context->component_instance = $_MIDCOM->componentloader->load($this->component_name, $page);
     $_MIDCOM->templating->append_directory($_MIDCOM->componentloader->component_to_filepath($this->component_name) . '/templates');
 }