示例#1
0
文件: Api.php 项目: raz0rsdge/horde
 /**
  * Create a new ticket.
  *
  * @param array $ticket_info An array of form variables representing all of the
  * data collected by CreateStep1Form, CreateStep2Form, CreateStep3Form, and
  * optionally CreateStep4Form.
  *
  * @return integer The new ticket id.
  */
 public function addTicket($ticket_info)
 {
     global $whups_driver;
     if (!is_array($ticket_info)) {
         throw new Whups_Exception('Invalid arguments');
     }
     $vars = new Horde_Variables($ticket_info);
     $form1 = new Whups_Form_Ticket_CreateStepOne($vars);
     $form2 = new Whups_Form_Ticket_CreateStepTwo($vars);
     $form3 = new Whups_Form_Ticket_CreateStepThree($vars);
     // FIXME: This is an almighty hack, but we can't have form
     // tokens in rpc calls.
     $form1->useToken(false);
     $form2->useToken(false);
     $form3->useToken(false);
     // Complain if we've been given bad parameters.
     if (!$form1->validate($vars, true)) {
         $f1 = var_export($form1->getErrors(), true);
         throw new Whups_Exception("Invalid arguments ({$f1})");
     }
     if (!$form2->validate($vars, true)) {
         $f2 = var_export($form2->getErrors(), true);
         throw new Whups_Exception("Invalid arguments ({$f2})");
     }
     if (!$form3->validate($vars, true)) {
         $f3 = var_export($form3->getErrors(), true);
         throw new Whups_Exception("Invalid arguments ({$f3})");
     }
     $form1->getInfo($vars, $info);
     $form2->getInfo($vars, $info);
     $form3->getInfo($vars, $info);
     // More checks if we're assigning the ticket at create-time.
     if ($GLOBALS['registry']->getAuth() && $whups_driver->isCategory('assigned', $vars->get('state'))) {
         $form4 = new Whups_Form_Ticket_CreateStepFour($vars);
         $form4->useToken(false);
         if (!$form4->validate($vars, true)) {
             throw new Whups_Exception('Invalid arguments (' . var_export($form4->getErrors(), true) . ')');
         }
         $form4->getInfo($vars, $info);
     }
     $ticket = Whups_Ticket::newTicket($info, $GLOBALS['registry']->getAuth());
     return $ticket->getId();
 }