Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public static function fromParams($data)
 {
     $uploadId = new static();
     $uploadId->loadData($data);
     return $uploadId;
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public static function fromArray($data)
 {
     $part = new static();
     $part->loadData($data);
     return $part;
 }
Ejemplo n.º 3
0
 /**
  * Update from row
  *
  * @param string|array|\stdClass $row
  * @param \Phalcon\DiInterface $di
  * @param \Phalcon\Events\ManagerInterface $eventsManager
  * @return array
  */
 public static function updateRow($row, \Phalcon\DiInterface $di = null, \Phalcon\Events\ManagerInterface $eventsManager = null)
 {
     $result = ['success' => false, 'error' => []];
     if (is_string($row)) {
         if (!\Engine\Tools\String::isJson($row)) {
             $result['error'][] = 'Params not valid';
             return $result;
         }
         $row = json_decode($row);
     }
     if ($row instanceof \stdClass) {
         $row = (array) $row;
     } elseif (!is_array($row)) {
         $result['error'][] = 'Params not valid';
         return $result;
     }
     $form = new static(null, [], $di, $eventsManager);
     $primary = $form->getPrimaryField();
     $primaryKey = $primary->getKey();
     if (isset($row[$primaryKey])) {
         $id = $row[$primaryKey];
         $form->loadData($id);
         unset($row[$primaryKey]);
     }
     $form->initForm();
     foreach ($row as $key => $value) {
         if (!isset($form->{$key})) {
             continue;
         }
         $form->{$key} = $value;
     }
     $rowResult = $form->save();
     if (is_array($rowResult)) {
         $result['error'] = array_merge($result['error'], $rowResult['error']);
     } else {
         $result['success'] = true;
         $result['msg'] = "Saved";
     }
     return $result;
 }