Example #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $recipes = ['Italian Ciabatta Burgers' => ['Beef', 'Sandwich'], 'Asian Noodle Salad' => ['Pasta', 'Sides', 'Salad'], 'Caesar Salad' => ['Appetizers', 'Salad', 'Sides'], 'Glazed Teriyaki Chicken' => ['Chicken'], 'Southwestern Chicken Sausage Chili' => ['Appetizers', 'Sides'], 'Coconut-Crusted Chicken Fingers' => ['Chicken'], 'Steak Au Poivre' => ['Beef', 'Sides']];
     foreach ($recipes as $title => $tags) {
         $recipe = \P4\Recipe::where('title', 'like', $title)->first();
         foreach ($tags as $tagName) {
             $tag = \P4\Tag::where('tag_name', 'like', $tagName)->first();
             $recipe->tags()->save($tag);
         }
     }
 }
Example #2
0
 public function getTagArticles(Request $request, $tag_id)
 {
     $user_id = \Auth::user()->id;
     $tag = \p4\Tag::where("id", "{$tag_id}")->first();
     # Submit a SQL statement for efficiency which retrieves the sorted list of articles for the logged in user
     $sql = "SELECT \n                a.id,\n                a.feed_id,\n                u.feed_name,\n                a.article_guid,\n                a.title,\n                a.article_text,\n                a.author,\n                a.url,\n                a.publish_date,\n                a.created_at,\n                a.updated_at\n                FROM \n                articles a \n                INNER JOIN feeds f ON f.id = a.feed_id                 \n                INNER JOIN feed_user u ON u.feed_id = f.id\n                INNER JOIN tags_users_articles tua ON a.id = tua.article_id\n                WHERE\n                u.user_id =" . $user_id . " AND\n                tua.tag_id = " . $tag_id . "\n                ORDER BY \n                tua.score DESC";
     $items = \DB::select(\DB::raw($sql));
     # Pagination needs to be done manually with raw SQL queries
     $page = $request->input('page', 1);
     $articles = $this->setupPagination($items, $page, env('PAGE_SIZE', 50));
     $articles->setPath('/Tags/' . $tag_id);
     return view('articles', ['title' => "Articles for #" . $tag->tag, 'articles' => $articles, 'user_id' => $user_id]);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $photos = ['Happy' => ['happy', 'busy'], 'Easy' => ['easy', 'crazy'], 'Dizzy' => ['dizzy', 'happy']];
     # Now loop through the above array, creating a new pivot for each photo to tag
     foreach ($photos as $title => $tags) {
         # First get the photo matched
         $photo = \P4\Photo::where('title', 'like', $title . '%')->first();
         # Loop through all tags for each photo
         foreach ($tags as $tagName) {
             $tag = \P4\Tag::where('name', 'LIKE', $tagName)->first();
             # Save the photo's tag info
             $photo->tags()->save($tag);
         }
     }
 }
Example #4
0
File: User.php Project: ccushing/p4
 public static function setSessionFeeds($user_id)
 {
     # Set Feeds for this user in the Session Variable
     $feeds = \p4\UserFeed::where('user_id', '=', $user_id)->orderby('weight', 'DESC')->get();
     $tags = \p4\Tag::where('user_id', '=', $user_id)->orderby('weight', 'DESC')->get();
     $categories = \p4\Category::where('user_id', '=', $user_id)->orderby('weight', 'DESC')->get();
     foreach ($feeds as $f) {
         $f->stats = $f->get_stats();
     }
     foreach ($tags as $t) {
         $t->stats = $t->get_stats();
     }
     \Session::forget('myfeeds');
     \Session::forget('mytags');
     \Session::forget('categories');
     \Session::push('myfeeds', $feeds);
     \Session::push('mytags', $tags);
     \Session::push('categories', $categories);
 }
Example #5
0
 public function getRemoveTag(Request $request, $tag_id)
 {
     $user_id = \Auth::user()->id;
     \p4\Tag::where('id', '=', $tag_id)->where('user_id', '=', $user_id)->delete();
     \p4\User::setSessionFeeds($user_id);
     return \Redirect::to('/ManageTags');
 }