/** * Set ticket attributes * * @param array $info Attributes to set * @param Whups_Ticket $ticket The ticket which attributes to set. */ public function setAttributes(array $info, Whups_Ticket &$ticket) { $ticket_id = $ticket->getId(); foreach ($info as $name => $value) { if (substr($name, 0, 10) == 'attribute_' && $ticket->get($name) != $value) { $attribute_id = (int) substr($name, 10); $serialized = $this->_serializeAttribute($value); $ticket->change($name, $value); $this->_setAttributeValue($ticket_id, $attribute_id, $serialized); $this->updateLog($ticket_id, $GLOBALS['registry']->getAuth(), array('attribute' => $attribute_id . ':' . $serialized)); } } }
/** * Creates a new ticket. * * Pretty bare wrapper around Whups_Driver::addTicket(). * * @static * * @param array $info A hash with ticket information. * * @return Whups_Ticket Whups_Ticket object. */ public static function newTicket($info, $requester) { global $whups_driver; if (!isset($info['type'])) { $info['type'] = $whups_driver->getDefaultType($info['queue']); if (!$info['type']) { $queue = $whups_driver->getQueue($info['queue']); throw new Whups_Exception(sprintf(_("No type for this ticket and no default type for queue \"%s\" specified."), $queue['name'])); } } if (!isset($info['state'])) { $info['state'] = $whups_driver->getDefaultState($info['type']); if (!$info['state']) { throw new Whups_Exception(sprintf(_("No state for this ticket and no default state for ticket type \"%s\" specified."), $whups_driver->getTypeName($info['type']))); } } if (!isset($info['priority'])) { $info['priority'] = $whups_driver->getDefaultPriority($info['type']); if (!$info['priority']) { throw new Whups_Exception(sprintf(_("No priority for this ticket and no default priority for ticket type \"%s\" specified."), $whups_driver->getTypeName($info['type']))); } } // Run hook. try { $info = Horde::callHook('ticket_create', array($info, $requester), 'whups'); } catch (Horde_Exception_HookNotSet $e) { } $id = $whups_driver->addTicket($info, $requester); $details = $whups_driver->getTicketDetails($id, false); $ticket = new Whups_Ticket($id, $details); // Add attachment if one was uploaded. if (!empty($info['newattachment']['name'])) { $ticket->change('attachment', array('name' => $info['newattachment']['name'], 'tmp_name' => $info['newattachment']['tmp_name'])); } // Check for a deferred attachment upload. $a_name = null; if (!empty($info['deferred_attachment']) && ($a_name = $GLOBALS['session']->get('whups', 'deferred_attachment/' . $info['deferred_attachment']))) { $ticket->change('attachment', array('name' => $info['deferred_attachment'], 'tmp_name' => $a_name)); } // Check for manually added attachments. if (!empty($info['attachments'])) { $ticket->change('attachments', $info['attachments']); } // Commit any changes (new attachments, etc.) $ticket->commit($ticket->get('user_id_requester'), $info['last-transaction'], false); // Delete deferred attachment now, because it will be attached in the // commit() call above. if ($a_name) { unlink($a_name); } // Send email notifications. $ticket->notify($ticket->get('user_id_requester'), true); return $ticket; }