public function saveAuthor(Request $request)
 {
     if ($request->author_id != "") {
         $author = Author::find($request->author_id);
         $author->name = $request->name;
         $author->profile = $request->profile;
         $check = $author->save();
         if ($check) {
             return "EDIT_SUCCEED";
         } else {
             return "Có lỗi xảy ra. Vui lòng thử lại sau!";
         }
     } else {
         $author = new Author();
         $author->name = $request->name;
         $author->country = $request->country;
         $author->profile = $request->profile;
         $check = $author->save();
         if ($check) {
             $data = array('msg' => 'ADD_SUCCEED', 'author_id' => $author->id);
             return $data;
         } else {
             return "Có lỗi xảy ra. Vui lòng thử lại sau!";
         }
     }
 }
Exemple #2
0
 private function saveAuthor($payload)
 {
     $author = new Author();
     $author->feed = $payload['feed'];
     $author->save();
     return $author;
 }
 /**
  * Show the form for creating a new resource.
  *
  * @return Response
  */
 public function postCreate(Request $request)
 {
     // name of the file
     if ($request->file('image')) {
         $filename = $request->file('image')->getClientOriginalName() . '_' . time();
     } else {
         $filename = "";
     }
     //
     $author = new Author();
     $author->name = $request->input('name');
     $author->email = $request->input('email');
     $author->bio = $request->input('bio');
     $author->facebook = $request->input('facebook');
     $author->google = $request->input('google');
     $author->twitter = $request->input('twitter');
     $author->website = $request->input('website');
     $author->image = $filename;
     $author->save();
     // destination where the image will be moved
     $destination = public_path() . '/uploads/authors/' . $author->id;
     // moving the files
     if ($request->file('image')) {
         $request->file('image')->move($destination, $filename);
     }
     return redirect('/admin/authors');
 }
Exemple #4
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function compose(Request $request)
 {
     //it will compose and save message in message collection.
     $message = new Message();
     $toMany = $request->messageTo;
     $message->subject = $request->subject;
     $message->message = $request->message;
     $message->save();
     //create inbox for each receiver of message
     foreach ($toMany as $to) {
         $inbox = new Inbox();
         $inbox->member_id = $to;
         $inbox->message()->associate($message);
         $inbox->save();
     }
     //create new author
     $author = new Author();
     $author_id = Auth::id();
     $author->mail_author = $author_id;
     $author->message()->associate($message);
     $author->save();
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $data = Request::all();
     $rules = ['authorcode' => 'required|numeric', 'authorfname' => 'required|alpha', 'authorlname' => 'required|alpha', 'authormname' => 'alpha'];
     $message = ['authorcode.required' => 'Author Code should not be empty.', 'authorcode.numeric' => 'Author Code may contain numbers only.', 'authorfname.required' => 'First Name should not be empty.', 'authorfname.alpha' => 'First Name may contain letters only.', 'authorlname.required' => 'Last Name should not be empty.', 'authorlname.alpha' => 'Last Name may contain letters only.', 'authormname.alpha' => 'Middle initial may contain letters only.'];
     $validation = Validator::make($data, $rules, $message);
     if ($validation->passes()) {
         if (Author::find($data['authorcode'])) {
             return back()->withInput();
         } else {
             $author = new Author();
             $author->authorcode = $data['authorcode'];
             $author->authorfname = $data['authorfname'];
             $author->authormname = $data['authormname'];
             $author->authorlname = $data['authorlname'];
             $author->authororder = $data['authororder'];
             $author->authortitle = $data['authortitle'];
             $author->save();
             return Redirect::to('/index');
         }
     } else {
         return Redirect::back()->withInput()->withErrors($validation);
     }
 }
