/** * Register a custom interaction from a zip package * * @param string $archive * @param boolean $replace * @return array * @throws \common_Exception * @throws ExtractException */ public function add($archive, $replace = false) { $returnValue = null; $qtiPackageParser = new CreatorPackageParser($archive); $qtiPackageParser->validate(); if ($qtiPackageParser->isValid()) { //obtain the id from manifest file $manifest = $qtiPackageParser->getManifest(true); $typeIdentifier = $manifest['typeIdentifier']; $label = $manifest['label']; //check if such PCI creator already exists $existingInteraction = $this->getResource($typeIdentifier); if ($existingInteraction) { if ($replace) { $this->remove($typeIdentifier); } else { throw new \common_Exception('The Creator Package already exists'); } } //extract the package $folder = $qtiPackageParser->extract(); if (!is_dir($folder)) { throw new ExtractException(); } $directory = $this->storage->spawnDirectory(true); $directoryId = $directory->getId(); //copy content in the directory: $this->storage->import($directoryId, $folder); $this->registryClass->createInstanceWithProperties(array($this->propTypeIdentifier->getUri() => $typeIdentifier, $this->propDirectory->getUri() => $directoryId, RDFS_LABEL => $label)); $returnValue = $this->get($typeIdentifier); } else { throw new \common_Exception('invalid PCI creator package format'); } return $returnValue; }