private function connect_to_signals($class) { midgard_object_class::connect_default($class, 'action-loaded-hook', array($this, 'on_loading'), array($class)); midgard_object_class::connect_default($class, 'action-create-hook', array($this, 'on_creating'), array($class)); midgard_object_class::connect_default($class, 'action-update-hook', array($this, 'on_updating'), array($class)); midgard_object_class::connect_default($class, 'action-delete-hook', array($this, 'on_deleting'), array($class)); }
public function connect_to_signals() { midgard_object_class::connect_default('midgard_attachment', 'action-created', array($this, 'on_creating'), array('attachment')); midgard_object_class::connect_default('midgard_attachment', 'action-deleted', array($this, 'on_deleting'), array()); // TODO: attachment cache needs undelete support // TODO: attachment cache needs approvals support }
public function prepareObject(TypeInterface $controller, $parent = null) { $config = $controller->getConfig(); $class = $config['storage']; $object = new $class(); if (null !== $parent) { $baseclass = \midcom_helper_reflector::resolve_baseclass($class); $reflector = new \midgard_reflection_property($baseclass); $up_property = \midgard_object_class::get_property_up($baseclass); if (!empty($up_property)) { $target_property = $reflector->get_link_target($up_property); $target_class = $reflector->get_link_name($up_property); if (\midcom_helper_reflector::resolve_baseclass($parent) === $target_class) { $object->{$up_property} = $parent->{$target_property}; } } $parent_property = \midgard_object_class::get_property_parent($baseclass); if (!empty($parent_property)) { $target_property = $reflector->get_link_target($parent_property); $target_class = $reflector->get_link_name($parent_property); if (\midcom_helper_reflector::resolve_baseclass($parent) === $target_class) { $object->{$parent_property} = $parent->{$target_property}; } else { $object->{$parent_property} = $parent->{$parent_property}; } } } return $object; }
public function get_object(array $args) { $this->_core->authorization->require_user(); $object = midgard_object_class::get_object_by_guid($args['guid']); if (!$object->guid) { throw new midgardmvc_exception_notfound("Object {$args['guid']} not found"); } $this->data['actions'] = $this->_core->componentloader->get_object_actions($object); }
public function inject_process(midgardmvc_core_request $request) { static $connected = false; if ($connected) { return; } // Subscribe to content changed signals from Midgard midgard_object_class::connect_default('fi_openkeidas_groups_group', 'action-created', array('fi_openkeidas_groups_injector', 'handle_created'), array($request)); $connected = true; }
private function connect_to_signals($class) { if (!isset($_MIDGARD['schema']['types'][$class])) { throw new Exception("{$class} is not an MgdSchema class"); } midgard_object_class::connect_default($class, 'action-loaded-hook', array($this, 'on_loading'), array($class)); midgard_object_class::connect_default($class, 'action-create-hook', array($this, 'on_creating'), array($class)); midgard_object_class::connect_default($class, 'action-update-hook', array($this, 'on_updating'), array($class)); midgard_object_class::connect_default($class, 'action-delete-hook', array($this, 'on_deleting'), array($class)); }
private function get_connected() { $mvc = midgardmvc_core::get_instance(); $language = $mvc->configuration->get('default_language'); if (!$language) { $language = 'en_US'; } $mvc->i18n->set_language($language, false); midgard_object_class::connect_default('com_meego_comments_comment', 'action-deleted', array('com_meego_ratings_injector', 'delete_rating_handler')); $this->connected = true; }
public function inject_process(midgardmvc_core_request $request) { static $connected = false; if ($connected) { return; } // Subscribe to content changed signals from Midgard midgard_object_class::connect_default('fi_openkeidas_diary_log', 'action-created', array('fi_openkeidas_diary', 'update_sport_and_group'), array($request)); midgard_object_class::connect_default('fi_openkeidas_diary_challenge', 'action-created', array('fi_openkeidas_diary', 'update_challenge_members'), array($request)); midgard_object_class::connect_default('fi_openkeidas_diary_challenge', 'action-delete', array('fi_openkeidas_diary', 'remove_challenge_members'), array($request)); $connected = true; }
public function inject_process(midgardmvc_core_request $request) { // Subscribe to content changed signals from Midgard so we can send content to FISE for analysis $mgdschemas = midgardmvc_core::get_instance()->dispatcher->get_mgdschema_classes(); foreach ($mgdschemas as $mgdschema) { if ($mgdschema == 'midgardmvc_core_login_session' || $mgdschema == 'midgard_parameter') { continue; } midgard_object_class::connect_default($mgdschema, 'action-created', array('eu_iksproject_fise_indexer', 'store'), array()); midgard_object_class::connect_default($mgdschema, 'action-updated', array('eu_iksproject_fise_indexer', 'store'), array()); } }
/** * This is a replacement for the original midgard_object_class::get_object_by_guid method, which takes * the MidCOM DBA system into account. * * @see http://www.midgard-project.org/documentation/php_midgard_object_class/ * * @param string $guid The object GUID. * @return object A MidCOM DBA object if the set GUID is known */ function get_object_by_guid($guid) { try { $tmp = midgard_object_class::get_object_by_guid($guid); } catch (midgard_error_exception $e) { debug_add('Loading object by GUID ' . $guid . ' failed, reason: ' . $e->getMessage(), MIDCOM_LOG_INFO); throw new midcom_error_midgard($e, $guid); } if (get_class($tmp) == 'midgard_person' && $GLOBALS['midcom_config']['person_class'] != 'midgard_person') { $tmp = new $GLOBALS['midcom_config']['person_class']($guid); } return $this->convert_midgard_to_midcom($tmp); }
public function inject_process(midgardmvc_core_request $request) { static $connected = false; if ($connected) { return; } // Subscribe to content changed signals from Midgard midgard_object_class::connect_default('com_meego_planet_feed', 'action-delete-hook', function ($feed) { array_walk(com_meego_planet_utils::get_items_for_feed($feed), function ($item) { $item->delete(); }); }); $connected = true; }
public function __construct() { static $connected = false; $this->check_dependencies(); $this->load_root_node(); if ($connected) { return; } // Subscribe to node editing signals midgard_object_class::connect_default('midgardmvc_core_node', 'action-updated', array($this, 'refresh_node')); midgard_object_class::connect_default('midgardmvc_core_node', 'action-create', array($this, 'check_node')); midgard_object_class::connect_default('midgardmvc_core_node', 'action-created', array($this, 'refresh_node_parent')); $connected = true; }
public function inject_process(midgardmvc_core_request $request) { static $connected = false; if (!$connected) { // Subscribe to content changed signals from Midgard midgard_object_class::connect_default('fi_openkeidas_articles_article', 'action-create', array('fi_openkeidas_articles_injector', 'check_node'), array($request)); $connected = true; } $component = $request->get_node()->get_component(); /* Patch out article authorization 200712 */ /* if ($component == 'fi_openkeidas_articles') { midgardmvc_core::get_instance()->authorization->require_user(); } */ }
private function connect_type($type, array $events) { if (!isset($this->connected_types[$type])) { $this->connected_types[$type] = array(); } foreach ($events as $event) { if (isset($this->connected_types[$type][$event])) { // We already listen for this signal return; } try { midgard_object_class::connect_default($type, $event, array($this, 'trigger'), array('type' => $type, 'event' => $event)); } catch (midgard_error_exception $e) { // Midgard connection not available. Ignore } } }
/** * Sets language, connectes signal handlers */ private function get_connected() { $this->mvc = midgardmvc_core::get_instance(); $this->mvc->i18n->set_translation_domain('com_meego_packages'); $default_language = $this->mvc->configuration->default_language; if (!isset($default_language)) { $default_language = 'en_US'; } $this->mvc->i18n->set_language($default_language, false); $request = $this->mvc->dispatcher->get_request(); //midgard_object_class::connect_default('midgard_attachment', 'action_loaded_hook', array('com_meego_packages_injector', 'register_download'), array($request)); midgard_object_class::connect_default('com_meego_ratings_rating', 'action_created', array('com_meego_packages_injector', 'register_rate_comment'), array($request)); midgard_object_class::connect_default('midgardmvc_ui_forms_form_instance', 'action_created', array('com_meego_packages_injector', 'register_qa_post'), array($request)); // Default title for Packages pages, override in controllers when possible $this->mvc->head->set_title($this->mvc->i18n->get('title_apps')); $_mc = midgard_connection::get_instance(); $res = $_mc->enable_replication(false); $this->connected = true; }
public function get_comments(array $args) { $this->data['to'] = midgard_object_class::get_object_by_guid($args['to']); if (!$this->data['to']) { throw new midgardmvc_exception_notfound("Comment target not found"); } $this->data['comments'] = array(); $storage = new midgard_query_storage('com_meego_comments_comment_author'); $q = new midgard_query_select($storage); $q->set_constraint(new midgard_query_constraint(new midgard_query_property('to', $storage), '=', new midgard_query_value($this->data['to']->guid))); $q->add_order(new midgard_query_property('posted', $storage), SORT_ASC); $q->execute(); $comments = $q->list_objects(); foreach ($comments as $comment) { $this->data['comments'][$comment->commentid] = $comment; } if (midgardmvc_core::get_instance()->authentication->is_user()) { $this->data['can_post'] = true; } else { $this->data['can_post'] = false; } }
public function addNode($relPath, $primaryNodeTypeName = NULL) { $parent_node = $this; $object_name = $relPath; // ItemExistsException // Node at given path exists. try { $parent_node = $this->getNode($relPath); throw new \PHPCR\ItemExistsException("Node at given path {$relPath} exists"); } catch (\PHPCR\PathNotFoundException $e) { // Do nothing } // PathNotFoundException // At least one (not last) node at given path doesn't exist if (strpos($relPath, '/') !== false) { $parts = explode('/', $relPath); $object_name = end($parts); $parent_path = array_pop($parts); $parent_node = $this->getNode($parent_path); } // ConstraintViolationException // Underying Midgard2 object has no tree support and path contains at least two elements // TODO, Determine Midgard2 type from given NodeTypeName // FIXME, Get unique property once midgard_reflector_object::get_property_unique is added to PHP extension // LockException // TODO // VersionException // TODO $mobject = \midgard_object_class::factory(get_class($this->getMidgard2Object())); $mobject->name = $object_name; $new_node = new Node($mobject, $parent_node, $parent_node->getSession()); $new_new->is_new = true; $parent_node->children[$object_name] = $new_node; // FIXME, Catch exception before returning new node return $new_node; // RepositoryException // Unspecified yet. throw new \PHPCR\RepositoryException("Not supported"); }
/** * Sets the average rating of the package * Sets the flag showing if the package was ever rated or not * Sets $this->data['stars'] that can be directly put to pages showing * the stars */ public function get_average(array $args) { $this->data['to'] = midgard_object_class::get_object_by_guid($args['to']); if (!$this->data['to']) { throw new midgardmvc_exception_notfound("rating target not found"); } parent::get_read($args); $this->data['ratings'] = array(); $this->data['average'] = 0; $this->data['rated'] = false; $storage = new midgard_query_storage('com_meego_ratings_rating_author'); $q = new midgard_query_select($storage); $q->set_constraint(new midgard_query_constraint(new midgard_query_property('to'), '=', new midgard_query_value($this->data['to']->guid))); $q->add_order(new midgard_query_property('posted'), SORT_DESC); $q->execute(); $ratings = $q->list_objects(); $sum = 0; // only contains ratings where rating is not 0 $num_of_valid_ratings = 0; if (count($ratings)) { $this->data['rated'] = true; foreach ($ratings as $rating) { $rating->stars = ''; if ($rating->ratingcomment) { $comment = new com_meego_comments_comment($rating->ratingcomment); $rating->ratingcommentcontent = $comment->content; } if ($rating->rating || $rating->ratingcomment) { // add a new property containing the stars to the rating object $rating->stars = $this->draw_stars($rating->rating); // pimp the posted date $rating->date = gmdate('Y-m-d H:i e', strtotime($rating->posted)); $sum += $rating->rating; if ($rating->rating) { // count only non zero ratings ++$num_of_valid_ratings; } } array_push($this->data['ratings'], $rating); } if ($num_of_valid_ratings) { $this->data['average'] = round($sum / $num_of_valid_ratings, 1); } } $this->get_stars($this->data['average']); }
private function connect_to_signals($class) { // Subscribe to the "after the fact" signals midgard_object_class::connect_default($class, 'action-loaded', array($this, 'register_object'), array($class)); midgard_object_class::connect_default($class, 'action-update', array($this, 'invalidate_object'), array($class)); midgard_object_class::connect_default($class, 'action-delete', array($this, 'invalidate_object'), array($class)); }
/** * Sets the average rating of the package * Sets $this->data['stars'] that can be directly put to pages showing * the stars */ public function get_average(array $args) { try { $this->data['to'] = midgard_object_class::get_object_by_guid($args['to']); } catch (midgard_error_exception $e) { midgardmvc_core::get_instance()->log(__CLASS__, 'Package with guid: ' . $args['to'] . ' not found. ' . $e->getMessage(), 'error'); return false; } $this->data['repository'] = new com_meego_repository($this->data['to']->repository); com_meego_ratings_controllers_rating::get_read($args); $storage = new midgard_query_storage('com_meego_package_statistics_calculated'); $q = new midgard_query_select($storage); $q->set_constraint(new midgard_query_constraint(new midgard_query_property('packageguid'), '=', new midgard_query_value($this->data['to']->guid))); $q->execute(); $cache = $q->list_objects(); $this->data['average'] = 0; $this->data['numberofratings'] = 0; $this->data['numberofcomments'] = 0; $this->data['rated'] = false; //load data from cache if (count($cache) > 0) { $this->data['average'] = $cache[0]->ratingvalue; $this->data['numberofratings'] = $cache[0]->ratings; $this->data['numberofcomments'] = $cache[0]->comments; $this->data['rated'] = true; } com_meego_ratings_caching_controllers_rating::get_stars($this->data['average']); }
public function get_document(array $args) { $object = midgard_object_class::get_object_by_guid($args['guid']); if (!$object || !$object->guid) { throw new midcom_exception_notfound("Object {$args['guid']} not found"); } // Map the object to CoudbDb format $status = array(); // CouchDb-specific metadata $status['_id'] = $object->guid; $status['_rev'] = org_couchdb_replication_controllers_server::get_rev($object); // Add normal object properties $status = array_merge($status, get_object_vars($object)); // Remove data we shouldn't send unset($status['id']); unset($status['guid']); unset($status['metadata']); foreach ($status as $key => $val) { if (is_a($val, 'midgard_datetime')) { $status[$key] = $val->format(DATE_ATOM); } } $this->data[]['ok'] = $status; }
/** * Get the target properties and return an array that is used e.g. in copying * * @param mixed $object MgdSchema object or MidCOM db object * @return array id, parent property, class and label of the object */ public static function get_target_properties($object) { $mgdschema_class = midcom_helper_reflector::resolve_baseclass($object); $mgdschema_object = new $mgdschema_class($object->guid); static $targets = array(); // Return the cached results if (isset($targets[$mgdschema_class])) { return $targets[$mgdschema_class]; } // Empty result set for the current class $target = array('id' => null, 'parent' => '', 'class' => $mgdschema_class, 'label' => '', 'reflector' => new midcom_helper_reflector($object)); // Try to get the parent property for determining, which property should be // used to point the parent of the new object. Attachments are a special case. if (!midcom::get('dbfactory')->is_a($object, 'midcom_db_attachment')) { $parent_property = midgard_object_class::get_property_parent($mgdschema_object); } else { $parent_property = 'parentobject'; } // Get the class label $target['label'] = $target['reflector']->get_label_property(); // Try once more to get the parent property, but now try up as a backup if (!$parent_property) { $up_property = midgard_object_class::get_property_up($mgdschema_object); if (!$up_property) { throw new midcom_error('Failed to get the parent property for copying'); } $target['parent'] = $up_property; } else { $target['parent'] = $parent_property; } // Cache the results $targets[$mgdschema_class] = $target; return $targets[$mgdschema_class]; }
public function prepare_new_object(array $args) { $this->data['parent'] = midgard_object_class::get_object_by_guid($args['to']); $this->object = new com_meego_comments_comment(); $this->object->to = $this->data['parent']->guid; }
/** * Get the GUID of the object's parent. This is done by reading up or parent * property values, which will give us the parent's ID. Since the ID => GUID relation * won't change, the corresponding GUID is then stored in an in-request static cache */ public static function get_parent_guid_uncached_static($object_guid, $class_name) { static $parent_mapping = array(); $class_name = midcom::get('dbclassloader')->get_mgdschema_class_name_for_midcom_class($class_name); $reflector = new midgard_reflection_property($class_name); $up_property = midgard_object_class::get_property_up($class_name); if (!empty($up_property)) { $target_property = $reflector->get_link_target($up_property); // Up takes precedence over parent $mc = new midgard_collector($class_name, 'guid', $object_guid); $mc->set_key_property($up_property); $mc->execute(); $link_values = $mc->list_keys(); if (!empty($link_values)) { list($link_value, $dummy) = each($link_values); unset($mc, $link_values, $dummy); if (!empty($link_value)) { if (!array_key_exists($class_name, $parent_mapping)) { $parent_mapping[$class_name] = array(); } if (array_key_exists($link_value, $parent_mapping[$class_name])) { return $parent_mapping[$class_name][$link_value]; } $mc2 = new midgard_collector($class_name, $target_property, $link_value); $mc2->set_key_property('guid'); $mc2->execute(); $guids = $mc2->list_keys(); if (!is_array($guids)) { unset($mc2, $guids, $link_value); $parent_mapping[$class_name][$link_value] = null; return $parent_mapping[$class_name][$link_value]; } list($parent_guid, $dummy) = each($guids); $parent_mapping[$class_name][$link_value] = $parent_guid; unset($mc2, $guids, $link_value, $dummy); return $parent_guid; } } else { unset($mc, $link_values); } } $parent_property = midgard_object_class::get_property_parent($class_name); if (!empty($parent_property) && $reflector->get_link_target($parent_property)) { $target_property = $reflector->get_link_target($parent_property); $target_class = $reflector->get_link_name($parent_property); $mc = new midgard_collector($class_name, 'guid', $object_guid); $mc->set_key_property($parent_property); $mc->execute(); $link_values = $mc->list_keys(); if (!empty($link_values)) { list($link_value, $dummy) = each($link_values); unset($mc, $link_values, $dummy); if (!empty($link_value)) { if (!array_key_exists($target_class, $parent_mapping)) { $parent_mapping[$target_class] = array(); } if (array_key_exists($link_value, $parent_mapping[$target_class])) { return $parent_mapping[$target_class][$link_value]; } $mc2 = new midgard_collector($target_class, $target_property, $link_value); $mc2->set_key_property('guid'); $mc2->execute(); $guids = $mc2->list_keys(); if (!is_array($guids)) { unset($mc2, $guids, $link_value); $parent_mapping[$target_class][$link_value] = null; return $parent_mapping[$target_class][$link_value]; } list($parent_guid, $dummy) = each($guids); $parent_mapping[$target_class][$link_value] = $parent_guid; unset($mc2, $guids, $link_value, $dummy); return $parent_guid; } } else { unset($mc, $link_values); } } // FIXME: Handle GUID linking return null; }
/** * Resolves the "root level" classes, used by get_root_classes() * * @return array of classnames (or false on critical failure) */ private static function _resolve_root_classes() { $root_exceptions_notroot = midcom_baseclasses_components_configuration::get('midcom.helper.reflector', 'config')->get('root_class_exceptions_notroot'); // Safety against misconfiguration if (!is_array($root_exceptions_notroot)) { debug_add("config->get('root_class_exceptions_notroot') did not return array, invalid configuration ??", MIDCOM_LOG_ERROR); $root_exceptions_notroot = array(); } $root_classes = array(); foreach (midcom_connection::get_schema_types() as $schema_type) { if (substr($schema_type, 0, 2) == '__') { continue; } if (in_array($schema_type, $root_exceptions_notroot)) { // Explicitly specified to not be root class, skip all heuristics continue; } // Class extensions mapping $schema_type = midcom_helper_reflector::class_rewrite($schema_type); // Make sure we only add classes once if (in_array($schema_type, $root_classes)) { // Already listed continue; } $parent = midgard_object_class::get_property_parent($schema_type); if (!empty($parent)) { // type has parent set, thus cannot be root type continue; } $dba_class = midcom::get('dbclassloader')->get_midcom_class_name_for_mgdschema_object($schema_type); if (!$dba_class) { // Not a MidCOM DBA object, skip continue; } $root_classes[] = $schema_type; } unset($root_exceptions_notroot); $root_exceptions_forceroot = midcom_baseclasses_components_configuration::get('midcom.helper.reflector', 'config')->get('root_class_exceptions_forceroot'); // Safety against misconfiguration if (!is_array($root_exceptions_forceroot)) { debug_add("config->get('root_class_exceptions_forceroot') did not return array, invalid configuration ??", MIDCOM_LOG_ERROR); $root_exceptions_forceroot = array(); } if (!empty($root_exceptions_forceroot)) { foreach ($root_exceptions_forceroot as $schema_type) { if (!class_exists($schema_type)) { // Not a valid class debug_add("Type {$schema_type} has been listed to always be root class, but the class does not exist", MIDCOM_LOG_WARN); continue; } if (in_array($schema_type, $root_classes)) { // Already listed continue; } $root_classes[] = $schema_type; } } usort($root_classes, 'strnatcmp'); return $root_classes; }
/** * Gets a list of link properties and the links target info * * Link info key specification * 'class' string link target class name * 'target' string link target property (of target class) * 'parent' boolean link is link to "parent" in object tree * 'up' boolean link is link to "up" in object tree * * @return array multidimensional array keyed by property, values are arrays with link info (or false in case of failure) */ public function get_link_properties() { // Return cached results if we have them static $cache = array(); if (isset($cache[$this->mgdschema_class])) { return $cache[$this->mgdschema_class]; } debug_add("Starting analysis for class {$this->mgdschema_class}"); // Shorthands $ref =& $this->_mgd_reflector; $obj =& $this->_dummy_object; // Get property list and start checking (or abort on error) $properties = get_object_vars($obj); if (empty($properties)) { debug_add("Could not list object properties, aborting", MIDCOM_LOG_ERROR); return false; } $links = array(); $parent_property = midgard_object_class::get_property_parent($obj); $up_property = midgard_object_class::get_property_up($obj); foreach ($properties as $property => $dummy) { if ($property == 'guid') { // GUID, even though of type MGD_TYPE_GUID, is never a link continue; } if (!$ref->is_link($property) && $ref->get_midgard_type($property) != MGD_TYPE_GUID) { continue; } debug_add("Processing property '{$property}'"); $linkinfo = array('class' => null, 'target' => null, 'parent' => false, 'up' => false, 'type' => $ref->get_midgard_type($property)); if (!empty($parent_property) && $parent_property === $property) { debug_add("Is 'parent' property"); $linkinfo['parent'] = true; } if (!empty($up_property) && $up_property === $property) { debug_add("Is 'up' property"); $linkinfo['up'] = true; } $type = $ref->get_link_name($property); debug_add("get_link_name returned '{$type}'"); if (!empty($type)) { $linkinfo['class'] = $type; } unset($type); $target = $ref->get_link_target($property); debug_add("get_link_target returned '{$target}'"); if (!empty($target)) { $linkinfo['target'] = $target; } elseif ($linkinfo['type'] == MGD_TYPE_GUID) { $linkinfo['target'] = 'guid'; } unset($target); $links[$property] = $linkinfo; unset($linkinfo); } debug_print_r("Links for {$this->mgdschema_class}: ", $links); $cache[$this->mgdschema_class] = $links; return $links; }
/** * Update, delete, undelete a basecategory */ public function post_manage_basecategory(array $args) { $this->mvc->authorization->require_admin(); $this->data['category'] = false; $this->data['undelete'] = false; $this->data['undelete_error'] = false; $this->data['form_action'] = $this->get_url_read($args['basecategory']); $this->data['indexurl'] = $this->get_url_admin_index(); // some counters need to be reset $this->data['mapping_counter'] = 0; $this->data['package_counter'] = 0; if (array_key_exists('undelete', $_POST)) { if (!midgard_object_class::undelete($args['basecategory'])) { $this->data['undelete_error'] = true; $this->data['status'] = 'error'; $this->data['feedback_objectname'] = $args['basecategory']; $this->data['feedback'] = 'feedback_basecategory_undelete_failed'; return; } } try { $this->load_object($args); } catch (midgard_error_exception $e) { $this->data['status'] = 'error'; $this->data['feedback_objectname'] = $args['basecategory']; $this->data['feedback'] = 'feedback_basecategory_does_not_exist'; $this->data['undelete_error'] = true; return; } if (array_key_exists('undelete', $_POST)) { $relations = self::load_relations_for_basecategory($this->object->id, true); if (is_array($relations)) { foreach ($relations as $relation) { midgard_object_class::undelete($relation->guid); } } // refresh mapping table $this->prepare_mapping($this->object); // set feedback and let it go $this->data['feedback'] = 'feedback_basecategory_undelete_ok'; } $this->data['status'] = 'status'; $this->data['category'] = $this->object; $this->data['feedback_objectname'] = $this->object->name; if (array_key_exists('update', $_POST)) { $new_name = trim(htmlentities($_POST['categories'][$this->object->name]['name'])); $new_description = trim(htmlentities($_POST['categories'][$this->object->name]['description'])); if (strlen($new_name) == 0) { $this->data['status'] = 'error'; $this->data['feedback'] = 'error_basecategory_name_empty'; return; } if ($new_name == $this->object->name) { if ($new_description == $this->object->description) { $this->data['feedback'] = 'feedback_basecategory_no_change'; return; } } $this->prepare_mapping($this->object); $this->object->name = $new_name; $this->object->description = $new_description; $this->object->update(); $this->data['feedback_objectname'] = $this->object->name; $this->data['feedback'] = 'feedback_basecategory_update_ok'; } elseif (array_key_exists('updatemapping', $_POST)) { // delete all mappings of this base category $this->delete_relations($this->object->id, true); // set relations to db if they were posted if (array_key_exists('mapped', $_POST)) { foreach ($_POST['mapped'] as $packagecategory) { $newrelation = new com_meego_package_category_relation(); $newrelation->basecategory = $this->object->id; $newrelation->packagecategory = $packagecategory; if ($newrelation->basecategory != 0 && $newrelation->packagecategory != 0) { $newrelation->create(); } } $this->data['feedback'] = 'feedback_category_mapping_updated_ok'; } // set the list of all package categories, but set it so // that parents are also part of the category name, e.g. Application:Games, not just Games $this->prepare_mapping($this->object); } elseif (array_key_exists('delete', $_POST)) { // delete the base category $this->object->delete(); // delete all its relations self::delete_relations($this->object->id, false); // allow undelete $this->data['undelete'] = true; // set feedback $this->data['feedback'] = 'feedback_basecategory_delete_ok'; // some counters need to be reset $this->data['mapping_counter'] = 0; $this->data['package_counter'] = 0; } elseif (array_key_exists('index', $_POST)) { $this->mvc->head->relocate($this->get_url_admin_index()); } }
private function getChildTypes($midgard_class) { $mgdschemas = $this->getTypes(); $child_types = array(); foreach ($mgdschemas as $mgdschema) { if ($mgdschema == 'midgard_attachment' || $mgdschema == 'midgard_parameter') { continue; } $link_properties = array('parent' => \midgard_object_class::get_property_parent($mgdschema), 'up' => \midgard_object_class::get_property_up($mgdschema)); $ref = new \midgard_reflection_property($mgdschema); foreach ($link_properties as $type => $property) { $link_class = $ref->get_link_name($property); if (empty($link_class) && $ref->get_midgard_type($property) === MGD_TYPE_GUID) { $child_types[] = $mgdschema; continue; } if ($link_class == $parent_class) { $child_types[] = $mgdschema; } } } return $child_types; }