Ejemplo n.º 1
0
 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!";
         }
     }
 }
Ejemplo n.º 2
0
 public static function editBook($data, $id)
 {
     $book = Book::find($id);
     if ($data['title'] != '') {
         $book->title = $data['title'];
     }
     if ($data['isbn10'] != '') {
         $book->isbn10 = $data['isbn10'];
     }
     $author = new Author();
     $genre = new Genre();
     $author->name = $data['author'];
     $genre->name = $data['genre'];
     $authorToRemove = Author::find($data['authors']);
     $genreToRemove = Genre::find($data['genres']);
     $exisitngAuthor = Author::find($data['existing-author']);
     $exisitngGenre = Genre::find($data['existing-genre']);
     $book->authors()->detach($authorToRemove['author_id']);
     $book->genres()->detach($genreToRemove['genre_id']);
     $book->authors()->attach($exisitngAuthor['author_id']);
     $book->genres()->attach($exisitngGenre['genre_id']);
     if ($data['author'] != '') {
         $book->authors()->save($author);
         var_dump($data['author']);
     }
     if ($data['genre'] != '') {
         $book->genres()->save($genre);
     }
     $book->save();
 }
Ejemplo n.º 3
0
 public function editAuthor($request, $response, $params)
 {
     $author = Author::find((int) $params['author_id']);
     if (!$author) {
         $uri = $request->getUri()->withQuery('')->withPath($this->router->pathFor('list-authors'));
         return $response->withRedirect((string) $uri);
     }
     $errors = null;
     if ($request->isPost()) {
         if ($request->getAttribute('csrf_status') === false) {
             $errors['form'] = 'CSRF failure';
         } else {
             $data = $request->getParsedBody();
             $validator = $author->getValidator($data);
             if ($validator->validate()) {
                 $author->update($data);
                 $this->flash->addMessage('message', 'Author updated');
                 $uri = $request->getUri()->withQuery('')->withPath($this->router->pathFor('author', ['author_id' => $author->id]));
                 return $response->withRedirect((string) $uri);
             } else {
                 $errors = $validator->errors();
             }
         }
     }
     return $this->view->render($response, 'author/edit.twig', ['author' => $author, 'errors' => $errors, 'csrf' => ['name' => $request->getAttribute('csrf_name'), 'value' => $request->getAttribute('csrf_value')]]);
 }
Ejemplo n.º 4
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     $application = Application::find($id);
     $author = Author::find($id);
     $applications = Application::all();
     $authors = Author::all();
     $versions = [1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0];
     return view('application.edit', compact('application', 'author', 'applications', 'authors', 'versions'));
 }
Ejemplo n.º 5
0
 public function saveBook(Request $request)
 {
     if ($request->book_id != "") {
         $book = Book::find($request->book_id);
         $book->title = $request->title;
         $book->genre_id = $request->genre_id;
         $book->author_id = $request->author_id;
         $book->publisher_id = $request->publisher_id;
         $book->image = $request->image;
         $book->isbn = $request->isbn;
         $book->description_short = $request->description_short;
         $book->description = $request->description;
         $book->price = $request->price;
         $book->sale = $request->sale;
         $book->quantity = $request->quantity;
         $check = $book->save();
         if ($check) {
             return "EDIT_SUCCEED";
         } else {
             return "Có lỗi xảy ra. Vui lòng thử lại sau!";
         }
     } else {
         $book = new Book();
         $book->title = $request->title;
         $book->genre_id = $request->genre_id;
         $book->author_id = $request->author_id;
         $book->publisher_id = $request->publisher_id;
         $book->image = $request->image;
         $book->isbn = $request->isbn;
         $book->description_short = $request->description_short;
         $book->description = $request->description;
         $book->price = $request->price;
         $book->sale = $request->sale;
         $book->quantity = $request->quantity;
         $check = $book->save();
         if ($check) {
             $genre_name = Genre::find($request->genre_id)->name;
             $author_name = Author::find($request->author_id)->name;
             $data = array('msg' => 'ADD_SUCCEED', 'book_id' => $book->id, 'genre_name' => $genre_name, 'author_name' => $author_name);
             return $data;
         } else {
             return "Có lỗi xảy ra. Vui lòng thử lại sau!";
         }
     }
 }
