示例#1
0
 public function index()
 {
     //Set keyword to proper format using Str::lower - it's the same as strtolower
     $keyword = Str::lower(Input::get('keyword'));
     //Use Query builder to look for the keyword in various category
     $data['comics'] = Comicbooks::where('book_name', 'LIKE', '%' . $keyword . '%')->select('book_name')->distinct()->get();
     $data['characters'] = Characters::where('character_name', 'LIKE', '%' . $keyword . '%')->select('character_name')->distinct()->get();
     $data['authors'] = Authors::where('author_name', 'LIKE', '%' . $keyword . '%')->select('author_name')->distinct()->get();
     $data['artists'] = Artists::where('artist_name', 'LIKE', '%' . $keyword . '%')->select('artist_name')->distinct()->get();
     $data['publishers'] = Publishers::where('publisher_name', 'LIKE', '%' . $keyword . '%')->select('publisher_name')->distinct()->get();
     $this->layout->content = View::make('search', $data);
 }
示例#2
0
 public function getBrowse($category)
 {
     //Get browse category
     $category_filtered = strtoupper(trim($category));
     //Page Title
     $data['title'] = $category_filtered;
     //Switch to get appropriate data, redirect to error if options aren't listed
     switch ($category_filtered) {
         case 'SERIES':
             $data['comics'] = Comicbooks::orderBy('book_name', 'asc')->get();
             break;
         case 'AUTHORS':
             $data['comics'] = Authors::select('author_name')->orderBy('author_name', 'asc')->distinct()->get();
             break;
         case 'ARTISTS':
             $data['comics'] = Artists::select('artist_name')->orderBy('artist_name', 'asc')->distinct()->get();
             break;
         case 'CHARACTERS':
             $data['comics'] = Characters::select('character_name')->orderBy('character_name', 'asc')->distinct()->get();
             break;
         case 'PUBLISHERS':
             $data['comics'] = Publishers::select('publisher_name')->orderBy('publisher_name', 'asc')->distinct()->get();
             break;
         case 'GENRES':
             $data['comics'] = Genres::orderBy('genre_name', 'asc')->get();
             break;
         case 'YEARS':
             //This needed to be a raw query because of the date
             $data['comics'] = Comicissues::select(DB::raw('year(published_date) as year'))->orderBy('published_date', 'asc')->distinct()->get();
             break;
         default:
             return Redirect::to('error');
             break;
     }
     $this->layout->content = View::make('browse', $data);
 }
示例#3
0
 /**
  * Update a comicbook series
  * PUT /content/{title}
  *
  * @param  int  $title
  * @return Response
  */
 public function update($title)
 {
     //Set rules
     $rules = array('book_name' => 'required|min:1', 'publisher_name' => 'required|min:1', 'book_description' => 'max:2000', 'genres' => 'min:1', 'characters' => 'min:1');
     //Validate
     $validator = Validator::make(Input::all(), $rules);
     //Instance of Comicbook model
     $comic = new Comicbooks();
     $book_id = $comic->series($title)->select('comicdb_books.id')->first();
     //If the comicbook series exists
     if (!is_null($book_id)) {
         //If validation passes
         if ($validator->passes()) {
             //Instance of Publisher model
             $publishers = new Publishers();
             //Set variables
             $book_name = strtolower(Input::get('book_name'));
             $publisher = strtolower(Input::get('publisher_name'));
             //If publisher already exists, get the id of that publisher from the comicdb_publishers table
             $publisherExists = $publishers->where('publisher_name', $publisher)->select('id')->first();
             if (isset($publisherExists->id)) {
                 $publisher_id = $publisherExists->id;
             } else {
                 $publisher_id = $publishers->insertGetId(array('publisher_name' => $publisher));
             }
             //Update comic series
             $update_comic = $comic->findOrFail($book_id->id);
             $update_comic->book_name = $book_name;
             $update_comic->book_description = Input::get('book_description');
             $update_comic->publisher_id_FK = $publisher_id;
             $update_comic->save();
             //Delete then reinsert all the values because that way is easier.
             DB::table('comicdb_genrebook')->where('book_id_FK', $update_comic->id)->delete();
             foreach (Input::get('genres') as $key => $genre) {
                 DB::table('comicdb_genrebook')->insert(array('book_id_FK' => $update_comic->id, 'genre_id_FK' => $genre));
             }
             //Add issue character information into the comicdb_character table and keys into the comicdb_characterbook table
             DB::table('comicdb_characterbook')->where('book_id_FK', $update_comic->id)->delete();
             foreach (Input::get('characters') as $key => $character) {
                 $character_id = Characters::insertGetId(array('character_name' => $character));
                 DB::table('comicdb_characterbook')->insert(array('book_id_FK' => $update_comic->id, 'character_id_FK' => $character_id));
             }
             return Redirect::to('browse')->with('postMsg', 'The book has been updated!');
         } else {
             return Redirect::to('content.series.edit')->with('postMsg', 'Whoops! Looks like you got some errors.')->withErrors($validator)->withInput();
         }
     } else {
         return Redirect::to('content.series.edit')->with('postMsg', 'That book does not exist!');
     }
 }
