Esempio n. 1
0
 function findEntity(Metadata $md, $field)
 {
     $otherClass = null;
     $join = null;
     if ($md->hasFKey($field)) {
         $class = $md->getFKey($field);
         $other = Store::me()->createAndAddClass($class);
         if (is_null($other)) {
             $other = Store::me()->get($class);
         }
         $join = new JoinFKey();
         $join->setFrom($md);
         $join->setTo($other);
     } else {
         if ($md->hasRKey($field)) {
             $class = $md->getRKey($field);
             $other = Store::me()->createAndAddClass($class);
             if (is_null($other)) {
                 $other = Store::me()->get($class);
             }
             $join = new JoinRKey();
             $join->setTo($md);
             $join->setFrom($other);
         } else {
             throw new \Exception("{$field} throws an error");
             //Notes::show( Store::me() );
         }
     }
     $join->setAlias($field);
     return $join;
 }
Esempio n. 2
0
 function mapFields(Metadata $md, $alias)
 {
     $fields = $md->getFields();
     array_walk($fields, function (&$item, &$key, $prefix) {
         $key = "{$prefix}__{$item}";
         $item = "{$prefix}.{$item} as {$prefix}__{$item}";
     }, $alias);
     return array_combine($fields, $fields);
 }
Esempio n. 3
0
 function __construct(Metadata $main, $data, $joins)
 {
     $this->main = $main;
     $this->joins = $joins;
     $this->collection = array();
     $this->reduce = array();
     if (count($data) == 0) {
         throw new \Exception("You should give a valid recordset");
     }
     /**
      * This is a adapter to php version <= 5.4.14
      */
     $_this = $this;
     array_walk($data, function ($value) use($_this) {
         $record = (array) $value;
         array_walk($value, array($_this, 'mapper'), $record);
     });
     array_walk($this->map[$main->getInstance()->getAlias()], array($this, 'reducer'));
     $this->map = array();
 }