Exemple #6
0
 public function addbooks()
 {
     header('Content-Type: text/html; charset=utf-8');
     for ($i = 0; $i <= 10; $i++) {
         $user = new User();
         $user->name = $this->generateRandomString(5);
         $user->password = bcrypt($user->name);
         $user->email = $user->name . '@gmail.com';
         $user->save();
     }
     $names = ['%22feliz%20gouveia%22', '%22nuno%20ribeiro%22', '%22jose%20torres%22', '%22borges%20gouveia%22', '%22Sophia%20breyner%22', '%22Fernando%20Pessoa%22', '%22Eça%20De%20Queiros%22'];
     foreach ($names as $name) {
         $content = file_get_contents('https://www.googleapis.com/books/v1/volumes?q=' . $name);
         $content = json_decode($content, true);
         $auts = Author::all('name');
         $authors = array();
         foreach ($auts as $aut) {
             $authors[] = $aut['name'];
         }
         $pubs = Publisher::all('publisher');
         $publishers = array();
         foreach ($pubs as $pub) {
             $publishers[] = $pub['publisher'];
         }
         $cats = Collection::all('collection');
         $categories = array();
         foreach ($cats as $cat) {
             $categories[] = $cat['collection'];
         }
         foreach ($content['items'] as $data) {
             $data = $data['volumeInfo'];
             $book = new Book();
             if (isset($data['title'])) {
                 $book->title = $data['title'];
             }
             if (isset($data['subtitle'])) {
                 $book->subtitle = $data['subtitle'];
             }
             if (isset($data['publishedDate'])) {
                 $book->publishedDate = $data['publishedDate'];
             }
             if (isset($data['description'])) {
                 $book->description = $data['description'];
             }
             if (isset($data['pageCount'])) {
                 $book->pages = $data['pageCount'];
             }
             if (isset($data['language'])) {
                 $book->language = $data['language'];
             }
             if (isset($data['industryIdentifiers'])) {
                 foreach ($data['industryIdentifiers'] as $value) {
                     if ($value['type'] == 'ISBN_13') {
                         $book->isbn13 = $value['identifier'];
                     }
                     if ($value['type'] == 'ISBN_10') {
                         $book->isbn10 = $value['identifier'];
                     }
                 }
             }
             if (isset($data['publisher'])) {
                 if (!in_array($data['publisher'], $publishers)) {
                     $publishers[] = $data['publisher'];
                     $publisher = new Publisher();
                     $publisher->publisher = $data['publisher'];
                     $publisher->save();
                     $publisher_id = $publisher->id;
                 } else {
                     $publisher = Publisher::where('publisher', '=', $data['publisher'])->limit(1)->get();
                     $publisher_id = $publisher[0]->id;
                 }
             }
             if (isset($data['imageLinks']['thumbnail'])) {
                 $book->cover = file_get_contents($data['imageLinks']['thumbnail']);
             }
             $book->price_day = random_int(0, 15);
             $book->price_bail = random_int(10, 50);
             $book->price_sale = random_int(10, 79);
             $books[] = $book;
             $book->id_publisher = $publisher_id;
             $book->id_user = rand(1, 10);
             $book->save();
             $book_id = $book->id;
             if (isset($data['categories'])) {
                 foreach ($data['categories'] as $value) {
                     if (!in_array($value, $categories)) {
                         $categories[] = $value;
                         $category = new Collection();
                         $category->collection = $value;
                         $category->save();
                         $category_id = $category->id;
                         $collections = new Book_Collection();
                         $collections->book_id = $book_id;
                         $collections->collection_id = $category_id;
                         $collections->save();
                     } else {
                         $category = Collection::where('collection', '=', $value)->limit(1)->get();
                         $collections = new Book_Collection();
                         $collections->book_id = $book_id;
                         $collections->collection_id = $category[0]->id;
                         $collections->save();
                     }
                 }
             }
             if (isset($data['authors'])) {
                 foreach ($data['authors'] as $value) {
                     if (!in_array($value, $authors)) {
                         $authors[] = $value;
                         $author = new Author();
                         $author->name = $value;
                         $author->save();
                         $author_id = $author->id;
                         $author_book = new Author_Book();
                         $author_book->book_id = $book_id;
                         $author_book->author_id = $author_id;
                         $author_book->save();
                     } else {
                         $author = Author::where('name', 'like', $value)->limit(1)->get();
                         $author_book = new Author_Book();
                         $author_book->book_id = $book_id;
                         $author_book->author_id = $author[0]->id;
                         $author_book->save();
                     }
                 }
             }
             # code...
         }
     }
 }
Exemple #7
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function edit()
 {
     $user_id = Auth::user()->id;
     $data = INPUT::all();
     $rules = $this->rules();
     $messages = $this->messages();
     $validator = Validator::make($data, $rules, $messages);
     if (!$validator->fails()) {
         $book = Book::find($data['id']);
         $book->title = $data['title'];
         $book->subtitle = $data['subtitle'];
         $book->publishedDate = $data['publishedDate'];
         $book->description = $data['description'];
         $book->pages = $data['pages'];
         $book->isbn10 = $data['isbn10'];
         $book->isbn13 = $data['isbn13'];
         $book->price_day = $data['price_day'];
         $book->price_bail = $data['price_bail'];
         $book->price_sale = $data['price_sale'];
         $book->language = $data['language'];
         if ($data['publisher'] != $book->id_publisher) {
             if ($data['publisher'] != '0') {
                 $book->id_publisher = $data['publisher'];
             } else {
                 $publisher = new Publisher();
                 $publisher->publisher = $data['newpublisher'];
                 $publisher->save();
                 $book->id_publisher = $publisher->id;
             }
         }
         if (isset($data['cover'])) {
             $book->cover = file_get_contents($data['cover']);
         }
         $book_id = $book->id;
         Book_Collection::where('book_id', $book_id)->delete();
         Author_Book::where('book_id', $book_id)->delete();
         $book_collection = new Book_Collection();
         $book_collection->book_id = $book_id;
         $book_collection->collection_id = $data['collection'];
         $authors = explode(',', $data['authors']);
         foreach ($authors as $author) {
             $tmp = Author::where('name', 'like', $author)->limit(1)->get();
             if (count($tmp) > 0) {
                 $author_book = new Author_Book();
                 $author_book->book_id = $book_id;
                 $author_book->author_id = $tmp[0]->id;
                 $author_book->save();
             } else {
                 $newAuthor = new Author();
                 $newAuthor->name = $author;
                 $newAuthor->save();
                 $author_id = $newAuthor->id;
                 $author_book = new Author_Book();
                 $author_book->book_id = $book_id;
                 $author_book->author_id = $author_id;
                 $author_book->save();
             }
         }
         $book->save();
         return redirect('book/edit/' . $book_id . '');
     }
     return back()->withInput($data)->withErrors($validator);
 }
Exemple #8
0
 public static function saveAuthor($data)
 {
     $author = new Author();
     $author->name = $data['name'];
     $author->save();
 }