Ejemplo n.º 6
0
 public function storeNewAuthor(Request $request)
 {
     $author = new Author();
     $id = $author->create($request->all())->id;
     if ($request->hasFile('img')) {
         $extension = $request->file('img')->getClientOriginalExtension();
         $days = date("Ymd");
         $secs = date("His", strtotime('+1 hour'));
         $imgName = "author_id_" . $id . "_" . $days . "_" . $secs . "." . $extension;
         $path = public_path() . '/upload/authors';
         $image = $request->file('img');
         $request->file('img')->move($path, $imgName);
         $image = Author::find($id);
         $image->image = $imgName;
         $image->save();
     }
     return redirect('/administration/author/showAllAuthors');
 }
Ejemplo n.º 7
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $author = \App\Author::find($id);
     if ($author) {
         $rules = \App\Author::$rules;
         //$rules['name'] = 'required|min:2';
         $validator = \Validator::make(\Input::all(), $rules);
         if ($validator->passes()) {
             $author = \App\Author::find($id);
             $author->name = \Input::get('name');
             $author->save();
             flash('Author updated.');
             return \Redirect::back();
         }
         return \Redirect::back()->withInput()->withErrors($validator);
     }
     flash()->error('Author does not exist.');
     return \Redirect::back();
 }
Ejemplo n.º 8
0
 /**
  * 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);
     }
 }
Ejemplo n.º 9
0
 public static function editAuthor($data, $id)
 {
     $author = Author::find($id);
     $author->name = $data['name'];
     $author->save();
 }
Ejemplo n.º 10
0
                        @endif
                        <td class="inbox-small-cells"><a href="#">
                                
                                
                                <i class="fa fa-star inbox-started"></i>
                            
                            
                            </a>
                            
                            
                            
                            &nbsp;&nbsp;&nbsp;
                        <?php 
$message_id = $inbox->message_id;
$sender = Author::find($message_id)->mail_author;
$fname = Member::find($sender)->first_name;
$lname = Member::find($sender)->last_name;
?>
                        {{$fname}}
                        
                        </td>
                        <td class="view-message  dont-show">{{$inbox->message->subject}}</td>
                        <td class="view-message ">{{HelperController::convertTimeWithAMPM($inbox->created_at)}}</td>
                        <td class="view-message  text-right">
                            <a data-toggle="modal" href="{{action('MailController@read',$inbox->message->id)}}" class="btn btn-sm btn-send">Read</a>   
                        </td>
                    </tr>
                    
                   
                    
Ejemplo n.º 11
0
 public function author()
 {
     if (Request::ajax()) {
         $data = Request::get('data');
         $sort = Request::get('sort');
         $list = Request::get('list');
         switch ($data) {
             case 'pp':
                 $author = Author::find($list);
                 $author_book = Book::where('author_id', $list)->get();
                 return view('front.partials.list_item_pp_author', ['data' => $author, 'author_book' => $author_book]);
             case 'word':
                 $author = Author::where('name', 'LIKE', $list . '%');
                 return view('front.partials.list_item_word', ['data' => $author->paginate(9), 'word' => $list]);
             default:
                 $authors = DB::table('Authors');
                 $author = HomeController::sort($authors, $sort);
                 return view('front.partials.list_item_all', ['data' => $author->paginate(9)]);
         }
     }
     $author_list = Author::orderBy('name', 'ASC')->paginate(9);
     $author_word = Author::select(DB::raw('substr(name,1,1) as alpha'))->groupBy(DB::raw('substr(name,1,1)'))->get();
     return view('front.tacgia', ['author_word' => $author_word, 'data' => $author_list, 'name_page' => 'Tác giả', 'table_name' => 'Authors']);
 }
Ejemplo n.º 12
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $author = Author::find($id);
     $author->delete();
     return Redirect('/authors');
 }