Beispiel #1
0
/*
STEATITE - Pictures archive for qualitative analysis

Copyright (C) 2010-2012 Aurelien Benel

OFFICIAL WEB SITE
http://www.hypertopic.org/

LEGAL ISSUES
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Affero General Public License as published by the Free 
Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU Affero General Public License for more details:
http://www.gnu.org/licenses/agpl.html
*/
include '../lib/Mustache.php';
include '../metadata.php';
$db = new PDO('sqlite:../attribute/database');
$query = $db->prepare("SELECT attribute_value FROM attributes " . "WHERE source_id=? AND attribute_name='name'");
$query->execute(array($_GET['item']));
$result = $query->fetch();
preg_match('#(.+)/item/#', $_SERVER['REQUEST_URI'], $path);
$source = "../picture/" . $_GET['item'];
$metadata = Metadata::getMetadata($source);
$data = array('corpus' => $_GET['corpus'], 'item' => $_GET['item'], 'service' => 'http://' . $_SERVER['HTTP_HOST'] . $path[1], 'name' => $result[0], 'created' => $metadata['created'], 'spatial' => $metadata['spatial']);
$renderer = new Mustache();
header('content-type: application/json');
echo $renderer->render(file_get_contents('../view/item.json'), $data);
Beispiel #2
0
 /**
  * Get saved values
  *
  * @param mixed $entity
  * @return array
  */
 public function getSavedValues($entity)
 {
     $metadata = Metadata::getMetadata($this->entity);
     if ($this->isMapped($entity)) {
         $data = $metadata->getValues($entity, FALSE);
         $data = array_diff($data, $this->originalData[spl_object_hash($entity)]);
     } else {
         $data = $metadata->getValues($entity);
     }
     $ref = new \Nette\Reflection\PropertyReflection($this->entity, '_associations');
     $ref->setAccessible(TRUE);
     $associationsData = $ref->getValue($entity);
     $ref->setAccessible(FALSE);
     foreach (array_merge($metadata->oneToOne, $metadata->manyToOne) as $association) {
         if ($association instanceof Associations\OneToOne && !empty($association->mapped)) {
             continue;
         }
         if (!$associationsData[$association->name] instanceof Associations\LazyLoad) {
             $original = $this->em->associationsMap->find($this->entity, $association->name, $metadata->getPrimaryKeyValue($entity));
             if (empty($associationsData[$association->name]) && !empty($original)) {
                 $data[$association->sourceColumn] = NULL;
             } else {
                 $targetMetadata = Metadata::getMetadata(get_class($associationsData[$association->name]));
                 $now = $targetMetadata->getPrimaryKeyValue($associationsData[$association->name]);
                 if ($original != $now) {
                     $data[$association->sourceColumn] = $now;
                 }
             }
         }
     }
     return $data;
 }
Beispiel #3
0
 /**
  * Save associations
  *
  * @param mixed $entity
  */
 protected function persistAssociations(&$entity)
 {
     $metadata = Metadata::getMetadata(get_class($entity));
     $data = $metadata->getAssociationsValues($entity);
     foreach (array_merge($metadata->oneToOne, $metadata->oneToMany, $metadata->manyToMany) as $association) {
         if (!array_key_exists($association->name, $data)) {
             continue;
         }
         if ($association instanceof Associations\OneToOne) {
             if (empty($association->mapped)) {
                 continue;
             }
             $original = $this->em->associationsMap->find(get_class($entity), $association->name, $metadata->getPrimaryKeyValue($entity));
             if (empty($data[$association->name]) && !empty($original)) {
                 $targetMetadata = Metadata::getMetadata($association->targetEntity);
                 $this->em->getPersister($association->targetEntity)->persistInversedOneToOneAssociation($association, $original, NULL);
             } elseif (!empty($data[$association->name]) && empty($original)) {
                 $this->em->getPersister($association->targetEntity)->persistInversedOneToOneAssociation($association, $data[$association->name], $metadata->getPrimaryKeyValue($entity));
             } elseif (!empty($original) && !empty($data[$association->name]) && $this->em->find($association->targetEntity, $original) != $data[$association->name]) {
                 $persister = $this->em->getPersister($association->targetEntity);
                 $persister->persistInversedOneToOneAssociation($association, $original, NULL);
                 $persister->persistInversedOneToOneAssociation($association, $data[$association->name], $metadata->getPrimaryKeyValue($entity));
             }
         }
         if ($association instanceof Associations\OneToMany) {
             $original = $this->em->associationsMap->find(get_class($entity), $association->name, $metadata->getPrimaryKeyValue($entity));
             if (empty($data[$association->name]) && !empty($original)) {
                 $this->em->getPersister($association->targetEntity)->persistOneToManyAssociation($association, $original, NULL);
             } elseif (!empty($data[$association->name]) && empty($original)) {
                 $this->em->getPersister($association->targetEntity)->persistOneToManyAssociation($association, $data[$association->name], $metadata->getPrimaryKeyValue($entity));
             } elseif (!empty($original) && !empty($data[$association->name]) && $this->em->find($association->targetEntity, $original) != $data[$association->name]) {
                 $persister = $this->em->getPersister($association->targetEntity);
                 $persister->persistOneToManyAssociation($association, array_diff($original, $data[$association->name]), NULL);
                 $persister->persistOneToManyAssociation($association, array_diff($data[$association->name], $original), $metadata->getPrimaryKeyValue($entity));
             }
         }
         if ($association instanceof Associations\ManyToMany) {
             $original = $this->em->associationsMap->find(get_class($entity), $association->name, $metadata->getPrimaryKeyValue($entity));
             if (empty($data[$association->name]) && !empty($original)) {
                 $this->em->getPersister($association->sourceEntity)->persistManyToManyAssociation($association, $metadata->getPrimaryKeyValue($entity), NULL);
             } elseif (!empty($data[$association->name]) && empty($original)) {
                 $this->em->getPersister($association->sourceEntity)->persistManyToManyAssociation($association, $metadata->getPrimaryKeyValue($entity), $data[$association->name]);
             } elseif (!empty($original) && !empty($data[$association->name]) && $this->em->find($association->sourceEntity, $original) != $data[$association->name]) {
                 $persister = $this->em->getPersister($association->sourceEntity);
                 $persister->persistManyToManyAssociation($association, $metadata->getPrimaryKeyValue($entity), array_diff($original, $data[$association->name]), TRUE);
                 $persister->persistManyToManyAssociation($association, $metadata->getPrimaryKeyValue($entity), array_diff($data[$association->name], $original));
             }
         }
     }
 }