コード例 #1
0
ファイル: Detail.php プロジェクト: rachelglover/entries
 /**
  * Return the number of free places on this detail
  */
 public function placesLeft()
 {
     $entries = Entry::where('detail_id', '=', $this->id);
     $numEntries = $entries->count();
     $left = $this->max - $numEntries;
     return $left;
 }
コード例 #2
0
ファイル: FrontController.php プロジェクト: jmramos02/roamio
 public function search(Request $request)
 {
     $searchTerm = is_null($request->input('query')) ? "" : $request->input('query');
     $city = is_null($request->input('city')) ? '' : $request->input('city');
     $category = is_null($request->input('category')) ? "" : $request->input('category');
     $participants = is_null($request->input('participants')) ? "" : $request->input('participants');
     $min = is_null($request->input('min_budget')) ? 0 : $request->input('min_budget');
     $max = is_null($request->input('max_budget')) ? 2147483647 : $request->input('max_budget');
     $entries = Entry::where('title', 'LIKE', "%{$searchTerm}%")->where('city', 'LIKE', "%{$city}%")->where('address', 'LIKE', "%{$city}%")->where('categories', "LIKE", "%{$category}%")->where('participants', 'LIKE', "%{$participants}%")->where('budget', '>=', $min)->where('budget', '<=', $max)->with('days')->with('hours')->with('tags');
     /*if($searchTerm != ''){
           $entries = Entry::where('title','LIKE',"%$searchTerm%");
       } else if($city != ''){
           $entries = $entries->where('description','LIKE',"%$searchTerm%");
       } else if($category != ''){
           $entries = $entries->where('categories','LIKE',"%$categories%");
       } else if($participants != ''){
           $entries = $entries->where('participants','LIKE',"");
       }*/
     $entries = $entries->get();
     $tags = Tag::where('description', 'LIKE', "%{$searchTerm}%")->get();
     foreach ($tags as $tag) {
         $entries->merge($tag->entry()->get());
     }
     header("Access-Control-Allow-Origin: *");
     header("Access-Control-Allow-Credentials: true ");
     header("Access-Control-Allow-Methods: OPTIONS, GET, POST");
     header("Access-Control-Allow-Headers: Content-Type, Depth, User-Agent, X-File-Size, \n          X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control");
     return $entries->toJson();
 }
コード例 #3
0
 public function viewEntries(Request $request)
 {
     $entries = [];
     if ($request->has('q')) {
         $entries = Entry::where('title', 'like', '%' . $request->input('q') . '%')->orderBy('created_at', 'desc')->get();
     } else {
         $entries = Entry::orderBy('created_at', 'desc')->get();
     }
     return view('entry.viewAll', ['user' => Auth::user(), 'entries' => $entries]);
 }
コード例 #4
0
ファイル: Goal.php プロジェクト: Cheddam/health
 /**
  * @todo this is f*****g gross
  */
 public function getCompletedAttribute()
 {
     if (\Auth::guest()) {
         return false;
     }
     $entry = Entry::where('goal_id', $this->id)->where('user_id', \Auth::user()->id)->where('completed_on', Carbon::today())->first();
     if ($entry) {
         return true;
     }
     return false;
 }
コード例 #5
0
ファイル: GoalController.php プロジェクト: Cheddam/health
 /**
  * Toggles a goal between completed and not (by adding or deleting a record)
  * @param  integer  $id      The ID of the goal to toggle.
  * @param  Request $request The request.
  * @return mixed           Either the newly created completion, or true (?)
  * @todo Make this code more concise.
  */
 public function toggleGoal($id, Request $request)
 {
     if ($entry = Entry::where('goal_id', $id)->where('user_id', \Auth::user()->id)->where('completed_on', Carbon::today())->first()) {
         $entry->delete();
         return json_encode('true');
     }
     $entry = new Entry();
     $entry->goal_id = $id;
     # TODO maybe use Laravel's relationships more here
     $entry->user_id = \Auth::user()->id;
     $entry->completed_on = Carbon::today();
     $entry->save();
     return $entry;
 }
