Esempio n. 1
0
 /**
  * Returns a style element that matches $name and is in style $id.
  * Unlike mgd_get_element_by_name2 it also returns an element if it is not in
  * the given style, but in one of its parent styles.
  *
  * @param int $id        The style id to search in.
  * @param string $name    The element to locate.
  * @return string    Value of the found element, or false on failure.
  */
 private function _get_element_in_styletree($id, $name)
 {
     static $cached = array();
     if (!isset($cached[$id])) {
         $cached[$id] = array();
     }
     if (array_key_exists($name, $cached[$id])) {
         return $cached[$id][$name];
     }
     $element_mc = midgard_element::new_collector('style', $id);
     $element_mc->set_key_property('guid');
     $element_mc->add_value_property('value');
     $element_mc->add_constraint('name', '=', $name);
     $element_mc->execute();
     $elements = $element_mc->list_keys();
     if ($elements) {
         foreach ($elements as $element_guid => $value) {
             $value = $element_mc->get_subkey($element_guid, 'value');
             midcom::get('cache')->content->register($element_guid);
             $cached[$id][$name] = $value;
             return $value;
         }
     }
     // No such element on this level, check parents
     $style_mc = midgard_style::new_collector('id', $id);
     $style_mc->set_key_property('guid');
     $style_mc->add_value_property('up');
     $style_mc->execute();
     $styles = $style_mc->list_keys();
     foreach ($styles as $style_guid => $value) {
         // FIXME: Should we register this also in the other case
         midcom::get('cache')->content->register($style_guid);
         $up = $style_mc->get_subkey($style_guid, 'up');
         if ($up && $up != 0) {
             $value = $this->_get_element_in_styletree($up, $name);
             $cached[$id][$name] = $value;
             return $value;
         }
     }
     $cached[$id][$name] = false;
     return $cached[$id][$name];
 }
Esempio n. 2
0
 private function handle_copy($route_id, &$data)
 {
     $destination = $this->check_destination($data['dest']);
     if (!$this->get_style($this->object_path)) {
         // Possibly copying elements instead
         if (!$this->get_element($this->object_path)) {
             throw new midgardmvc_exception_notfound("Style {$this->object_path} not found");
         }
         $new_element = new midgard_element();
         $new_element->style = $destination['style']->id;
         $new_element->name = str_replace('.php', '', $destination['name']);
         $new_element->value = $this->element->value;
         $new_element->create();
         return;
     }
     $new_style = new midgard_style();
     $new_style->up = $destination['style']->id;
     $new_style->name = $destination['name'];
     $new_style->create();
 }