Example #1
0
 public function save($data = null, $whiteList = null)
 {
     $response = array();
     if (parent::save($data, $whiteList) == false) {
         foreach (parent::getMessages() as $message) {
             $response['errors'][] = (string) $message;
         }
     } else {
         foreach (parent::toArray() as $key => $value) {
             $response[$key] = $value;
         }
         $response['msg'] = 'ok';
     }
     return $response;
 }
Example #2
0
 public function toArray($columns = null)
 {
     if (is_null($columns) && is_array($this->visible)) {
         // Only show the visible columns
         $columns = $this->visible;
     }
     $attributes = parent::toArray($columns);
     if (is_null($columns) && is_array($this->hidden) && count($attributes)) {
         // Only show columns which have not been hidden
         foreach ($attributes as $key => $value) {
             if (in_array($key, $this->hidden)) {
                 unset($attributes[$key]);
             }
         }
     }
     return $attributes;
 }
 protected function onRemoveFailed(Model $item)
 {
     throw new Exception(ErrorCodes::DATA_FAILED, 'Unable to remove item', ['messages' => $this->_getMessages($item->getMessages()), 'item' => $item->toArray()]);
 }
 /**
  * @return \Diff\DiffOp\DiffOp[]
  */
 protected function getDiff()
 {
     $oldModel = $this->oldModel ? $this->oldModel->toArray() : array();
     $newModel = $this->newModel ? $this->newModel->toArray() : array();
     return $this->differ->doDiff($oldModel, $newModel);
 }
Example #5
0
 /**
  * Respond with a single model, pass function name
  */
 protected function respondWithModel(Model $model, $functionName = null)
 {
     // Return a partial response
     if ($functionName && isset($this->partialFields)) {
         // Validate that there are fields set for this method
         if (!isset($this->allowedPartialFields[$functionName])) {
             throw new Exception('Partial fields not specified for ' . $functionName);
         }
         // Determines if fields is a strict subset of allowed fields
         if (array_diff($this->partialFields, $this->allowedPartialFields[$functionName])) {
             // todo rework exception
             throw new HTTPException("The fields you asked for cannot be returned.", 401, array('dev' => 'You requested to return fields that are not available to be returned in partial responses.', 'internalCode' => 'P1000', 'more' => ''));
         }
         $this->response->data = $model->toArray($this->partialFields);
     } else {
         $this->response->data = (object) $model->toArray();
         $this->response->getMeta()->count = count($this->response->data);
     }
     // Expand related models
     if ($this->isExpand) {
         // todo allow for parsed related fields, model.field
         foreach ($this->expandFields as $modelField) {
             //$this->response[$modelField] = $model->getRelated($modelField)->toArray();
         }
     }
     return $this->response;
 }