Пример #1
0
 public function __construct($data = null, $status = 200, $headers = array(), $options = 0)
 {
     if ($data instanceof \Exception) {
         $data = array("code" => $data->getCode(), "error" => $data->getMessage());
     } else {
         // move the prepare function here
         Carbon::setToStringFormat('Y-m-d\\TH:i:s.z\\Z');
         $data = ParseHelper::prepareResponse($data);
     }
     parent::__construct($data, $status, $headers, $options);
 }
Пример #2
0
 /**
  * Deleting Objects
  * https://parse.com/docs/rest/guide#objects-deleting-objects
  *
  * @param $className
  * @param $objectId
  * @return mixed
  */
 public function delete($className, $objectId)
 {
     $this->prepareClassMetadata($className);
     $object = ParseHelper::makeModelObject($className);
     $find = $object->find($objectId);
     if (count($find) == 0) {
         return array("code" => 101, "error" => "object not found for delete");
     }
     $find->delete();
     return \Response::json(new \stdClass());
 }
Пример #3
0
 /**
  * @param $account
  * @param $details
  * @param $type
  * @throws \Exception
  */
 private function validateLink($account, $details, $type)
 {
     if ($account->auth_id != $details->get('id')) {
         $duplicatedAccount = LinkedAccount::first(array("auth" => $type, "auth_id" => $details->get('id')));
         if ($duplicatedAccount) {
             // todo can we merge the two users?
             ParseHelper::throwException(105, "this auth ID already linked with user:" . $duplicatedAccount->user_id);
         }
     }
 }
Пример #4
0
 /**
  * @param $className
  * @param $parameters
  * @param null $objectId
  * @return ParseResponse
  * @throws \Exception
  */
 public function save($className, $parameters, $objectId = null)
 {
     $values = array();
     // if update, try to get the current object at first
     if ($objectId) {
         $this->object = $this->object->findOrFail($objectId);
     }
     foreach ($parameters as $key => $val) {
         if (in_array($key, $this->columns)) {
             if (is_array($val) && ($operation = array_get($val, '__op'))) {
                 switch ($operation) {
                     case "Increment":
                         $val = $this->object->{$key} ? $this->object->{$key} + $val['amount'] : $val['amount'];
                         break;
                     case "decrement":
                         $val = $this->object->{$key} - $val['amount'];
                         break;
                     case "Delete":
                         $val = null;
                         break;
                     case "Batch":
                         //                            $ops = $val['ops'];
                         //                            foreach ($ops as $ops_key => $ops_val) {
                         //                                if ($ops_val['__op'] == 'AddRelation') {
                         //                                    foreach ($ops_val['objects'] as $objects_key => $objects_val) {
                         //                                        $relation_type = $objects_val['__type'];
                         //                                        $relation_class_name = $objects_val['className'];
                         //                                        $relation_class_name = ParseHelperClass::removeUnderscoreFromClassName($relation_class_name);     // to remove '_' character if founded in the name of class _User
                         //                                        $relation_objectId = $objects_val['objectId'];
                         //                                        $relation_object = ParseHelperClass::createObject($relation_class_name);
                         //                                        $updatedAt = '';
                         //
                         //                                        if (!$relation_object) {
                         //                                            return ParseHelperClass::error_message_return('105');
                         //                                        }
                         //
                         //                                        $object->find($objectId)->$key()->sync([$relation_objectId], false);
                         //
                         //                                        $relation_data_of_object = $object::find(60)->$key()->where($relation_class_name . '_id',
                         //                                            '=', $relation_objectId)->get();
                         //
                         //                                        foreach ($relation_data_of_object as $relation_data) {
                         //                                            $updatedAt = $relation_data->pivot->createdAt;
                         //                                        }
                         //                                    }
                         //
                         //                                    return array(
                         //                                        "updatedAt" => Carbon::parse($updatedAt)->format('Y-m-d\TH:i:s.z\Z')
                         //                                    );
                         //                                }
                         //                            }
                         break;
                 }
             }
             $values[$key] = $val;
         } elseif (in_array($key, $this->relations)) {
             //
         } else {
             if ($key != "ACL") {
                 ParseHelper::throwException('210', $key);
             }
         }
     }
     $this->object->fill($values);
     try {
         $event = $this->object->getKey() ? 'update' : 'insert';
         \Event::fire("before.{$event}." . $this->object->getTable(), $this->object);
         $this->object->save();
         //create new object
         // now we can attach the relations
         foreach ($parameters as $key => $val) {
             if (in_array($key, $this->relations)) {
                 if ($operation = array_get($val, '__op')) {
                     switch ($operation) {
                         case "Delete":
                             $this->object->{$key}()->delete($val);
                             break;
                     }
                 } elseif ($this->object->{$key}() instanceof BelongsTo) {
                     $this->object->{$key}()->associate($val);
                 } elseif (!$this->object->{$key}() instanceof BelongsTo) {
                     $this->object->{$key}()->save($val);
                 } else {
                     ParseHelper::throwException(105);
                 }
             }
         }
         \Event::fire("after.{$event}." . $this->object->getTable(), $this->object);
     } catch (\Exception $ex) {
         ParseHelper::throwException(141, $ex->getMessage());
     }
 }