コード例 #1
0
ファイル: image.php プロジェクト: JohnEffland/PartKeepr
    $tmpImageId = str_replace("TMP:", "", $id);
    $image = TempImage::loadById($tmpImageId);
} else {
    try {
        switch ($type) {
            case Image::IMAGE_ICLOGO:
                $image = ManufacturerICLogo::loadById($id);
                break;
            case Image::IMAGE_FOOTPRINT:
                $image = FootprintImage::loadById($id);
                break;
            case Image::IMAGE_STORAGELOCATION:
                $image = StorageLocationImage::loadById($id);
                break;
            case "partattachment":
                $attachment = PartAttachment::loadById($id);
                $image = new PartImage();
                $image->replace($attachment->getFilename());
                break;
            default:
                $image = null;
                // Add default image?
        }
    } catch (\Exception $e) {
        $image = null;
        // Something bad happened
    }
}
if ($image == null) {
    // Could not find the image, but maybe we want a temporary image?
    if (array_key_exists("tmpId", $_REQUEST)) {
コード例 #2
0
 /**
  * Deserializes the part attachment
  * @param array $parameters The array with the parameters to set
  */
 public function deserialize(array $parameters)
 {
     if (array_key_exists("id", $parameters)) {
         if (substr($parameters["id"], 0, 4) === "TMP:") {
             $this->replaceFromTemporaryFile($parameters["id"]);
         } else {
             // In case the part has been copied, the ID doesn't match. In that case we copy the attachment
             if ($this->getId() !== $parameters["id"]) {
                 $otherAttachment = PartAttachment::loadById($parameters["id"]);
                 $this->replace($otherAttachment->getFilename());
                 $this->setOriginalFilename($otherAttachment->getOriginalFilename());
             }
         }
     }
     foreach ($parameters as $key => $value) {
         switch ($key) {
             case "description":
                 $this->setDescription($value);
                 break;
         }
     }
 }
コード例 #3
0
ファイル: file.php プロジェクト: JohnEffland/PartKeepr
namespace PartKeepr\Frontend;

use PartKeepr\Footprint\FootprintAttachment, PartKeepr\Project\ProjectAttachment, PartKeepr\Part\PartAttachment, PartKeepr\UploadedFile\TempUploadedFile, PartKeepr\UploadedFile\UploadedFile, PartKeepr\PartKeepr, PartKeepr\Image\Image, PartKeepr\Manufacturer\ManufacturerICLogo;
include "../src/backend/PartKeepr/PartKeepr.php";
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?
コード例 #4
0
ファイル: PartManager.php プロジェクト: JohnEffland/PartKeepr
 private function processAttachmentChanges(Part $part, array $data)
 {
     if (array_key_exists("updates", $data)) {
         foreach ($data["updates"] as $record) {
             foreach ($part->getAttachments() as $partAttachment) {
                 if ($partAttachment->getId() == $record["id"]) {
                     $partAttachment->setDescription($record["description"]);
                     break;
                 }
             }
         }
     }
     if (array_key_exists("removals", $data)) {
         foreach ($data["removals"] as $record) {
             foreach ($part->getAttachments() as $partAttachment) {
                 if ($partAttachment->getId() == $record["id"]) {
                     PartKeepr::getEM()->remove($partAttachment);
                     $part->getAttachments()->removeElement($partAttachment);
                     break;
                 }
             }
         }
     }
     if (array_key_exists("inserts", $data)) {
         foreach ($data["inserts"] as $record) {
             $attachment = new PartAttachment();
             $attachment->setPart($part);
             $attachment->setDescription($record["description"]);
             $file = TempUploadedFile::loadById($record["tmp_id"]);
             $attachment->replace($file->getFilename());
             $attachment->setOriginalFilename($file->getOriginalFilename());
             $part->getAttachments()->add($attachment);
         }
     }
 }