Login or Register

RSS IconRecent posts in this topic

avatar
ipedja on Feb 27. 2008. 1:44 am
CAUTION!!! I am a PHP lamer.

OK, here it goes. We desperately needed information about employee (user either from Owner company or Client companies) when adding a Ticket. I managed to add a combo, it is bound with Users over integer_field_2. Problem is that later when I try to EDIT ticket (Add works fine, I checked in DB) combo won't refresh with correct data. It is always first record (user).
avatar
Ilija Studen on Feb 27. 2008. 2:27 am
Open TicketsController and in edit() action see how initial form data is set:

$ticket_data = $this->request->post('ticket');
if(!is_array($ticket_data)) {
  $ticket_data = array(
    'name' => $this->active_ticket->getName(),
    'body' => $this->active_ticket->getBody(),
    'visibility' => $this->active_ticket->getVisibility(),
    'parent_id' => $this->active_ticket->getParentId(),
    'milestone_id' => $this->active_ticket->getMilestoneId(),
    'priority' => $this->active_ticket->getPriority(),
    'assignees' => Assignments::findAssignmentDataByObject($this->active_ticket),
    'tags' => $this->active_ticket->getTags(),
    'due_on' => $this->active_ticket->getDueOn(),
  );
} // if
$this->smarty->assign('ticket_data', $ticket_data);


Just add your field value to associative array and proper value should be selected in the form. Data from this array is available as $ticket_data in templates.
activeCollab team member
avatar
ipedja on Feb 27. 2008. 6:42 am
Thank you, it worked.

What if I wanted to display this Emplyee on main Tickets page (index.tpl). I managed to display ID:

<tbody>
{foreach from=$tickets_by_milestone.objects item=ticket}
  <tr class="ticket {cycle values='odd,even'}" id="ticket{$ticket->getId()}">
    <td class="star">{object_star object=$ticket user=$logged_user}</td>
    <td class="priority">{object_priority object=$ticket}</td>
    <td class="ticket_id">#{$ticket->getTicketId()}</td>
    <td class="korisnik_id">#{$ticket->getEmplyeeId()}</td>
    <td class="name"><a href="{$ticket->getViewUrl()}">{$ticket->getName()|clean}</h3>
    </td>
    <td class="checkbox"><input type="checkbox" name="tickets[]" value="{$ticket->getId()}" class="auto" /></td>
  </tr>


but of course that is not realy usable. Can someone help me about some kind of getEmployeeName() function...
avatar
Ilija Studen on Feb 27. 2008. 7:09 am
Create function (with additional field) in Ticket class:

var $employee = false;

function getEmployee() {
  if($this->employee === false) {
    $this->employee =  Users::findById($this->getEmployeeId());
  }
  return $this->employee;
}


in template you would use something like this:

{if instance_of($ticket->getEmployee(), 'User')}
  {user_link user=$ticket->getEmployee()}
{else}
  -- Unknown User --
{/if}
activeCollab team member
avatar
ipedja on Feb 27. 2008. 8:02 am
Brilliant!

Everything works fine, thank you...

RSS IconRecent posts in this topic