Exemple #1
0
 /**
  * @param $key
  *
  * @return null
  */
 public function __get($key)
 {
     /**
      * Return value via getter
      */
     if (method_exists($this, 'get' . Convention::toPascal($key) . 'Attribute')) {
         return $this->{'get' . Convention::toPascal($key) . 'Attribute'}();
     }
     /**
      * Return value, even if it's null or not set.
      */
     if ($this->keyExists($key)) {
         return $this->getValue($key);
     }
     /**
      * Return value from existing relation (Collection or Record).
      */
     if ($this->relationExists($key)) {
         return $this->getRelation($key);
     }
     /**
      * @T00D00 - Entity is needed here just for cache, optimize this ... :/
      *         $Reflection = new ReflectionProperty(get_class($a), 'a');
      */
     $entity = $this->getEntity();
     if ($entity->getRepository()->getCache()->tableHasField($entity->getTable(), $key)) {
         return $this->getValue($key);
     }
     /**
      * Return value from empty relation.
      *
      * @T00D00 - optimize this
      */
     if (method_exists($entity, $key)) {
         $relation = $entity->{$key}();
         $relation->fillRecord($this);
         return $this->getRelation($relation->getFill());
     }
     /**
      * Return value from extension.
      */
     if ($chains = $this->getEntityChains($entity, $key, '__get')) {
         return chain($chains);
     }
     return null;
 }
Exemple #2
0
 /**
  *
  */
 protected function guessDefaults()
 {
     if (!$this->table) {
         if (static::class == Entity::class) {
             $this->table = null;
         } else {
             $class = explode('\\', static::class);
             $this->table = Convention::fromCamel(end($class));
         }
     }
     if (!$this->record) {
         $class = static::class;
         if ($class == Entity::class) {
             $this->record = Record::class;
         } else {
             if (strpos('\\Entity\\', $class)) {
                 $class = explode('\\', str_replace('\\Entity\\', '\\Record\\', $class));
                 $class[count($class) - 1] = Convention::nameOne($class[count($class) - 1]);
                 $class = implode('\\', $class);
                 if (class_exists($class)) {
                     $this->record = $class;
                 }
             }
         }
     }
 }
Exemple #3
0
 public function postUploadAction(Table $table, Record $record, Field $field)
 {
     $file = $_FILES['file'];
     if ($file['error']) {
         return ['success' => false, 'message' => 'Error uploading file ...'];
     }
     if (!$file['size']) {
         return ['success' => false, 'message' => 'Empty file size ...'];
     }
     $entity = $table->createEntity();
     $record->setEntity($entity);
     $dir = $field->getAbsoluteDir($field->getSetting('pckg.dynamic.field.dir'));
     $name = Convention::url(substr($file['name'], 0, strrpos($file['name'], '.')));
     $extension = substr($file['name'], strrpos($file['name'], '.'));
     $i = 0;
     do {
         $filename = $name . ($i ? '_' . $i : '') . $extension;
         $i++;
     } while (is_file($dir . $filename));
     if (!is_dir($dir)) {
         mkdir($dir, 0777, true);
     }
     move_uploaded_file($file['tmp_name'], $dir . $filename);
     $record->{$field->field} = $filename;
     $record->save($entity);
     return ['success' => 'true', 'url' => img($record->{$field->field}, null, true, $dir)];
 }
Exemple #4
0
 public function prepare(Order $order, $handler, Log $logger)
 {
     $this->setOrder($order);
     $this->{'use' . Convention::toPascal($handler) . 'Handler'}();
     $this->getHandler()->setLogger($logger)->setEnvironment($this->environment);
 }
Exemple #5
0
 public function getToArrayValues()
 {
     $values = [];
     foreach ($this->toArray as $key) {
         if ($this->hasKey($key)) {
             $values[$key] = $this->{$key};
         } elseif ($this->hasRelation($key)) {
             $values[$key] = $this->getRelationIfSet($key);
         } elseif (method_exists($this, 'get' . Convention::toPascal($key) . 'Attribute')) {
             $values[$key] = $this->{'get' . Convention::toPascal($key) . 'Attribute'}();
         }
     }
     return $values;
 }
Exemple #6
0
 public function getRightForeignKey()
 {
     $class = explode('\\', get_class($this->getRightEntity()));
     return lcfirst(Convention::nameOne(array_pop($class))) . '_id';
 }
Exemple #7
0
 protected function transformRecord(RecordInterface $record)
 {
     $transformed = [];
     /**
      * Table fields
      */
     foreach ($this->getFields() as $key => $field) {
         $transformed[is_string($key) ? $key : (is_string($field) ? $field : $field->field)] = $this->getRecordValue($field, $record);
     }
     /**
      * Additional fields
      */
     foreach ($this->getFieldTransformations() as $key => $field) {
         $transformed[is_string($key) ? $key : (is_string($field) ? $field : $field->field)] = $this->getRecordValue($field, $record);
     }
     /**
      * We also need to fetch URLs.
      */
     if (!$this->dataOnly) {
         foreach ($this->getRecordActions() as $recordAction) {
             $method = is_string($recordAction) ? $recordAction : $recordAction->slug;
             if ($method && method_exists($record, 'get' . Convention::toPascal($method) . 'Url')) {
                 $transformed[$method . 'Url'] = $record->{'get' . Convention::toPascal($method) . 'Url'}();
             }
         }
         $transformed = array_merge($record->getToArrayValues(), $transformed);
         /*foreach ($record->getToArrayValues() as $key => $value) {
               $transformed[$key] = $value;
           }*/
     }
     return $transformed;
 }