示例#4
0
 public function getAdmin()
 {
     //Get info
     $data['users'] = User::paginate(5);
     $data['recent_books'] = Comicbooks::select('book_name', 'updated_at')->orderBy('updated_at', 'desc')->paginate(3);
     $data['user_count'] = User::where('id', '>', 0)->count();
     $data['publisher_count'] = Publishers::where('id', '>', 0)->count();
     $data['books_count'] = Comicbooks::where('id', '>', 0)->count();
     $data['issue_count'] = Comicissues::where('issue_id', '>', 0)->where('book_id', '>', 0)->count();
     $data['artist_count'] = Artists::count();
     $data['author_count'] = Authors::count();
     $data['books_created'] = Comicbooks::select(DB::raw('count(*) as count'), 'created_at')->groupby(DB::raw('date_format(created_at, "%b %Y")'))->orderby('created_at', 'asc')->get();
     $data['issues_created'] = Comicissues::select(DB::raw('count(*) as count'), 'created_at')->groupby(DB::raw('date_format(created_at, "%b %Y")'))->orderby('created_at', 'asc')->get();
     //Check if there are any comicbook series
     if (count($data['books_created']) > 0) {
         //Get the count of books per the month/year then return the json encoded string
         foreach ($data['books_created'] as $created) {
             $created_books[] = $created->count;
             $created_books_date[] = date_format($created->created_at, "M Y");
         }
         $data['created_books'] = json_encode($created_books);
     }
     //Check if there are any comicbook issue
     if (count($data['issues_created']) > 0) {
         //Get the count of issues per the month/year then return the json encoded string
         foreach ($data['issues_created'] as $created) {
             $created_issues[] = $created->count;
             $created_issues_date[] = date_format($created->created_at, "M Y");
         }
         $data['created_issues'] = json_encode($created_issues);
     }
     //Merge dates from comicbook series and issues created then return the json encoded string
     $data['created_dates'] = json_encode(array_unique(array_merge($created_issues_date, $created_books_date)));
     $this->layout->content = View::make('admin.index', $data);
 }
示例#5
0
文件: index.php 项目: BidTorrent/api
require 'users.php';
require 'stats.php';
require 'csv.php';
define("USER_ID_CACHE_DURATION", 450);
if (!file_exists('config/config.php')) {
    die('config/config.php is not found');
}
$config = array();
include_once "config/config.php";
$app = new \Slim\Slim();
$app->config('debug', $config['debug']);
$db = new RedMap\Drivers\MySQLiDriver('UTF8');
$db->connect($config['db_user'], $config['db_password'], $config['db_name']);
$users = new Users($db);
$bidders = new Bidders($db, $users);
$publishers = new Publishers($db, $users);
$stats = new Stats($db);
$gitkitClient = Gitkit_Client::createFromFile('config/gitkit-server-config.json');
$app->get('/bidders/', function () use($app, $bidders) {
    $uiFormat = $app->request()->get('format') === 'ui';
    if (!$uiFormat) {
        $app->expires('+3 hour');
    }
    displayResultJson($app, $bidders->getAll($app, $uiFormat));
});
$app->get('/bidders/:id', function ($id) use($app, $bidders) {
    $uiFormat = $app->request()->get('format') === 'ui';
    if (!$uiFormat) {
        $app->expires('+3 hour');
    }
    displayResultJson($app, $bidders->get($app, $id, $uiFormat));
示例#6
0
 /**
  * Set publisher detail to view.
  * @param $publisher_id
  * @param $view
  * @exception Exception
  */
 protected static function _setPublisherDataToView($publisher_id, $view)
 {
     if (empty($publisher_id)) {
         throw new Exception('[TemplatingManager][setPublisherDataToView] :Can not get publisher info for publisher[publisher id = ' . $publisher_id . ']');
     }
     $publishersTable = new Publishers();
     $publisher = $publishersTable->getPublisherByPublisherId($publisher_id);
     if (empty($publisher)) {
         throw new Exception('[TemplatingManager][setPublisherDataToView] :Can not get pubisher info for publisher[publisher id = ' . $publisher_id . ']');
     }
     foreach ($publisher->toArray() as $key => $value) {
         $keyname = 'publisher_' . $key;
         $view->{$keyname} = $value;
         //echo $keyname . "\n";
     }
     return $view;
 }