コード例 #1
0
 public function getNews()
 {
     $issue_id = Input::get('issue_id');
     $issue = Issue::find($issue_id);
     $user_id = Input::get('user_id');
     $politician_id = Input::get('politician_id');
     $politician = Politician::find($politician_id);
     $news = $issue->googleNews($politician->full_name);
     $date = new DateTime();
     $date->modify('-1 hour');
     $formatted_date = $date->format('Y-m-d H:i:s');
     $sum = Rating::where('user_id', '=', $user_id)->where('politician_id', '=', $politician->id)->where('issue_id', '=', $issue->id)->where('created_at', '>=', $formatted_date)->sum('value');
     $response = array('sum' => $sum, 'news' => $news);
     return Response::json($response);
 }
コード例 #2
0
 public function rantSubmit()
 {
     $validator = Validator::make(Input::all(), array('auto-politician' => 'required|min:3'));
     if ($validator->fails()) {
         return Redirect::route('home')->withErrors($validator)->withInput();
     } else {
         $auto_politician = Input::get('auto-politician');
         $rant = Input::get('rant');
         if (Auth::check()) {
             $search_query = '%' . $auto_politician . '%';
             $politician = Politician::where('full_name', 'like', $search_query)->first();
             $rant = Input::get('rant');
             $comment = Comment::create(array('content' => $rant, 'politician_id' => $politician->id, 'user_id' => Auth::user()->id, 'parent_id' => 0));
             $comment->save();
             return Redirect::to('/politicians/' . $comment->politician->full_name . '/#' . $comment->user->username . '-' . $comment->id);
         } else {
             //return Redirect::route('create-get-1', array('auto-politician' =>$auto_politician_name,'rant'=>$rant));
             return View::make('create-1')->with('rant_data', array('auto-politician' => $auto_politician, 'rant' => $rant));
         }
     }
 }
コード例 #3
0
 public function postCreate2()
 {
     $user = Auth::user();
     $user->sex = Input::get('sex');
     $user->birth_month = Input::get('birth_month');
     $user->birth_day = Input::get('birth_day');
     $user->birth_year = Input::get('birth_year');
     $user->party = Input::get('party');
     $user->bio = Input::get('bio');
     $user->username = Input::get('username');
     //Upload Image
     $file = Input::file('photo');
     $validator = Validator::make(Input::all(), array('photo' => 'image'));
     if ($validator->fails()) {
         return Redirect::route('create-post-2')->withErrors($validator)->withInput();
     } else {
         if (isset($file)) {
             if ($file->isValid()) {
                 $destinationPath = public_path() . '/assets/images/avatars/';
                 // The destination were you store the image.
                 $filename = $file->getClientOriginalName();
                 $file->move($destinationPath, $filename);
                 $user->pic_url = '/assets/images/avatars/' . $filename;
             }
         }
         $user->save();
         $issues = Issue::all();
         foreach ($issues as $issue) {
             $issue_checkbox = Input::get($issue->id);
             if (isset($issue_checkbox)) {
                 $issues_follows = IssueFollow::create(array('issue_id' => $issue_checkbox, 'user_id' => $user->id));
                 $issues_follows->save();
             }
         }
         $auto_politician = Input::get('auto-politician');
         $rant = Input::get('rant');
         if (isset($auto_politician) && isset($rant)) {
             $search_query = '%' . $auto_politician . '%';
             $politician = Politician::where('full_name', 'like', $search_query)->first();
             $rant = Input::get('rant');
             $comment = Comment::create(array('content' => $rant, 'politician_id' => $politician->id, 'user_id' => Auth::user()->id, 'parent_id' => 0));
             $comment->save();
             return Redirect::to('/politicians/' . $comment->politician->full_name . '/#' . $comment->user->username . '-' . $comment->id);
         } else {
             //Redirect to login page - added to redirect to home upon successful account
             return Redirect::route('myprofile');
         }
     }
 }
コード例 #4
0
						<th>Created By</th>
						<th>About/Politician</th>	
					    	<th>Content</th>
						<th>Parent</th>
					        <th>Responses</th>
						<th>Created At</th>
						<th>Delete</th>

						    
						   </tr>
						</thead>
						<tbody>
						@foreach ($comments as $comment) 
                                                <?php 
$username = User::find($comment->user_id)->username;
$politician_name = Politician::find($comment->politician_id)->full_name;
?>

	
							<tr>
							      <td>{{$comment->id}}</td>
	   						    <td><a href="{{URL::route('profile-user',$username)}}" >{{$username}}</a></td>
							    <td><a href="{{URL::route('profile-politician',$politician_name)}}">{{$politician_name}}</a></td>
							    <td><a id ="{{'content-'.$comment->id}}" href="{{'http://iratepolitics.com/politicians/'.$politician_name.'/#'.$username.'-'.$comment->id}}">{{$comment->content}}</a></td>
							    <td>{{$comment->parent_id}}</a></td>
							    <td>{{Comment::where('parent_id','=',$comment->id)->count()}}</td>	
	   						    <td>{{$comment->created_at}}</td>
						  	    <td><a data-toggle="modal" data-target="#delete-comment" class ="comment-delete-link" href="{{$comment->id}}">Delete</a></td>					  
							</tr>
						
			    
