private function get_style_children($style_id) { // Load children for PROPFIND purposes $children = array(array('uri' => "{midgardmvc_core::get_instance()->context->prefix}mgd:styles{$this->object_path}/", 'title' => $this->object_path, 'mimetype' => 'httpd/unix-directory', 'resource' => 'collection')); // Styles $mc = midgard_style::new_collector('up', $style_id); $mc->set_key_property('name'); $mc->execute(); $styles = $mc->list_keys(); if (is_array($styles)) { foreach ($styles as $name => $array) { if (empty($name)) { continue; } $children[] = array('uri' => "{midgardmvc_core::get_instance()->context->prefix}mgd:styles{$this->object_path}/{$name}/", 'title' => $name, 'mimetype' => 'httpd/unix-directory', 'resource' => 'collection'); } } // Elements $qb = new midgard_query_builder('midgard_element'); $qb->add_constraint('style', '=', $style_id); $qb->add_constraint('name', '<>', ''); $elements = $qb->execute(); if (is_array($elements)) { foreach ($elements as $element) { $children[] = array('uri' => "{midgardmvc_core::get_instance()->context->prefix}mgd:styles{$this->object_path}/{$element->name}.php", 'title' => $element->name, 'mimetype' => 'text/plain', 'size' => $element->metadata->size, 'revised' => $element->metadata->revised); } } return $children; }
/** * 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]; }