Imbo\Resource\Images\Query::returnMetadata PHP Method

returnMetadata() public method

Set or get the returnMetadata flag
public returnMetadata ( boolean $returnMetadata = null ) : boolean | self
$returnMetadata boolean Give this a value to set the returnMetadata flag
return boolean | self
    public function returnMetadata($returnMetadata = null)
    {
        if ($returnMetadata === null) {
            return $this->returnMetadata;
        }
        $this->returnMetadata = (bool) $returnMetadata;
        return $this;
    }

Usage Example

Example #1
0
 /**
  * {@inheritdoc}
  */
 public function getImages($publicKey, Query $query, Images $model)
 {
     $images = array();
     $qb = $this->getConnection()->createQueryBuilder();
     $qb->select('*')->from($this->tableNames['imageinfo'], 'i')->where('i.publicKey = :publicKey')->setParameter(':publicKey', $publicKey);
     if ($sort = $query->sort()) {
         // Fields valid for sorting
         $validFields = array('size' => true, 'publicKey' => true, 'imageIdentifier' => true, 'extension' => true, 'mime' => true, 'added' => true, 'updated' => true, 'width' => true, 'height' => true, 'checksum' => true, 'originalChecksum' => true);
         foreach ($sort as $f) {
             if (!isset($validFields[$f['field']])) {
                 throw new InvalidArgumentException('Invalid sort field: ' . $f['field'], 400);
             }
             $qb->addOrderBy($f['field'], $f['sort']);
         }
     } else {
         $qb->orderBy('added', 'DESC');
     }
     $from = $query->from();
     $to = $query->to();
     if ($from || $to) {
         if ($from !== null) {
             $qb->andWhere('added >= :from')->setParameter(':from', $from);
         }
         if ($to !== null) {
             $qb->andWhere('added <= :to')->setParameter(':to', $to);
         }
     }
     if ($imageIdentifiers = $query->imageIdentifiers()) {
         $expr = $qb->expr();
         $composite = $expr->orX();
         foreach ($imageIdentifiers as $i => $id) {
             $composite->add($expr->eq('i.imageIdentifier', ':imageIdentifier' . $i));
             $qb->setParameter(':imageIdentifier' . $i, $id);
         }
         $qb->andWhere($composite);
     }
     if ($checksums = $query->checksums()) {
         $expr = $qb->expr();
         $composite = $expr->orX();
         foreach ($checksums as $i => $id) {
             $composite->add($expr->eq('i.checksum', ':checksum' . $i));
             $qb->setParameter(':checksum' . $i, $id);
         }
         $qb->andWhere($composite);
     }
     if ($originalChecksums = $query->originalChecksums()) {
         $expr = $qb->expr();
         $composite = $expr->orX();
         foreach ($originalChecksums as $i => $id) {
             $composite->add($expr->eq('i.originalChecksum', ':originalChecksum' . $i));
             $qb->setParameter(':originalChecksum' . $i, $id);
         }
         $qb->andWhere($composite);
     }
     // Create a querybuilder that will be used to fetch the hits number, and update the model
     $hitsQb = clone $qb;
     $hitsQb->select('COUNT(i.id)');
     $stmt = $hitsQb->execute();
     $model->setHits((int) $stmt->fetchColumn());
     if ($limit = $query->limit()) {
         $qb->setMaxResults($limit);
     }
     if ($page = $query->page()) {
         $offset = (int) $query->limit() * ($page - 1);
         $qb->setFirstResult($offset);
     }
     $stmt = $qb->execute();
     $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $returnMetadata = $query->returnMetadata();
     foreach ($rows as $row) {
         $image = array('extension' => $row['extension'], 'added' => new DateTime('@' . $row['added'], new DateTimeZone('UTC')), 'updated' => new DateTime('@' . $row['updated'], new DateTimeZone('UTC')), 'checksum' => $row['checksum'], 'originalChecksum' => isset($row['originalChecksum']) ? $row['originalChecksum'] : null, 'publicKey' => $row['publicKey'], 'imageIdentifier' => $row['imageIdentifier'], 'mime' => $row['mime'], 'size' => (int) $row['size'], 'width' => (int) $row['width'], 'height' => (int) $row['height']);
         if ($returnMetadata) {
             $image['metadata'] = $this->getMetadata($publicKey, $row['imageIdentifier']);
         }
         $images[] = $image;
     }
     return $images;
 }
All Usage Examples Of Imbo\Resource\Images\Query::returnMetadata