/** * generate unique string id for annotation */ public function getUniqueAnnotationId() { $dc = kDataCenterMgr::getCurrentDc(); for ($i = 0; $i < 10; $i++) { $id = $dc["id"] . '_' . kString::generateStringId(); $existingObject = AnnotationPeer::retrieveByPK($id); if ($existingObject) { KalturaLog::log(__METHOD__ . ": id [{$id}] already exists"); } else { return $id; } } throw new Exception("Could not find unique id for annotation"); }
public function validateStartTime(KalturaAnnotation $annotation, $annotationId = null) { if ($annotation->startTime === null) { $annotation->startTime = 0; } if ($annotation->startTime < 0) { throw new KalturaAPIException(KalturaAnnotationErrors::START_TIME_CANNOT_BE_LESS_THAN_0); } if ($annotationId !== null) { //update $dbAnnotation = AnnotationPeer::retrieveByPK($annotationId); if (!$dbAnnotation) { throw new KalturaAPIException(KalturaAnnotationErrors::INVALID_OBJECT_ID, $annotationId); } $dbEntry = entryPeer::retrieveByPK($dbAnnotation->getEntryId()); } else { $dbEntry = entryPeer::retrieveByPK($annotation->entryId); if (!$dbEntry) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $annotation->entryId); } } if ($dbEntry->getLengthInMsecs() < $annotation->startTime) { throw new KalturaAPIException(KalturaAnnotationErrors::START_TIME_IS_BIGGER_THAN_ENTRY_END_TIME, $annotation->startTime, $dbEntry->getLengthInMsecs()); } }
/** * Update annotation by id * * @action update * @param string $id * @param KalturaAnnotation $annotation * @return KalturaAnnotation */ function updateAction($id, KalturaAnnotation $annotation) { kalturalog::debug("annotation service updateAction"); $dbAnnotation = AnnotationPeer::retrieveByPK($id); if ($dbAnnotation->getType() != AnnotationType::ANNOTATION) { throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $id); } if (!$dbAnnotation) { throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $id); } if ($annotation->text !== null) { $annotation->validatePropertyMaxLength("text", AnnotationPeer::MAX_ANNOTATION_TEXT); } if ($annotation->tags !== null) { $annotation->validatePropertyMaxLength("tags", AnnotationPeer::MAX_ANNOTATION_TAGS); } if ($annotation->entryId !== null) { $annotation->validateEntryId($annotation, $id); } if ($annotation->parentId !== null) { $annotation->validateParentId($annotation, $id); } if ($annotation->startTime !== null) { $annotation->validateStartTime($annotation, $id); } if ($annotation->endTime !== null) { $annotation->validateEndTime($annotation, $id); } $dbAnnotation = $annotation->toUpdatableObject($dbAnnotation); $dbAnnotation->setKuserId($this->getKuser()->getId()); $dbAnnotation->save(); $annotation->fromObject($dbAnnotation); return $annotation; }