/** * Cast a survey to an array for response * * @param Survey survey * * @return array */ public static function cast(Survey $survey) { // Do not add survey_id to vote response unless vote id is ungessable, it would otherwise allow to easily discover surveys $data = array('id' => $survey->id, 'user_id' => $survey->user_id, 'type' => $survey->type, 'title' => $survey->title, 'description' => $survey->description, 'created' => RestUtilities::formatDate($survey->created), 'choices' => $survey->choices, 'permissions' => $survey->can); if ($survey->owner->is(Auth::user()) || Auth::isAdmin()) { $data['guests'] = $survey->guests; } return $data; }
/** * Cast a User to an array for response * * @param User user * * @return array */ public static function cast(User $user) { return array('id' => $user->id, 'additional_attributes' => $user->additional_attributes, 'created' => RestUtilities::formatDate($user->created), 'last_activity' => RestUtilities::formatDate($user->last_activity), 'lang' => $user->lang, 'remote_config' => Config::get('auth_remote_user_enabled') ? $user->remote_config : null); }
/** * Cast a Vote to an array for response * * @param Vote vote * * @return array */ public static function cast(Vote $vote) { // Do not add survey_id to vote response unless vote id is ungessable, it would otherwise allow to easily discover surveys return array('id' => $vote->id, 'user_id' => $vote->user_id, 'created' => RestUtilities::formatDate($vote->created), 'updated' => is_null($vote->updated) ? null : RestUtilities::formatDate($vote->updated), 'answers' => $vote->answers); }