Ejemplo n.º 1
0
 public function testGetSignedLatitude()
 {
     $position = new GpsPosition();
     $position->set('Latitude', 48.856578);
     $this->assertEquals(48.856578, $position->getSignedLatitude());
     $position = new GpsPosition();
     $position->set('LatitudeRef', 'N');
     $this->assertNull($position->getSignedLatitude());
     $position = new GpsPosition();
     $position->set('Latitude', 48.856578);
     $position->set('LatitudeRef', 'N');
     $this->assertEquals(48.856578, $position->getSignedLatitude());
     $position = new GpsPosition();
     $position->set('Latitude', 48.856578);
     $position->set('LatitudeRef', 'S');
     $this->assertEquals(-48.856578, $position->getSignedLatitude());
 }
Ejemplo n.º 2
0
    public function hydrateRecords(array &$records)
    {
        $sql = <<<SQL
            (SELECT record_id, ms.name AS `key`, m.value AS value, 'caption' AS type, ms.business AS private
            FROM metadatas AS m
            INNER JOIN metadatas_structure AS ms ON (ms.id = m.meta_struct_id)
            WHERE record_id IN (?))

            UNION

            (SELECT record_id, t.name AS `key`, t.value AS value, 'exif' AS type, 0 AS private
            FROM technical_datas AS t
            WHERE record_id IN (?))
SQL;
        $ids = array_keys($records);
        $statement = $this->connection->executeQuery($sql, array($ids, $ids), array(Connection::PARAM_INT_ARRAY, Connection::PARAM_INT_ARRAY));
        while ($metadata = $statement->fetch()) {
            // Store metadata value
            $key = $metadata['key'];
            $value = $metadata['value'];
            // Do not keep empty values
            if ($key === '' || $value === '') {
                continue;
            }
            $id = $metadata['record_id'];
            if (isset($records[$id])) {
                $record =& $records[$id];
            } else {
                throw new Exception('Received metadata from unexpected record');
            }
            switch ($metadata['type']) {
                case 'caption':
                    // Sanitize fields
                    $value = StringHelper::crlfNormalize($value);
                    $value = $this->sanitizeValue($value, $this->structure->typeOf($key));
                    // Private caption fields are kept apart
                    $type = $metadata['private'] ? 'private_caption' : 'caption';
                    // Caption are multi-valued
                    if (!isset($record[$type][$key])) {
                        $record[$type][$key] = array();
                    }
                    $record[$type][$key][] = $value;
                    // Collect value in the "all" field
                    $field = sprintf('%s_all', $type);
                    if (!isset($record[$field])) {
                        $record[$field] = array();
                    }
                    $record[$field][] = $value;
                    break;
                case 'exif':
                    if (GpsPosition::isSupportedTagName($key)) {
                        $this->handleGpsPosition($records, $id, $key, $value);
                        break;
                    }
                    $tag = $this->structure->getMetadataTagByName($key);
                    if ($tag) {
                        $value = $this->sanitizeValue($value, $tag->getType());
                    }
                    // EXIF data is single-valued
                    $record['metadata_tags'][$key] = $value;
                    break;
                default:
                    throw new Exception('Unexpected metadata type');
                    break;
            }
        }
        $this->clearGpsPositionBuffer();
    }