Example #1
0
 public function showIndex()
 {
     if (!Auth::check()) {
         return View::make('login', array('title' => 'edison'));
     }
     $category_names = array('ent' => 'エンターテイメント', 'music' => '音楽', 'sing' => '歌ってみた', 'play' => '演奏してみた', 'dance' => '踊ってみた', 'vocaloid' => 'VOCALOID', 'nicoindies' => 'ニコニコインディーズ', 'animal' => '動物', 'cooking' => '料理', 'nature' => '自然', 'travel' => '旅行', 'sport' => 'スポーツ', 'lecture' => 'ニコニコ動画講座', 'drive' => '車載動画', 'history' => '歴史', 'politics' => '政治', 'science' => '科学', 'tech' => 'ニコニコ技術部', 'handcraft' => 'ニコニコ手芸部', 'make' => '作ってみた', 'anime' => 'アニメ', 'game' => 'ゲーム', 'toho' => '東方', 'imas' => 'アイドルマスター', 'radio' => 'ラジオ', 'draw' => '描いてみた', 'are' => '例のアレ', 'diary' => '日記', 'other' => 'その他', 'r18' => 'R-18', 'original' => 'オリジナル', 'portrait' => '似顔絵', 'character' => 'キャラクター');
     $all_items = Item::orderBy('created_at', 'desc')->take(10)->get();
     foreach ($all_items as &$item) {
         $item['user'] = User::where('id', '=', $item->user_id)->get()[0];
         $item['star_count'] = Starmap::where('item_id', '=', $item->id)->count();
         $item['comment_count'] = Comment::where('item_id', '=', $item->id)->count();
         if ($item->category_id != 0) {
             $item['category'] = Category::where('id', '=', $item->category_id)->get()[0]->content;
         }
     }
     $recent_works = Work::orderBy('created_at', 'desc')->take(10)->get();
     foreach ($recent_works as &$work) {
         $item = Item::where('id', '=', $work->item_id)->get()[0];
         $work['item'] = $item;
         $work['user'] = User::where('id', '=', $work->user_id)->get()[0];
         $work['item_poster_screen_name'] = User::where('id', '=', $item->user_id)->get()[0]->screen_name;
         if ($item->category_id != 0) {
             $work['item_category'] = Category::where('id', '=', $item->category_id)->get()[0]->content;
         }
     }
     $user = User::where('screen_name', '=', Auth::user()->screen_name)->get()[0];
     $data = array('title' => 'edison', 'user' => $user, 'all_items' => $all_items, 'recent_works' => $recent_works, 'categories' => $category_names, 'star_count' => Starmap::where('user_id', '=', $user->id)->count(), 'work_count' => Work::where('user_id', '=', Auth::user()->id)->count());
     return View::make('index', $data);
 }
Example #2
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     if ($this->user->inGroup(Sentry::findGroupByName('supporter')) || $this->user->inGroup(Sentry::findGroupByName('administer'))) {
         $items = Item::orderBy('id', 'desc')->paginate(10);
     } else {
         $items = Item::where('user_id', '=', $this->user->id)->orderBy('id', 'desc')->paginate(10);
     }
     return View::make('items.index', compact('items'));
 }
Example #3
0
 /**
  * The attributes excluded from the model's JSON form.
  *
  * @var array
  */
 public static function generateId()
 {
     $product = Item::orderBy('itemID', 'DESC')->get()->first();
     $productId = $product->itemID;
     $productId = substr($productId, 4);
     $newId = (int) $productId;
     $newId++;
     $newIdString = (string) $newId;
     $newIdString = "0000000" . $newIdString;
     if (strlen($newIdString) > 3) {
         $newIdString = substr($newIdString, strlen($newIdString) - 3);
     }
     $newIdString = "item" . $newIdString;
     return $newIdString;
 }
 /**
  * Handle searching by session title and/or speaker name.
  *
  * @param  int  $id
  * @return Response
  */
 public function search()
 {
     $input = urldecode(Input::get('search'));
     if (!empty($input)) {
         $searchTerms = explode(',', $input);
         $query = Item::orderBy('id', 'desc');
         // Assign index 0 search terms directly...
         $query->where('speaker_name', 'LIKE', '%' . $searchTerms[0] . '%');
         $query->whereOr('session_title', 'LIKE', '%' . $searchTerms[0] . '%');
         foreach ($searchTerms as $key => $value) {
             if ($key > 0) {
                 $query->whereOr('speaker_name', 'LIKE', '%' . $searchTerms[$key] . '%');
                 $query->whereOr('session_title', 'LIKE', '%' . $searchTerms[$key] . '%');
             }
         }
         $results = $query->remember(5)->get();
         //->paginate(20);
         // http://stackoverflow.com/a/23881516
         $paginator = json_decode($results);
         $perPage = 20;
         $page = Input::get('page', 1);
         if ($page > count($paginator) or $page < 1) {
             $page = 1;
         }
         $offset = $page * $perPage - $perPage;
         $dataSubset = array_slice($paginator, $offset, $perPage);
         $items = Paginator::make($dataSubset, count($paginator), $perPage);
         $this->layout->content = View::make('items.index', compact('items'))->with('search_criteria', urlencode($input));
     }
 }