コード例 #5
0
 public function search()
 {
     $search_term = Input::get('search_term');
     if (isset($search_term) && $search_term != '') {
         $search_query = '%' . $search_term . '%';
         $politicians = Politician::where('full_name', 'like', $search_query)->orWhere('party', 'like', $search_query)->orWhere('state', 'like', $search_query)->orWhere('city', 'like', $search_query)->orWhere('office', 'like', $search_query)->orWhere('sex', 'like', $search_query)->orWhere('bio', 'like', $search_query)->orWhere('district', 'like', $search_query)->get();
         if ($politicians->count() == 0) {
             $politicians = null;
         }
         $users = User::where('username', 'like', $search_query)->orWhere('first_name', 'like', $search_query)->orWhere('last_name', 'like', $search_query)->orWhere('email', 'like', $search_query)->orWhere('party', 'like', $search_query)->orWhere('state', 'like', $search_query)->orWhere('city', 'like', $search_query)->get();
         if ($users->count() == 0) {
             $users = null;
         }
         $issue = Issue::where('issue_name', '=', $search_term)->first();
         //don't want to repeat same articles in issue and in news.
         //don't want to do unnescesarry google news calls either
         //either news or issues
         if ($issue == null) {
             $news = $this->gNews($search_term);
         } else {
             $news = null;
         }
         $found = !($issue == null && $politicians == null && $news == null && $users == null);
         $user_id = Auth::check() ? Auth::user()->id : 0;
         //we're saving search attempts for study later. who searches and wether results are given.
         $search = Search::create(array('search_term' => $search_term, 'found' => $found, 'user_id' => $user_id));
         $search->save();
     } else {
         $politicians = null;
         $issue = null;
         $news = null;
         $users = null;
     }
     return View::make('results')->with('politicians', $politicians)->with('news', $news)->with('users', $users)->with('issue', $issue);
 }
コード例 #6
0
            <div class="excerpt">
              <p>{{$topArticle->content}}</p>
            </div>
            
            <div class="tags">
              <a href="{{URL::route('profile-politician',$politician->full_name)}}">{{$politician->full_name}}</a>, <a href="{{URL::route('news',$issue->issue_name)}}">{{$issue->issue_name}}</a>
            </div>
        </div>
        
        <div class="box-item">
	<?php 
$second_url = $topArticle->unescapedUrl;
$error = false;
do {
    try {
        $politician = Politician::find($most_popular_politicians[rand(0, 3)]->politician_id);
        $topIssuesList = $politician->topIssues();
        $issue = Issue::find($topIssuesList[rand(0, 4)]->issue_id);
        $topArticle = $issue->googleNews($politician->full_name)[0];
    } catch (Exception $e) {
        $error = true;
    }
} while ($error || $first_url == $topArticle->unescapedUrl || $second_url == $topArticle->unescapedUrl);
?>
        @if(isset($topArticle->image->url))
            <div class="article" title="" style="background-image: url('{{$topArticle->image->url}}');">
              <a href="{{URL::route('article')}}{{'?url='.$topArticle->unescapedUrl}}{{'&pic='.$topArticle->image->url}}{{'&summary='.$topArticle->content}}{{'&title='.$topArticle->title}}"  class="article-inner">
                <span class="sprite news">NEWS</span>
              </a>
            </div>
	@endif
コード例 #7
0
 public function follow()
 {
     // get politician id from fullname
     // get user id from user name
     //create poltiican record from user id, politician id
     $politician_id = Input::get('politician_id');
     $politician = Politician::where('id', '=', $politician_id);
     $user = Auth::user();
     $politician_follow = PoliticianFollow::where(function ($query) use($politician) {
         $query->where('politician_id', '=', Input::get('politician_id'))->where('user_id', '=', Auth::user()->id);
     });
     if ($politician_follow->count()) {
         //UN-FOLLOW
         $politician_follow->delete();
     } else {
         //FOLLOW
         $politician_follow = PoliticianFollow::create(array('politician_id' => $politician_id, 'user_id' => $user->id));
     }
     //return Redirect::back();
 }
コード例 #8
0
$result = isset($db->host);
$result = empty($db->host);
class Politician
{
    // called when calling a non-existing method
    public function __call($method, $arguments)
    {
        echo __CLASS__ . " has no method called {$method}" . PHP_EOL;
    }
    // called when calling a non-existing static method
    public function __callStatic($method, $arguments)
    {
        echo __CLASS__ . " has no static method called {$method}" . PHP_EOL;
    }
}
$foo = new Politician();
$foo->honesty();
Politician::loyalty();
class CallableObject
{
    // called when calling an object as a function
    public function __invoke($number)
    {
        return $number ** 2;
    }
}
$obj = new CallableObject();
echo $obj(10) . PHP_EOL;
class DebugObject
{
    private $private = 10;
コード例 #9
0
 private function getName($id, $cat = 'P')
 {
     if ($cat == 'P') {
         return Politician::find($id)->full_name;
     } else {
         return User::find($id)->username;
     }
 }