public function actionRemove($b_id) { Yii::app()->db->createCommand()->delete('lt_books_authors', 'book_id=' . $b_id); //removing records from link table Books::model()->deleteByPk($b_id); $this->actionIndex(); }
public function actionIndex() { $book_model = Books::model(); $authors_model = Authors::model(); $params = array('book_model' => $book_model, 'authors_model' => $authors_model); $this->render('report', $params); }
private function getBooksFromFiltr($arg) { //прием аргументов фильтрации, снова повторюсь сори что без валидации $authors = $arg['authors']; $genre = $arg['genre']; $from_year = $arg['from_year']; $to_year = $arg['to_year']; //все индификаторы книг что прошли фильтр по автору и по жанрам $book_author = BookAuthor::model()->with('books')->findAllByAttributes($authors); $book_gerne = BookGenre::model()->with('books')->findAllByAttributes($genre); foreach ($book_author as $class) { $flag[$class->bid] = true; //методом флажок - выясню есть ли в другом масиве теже bid } foreach ($book_gerne as $class) { if ($flag[$class->bid]) { $bids[] = $class->bid; } //если была создана ячека флажка, то значит что первый фильтр bid прошел } //выборка всех книг по фильтрованым индификаторам $books = Books::model()->findAllByAttributes(array('bid' => $bids), 'year>=' . $from_year . ' AND year<=' . $to_year); //хочу свормировать красивый масив без ячеек, которые сотворил yii $result = array(); $i = 0; foreach ($books as $book) { $result[$i]['authors'] = $this->getAuthorsFromBid($book->bid); $result[$i]['genres'] = $this->getGenresFromBid($book->bid); $result[$i]['book']['bid'] = $book->bid; $result[$i]['book']['name'] = $book->name; $result[$i]['book']['year'] = $book->year; $i = $i + 1; } return $result; }
public function actionSearch() { $model = Books::model(); $params = array('result' => $model->searchPhrase($_POST['search_field'])); $this->render('search', $params); //echo '<pre>'; print_r($_POST); echo'</pre>'; }
public function actionAbout($id) { $book = Books::model()->findByPk($id); if (!empty($book)) { $comments = BooksComments::model()->findAll(array('condition' => 'book_id = :bookId', 'params' => array(':bookId' => $book->id), 'order' => 'id DESC', 'limit' => '10')); $this->render('about', array('book' => $book, 'comments' => $comments)); } else { $this->redirect(array('index/index')); } }
public function loadModel($id = null, $new = false) { if ($this->_book === null) { if ($new) { return $this->_book = new Books(); } $this->_book = Books::model()->findByPk($_GET['id']); if ($this->_book === null) { throw new CHttpException(404, 'Sorry! There is no such book.'); } } return $this->_book; }
/** * @property Books $book */ public static function setBookRate($id, $percent) { $percent = $percent > 100 ? 100 : $percent < 0 ? 0 : $percent; $rate = self::model()->findByAttributes(array('book_id' => $id, 'user_id' => Yii::app()->user->id)); if (empty($rate)) { $rate = new BookRate(); $rate->book_id = $id; $rate->user_id = Yii::app()->user->id; } $rate->rate = $percent; $rate->save(); $book = Books::model()->findByPk($id); if (!empty($book)) { $book->updateRate(); } return $book->rate; }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Books the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Books::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionIndex() { $books = Books::model()->findAll(array('order' => 'RAND()', 'limit' => 10)); $this->render("index", array('books' => $books)); }
public function detailBook($book_id) { $data = Books::model()->findByAttributes(array('id' => $book_id)); return $data; }
public function actionUpdateLibraryData($id) { $params = $_POST['ReadersBooksRelation']; $book_id = $_POST['books_list']; $params['book_id'] = $book_id; $params['reader_id'] = $_POST['reader_list']; $model = new ReadersBooksRelation(); $last_count = ($res = $model->getDataRelationById($id)) ? (int) $params['count_books'] - (int) $res->count_books : $params['count_books']; $free_book = Books::model()->isFreeBook($book_id, $last_count); $message = ''; $color = ''; if (!$free_book) { $message = 'Все экземпляры книги находятся у читателей!!!'; $color = TbHtml::ALERT_COLOR_WARNING; } else { $model->deleteByPk($id); $model->attributes = $params; if ($model->validate()) { if ($model->save()) { $message = 'Обновление Прошло успешно'; $color = TbHtml::ALERT_COLOR_SUCCESS; } } } Yii::app()->user->setFlash($color, $message); $this->redirect(array('library/tabs&tab_id=library')); }
public function actionSearch() { $request = Yii::app()->request; try { $query = $request->getQuery('query'); $limit = $request->getQuery('limit'); $offset = $request->getQuery('offset'); $data = Books::model()->searchBooks($query, $limit, $offset); ResponseHelper::JsonReturnSuccess($data, "Success"); } catch (Exception $ex) { var_dump($ex->getMessage()); } }