/** * Checks this ticket is creatable */ public function checkCreatable() { parent::checkCreatable(); $this->checkFieldsSet(array('subject', 'comment')); }
/** * Create an entity * * @param BaseEntity $entity * @param $endPoint * @return ChangeResult|null */ public function saveEntity(BaseEntity $entity, $endPoint = '', $extraData = null) { $end_point = strtolower($endPoint); if (strpos($end_point, 'http') !== 0) { $end_point = $this->api->getApiUrl() . $end_point; } $type = $this->getType(); $className = explode('\\', $type); $baseName = strtolower(end($className)); $method = $entity->getId() ? 'put' : 'post'; if ($method == 'post') { $entity->checkCreatable(); } $changes = $entity->toArray(true, $extraData); if (empty($changes)) { return null; } $request = $this->api->{$method}($end_point, null, json_encode(array($baseName => $changes))); $response = $this->processRequest($request); $result = $response->json(); if ($result && isset($result[$baseName])) { $changeResult = new ChangeResult(); $t = new $type(); $this->manage($t); $t->fromArray($result[$baseName]); $changeResult->setItem($t); if (isset($result['audit'])) { $audit = new TicketAudit(); $audit->fromArray($result['audit']); $changeResult->setAudit($audit); } return $changeResult; } return null; }