a better way to do this?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Good morning group,

Working on a generic ticketing system...each ticket can have multiple
comments, each comment can have multiple people concurring the comment
(generates a child comment record in the ticket_comments table and a
concurrence record (indicating if they approved or disapproved) in the
comment_concurrences table).  Have everything working...wonderful.  I
decided to print all my queries before releasing beta version and
apparently working on a very fast intranet afforded me to be sloppy!

Basically what I have going on:
The ticket class has a comments container that is an array of related
comments objects.
The comments class has a concurrence container that is an array of
concurrence objects.

When the ticket factory method is called, it calls the comments
factory method, which in turn calls the concurrence factory method.
Like I said, works fine...but right now it's using loops to generate
each concurrence set for each comment, resulting in an ever growing
number of queries for every request.

So, a new concurrence method:

public static function getTicketConcurrences ($comments) {
 //@param $comments is an array of comment objects
 foreach ($comments as $c) {
  $c_ids[] = $c->getCommentId();
 $res = db::getTicketConcurrences($c_ids);
 while ($r = mysql_fetch_array($r)) {
  $concurrence = new concurrence($r);
  foreach ($comments as &$c)
{                                                         #####
   if ($c->getCommentId() == $concurrence->getCommentId())
{            #####
Quoted text here. Click to load it
  } // end foreach
 } //end while
 return $comments;
} // end getTicketConcurrences() method

My question is...is there a better way for me to do what I have marked
(#####)?  Looping through the objects and the like just seem ugly.
Maybe an array function like array_search...but will let me look at a
specific property within the object?



Site Timeline