Example #1
0
 /**
  * @dataProvider providerGet_object_title
  */
 public function testGet_object_title($classname, $data, $label)
 {
     $object = new $classname();
     foreach ($data as $field => $value) {
         $object->{$field} = $value;
     }
     $reflector = new midcom_helper_reflector($object);
     $this->assertEquals($label, $reflector->get_object_title($object));
 }
Example #2
0
 /**
  * Handler method for listing style elements for the currently used component topic
  *
  * @param string $handler_id Name of the used handler
  * @param mixed $args Array containing the variable arguments passed to the handler
  * @param mixed &$data Data passed to the show method
  */
 public function _handler_edit($handler_id, array $args, array &$data)
 {
     $this->_group = new midcom_db_group($args[0]);
     $this->_group->require_do('midgard:update');
     $controller = $this->get_controller('simple', $this->_group);
     switch ($controller->process_form()) {
         case 'save':
             // Show confirmation for the group
             midcom::get('uimessages')->add($this->_l10n->get('midcom.admin.user'), sprintf($this->_l10n->get('group %s saved'), $this->_group->name));
             return new midcom_response_relocate("__mfa/asgard_midcom.admin.user/group/edit/{$this->_group->guid}/");
         case 'cancel':
             return new midcom_response_relocate('__mfa/asgard_midcom.admin.user/');
     }
     $data['group'] =& $this->_group;
     $data['controller'] =& $controller;
     $ref = new midcom_helper_reflector($this->_group);
     $data['view_title'] = sprintf(midcom::get('i18n')->get_string('edit %s', 'midcom.admin.user'), $ref->get_object_title($this->_group));
     midcom::get('head')->set_pagetitle($data['view_title']);
     $this->_update_breadcrumb();
     $data['asgard_toolbar']->add_item(array(MIDCOM_TOOLBAR_URL => "__mfa/asgard_midcom.admin.user/group/move/{$this->_group->guid}/", MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('move group', 'midcom.admin.user'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/save-as.png'));
     $data['asgard_toolbar']->add_item(array(MIDCOM_TOOLBAR_URL => "__mfa/asgard_midcom.admin.user/group/folders/{$this->_group->guid}/", MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('folders', 'midcom.admin.user'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/folder.png'));
     midgard_admin_asgard_plugin::bind_to_object($this->_group, $handler_id, $data);
 }
Example #3
0
 /**
  * Generates an unique name for the given object.
  *
  * 1st IF name is empty, we generate one from title (if title is empty too, we return false)
  * Then we check if it's unique, if not we add an incrementing
  * number to it (before this we make some educated guesses about a
  * good starting value)
  *
  * @param string $title_property, property of the object to use at title, if null will be reflected (see midcom_helper_reflector::get_object_title())
  * @param string $extension The file extension, when working with attachments
  * @return string string usable as name or boolean false on critical failures
  */
 public function generate_unique_name($title_property = null, $extension = '')
 {
     // Get current name and sanity-check
     $original_name = $this->get_object_name();
     if ($original_name === false) {
         // Fatal error with name resolution
         debug_add("Object " . get_class($this->_object) . " #{$this->_object->id} returned critical failure for name resolution, aborting", MIDCOM_LOG_WARN);
         return false;
     }
     // We need the name of the "name" property later
     $name_prop = midcom_helper_reflector::get_name_property($this->_object);
     if (!empty($original_name)) {
         $current_name = (string) $original_name;
     } else {
         // Empty name, try to generate from title
         $title_copy = midcom_helper_reflector::get_object_title($this->_object, $title_property);
         if ($title_copy === false) {
             unset($title_copy);
             // Fatal error with title resolution
             debug_add("Object " . get_class($this->_object) . " #{$this->_object->id} returned critical failure for title resolution when name was empty, aborting", MIDCOM_LOG_WARN);
             return false;
         }
         if (empty($title_copy)) {
             unset($title_copy);
             debug_add("Object " . get_class($this->_object) . " #{$this->_object->id} has empty name and title, aborting", MIDCOM_LOG_WARN);
             return false;
         }
         $current_name = midcom_helper_misc::generate_urlname_from_string($title_copy);
         unset($title_copy);
     }
     // incrementer, the number to add as suffix and the base name. see _generate_unique_name_resolve_i()
     list($i, $base_name) = $this->_generate_unique_name_resolve_i($current_name, $extension);
     $this->_object->name = $base_name;
     // decrementer, do not try more than this many times (the incrementer can raise above this if we start high enough.
     $d = 100;
     // The loop, usually we *should* hit gold in first try
     do {
         if ($i > 1) {
             // Start suffixes from -002
             $this->_object->{$name_prop} = $base_name . sprintf('-%03d', $i) . $extension;
         }
         // Handle the decrementer
         --$d;
         if ($d < 1) {
             // Decrementer undeflowed
             debug_add("Maximum number of tries exceeded, current name was: " . $this->_object->{$name_prop}, MIDCOM_LOG_ERROR);
             $this->_object->{$name_prop} = $original_name;
             unset($i, $d, $name_prop, $original_name, $base_name);
             return false;
         }
         // and the incrementer
         ++$i;
     } while (!$this->name_is_unique());
     unset($i, $d);
     // Get a copy of the current, usable name
     $ret = (string) $this->_object->{$name_prop};
     // Restore the original name
     $this->_object->{$name_prop} = $original_name;
     unset($name_prop, $original_name, $base_name);
     return $ret;
 }