protected function loadData() { $days = $this->property('days'); if (!$days) { throw new ApplicationException('Invalid days value: ' . $days); } // all accesses for last month $items = AccessLog::where('created_at', '>=', Carbon::now()->subDays($days)->format('Y-m-d'))->get(); // parse data $all = []; $users = []; $user_rows = []; foreach ($items as $item) { // user $user_id = $item->user_id ? $item->user_id : 0; $users[$user_id] = $user_id > 0 ? User::find($user_id) : $this->getDeletedFakeUser(); // date $timestamp = strtotime($item->created_at) * 1000; $day = Carbon::createFromFormat('Y-m-d H:i:s', $item->created_at)->format('Y-m-d'); if (isset($user_rows[$user_id][$day])) { $user_rows[$user_id][$day][1]++; } else { $user_rows[$user_id][$day] = [$timestamp, 1]; } // init empty day if (!isset($all[$day])) { $all[$day] = ['timestamp' => $timestamp, 'date' => $day, 'count' => 0]; } // increase count $all[$day]['count']++; } // we need at least two days, to display chart if (sizeof($all) == 1) { $day = reset($all); $date = Carbon::createFromFormat('Y-m-d', $day['date'])->subDays(1); $dateFormated = $date->format('Y-m-d'); $all[$dateFormated] = ['timestamp' => $date->timestamp * 1000, 'date' => $dateFormated, 'count' => 0]; } // transform user line to json foreach ($user_rows as $key => $user_row) { $rows = []; foreach ($user_row as $row) { $rows[] = [$row[0], $row[1]]; } // we need at least two days, to display chart if (sizeof($rows) == 1) { $first = reset($rows); $rows[] = [$first[0] - 86400000, 0]; } $user_rows[$key] = $rows; } // count all $all_render = []; foreach ($all as $a) { $all_render[] = [$a['timestamp'], $a['count']]; } return ['all' => $all_render, 'user_rows' => $user_rows, 'users' => $users]; }
public function __construct() { parent::__construct(); BackendMenu::setContext('Klubitus.Calendar', 'calendar', 'import'); SettingsManager::setContext('Klubitus.Calendar', 'settings'); $this->vars['importEnabled'] = $this->importEnabled = (bool) CalendarSettings::get('facebook_import_enabled'); $this->vars['importUrl'] = $this->importUrl = CalendarSettings::get('facebook_import_url'); $this->vars['importUser'] = $this->importUser = UserModel::find(CalendarSettings::get('facebook_import_user_id')); }
public function getUserAttribute() { $user_name = ''; if (isset($this->attribute['user_id'])) { $user = User::find($this->attribute['user_id']); $user_name = $user->name; } return $user_name; }
/** * Automatically creates a metadata entry for a user if not one already. * @param RainLab\User\Models\User $user * @return DMA\Friends\Models\Usermeta */ public static function getFromUser($user = null) { if (!$user) { return null; } if (!$user->metadata) { $meta = new static(); User::find($user->getKey())->metadata()->save($meta); $user = User::find($user->getKey()); } return $user->metadata; }
public static function get_user_charge_money($user_id = 0) { if (!$user_id) { return 0; } $user = User::find($user_id); $money_account = $user->money_charge - $user->money_spent; if ($money_account > 0) { return $money_account; } else { return 0; } }
public function onTransferPassword($recordId = null) { if (!$recordId or !post('sourceId')) { return null; } $userTo = user::find($recordId); $userFrom = user::find(post('sourceId')); if (!$userTo or !$userFrom) { return null; } $userTo->setPasswordAttribute($userFrom->password); $userTo->forceSave(); return ['#layout-flash-messages' => '<p data-control="flash-message" class="flash-message success" data-interval="5">The password for ' . $userTo->name . ' ' . $userTo->surname . ' has been updated to match the source user password.</p>']; }
public function onRun() { $userPermision = $this->property('permission'); if ($userPermision) { if (!UserGroup::can($userPermision)) { return; } } $person = user::find(intval($this->property('SLSlug'))); if ($person) { $filename = $person->surname . '_' . $person->name . '.vcf'; return response($this->renderPartial('@vcard', ['person' => $person]))->header('Content-Type', 'text/directory')->header('Content-Disposition', 'attachment; filename=' . $filename)->header('Pragma', 'public'); } }
public static function can($permissions) { $account = new Account(); $permissions = !is_array($permissions) ? [$permissions] : $permissions; if (Auth::check()) { $roles = json_decode(User::find($account->user()->id)->groups); foreach ($roles as $role) { foreach (UserGroup::find($role->id)->perms as $perm) { if (in_array($perm->name, $permissions)) { return true; } } } } }
public function pdf($id) { $user = User::find($id); if (!$user) { throw new ApplicationException('User not found.'); } $templateCode = Config::get('vojtasvoboda.userexportpdf::config.template', 'rainlab::user'); $data = ['user' => $user]; $filename = Str::slug($user->name . '-' . $user->username) . ".pdf"; try { return PDF::loadTemplate($templateCode, $data)->download($filename); } catch (Exception $e) { throw new ApplicationException($e->getMessage()); } }
/** * Deleted checked users. */ public function index_onDelete() { if (($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) { foreach ($checkedIds as $userId) { if (!($user = User::find($userId))) { continue; } $user->delete(); } Flash::success(Lang::get('rainlab.user::lang.users.delete_selected_success')); } else { Flash::error(Lang::get('rainlab.user::lang.users.delete_selected_empty')); } return $this->listRefresh(); }
protected function loadData() { $days = $this->property('days'); if (!$days) { throw new ApplicationException('Invalid days value: ' . $days); } // all accesses for last month $items = AccessLog::where('created_at', '>=', Carbon::now()->subDays($days)->format('Y-m-d'))->get(); // parse data $all = []; $users = []; $user_rows = []; foreach ($items as $item) { // user $user_id = $item->user_id ? $item->user_id : 0; $users[$user_id] = $user_id > 0 ? User::find($user_id) : $this->getDeletedFakeUser(); // date $timestamp = strtotime($item->created_at) * 1000; $day = Carbon::createFromFormat('Y-m-d H:i:s', $item->created_at)->format('Y-m-d'); if (isset($user_rows[$user_id][$day])) { $user_rows[$user_id][$day][1]++; } else { $user_rows[$user_id][$day] = [$timestamp, 1]; } if (isset($all[$day])) { $all[$day][1]++; } else { $all[$day] = [$timestamp, 1]; } } // transform user line to json foreach ($user_rows as $key => $user_row) { $rows = []; foreach ($user_row as $row) { $rows[] = [$row[0], $row[1]]; } $user_rows[$key] = $rows; } // count all $all_render = []; foreach ($all as $a) { $all_render[] = [$a[0], $a[1]]; } return ['all' => $all_render, 'user_rows' => $user_rows, 'users' => $users]; }
public function oneUser($id) { $this->page['person'] = $this->person = user::find($id); $this->page['avatarThumb'] = $this->person->getAvatarThumb(200); $this->page['epsettings'] = ExtendedInfo::loadSettings($this->person); //$this->page['hint'] = count($this->page['epsettings']); }
/** * @SWG\Definition( * definition="response.redeem", * required={"data"}, * @SWG\Property( * property="data", * type="object", * ref="#/definitions/redeem.payload" * ) * ) * * @SWG\Definition( * definition="redeem.payload", * required={"success", "message", "user"}, * @SWG\Property( * property="success", * type="boolean" * ), * @SWG\Property( * property="message", * type="string" * ), * @SWG\Property( * property="user", * type="object", * ref="#/definitions/user.info.points" * ) * ) * * * @SWG\GET( * path="rewards/redeem/{reward}/user/{user}", * description="Redeem user points for rewards", * summary="Redeem a reward", * tags={ "rewards"}, * * @SWG\Parameter( * description="ID of reward to redeem", * format="int64", * in="path", * name="reward", * required=true, * type="integer" * ), * @SWG\Parameter( * description="ID of user", * format="int64", * in="path", * name="user", * required=true, * type="integer" * ), * @SWG\Response( * response=200, * description="Unsuccessful response", * @SWG\Schema(ref="#/definitions/response.redeem") * ), * @SWG\Response( * response=201, * description="Successful response", * @SWG\Schema(ref="#/definitions/response.redeem") * ), * @SWG\Response( * response=500, * description="Unexpected error", * @SWG\Schema(ref="#/definitions/error500") * ), * @SWG\Response( * response=404, * description="User not found", * @SWG\Schema(ref="#/definitions/UserError404") * ) * ) */ public function redeemByGet($rewardId, $userId) { if (is_null($user = User::find($userId))) { return Response::api()->errorNotFound('User not found'); } if (is_null($reward = Reward::find($rewardId))) { return Response::api()->errorNotFound('Reward not found'); } RewardManager::redeem($rewardId, $user); // Check if redeem was successful $message = Session::pull('rewardMessage'); $type = $message ? 'info' : 'error'; $success = true; $httpCode = 201; if ($type == 'error') { $success = false; $httpCode = 200; $message = Session::pull('rewardError'); } // Get common user points format via UserProfileTransformer $userTransformer = new UserProfileTransformer(); $points = $userTransformer->getUserPoints($user); $payload = ['data' => ['success' => $success, 'message' => $message, 'user' => ['id' => $user->getKey(), 'points' => $points]]]; return Response::api()->setStatusCode($httpCode)->withArray($payload); }
/** * Ajax handler for removing members */ public function onRemoveMember() { // refresh current step $this->currentStep = self::STEP_MEMBERS; if (($memberId = post('memberId')) != '' && ($groupId = post('groupId')) != '') { $user = User::find($memberId); if ($user) { if ($group = $this->getGroup($groupId)) { // remove from group $group->removeUser($user); // Refresh current groupid $this->currentGroupId = $groupId; // Updated list of users and other vars $this->prepareVars(); $message = Lang::get('dma.friends::lang.groups.memberRemoved'); Flash::info($message); } } else { $message = Lang::get('dma.friends::lang.exceptions.userNotFound'); Flash::info($message); } } }
public function rate($rating) { $user = User::find($this->user_id); $this->rating = $rating; $user->touch(); }
/** * Return activity metadata by the given user filtered * by activities types * @param string $types comma separted strings * @param string $user * @return Response */ public function indexByTypeAndUser($types = null, $userId = null) { // Apply query filters and sort parameters $query = $this->applyFilters(); if (!is_null($userId)) { if (is_null($user = User::find($userId))) { return Response::api()->errorNotFound('User not found'); } // Filter query by user $query = $query->where('user_id', $user->getKey()); } // Filter by activity type $types = !is_null($types) ? explode(',', $types) : $types; if (!is_null($types)) { $query = $query->whereHas('activity', function ($q) use($types) { $q->whereIn('activity_type', $types); }); } return $this->paginateResult($query); }
private function genericUserRelationResource($userId, $attrRelation, $transformer) { if (is_null($user = User::find($userId))) { return Response::api()->errorNotFound('User not found'); } $pageSize = $this->getPageSize(); $sortBy = $this->getSortBy(); $query = $user->{$attrRelation}(); $transformer = new $transformer(); if ($pageSize > 0) { $paginator = $query->paginate($pageSize); return Response::api()->withPaginator($paginator, $transformer); } else { return Response::api()->withCollection($query->get(), $transformer); } }
/** * Ajax handler for adding members */ public function onDelete() { if (($removeUser = post('removeUser')) != '') { $user = User::find($removeUser); if ($user) { // remove from group $group = $this->getGroup(); $group->removeUser($user); // Updated list of users and other vars $this->prepareVars($group); } else { throw new \Exception('User not found.'); } } }
/** * Provide aliases to object_type and user_id filters * @param string $types comma separted strings * @param string $user * @return Response */ public function indexByTypeAndUser($types = null, $user = null) { $filters = []; if (!is_null($types)) { $relModel = ['reward' => 'DMA\\Friends\\Models\\Reward', 'activity' => 'DMA\\Friends\\Models\\Activity', 'badge' => 'DMA\\Friends\\Models\\Badge', 'step' => 'DMA\\Friends\\Models\\Step']; $types = !is_null($types) ? explode(',', $types) : $types; try { $object_types = array_map(function ($t) use($relModel) { $t = strtolower(trim($t)); return $relModel[$t]; }, $types); } catch (\Exception $e) { Log::error('API endpoint ' . get_class($this) . ' : ' . $e->getMessage()); $message = 'One of the given types is not valid. Valid types are [ ' . implode(', ', array_keys($relModel)) . ' ]'; return Response::api()->errorInternalError($message); } if (count($object_types) > 0) { $filters['object_type__in'] = $object_types; } } if (!is_null($user)) { // Find user if exists $user = User::find($user); if ($user) { $filters['user_id'] = $user->getKey(); } else { return Response::api()->errorNotFound('User not found'); } } // Update or inject Input filters Input::merge($filters); // Call index and the filters will do the magic return parent::index(); }
protected function handleOptOutLinks() { if (!($topic = $this->getTopic())) { return; } if (!($action = post('action'))) { return; } if (!in_array($action, ['unfollow', 'unsubscribe'])) { return; } /* * Attempt to find member using dry authentication */ if (!($member = $this->getMember())) { if (!($authCode = post('auth')) || !strpos($authCode, '!')) { return; } list($hash, $userId) = explode('!', $authCode); if (!($user = UserModel::find($userId))) { return; } if (!($member = MemberModel::getFromUser($user))) { return; } $expectedCode = TopicFollow::makeAuthCode($action, $topic, $member); if ($authCode != $expectedCode) { Flash::error('Invalid authentication code, please sign in and try the link again.'); return; } } /* * Unfollow link */ if ($action == 'unfollow') { TopicFollow::unfollow($topic, $member); Flash::success('You will no longer receive notifications about this topic.'); } /* * Unsubscribe link */ if ($action == 'unsubscribe' && $member->user) { MailBlocker::addBlock('rainlab.forum::mail.topic_reply', $member->user); Flash::success('You will no longer receive notifications about any topics in this forum.'); } }
/** * @SWG\Definition( * definition="request.bulk.checkin", * type="object", * required={"codes"}, * @SWG\Property( * type="array", * items=@SWG\Schema(type="string"), * property="codes", * ) * ) * * @SWG\Definition( * definition="response.bulk.checkin", * type="object", * required={"data"}, * @SWG\Property( * property="data", * ref="#/definitions/response.bulk.activity.code.user" * ) * ) * * * @SWG\Definition( * definition="response.bulks.checkin", * description="Single response checking", * type="object", * required={"data"}, * @SWG\Property( * property="data", * type="object", * ref="#/definitions/response.activity.code.user" * ), * ) * * @SWG\Post( * path="activities/bulk-checkin/{user}", * description="Bulk checkin user activities", * summary="Bulk activity checkin", * tags={ "activity"}, * * @SWG\Parameter( * description="ID of the user checking the activity", * format="int64", * in="path", * name="user", * required=true, * type="integer" * ), * * @SWG\Parameter( * description="Activity codes and/or accessioned number", * name="body", * in="body", * required=true, * schema=@SWG\Schema(ref="#/definitions/request.bulk.checkin") * ), * * @SWG\Response( * response=200, * description="Successful response", * @SWG\Schema(ref="#/definitions/response.bulk.checkin", type="array") * ), * @SWG\Response( * response=500, * description="Unexpected error", * @SWG\Schema(ref="#/definitions/error500") * ), * @SWG\Response( * response=404, * description="User not found", * @SWG\Schema(ref="#/definitions/UserError404") * ) * ) * * * @SWG\Get( * path="activities/bulk-checkin/{user}/{codes}", * description="Bulk checkin user activities", * summary="Bulk activity checkin", * tags={ "activity"}, * * @SWG\Parameter( * description="ID of the user checking the activity", * format="int64", * in="path", * name="user", * required=true, * type="integer" * ), * * @SWG\Parameter( * description="Activity codes and/or accessioned numbers", * in="path", * name="codes", * type="array", * required=true, * items=@SWG\Schema(type="string"), * collectionFormat="csv", * ), * * @SWG\Response( * response=200, * description="Successful response", * @SWG\Schema(ref="#/definitions/response.bulk.checkin", type="array") * ), * @SWG\Response( * response=500, * description="Unexpected error", * @SWG\Schema(ref="#/definitions/error500") * ), * @SWG\Response( * response=404, * description="User not found", * @SWG\Schema(ref="#/definitions/UserError404") * ) * ) */ public function bulkCheckins($user, $codes = null) { $user = User::find($user); if (!is_null($user)) { // Check if codes are given in the URL or are part of the body request if (is_null($codes)) { // Check if codes are in the body of the request $data = Request::all(); $codes = array_get($data, 'codes'); } if (is_null($codes)) { $message = "'codes' argument is required"; return Response::api()->errorWrongArgs($message); } // Convert into array if necessary if (is_string($codes)) { $codes = explode(',', $codes); } $payload = []; foreach ($codes as $code) { // Process activity code $code = trim($code); $response = $this->processActivityCode($user, $code); $httpCode = array_get($response, 'http_code'); $activity = array_get($response, 'payload'); $payload['data']['checkins'][] = array_merge(['http_code' => $httpCode], $activity); } // Get user info $payload['data']['user'] = $this->getUserInfo($user); $httpCode = 200; return Response::api()->setStatusCode($httpCode)->withArray($payload); } return Response::api()->errorNotFound('User not found'); }
/** * Execute the console command. * @return void */ public function fire() { // Taxonomy terms $termRelations = $this->db->table('wp_term_relationships')->get(); foreach ($termRelations as $relation) { $activity = Activity::findWordpress($relation->object_id)->first(); if ($activity) { if (!$activity->categories->contains($relation->term_taxonomy_id)) { $category = Category::find($relation->term_taxonomy_id); if ($category) { $activity->categories()->save($category); } } } } // p2p connections $p2ps = $this->db->table('wp_p2p')->get(); foreach ($p2ps as $p2p) { list($from, $t, $to) = explode('-', $p2p->p2p_type); switch ($from) { case 'activity': $from = Activity::findWordpress($p2p->p2p_from)->first(); $from_table = 'activity'; break; case 'badge': $from = Badge::findWordpress($p2p->p2p_from)->first(); $from_table = 'badge'; break; case 'dma-location': $from = Location::findWordpress($p2p->p2p_from)->first(); $from_table = 'location'; break; case 'step': $from = Step::findWordpress($p2p->p2p_from)->first(); $from_table = 'step'; break; default: $from = false; } switch ($to) { case 'activity': $to = Activity::findWordpress($p2p->p2p_to)->first(); $to_table = 'activity'; break; case 'badge': $to = Badge::findWordpress($p2p->p2p_to)->first(); $to_table = 'badge'; break; case 'dma-location': $to = Location::findWordpress($p2p->p2p_to)->first(); $to_table = 'location'; break; case 'step': $to = Step::findWordpress($p2p->p2p_to)->first(); $to_table = 'step'; break; default: $to = false; } if ($from && $to) { $table = 'dma_friends_' . $from_table . '_' . $to_table; switch ($table) { case 'dma_friends_activity_step': $from->steps()->save($to); $this->info('activity: ' . $from->title . ' --> step: ' . $to->title); break; case 'dma_friends_step_badge': $to->steps()->save($from); $this->info('step: ' . $from->title . ' --> badge: ' . $to->title); break; default: $values = [$from_table . '_id' => $from->id, $to_table . '_id' => $to->id]; if (Schema::hasTable($table)) { DB::table($table)->insert($values); $this->info('from: ' . $from->title . ' ----- ' . $to->title); } else { $this->error('table doesnt exist: ' . $table); } } } } // User achievements $achievements = $this->db->table('wp_usermeta')->where('meta_key', '_badgeos_achievements')->get(); $post = new Post(); $this->info('Sync Achievements'); foreach ($achievements as $achievement) { $user = User::find($achievement->user_id); if (empty($user)) { continue; } // Flush existing records DB::table($this->userStepTable)->where('user_id', $user->id)->delete(); DB::table($this->userBadgeTable)->where('user_id', $user->id)->delete(); $data = unserialize($achievement->meta_value); // wtf we don't need arrays in our arrays if we want to array $data = array_pop($data); foreach ($data as $d) { $link = ['user_id' => $user->id, 'created_at' => $post->epochToTimestamp($d->date_earned)]; // About half way thru the data for the location key changes. // so lets deal with that if (isset($d->location)) { $location_id = $d->location; } elseif (isset($d->location_earned)) { $location_id = $d->location_earned; } else { $location_id = null; } $location = Location::findWordpress($location_id)->first(); if (isset($location->id)) { $link['location_id'] = $location->id; } if ($d->post_type == 'step') { $step = Step::findWordpress($d->ID)->first(); if ($step) { $link['step_id'] = $step->id; DB::table($this->userStepTable)->insert($link); } } elseif ($d->post_type == 'badge') { $badge = Badge::findWordpress($d->ID)->first(); if ($badge) { $link['badge_id'] = $badge->id; DB::table($this->userBadgeTable)->insert($link); } } } } // Syncronize activities and users $this->info('Importing Activity/User relations'); $table = 'dma_friends_activity_user'; DB::table($table)->delete(); ActivityLog::where('action', '=', 'activity')->chunk(100, function ($activityLogs) use($table) { foreach ($activityLogs as $activityLog) { if ($activityLog->object_id) { echo '.'; $pivotTable = ['user_id' => $activityLog->user_id, 'activity_id' => $activityLog->object_id, 'created_at' => $activityLog->timestamp, 'updated_at' => $activityLog->timestamp]; DB::table($table)->insert($pivotTable); } } }); // Syncronize rewards and users $this->info('Importing Reward/User relations'); $table = 'dma_friends_reward_user'; //DB::table($table)->delete(); ActivityLog::where('action', '=', 'reward')->where('timestamp', '<', '2015-02-02 12:10:35')->chunk(100, function ($activityLogs) use($table) { foreach ($activityLogs as $activityLog) { if ($activityLog->object_id) { echo '.'; if (Reward::find($activityLog->object_id) && User::find($activityLog->user_id)) { $pivotTable = ['user_id' => $activityLog->user_id, 'reward_id' => $activityLog->object_id, 'created_at' => $activityLog->timestamp, 'updated_at' => $activityLog->timestamp]; DB::table($table)->insert($pivotTable); } } } }); $this->info('Sync complete'); }
/** * @SWG\Definition( * definition="response.rate", * required={"data"}, * @SWG\Property( * property="data", * type="object", * ref="#/definitions/rate.payload" * ) * ) * * @SWG\Definition( * definition="rate.payload", * required={"success", "message", "user", "rating"}, * @SWG\Property( * property="success", * type="boolean" * ), * @SWG\Property( * property="message", * type="string" * ), * @SWG\Property( * property="user", * type="object", * ref="#/definitions/user.info.points" * ), * @SWG\Property( * property="rating", * type="object", * ref="#/definitions/rating.stats" * ) * ) * * @SWG\Definition( * definition="rating.stats", * required={"total", "average", "object_type", "object_id"}, * @SWG\Property( * property="total", * type="number", * format="float" * ), * @SWG\Property( * property="average", * type="number", * format="float" * ), * @SWG\Property( * property="object_type", * type="string" * ), * @SWG\Property( * property="object_id", * type="integer", * format="int32" * ) * ) * * * @SWG\GET( * path="ratings/rate/{object}/{objectId}/user/{user}/{rate}", * description="Rate an object", * summary="Rate an object", * tags={ "ratings"}, * * @SWG\Parameter( * description="Object to rate", * in="path", * name="object", * required=true, * type="string", * enum={"activity", "badge"} * ), * @SWG\Parameter( * description="ID of object to rate", * format="int64", * in="path", * name="objectId", * required=true, * type="integer" * ), * @SWG\Parameter( * description="ID of user", * format="int64", * in="path", * name="user", * required=true, * type="integer" * ), * @SWG\Parameter( * description="Rate value", * format="float", * in="path", * name="rate", * required=true, * type="number", * minimum=1, * maximum=5 * ), * @SWG\Response( * response=200, * description="Successful response", * @SWG\Schema(ref="#/definitions/response.rate") * ), * @SWG\Response( * response=500, * description="Unexpected error", * @SWG\Schema(ref="#/definitions/error500") * ), * @SWG\Response( * response=404, * description="User not found", * @SWG\Schema(ref="#/definitions/UserError404") * ) * ) */ public function addObjectRating($objectType, $objectId, $user, $rateValue, $comment = null) { if ($user = User::find($user)) { if ($instance = $this->getObject($objectType, $objectId)) { list($success, $rating) = $instance->addRating($user, $rateValue, $comment); // Get common user points format via UserProfileTransformer $userTransformer = new UserProfileTransformer(); $points = $userTransformer->getUserPoints($user); $payload = ['data' => ['success' => $success, 'message' => "{$objectType} has been rate succesfully.", 'user' => ['id' => $user->getKey(), 'points' => $points], 'rating' => array_merge($instance->getRatingStats(), ['object_type' => $objectType, 'object_id' => intVal($objectId)])]]; $httpCode = 201; if (!$success) { $httpCode = 200; $payload['data']['message'] = "User has already rate this {$objectType}"; } return Response::api()->setStatusCode($httpCode)->withArray($payload); } else { return Response::api()->errorNotFound("{$object} not found"); } } else { return Response::api()->errorNotFound('User not found'); } }