0

I got a Joomla ticketing module, that displays at a certain part of the page, the current tickets of the current user. I want to create user groups, in which the group members can view all of the tickets belongin to that group. I thought the easiest way is to create Joomla groups, assign the users to those, and to when a user loges in, it can see all of the tickets in its group. I added my code to the start of the function, but something is wrong... For every user (currently the "Registered" ones) displays the same result, that of the last users tickets, and I don't know why: Here is the code:

function gTickets()
{
$user    =& JFactory::getUser();
$user_id = (int) $user->get('id');

//get user_group_id  from db based on current users id
    {...}

//get all users with that user_group_id
$db1->setQuery($db1->getQuery(true)
        ->select('*')
    ->from("#__user_usergroup_map")
    ->where("group_id = '$groupss'")
    );

$groupss1=$db1->loadRowList();      
$return1=array();

// for every user_id    
foreach ($groupss1 as $keya)
{       
    $user_id = $keya[0]; // the id of users

    $where = "";
    if ($this->is_staff)
        $where .= " AND t.`staff_id`='".$user_id."'";
    else
        $where .= " AND t.`customer_id`='".$user_id."'";

    $tickets = $this->_getList(
"SELECT t.id, t.subject, t.last_reply_customer, s.name AS status_name FROM
#__rsticketspro_tickets t LEFT JOIN #__rsticketspro_statuses s ON 
(t.status_id=s.id) WHERE 1 $where ORDER BY `last_reply` DESC", 0, 
$this->params->get('tickets_limit', 3));

    print_r($tickets);      
    return $tickets;
}

I got some questions, that I didn't know how to seach for...

  1. what is the letter dot fieldname in the sql query? eg: SELECT m.ticket_id, m.message FROM #__ticket_messages m WHERE m.user_id !='".$user_id."
  2. what does the "m" mean before the WHERE?
  3. what does the "1" do here: WHERE 1 $where

Also, I looked in the ACL managers, but could not make it work with this code.

Edit: Thanks for the fast answers! I got 1 more, and I think it's an easy one, but I can't get it to work...

If I print the content of the $ticket array into another array, I get an array with multiple arrays. That is why my code is not working... The array i'm getting is:

Array ( 
  [0] => stdClass Object ( 
    [id] => 1 
    [subject] => use1 
    [last_reply_customer] => 1 
    [status_name] => open 
  ) 
) 
Array ( 
  [0] => stdClass Object ( 
    [id] => 3 
    [subject] => use2 
    [last_reply_customer] => 1 
    [status_name] => open 
    )
  [1] => stdClass Object ( 
    [id] => 2 
    [subject] => use2 
    [last_reply_customer] => 1 
    [status_name] => open 
    ) 
) 

I would like the array to look like this:

Array ( 
  [0] => stdClass Object ( 
    [id] => 1 
    [subject] => use1 
    [last_reply_customer] => 1 
    [status_name] => open 
    )
  [1] => stdClass Object ( 
    [id] => 3 
    [subject] => use2 
    [last_reply_customer] => 1 
    [status_name] => open 
    )
  [2] => stdClass Object ( 
    [id] => 2 
    [subject] => use2 
    [last_reply_customer] => 1 
    [status_name] => open 
    ) 
) 

Thanks!

Edit: is all of this complicated to achieve?

Magor Menessy
  • 381
  • 4
  • 13

1 Answers1

0

Look into ACL to get that part working, but to answer the 3 questions you posted at the bottom of your question:

1) the letter.field_name in the query represents the table alias.field_name in the query. The alias (m) makes it easier so you don't have to keep typing the full table name each time.

2) The m before the WHERE is actually setting the table alias, but with lazy syntax. It should say:

SELECT m.ticket_id, m.message FROM #__ticket_messages AS m

3) The "WHERE 1" is the SQL way of saying "if (true)". Since they are immediately appending the $where clause afterwards "WHERE 1 $where", the resulting query looks like this:

WHERE 1 AND t.staff_id = '" . $user_id . "'

Did you code this originally? or is it a component that you picked up somewhere? It should be using the query builder instead of direct SQL like it currently is, to make it more portable and more clear as to what it is doing.

Don Gilbert
  • 740
  • 4
  • 11