/**
  * (non-PHPdoc)
  * @see PartKeepr\Service.RestfulService::destroy()
  */
 public function destroy()
 {
     $this->requireParameter("id");
     $file = FootprintAttachment::loadById($this->getParameter("id"));
     PartKeepr::getEM()->remove($file);
     PartKeepr::getEM()->flush();
     return array("data" => null);
 }
Пример #2
0
PartKeepr::initialize("");
$type = $_REQUEST["type"];
$id = $_REQUEST["id"];
if (substr($id, 0, 4) === "TMP:") {
    $tmpFileId = str_replace("TMP:", "", $id);
    $file = TempUploadedFile::loadById($tmpFileId);
} else {
    try {
        switch ($type) {
            case "PartKeepr.PartAttachment":
            case "PartAttachment":
                $file = PartAttachment::loadById($id);
                break;
            case "FootprintAttachment":
            case "PartKeepr.FootprintAttachment":
                $file = FootprintAttachment::loadById($id);
                break;
            case "ProjectAttachment":
            case "PartKeepr.ProjectAttachment":
                $file = ProjectAttachment::loadById($id);
                break;
            case "Print":
                $file = TempUploadedFile::loadById($id);
                break;
            default:
                $file = null;
                // Add default image?
        }
    } catch (\Exception $e) {
        $file = null;
        // Something bad happened
Пример #3
0
 /**
  * Imports the footprints
  * @throws \Exception
  */
 public function importFootprintData()
 {
     $count = 0;
     $skipped = 0;
     /* Import pre-defined footprints */
     $data = Setup::loadYAML(self::FOOTPRINT_FILE);
     foreach ($data as $footprintName => $footprintData) {
         /* Check if the footprint with the name already exists. If yes, skip the import for the single footprint */
         if ($this->footprintExists($footprintName)) {
             $skipped++;
             continue;
         }
         $footprint = new Footprint();
         $footprint->setName($footprintName);
         if (array_key_exists("description", $footprintData)) {
             $footprint->setDescription($footprintData["description"]);
         }
         if (array_key_exists("category", $footprintData)) {
             $footprintCategory = $this->addFootprintPath(explode("/", $footprintData["category"]), FootprintCategoryManager::getInstance()->getRootNode());
             $footprint->setCategory($footprintCategory->getNode());
         }
         if (array_key_exists("image", $footprintData)) {
             $footprintImage = new FootprintImage();
             $footprintImage->setFootprint($footprint);
             $footprintImage->replace(self::FOOTPRINT_PATH . $footprintData["image"]);
             $footprint->setImage($footprintImage);
         }
         if (array_key_exists("attachments", $footprintData) && is_array($footprintData["attachments"])) {
             foreach ($footprintData["attachments"] as $attachment) {
                 if (!is_array($attachment)) {
                     throw new \Exception("Error: The property 'attachments' of {$footprintName} is not an array!");
                 }
                 if (array_key_exists("url", $attachment)) {
                     try {
                         $footprintAttachment = new FootprintAttachment();
                         $footprintAttachment->setFootprint($footprint);
                         $footprintAttachment->replaceFromURL($attachment["url"]);
                         if (array_key_exists("description", $attachment)) {
                             $footprintAttachment->setDescription($attachment["description"]);
                         }
                         $footprint->getAttachments()->add($footprintAttachment);
                     } catch (\Exception $e) {
                         //echo "error with url ".$attachment["url"]."\n";
                     }
                 }
             }
         }
         $this->entityManager->persist($footprint);
         $count++;
     }
     $this->entityManager->flush();
     $this->logMessage(sprintf("Imported %d footprints, skipped %d because they already existed", $count, $skipped));
 }