Example #1
0
 /**
  * @test
  */
 public function photoWorks()
 {
     $photoFile = new PhotoFile(__DIR__ . '/pixel.png');
     $photoId = new PhotoId();
     $lang = new Lang(Lang::LANGUAGE_EN);
     $alt = new PhotoAlt($photoId, 'alt', $lang);
     $photoAltCollection = new PhotoAltCollection([$alt]);
     $photo = new Photo($photoId, new ResourceId(1), new PhotoName('testing'), new HttpUrl('http://works'), new PhotoAltCollection([new PhotoAlt($photoId, 'alt', new Lang(Lang::LANGUAGE_EN))]), new Position(1), $photoFile);
     $this->assertEquals($photoId->id(), $photo->id());
     $this->assertEquals(1, $photo->resourceId());
     $this->assertEquals('testing', $photo->name());
     $this->assertEquals('testing', $photo->slug());
     $this->assertEquals('http://works', $photo->getPhotoHttpUrl());
     $this->assertEquals($photoAltCollection, $photo->altCollection());
     $this->assertEquals($alt, $photo->altByLang($lang));
     $this->assertNull($photo->altByLang(new Lang(Lang::LANGUAGE_ES)));
     $this->assertSame($photo->position(), 1);
     $this->assertSame($photoFile, $photo->photoFile());
 }
 /**
  * @param Photo $photo
  * @return void
  */
 public function save(Photo $photo)
 {
     $sentence = $this->pdo->prepare("INSERT INTO Photo(\"uuid\", \"resourceId\", \"name\", \"httpUrl\", \"position\",\"filePath\") " . "VALUES(:uuid, :resourceId, :name, :httpUrl, :position, :filePath)");
     $sentence->bindValue(':uuid', $photo->id());
     $sentence->bindValue(':resourceId', $photo->resourceId());
     $sentence->bindValue(':name', $photo->name());
     $sentence->bindValue(':httpUrl', $photo->getPhotoHttpUrl());
     $sentence->bindValue(':position', $photo->position());
     $filePath = is_null($photo->photoFile()) ? null : $photo->photoFile()->filePath();
     $filePathType = is_null($photo->photoFile()) ? \PDO::PARAM_NULL : \PDO::PARAM_STR;
     $sentence->bindValue(':filePath', $filePath, $filePathType);
     $sentence->execute();
     foreach ($photo->altCollection() as $photoAlt) {
         $this->saveAlternativeText(new PhotoId($photo->id()), $photoAlt);
     }
 }
 /**
  * @param Photo $photo
  * @return void
  */
 public function save(Photo $photo)
 {
     $sentence = $this->pdo->prepare("INSERT INTO `photo`(`id`, `resourceId`, `name`, `httpUrl`, `position`, `filePath`) " . "VALUES(:id, :resourceId, :name, :httpUrl, :position, :filePath)");
     $sentence->bindValue(':id', $photo->id());
     $sentence->bindValue(':resourceId', $photo->resourceId());
     $sentence->bindValue(':name', $photo->name());
     $sentence->bindValue(':httpUrl', $photo->getPhotoHttpUrl());
     $position = $photo->position();
     if ($photo->position() === 9999) {
         $result = $this->pdo->query("SELECT COUNT(*) as amount FROM `photo` WHERE `resourceId`='" . $photo->resourceId() . "'")->fetch(\PDO::FETCH_ASSOC);
         $position = $result['amount'] + 1;
     }
     $sentence->bindValue(':position', $position);
     $filePath = is_null($photo->photoFile()) ? null : $photo->photoFile()->filePath();
     $filePathType = is_null($photo->photoFile()) ? \PDO::PARAM_NULL : \PDO::PARAM_STR;
     $sentence->bindValue(':filePath', $filePath, $filePathType);
     $sentence->execute();
     foreach ($photo->altCollection() as $photoAlt) {
         $this->saveAlternativeText(new PhotoId($photo->id()), $photoAlt);
     }
 }