[Tickets #6569] Restrict Comment To: groups lose group id when rendered

bugs at horde.org bugs at horde.org
Fri Apr 4 22:06:59 UTC 2008


DO NOT REPLY TO THIS MESSAGE. THIS EMAIL ADDRESS IS NOT MONITORED.

Ticket URL: http://bugs.horde.org/ticket/6569
-----------------------------------------------------------------------
 Ticket             | 6569
 Created By         | php at ideacode.com
 Summary            | Restrict Comment To: groups lose group id when
rendered
 Queue              | Whups
 Type               | Bug
 State              | Unconfirmed
 Priority           | 1. Low
 Milestone          |
 Patch              |
 Owners             |
+New Attachment     | issue.diff
-----------------------------------------------------------------------


php at ideacode.com (2008-04-04 18:06) wrote:

In lib/Forms/EditTicket.php, the comment restriction code goes like this
(I've annotated, as the code isn't commented):
// get all the groups I can access in array (group_id => label, ...)
format
foreach (array_keys($mygroups) as $gid) {
    $grouplist[$gid] = $groups->getGroupName($gid, true);
}
// sort those by name
asort($grouplist);
// tack "Any Group" onto the front
$grouplist = array_merge(array(0 => _("Any Group")), $grouplist);
// push into the form
$this->addVariable(_("Restrict Comment to:"), 'group', 'enum', true,
false, null, array($grouplist));

The intent of this code seems to be to create the drop-down for
restricting comments using the group ID (from the data tree) as the option
value and the group Name (also from the data tree) as the option label.

However, array_merge() screws that up, because PHP 5 & PHP 4 re-index the
array, destroying the key association needed:
[bishop at predator staging]$ cat array_merge.php
<?php
$a = array (23 => 'Hello', '42' => 'World');
$a = array_merge(array (0 => 'I say, '), $a);
var_dump($a);
?>
[bishop at predator staging]$ php-5.2.5 array_merge.php
array(3) {
  [0]=>
  string(7) "I say, "
  [1]=>
  string(5) "Hello"
  [2]=>
  string(5) "World"
}
[bishop at predator staging]$ php-4.4.7 array_merge.php
array(3) {
  [0]=>
  string(7) "I say, "
  [1]=>
  string(5) "Hello"
  [2]=>
  string(5) "World"
}

My suggested patch (attached) is to replace array_merge() with the plus
operator.





More information about the bugs mailing list