コード例 #6
0
    public function get()
    {
        $entry_id = Request::input('entry_id');
        $entry = Entry::where('id', '=', $entry_id)->first();
        if ($entry) {
            $my_teams = array();
            $global_moderator = false;
            $team_moderator = false;
            $entry_user = $entry->user()->first();
            $user = NULL;
            if (!Auth::check()) {
                if (!$entry->public) {
                    return json_encode(['status' => 'error', 'message' => 'Error. Logout and try again']);
                }
            } else {
                $entry_teams = $entry->teams()->get();
                $user = Auth::user();
                foreach ($entry_teams as $team) {
                    if ($entry->user_id == $user->id || !$team->pivot->removed_from_team) {
                        $check = $team->users()->where('user_id', '=', $user->id)->first();
                        if ($check) {
                            $role = $check->pivot->role;
                            $my_teams[] = ["name" => $team->name, "role" => $role];
                            if ($role && ($role == 'owner' || $role == 'moderator')) {
                                $team_moderator = true;
                            }
                        }
                    }
                }
                if (!$entry->public && !count($my_teams) && $entry->user_id != $user->id) {
                    return json_encode(['status' => 'error', 'message' => 'Error. Logout and try again']);
                }
                if ($entry->public && $user->moderator) {
                    $global_moderator = true;
                }
            }
            $body_rendered = $entry->body_rendered;
            $body = '
            <!DOCTYPE html>
            <html lang="en">
                <head>
                    <title>".$entry->title."</title>
                    <meta charset="utf-8" />
                    <meta name="viewport" content="width=device-width, initial-scale=1">
                    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
                    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css">
                    <style>
                        code {
                            color: black;
                            background-color: #f5f5f5;
                            border-radius: 4px;
                            border: 1px solid #ccc;
                            padding: 1px 5px;
                        }
                        pre code {
                            border: none;
                        }

                        /* Pygmentize theme: Friendly */
                        .highlight .hll { background-color: #ffffcc }
                        .highlight .c { color: #60a0b0; font-style: italic } /* Comment */
                        .highlight .err { border: 1px solid #FF0000 } /* Error */
                        .highlight .k { color: #007020; font-weight: bold } /* Keyword */
                        .highlight .o { color: #666666 } /* Operator */
                        .highlight .cm { color: #60a0b0; font-style: italic } /* Comment.Multiline */
                        .highlight .cp { color: #007020 } /* Comment.Preproc */
                        .highlight .c1 { color: #60a0b0; font-style: italic } /* Comment.Single */
                        .highlight .cs { color: #60a0b0; background-color: #fff0f0 } /* Comment.Special */
                        .highlight .gd { color: #A00000 } /* Generic.Deleted */
                        .highlight .ge { font-style: italic } /* Generic.Emph */
                        .highlight .gr { color: #FF0000 } /* Generic.Error */
                        .highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
                        .highlight .gi { color: #00A000 } /* Generic.Inserted */
                        .highlight .go { color: #808080 } /* Generic.Output */
                        .highlight .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */
                        .highlight .gs { font-weight: bold } /* Generic.Strong */
                        .highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
                        .highlight .gt { color: #0040D0 } /* Generic.Traceback */
                        .highlight .kc { color: #007020; font-weight: bold } /* Keyword.Constant */
                        .highlight .kd { color: #007020; font-weight: bold } /* Keyword.Declaration */
                        .highlight .kn { color: #007020; font-weight: bold } /* Keyword.Namespace */
                        .highlight .kp { color: #007020 } /* Keyword.Pseudo */
                        .highlight .kr { color: #007020; font-weight: bold } /* Keyword.Reserved */
                        .highlight .kt { color: #902000 } /* Keyword.Type */
                        .highlight .m { color: #40a070 } /* Literal.Number */
                        .highlight .s { color: #4070a0 } /* Literal.String */
                        .highlight .na { color: #4070a0 } /* Name.Attribute */
                        .highlight .nb { color: #007020 } /* Name.Builtin */
                        .highlight .nc { color: #0e84b5; font-weight: bold } /* Name.Class */
                        .highlight .no { color: #60add5 } /* Name.Constant */
                        .highlight .nd { color: #555555; font-weight: bold } /* Name.Decorator */
                        .highlight .ni { color: #d55537; font-weight: bold } /* Name.Entity */
                        .highlight .ne { color: #007020 } /* Name.Exception */
                        .highlight .nf { color: #06287e } /* Name.Function */
                        .highlight .nl { color: #002070; font-weight: bold } /* Name.Label */
                        .highlight .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */
                        .highlight .nt { color: #062873; font-weight: bold } /* Name.Tag */
                        .highlight .nv { color: #bb60d5 } /* Name.Variable */
                        .highlight .ow { color: #007020; font-weight: bold } /* Operator.Word */
                        .highlight .w { color: #bbbbbb } /* Text.Whitespace */
                        .highlight .mf { color: #40a070 } /* Literal.Number.Float */
                        .highlight .mh { color: #40a070 } /* Literal.Number.Hex */
                        .highlight .mi { color: #40a070 } /* Literal.Number.Integer */
                        .highlight .mo { color: #40a070 } /* Literal.Number.Oct */
                        .highlight .sb { color: #4070a0 } /* Literal.String.Backtick */
                        .highlight .sc { color: #4070a0 } /* Literal.String.Char */
                        .highlight .sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */
                        .highlight .s2 { color: #4070a0 } /* Literal.String.Double */
                        .highlight .se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */
                        .highlight .sh { color: #4070a0 } /* Literal.String.Heredoc */
                        .highlight .si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */
                        .highlight .sx { color: #c65d09 } /* Literal.String.Other */
                        .highlight .sr { color: #235388 } /* Literal.String.Regex */
                        .highlight .s1 { color: #4070a0 } /* Literal.String.Single */
                        .highlight .ss { color: #517918 } /* Literal.String.Symbol */
                        .highlight .bp { color: #007020 } /* Name.Builtin.Pseudo */
                        .highlight .vc { color: #bb60d5 } /* Name.Variable.Class */
                        .highlight .vg { color: #bb60d5 } /* Name.Variable.Global */
                        .highlight .vi { color: #bb60d5 } /* Name.Variable.Instance */
                        .highlight .il { color: #40a070 } /* Literal.Number.Integer.Long */


                        html, body {
                            background-color:transparent;
                        }
                        h1 {
                            font-size:24px;
                        }
                        h2 {
                            font-size:22px;
                        }
                        h3 {
                            font-size:20px;
                        }
                        h4 {
                            font-size:18px;
                        }
                        h5 {
                            font-size:16px;
                        }
                        h6 {
                            font-size:14px;
                        }

                        h2.title {
                            padding-bottom:0px;
                            margin-bottom:2px;
                            margin-top:12px;
                        }

                        p.description {
                            padding-bottom:2px;
                            margin-top:3px;
                        }

                        .vote {
                            float:left;
                            width:48px;
                            text-align: center;
                            height:64px;
                            margin-left:-10px;
                            margin-top:1px;
                        }

                        .score {
                            line-height:12px;
                            font-size:18px;
                            padding-top: 1px;
                            margin-left:2px;
                        }

                        .arrow-up {
                            padding-top:9px;
                            cursor: pointer;
                        }
                        .arrow-down {
                            padding-top:3px;
                            cursor: pointer;
                        }
                        .arrow-up.voted {
                            color:green;
                        }
                        .arrow-down.voted {
                            color:red;
                        }
                        .noselect {
                            -webkit-touch-callout: none;
                            -webkit-user-select: none;
                            user-select:none;
                        }
                        .actions {
                            padding: 1px 4px;
                            font-size: 90%;
                            vertical-align:1px;
                            cursor: pointer;
                            white-space:nowrap;
                            box-shadow:none;
                            font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
                        }
                        .actions.edit {
                            background-color:#286090;
                        }
                        .actions.delete {
                            background-color:#c9302c;
                        }
                        .dash-internal {
                            color: inherit !important;
                            text-decoration: none !important;
                        }

                    </style>
                </head>
                <body>
                    <div class="container-fluid">';
            if ($entry->public || count($my_teams)) {
                $voted_up = "";
                $voted_down = "";
                if ($user) {
                    $vote = Vote::where('user_id', '=', $user->id)->where('entry_id', '=', $entry->id)->first();
                    if ($vote) {
                        $voted_up = $vote->type == 1 ? "voted" : "";
                        $voted_down = $vote->type == -1 ? "voted" : "";
                    }
                }
                $score = $entry->score > 999 ? 999 : $entry->score;
                $score = $score < -999 ? -999 : $score;
                $body .= '
                    <div class="vote noselect">
                        <a class="dash-internal" href="#dashInternalVoteUp"><div class="arrow-up glyphicon glyphicon-arrow-up ' . $voted_up . '"></div></a>
                        <div class="score">' . $score . '</div>
                        <a class="dash-internal" href="#dashInternalVoteDown"><div class="arrow-down glyphicon glyphicon-arrow-down ' . $voted_down . '"></div></a>
                    </div>';
            }
            $body .= '
                    <div><h2 class="title">' . htmlentities($entry->title, ENT_QUOTES) . '</h2>
                    <p class="description"><small>';
            $body .= $entry->public && !($entry->removed_from_public && $global_moderator) ? "Public annotation " : @"Private annotation ";
            $body .= 'by <u>' . htmlentities($entry_user->username, ENT_QUOTES) . '</u>';
            $team_string = "";
            $i = 0;
            foreach ($my_teams as $team) {
                ++$i;
                if (strlen($team_string)) {
                    $team_string .= count($my_teams) == $i ? " and " : ", ";
                }
                $team_string .= '<u>' . htmlentities($team['name'], ENT_QUOTES) . '</u>';
            }
            if (strlen($team_string)) {
                $body .= ' in ' . $team_string . '';
            }
            $body .= ' ';
            if ($user && $user->id == $entry->user_id) {
                $body .= '&nbsp;<a class="dash-internal" href="#dashInternalEdit"><kbd class="actions edit">Edit</kbd></a>';
                $body .= '&nbsp;<a class="dash-internal" href="#dashInternalDelete"><kbd class="actions delete">Delete</kbd></a>';
            } else {
                if ($global_moderator && $entry->public && !$entry->removed_from_public) {
                    $body .= '&nbsp;<a class="dash-internal" href="#dashInternalRemoveFromPublic"><kbd class="actions delete">Remove From Public</kbd></a>';
                }
                if ($team_moderator) {
                    $body .= '&nbsp;<a class="dash-internal" href="#dashInternalRemoveFromTeams"><kbd class="actions delete">Remove From Team';
                    if (count($my_teams) > 1) {
                        $body .= 's';
                    }
                    $body .= '</kbd></a>';
                }
            }
            $body .= '</small><p></div>
                    <p>' . $body_rendered . '</P>
                    </div>
                </body>
            </html>';
            return ["status" => "success", "body" => $entry->body, "body_rendered" => $body, "teams" => $my_teams, "global_moderator" => $global_moderator];
        }
        return json_encode(['status' => 'error', 'message' => 'Error. Logout and try again']);
    }
コード例 #7
0
 /**
  * Get any refunds/cancellations that are currently pending. These are entries
  * where 'paymentStatus' == 'pending_cancellation_single|pending_cancellation_event'.
  */
 private function getRefundsPending()
 {
     $cancellations = Entry::where('paymentStatus', '=', 'pending_cancellation_single')->orWhere('paymentStatus', '=', 'pending_cancellation_event')->get();
     return $cancellations;
 }
コード例 #8
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($slug)
 {
     $entry = Entry::where('slug', $slug)->first();
     return view('thoughts.show', compact('entry'));
 }