function midgard_admin_asgard_trash_type_show($object, $indent = 0, $prefix = '', $enable_undelete = true) { static $persons = array(); static $shown = array(); static $url_prefix = ''; if (!$url_prefix) { $url_prefix = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX); } if (isset($shown[$object->guid])) { return; } if (!isset($persons[$object->metadata->revisor])) { $persons[$object->metadata->revisor] = midcom::get('auth')->get_user($object->metadata->revisor); } $reflector = midcom_helper_reflector_tree::get($object); $icon = $reflector->get_object_icon($object); echo "{$prefix}<tr>\n"; $disabled = ''; if (!$enable_undelete) { $disabled = ' disabled="disabled"'; } $object_label = $reflector->get_object_label($object); if (empty($object_label)) { $object_label = $object->guid; } echo "{$prefix} <td class=\"checkbox\"><input type=\"checkbox\" name=\"undelete[]\"{$disabled} value=\"{$object->guid}\" id=\"guid_{$object->guid}\" /></td>\n"; echo "{$prefix} <td class=\"label\" style=\"padding-left: {$indent}px\"><label for=\"guid_{$object->guid}\">{$icon}" . $object_label . "</label></td>\n"; echo "{$prefix} <td class=\"nowrap\">" . strftime('%x %X', strtotime($object->metadata->revised)) . "</td>\n"; if (isset($persons[$object->metadata->revisor]->guid)) { echo "{$prefix} <td><a href=\"{$url_prefix}__mfa/asgard/object/view/{$persons[$object->metadata->revisor]->guid}/\">{$persons[$object->metadata->revisor]->name}</a></td>\n"; } else { echo "{$prefix} <td> </td>\n"; } echo "{$prefix} <td>" . midcom_helper_misc::filesize_to_string($object->metadata->size) . "</td>\n"; echo "{$prefix}</tr>\n"; $child_types = midcom_helper_reflector_tree::get_child_objects($object, true); if (is_array($child_types) && count($child_types) > 0) { $child_indent = $indent + 20; echo "{$prefix}<tbody class=\"children\">\n"; foreach ($child_types as $type => $children) { if (count($children) < 10 || isset($_GET['show_children'][$object->guid][$type])) { foreach ($children as $child) { midgard_admin_asgard_trash_type_show($child, $child_indent, "{$prefix} ", false); } } else { echo "{$prefix} <tr>\n"; echo "{$prefix} <td class=\"label\" style=\"padding-left: {$child_indent}px\" colspan=\"5\"><a href=\"?show_children[{$object->guid}][{$type}]=1\">" . sprintf(midcom::get('i18n')->get_string('show %s %s children', 'midgard.admin.asgard'), count($children), midgard_admin_asgard_plugin::get_type_label($type)) . "</a></td>\n"; echo "{$prefix} </tr>\n"; } } echo "{$prefix}</tbody>\n"; } $shown[$object->guid] = true; }
function &_get_reflector(&$object) { if (is_string($object)) { $classname = $object; } else { $classname = get_class($object); } if (!isset($this->_reflectors[$classname])) { $this->_reflectors[$classname] = midcom_helper_reflector_tree::get($object); } return $this->_reflectors[$classname]; }
/** * Static method for binding view to an object */ public static function bind_to_object($object, $handler_id, &$data) { // Tell our object to MidCOM midcom::get('metadata')->set_request_metadata($object->metadata->revised, $object->guid); $data['object_reflector'] = midcom_helper_reflector::get($object); $data['tree_reflector'] = midcom_helper_reflector_tree::get($object); $data['object'] =& $object; // Populate toolbars if (midcom::get('dbclassloader')->is_midcom_db_object($object)) { $context = midcom_core_context::get(); // Bind the object to the metadata service midcom::get('metadata')->bind_metadata_to_object(MIDCOM_METADATA_VIEW, $object, $context->id); // These toolbars only work with DBA objects as they do ACL checks $view_toolbar = midcom::get('toolbars')->get_view_toolbar($context->id); $view_toolbar->bind_to($object); $data['asgard_toolbar']->bind_to_object($object, $handler_id, $data); self::_set_object_breadcrumb($object, $handler_id, $data); } self::set_pagetitle($object, $handler_id, $data); }
/** * Static method to add default ("title" and "name") sorts to a QB instance * * @param midgard_query_builder $qb reference to QB instance * @param string $schema_type valid mgdschema class name */ public static function add_schema_sorts_to_qb(&$qb, $schema_type) { // Sort by "title" and "name" if available $ref = midcom_helper_reflector_tree::get($schema_type); $dummy = new $schema_type(); $title_property = $ref->get_title_property($dummy); if (is_string($title_property) && midcom::get('dbfactory')->property_exists($schema_type, $title_property)) { $qb->add_order($title_property); } $name_property = $ref->get_name_property($dummy); if (is_string($name_property) && midcom::get('dbfactory')->property_exists($schema_type, $name_property)) { $qb->add_order($name_property); } unset($title_property, $name_property, $ref, $dummy); }
/** * Helper to resolve the base value for the incrementing suffix and for the name. * * @see midcom_helper_reflector_nameresolver::generate_unique_name() * @param string $current_name the "current name" of the object (might not be the actual name value see the title logic in generate_unique_name()) * @param string $extension The file extension, when working with attachments * @return array first key is the resolved $i second is the $base_name, which is $current_name without numeric suffix */ private function _generate_unique_name_resolve_i($current_name, $extension) { if (preg_match('/(.*?)-([0-9]{3,})' . $extension . '$/', $current_name, $name_matches)) { // Name already has i and base parts, split them. $i = (int) $name_matches[2]; $base_name = (string) $name_matches[1]; unset($name_matches); } else { // Defaults $i = 1; $base_name = $current_name; } // Look for siblings with similar names and see if they have higher i. midcom::get('auth')->request_sudo('midcom.helper.reflector'); $parent = midcom_helper_reflector_tree::get_parent($this->_object); // TODO: Refactor to reduce duplicate code with _name_is_unique_check_siblings if ($parent && !empty($parent->guid)) { // We have parent, check siblings $parent_resolver = new midcom_helper_reflector_tree($parent); $sibling_classes = $parent_resolver->get_child_classes(); if (!in_array('midgard_attachment', $sibling_classes)) { $sibling_classes[] = 'midgard_attachment'; } foreach ($sibling_classes as $schema_type) { $dummy = new $schema_type(); $child_name_property = midcom_helper_reflector::get_name_property($dummy); unset($dummy); if (empty($child_name_property)) { // This sibling class does not use names continue; } $resolver = midcom_helper_reflector_tree::get($schema_type); $qb =& $resolver->_child_objects_type_qb($schema_type, $parent, false); if (!is_object($qb)) { continue; } $qb->add_constraint($child_name_property, 'LIKE', "{$base_name}-%" . $extension); // Do not include current object in results, this is the easiest way if (!empty($this->_object->guid)) { $qb->add_constraint('guid', '<>', $this->_object->guid); } $qb->add_order('name', 'DESC'); // One result should be enough $qb->set_limit(1); $siblings = $qb->execute(); if (empty($siblings)) { // we don't care about fatal qb errors here continue; } $sibling = $siblings[0]; $sibling_name = $sibling->{$child_name_property}; if (preg_match('/(.*?)-([0-9]{3,})' . $extension . '$/', $sibling_name, $name_matches)) { // Name already has i and base parts, split them. $sibling_i = (int) $name_matches[2]; if ($sibling_i >= $i) { $i = $sibling_i + 1; } unset($sibling_i, $name_matches); } } unset($parent, $parent_resolver, $sibling_classes, $schema_type, $child_name_property, $sibling, $sibling_name); } else { unset($parent); // No parent, we might be a root level class $is_root_class = false; $root_classes = midcom_helper_reflector_tree::get_root_classes(); foreach ($root_classes as $schema_type) { if (midcom::get('dbfactory')->is_a($this->_object, $schema_type)) { $is_root_class = true; } } if (!$is_root_class) { // This should not happen, logging error and returning true (even though it's potentially dangerous) midcom::get('auth')->drop_sudo(); debug_add("Object #{$this->_object->guid} has no valid parent but is not listed in the root classes, don't know what to do, letting higher level decide", MIDCOM_LOG_ERROR); unset($root_classes, $is_root_class); return array($i, $base_name); } else { // TODO: Refactor to reduce duplicate code with _name_is_unique_check_roots foreach ($root_classes as $schema_type) { $dummy = new $schema_type(); $child_name_property = midcom_helper_reflector::get_name_property($dummy); unset($dummy); if (empty($child_name_property)) { // This sibling class does not use names continue; } $resolver =& midcom_helper_reflector_tree::get($schema_type); $deleted = false; $qb =& $resolver->_root_objects_qb($deleted); if (!$qb) { continue; } unset($deleted); $qb->add_constraint($child_name_property, 'LIKE', "{$base_name}-%" . $extension); // Do not include current object in results, this is the easiest way if (!empty($this->_object->guid)) { $qb->add_constraint('guid', '<>', $this->_object->guid); } $qb->add_order($child_name_property, 'DESC'); // One result should be enough $qb->set_limit(1); $siblings = $qb->execute(); if (empty($siblings)) { // we dont' care about fatal qb errors here continue; } $sibling = $siblings[0]; $sibling_name = $sibling->{$child_name_property}; if (preg_match('/(.*?)-([0-9]{3,})' . $extension . '$/', $sibling_name, $name_matches)) { // Name already has i and base parts, split them. $sibling_i = (int) $name_matches[2]; if ($sibling_i >= $i) { $i = $sibling_i + 1; } unset($sibling_i, $name_matches); } } unset($root_classes, $schema_type, $child_name_property, $sibling, $sibling_name); } } midcom::get('auth')->drop_sudo(); return array($i, $base_name); }