public function review(Request $request, $id)
 {
     $validation = Validator::make($request->all(), ['rating' => 'required|between:1,10', 'title' => 'required|min:5', 'description' => 'required|min:5']);
     if ($validation->fails()) {
         return redirect('dvds/' . $id)->withInput()->withErrors($validation);
     }
     $review = new Review(['rating' => $request->input('rating'), 'title' => $request->input('title'), 'description' => $request->input('description'), 'dvd_id' => $id]);
     $review->save();
     return redirect('dvds/' . $id)->with('success', true);
 }
Пример #2
0
 public function actionCreate()
 {
     $model = new Review();
     if (isset($_POST['Review'])) {
         $model->attributes = $_POST['Review'];
         if ($model->validate() && $model->save()) {
             $this->redirect(array('index'));
         }
     }
     $statuses = array(0 => Yii::t('common', 'Disabled'), 1 => Yii::t('common', 'Enabled'));
     $this->render('create', array('model' => $model, 'statuses' => $statuses));
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Review();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Review'])) {
         $model->attributes = $_POST['Review'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Пример #4
0
 /**
  * 录入
  *
  */
 public function actionCreate()
 {
     parent::_acl();
     $model = new Review();
     if (isset($_POST['Review'])) {
         $acl = $this->_gets->getPost('acl');
         $model->attributes = $_POST['Review'];
         if ($model->save()) {
             AdminLogger::_create(array('catalog' => 'create', 'intro' => '录入内容,ID:' . $model->id));
             $this->redirect(array('index'));
         }
     }
     $this->render('review_create', array('model' => $model));
 }
Пример #5
0
 public function grabber(array $directory_user)
 {
     log_message('TASK_DEBUG', __FUNCTION__ . ' > ' . 'Reviews grabber');
     try {
         $directoryUser = new Directory_User($directory_user['id']);
         if (!$directoryUser->exists()) {
             throw new Exception('Directory_User id:' . $directory_user['id'] . ' doesn\'t exist');
         }
         $directory = $directoryUser->directory->get();
         if (!$directory->exists()) {
             throw new Exception('Directory id:' . $directory_user['directory_id'] . ' doesn\'t exist');
         }
         if (!$directory->status) {
             throw new Exception('Directory id:' . $directory_user['directory_id'] . ' is disabled');
         }
         $link = !empty($directory_user['additional']) ? $directory_user['additional'] : $directory_user['link'];
         log_message('TASK_DEBUG', __FUNCTION__ . ' > ' . 'Try to grabb - ' . $directory->name);
         $aac = $this->getAAC();
         $user = new User($directory_user['user_id']);
         if (!$user->exists()) {
             return;
         }
         $aac->setUser($user);
         $directory_parcer = Directory_Parser::factory($directory->type)->set_url($link);
         $reviews = $directory_parcer->get_reviews();
         /**
          * Store additional data to
          */
         if ($directory_parcer instanceof Directory_Interface_UserStorage) {
             $directoryUser->setAdditional($directory_parcer->getDataToStore())->save();
         }
     } catch (Exception $e) {
         log_message('TASK_ERROR', __FUNCTION__ . ' > ' . 'Reviews: ' . $e->getMessage());
         throw $e;
     }
     //$today_midnight = strtotime('-7 day midnight');
     $today_midnight = strtotime('-14 day midnight');
     if (is_array($reviews) && !empty($reviews)) {
         foreach ($reviews as $_review) {
             $review_model = new Review();
             $review_model->from_array($_review);
             $review_model->user_id = $directory_user['user_id'];
             $review_model->directory_id = $directory_user['directory_id'];
             $review_model->profile_id = $directory_user['profile_id'];
             $review_model->posted_date = date('Y-m-d', $_review['posted']);
             $review_model->save();
             log_message('TASK_DEBUG', __FUNCTION__ . ' > ' . 'Review saved');
         }
     }
 }
Пример #6
0
 function test_getAll()
 {
     //Arrange
     $review = "Pizza was dope";
     $restaurant_id = 1;
     $test_review = new Review($review, $restaurant_id);
     $test_review->save();
     $review2 = "DAMN DAT GRILLED CHEESE IS FIRE";
     $restaurant_id2 = 2;
     $test_review2 = new Review($review2, $restaurant_id2);
     $test_review2->save();
     //Act
     $result = Review::getAll();
     //Assert
     $this->assertEquals([$test_review, $test_review2], $result);
 }
Пример #7
0
 public function actionAdd()
 {
     $model = new Review();
     $model->unsetAttributes();
     $model->user_id = $this->user->id;
     $model->date = time();
     if (isset($_POST['Review'])) {
         $model->attributes = $_POST['Review'];
         if ($model->save()) {
             Yii::app()->user->setFlash('success', '新加评价成功');
             $this->redirect(array('/board/review/index'));
         }
     }
     $model->formatDate();
     $this->render('edit', array('model' => $model));
 }
 function render_for_post()
 {
     if (empty(PA::$login_user)) {
         return __("Login required");
     }
     $rev = new Review();
     $rev->author_id = PA::$login_user->user_id;
     $rev->subject_type = $this->params["subject_type"];
     $rev->subject_id = $this->params["subject_id"];
     //TODO: validate subject_type and subject_id
     $rev->title = $this->params["title"];
     $rev->body = $this->params["body"];
     //TODO: ensure html is stripped properly
     $rev->save();
     return $this->render();
 }
Пример #9
0
 /**
  * Display a listing of destinos
  *
  * @return Response
  */
 public function postIndex()
 {
     $input = Input::all();
     if (!empty($input)) {
         $review = new Review();
         $review->cliente_id = Auth::user()->id;
         $review->produto_id = $input['produto_id'];
         $review->titulo = $input['review-titulo'];
         $review->texto = $input['review-texto'];
         $review->nota = $input['review-nota'];
         $review->save();
         return Redirect::back()->with('success', array('Sua avaliação foi enviada e em breve sera analisada.'));
     } else {
         return Redirect::back()->with('danger', array('preencha todos os campos da avaliação.'));
     }
 }
Пример #10
0
 public function actionView($id)
 {
     $teacher = $this->loadModel($id);
     $this->_seoTitle = '名师 - ' . $teacher->name;
     $userId = $this->_cookiesGet('userId');
     $userType = $this->_cookiesGet('userType');
     $reviewModel = new Review();
     if ($userType === 'student' and isset($_POST['Review'])) {
         $reviewModel->attributes = $_POST['Review'];
         $reviewModel->teacher_id = $id;
         $reviewModel->student_id = $userId;
         $reviewModel->ctime = time();
         if ($reviewModel->validate() and $reviewModel->save()) {
             Yii::app()->user->setFlash('success', '保存成功');
         }
     }
     $criteria = new CDbCriteria();
     $books = Book::model()->findAllByAttributes(array('teacher_id' => $id));
     $lessons = array();
     $reviews = array();
     $list = yii::app()->request->getParam('list');
     if ($list === null or $list === 'lesson') {
         $model = Lesson::model();
         $count = $model->count($criteria->addCondition("teacher_id = {$id}"));
         $pager = new CPagination($count);
         $pager->pageSize = 4;
         $pager->applyLimit($criteria);
         $lessons = $model->findAll($criteria);
     } else {
         $model = Review::model();
         $count = $model->count($criteria->addCondition("teacher_id = {$id}"));
         $pager = new CPagination($count);
         $pager->pageSize = 4;
         $pager->applyLimit($criteria);
         $reviews = Yii::app()->db->createCommand()->select('s.*, r.contents, r.ctime')->from('seed_review r')->leftjoin('seed_student s', 's.id=r.student_id')->where('r.teacher_id=:teacher_id', array(':teacher_id' => $id))->order('ctime desc')->limit(4, $pager->currentPage * $pager->pageSize)->queryAll();
     }
     //判断学员已关注老师
     if ($userType === 'student') {
         $is_focus = StudentTeacher::model()->findByAttributes(array('student_id' => $userId, 'teacher_id' => $id));
     }
     $this->render('view', array('is_focus' => $is_focus, 'teacher' => $teacher, 'lessons' => $lessons, 'reviews' => $reviews, 'books' => $books, 'userType' => $userType, 'reviewModel' => $reviewModel, 'count' => $count, 'pager' => $pager, 'list' => $_GET['list']));
 }
Пример #11
0
 public function actionReplySave()
 {
     $model = new Review();
     if (isset($_POST['text'])) {
         $model->create_at = time();
         $model->content = $_POST['text'];
         $model->customer_id = Yii::app()->user->id;
         $model->entity_id = 2;
         $model->entity_pk_value = $_POST['customerId'];
         if ($model->customer_id != '') {
             if ($model->save()) {
                 return ture;
             }
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     //echo $this->loadModel($_GET['id']);
     // exit();
     //
     $model = Review::model()->findByAttributes(array('tmvdb_id' => $_GET['id']));
     //
     if ($model == null) {
         $model = new Review();
     }
     //                $model=new Review;
     //            }
     //print_r ($model);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Review'])) {
         $model->attributes = $_POST['Review'];
         if ($model->save()) {
             $this->redirect('../site/index');
         }
     }
     $this->render('create', array('model' => $model));
 }
 public function actionCreate()
 {
     $model = new Review();
     if (isset($_POST['rating1'], $_POST['product_id'])) {
         $rId = $this->addRate($_POST['rating1'], $_POST['product_id']);
     }
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['review_title'])) {
         $model->review_title = $_POST['review_title'];
         $model->review_content = $_POST['review_content'];
         $model->product_id = $_POST['product_id'];
         //echo $id; die();
         //                        $ratingIdfromSaveRating=new CHttpSession;
         //                        $ratingIdfromSaveRating->open();
         if ($rId) {
             $model->rating_id = $rId;
             // strip_tags($ratingIdfromSaveRating['rating_id']);
             $model->user_id = Yii::app()->user->user_id;
             //$model->attributes=$_POST['Review'];
             if ($model->save()) {
                 // echo var_dump($model); die();
             } else {
                 die(var_dump($model->getErrors()));
             }
             //echo 'not in'; die();
             //				$this->redirect(array('view','id'=>$model->review_id));
         }
     }
     $this->render('create', array('model' => $model, 'productId' => $model->product_id));
 }
 function test_deleteReviews()
 {
     $name = "Asian";
     $id = null;
     $test_cuisine = new Cuisine($name, $id);
     $test_cuisine->save();
     $restaurant_name = "The Golden Duck";
     $location = "898 SW 5th Ave, Portland, OR";
     $description = "A Chill Asian experince";
     $price = "\$\$";
     $cuisine_id = $test_cuisine->getId();
     $test_restaurant = new Restaurant($restaurant_name, $location, $description, $price, $cuisine_id);
     $test_restaurant->save();
     $restaurant_name2 = "The Red Dragon";
     $location2 = "899 SW 5th Ave, Portland, OR";
     $description2 = "A Intense Asian experince";
     $price2 = "\$\$\$";
     $cuisine_id2 = $test_cuisine->getId();
     $test_restaurant2 = new Restaurant($restaurant_name2, $location2, $description2, $price2, $cuisine_id2);
     $test_restaurant2->save();
     $user = "******";
     $stars = 3;
     $headline = "It is aight.";
     $body = "Yeah, pretty aight bro";
     $restaurant_id = $test_restaurant->getId();
     $test_review = new Review($user, $stars, $headline, $body, $restaurant_id);
     $test_review->save();
     $user2 = "6969babygirl";
     $stars2 = 3;
     $headline2 = "XOXO";
     $body2 = "I cant even";
     $restaurant_id2 = $test_restaurant->getId();
     $test_review2 = new Review($user2, $stars2, $headline2, $body2, $restaurant_id2);
     $test_review2->save();
     $test_restaurant->delete();
     $result = Review::getAll();
     //var_dump($result);
     $this->assertEquals([], $result);
 }
Пример #15
0
 function test_getReviews()
 {
     $unisex = 0;
     $key_required = 0;
     $public = 0;
     $handicap = 0;
     $changing_table = 0;
     $marker_id = 2;
     $test_bathroom = new Bathroom($unisex, $key_required, $public, $handicap, $changing_table, $marker_id);
     $test_bathroom->save();
     $rating = 1;
     $comment = "This place sucks!";
     $test_review = new Review($rating, $comment);
     $test_review->save();
     $rating2 = 3;
     $comment2 = "Its aight!";
     $test_review2 = new Review($rating2, $comment2);
     $test_review2->save();
     $test_bathroom->addReview($test_review->getId());
     $test_bathroom->addReview($test_review2->getId());
     $result = $test_bathroom->getReviews();
     $this->assertEquals([$test_review, $test_review2], $result);
 }
Пример #16
0
 protected function grabb($directory_user)
 {
     log_message('TASK_ERROR', __FUNCTION__ . ' > ' . 'Reviews grabber');
     try {
         $directory = new DM_Directory($directory_user['directory_id']);
         if (!$directory->exists()) {
             throw new Exception('Directory id:' . $directory_user['directory_id'] . ' doesn\'t exist');
         }
         if (!$directory->status) {
             throw new Exception('Directory id:' . $directory_user['directory_id'] . ' is disabled');
         }
         $link = !empty($directory_user['additional']) && !($directory->type == 'Foursquare') ? $directory_user['additional'] : $directory_user['link'];
         $directory_parcer = Directory_Parser::factory($directory->type)->set_url($link);
         //For fousquare only
         $directory_parcer->set_directory_user($directory_user);
         $reviews = $directory_parcer->get_reviews();
     } catch (Exception $e) {
         log_message('TASK_ERROR', __FUNCTION__ . ' > ' . 'Reviews: ' . $e->getMessage());
         throw $e;
     }
     //$today_midnight = strtotime('-7 day midnight');
     $today_midnight = strtotime('-34 day midnight');
     if (is_array($reviews) && !empty($reviews)) {
         foreach ($reviews as $_review) {
             $review_model = new Review();
             $review_model->from_array($_review);
             $review_model->user_id = $directory_user['user_id'];
             $review_model->directory_id = $directory_user['directory_id'];
             $review_model->posted_date = date('Y-m-d', $_review['posted']);
             $review_model->save();
             if (!$review_model->id) {
                 var_dump($review_model->error);
             }
             log_message('TASK_ERROR', __FUNCTION__ . ' > ' . 'Review saved');
             // notify user about new review
             if ($_review['posted'] > $today_midnight && !empty($review_model->id) && !empty($directory_user['user_id']) && !empty($directory_user['notify'])) {
                 $obj = Reviews_notification::addOne($directory_user['user_id'], $review_model->id);
                 if (!$obj->id) {
                     echo 'Error notification: ' . date('d-m-Y H:i') . ' - ' . $obj->error->string . PHP_EOL;
                 }
             }
         }
     }
 }
Пример #17
0
 function test_save()
 {
     $restaurant = new Restaurant("Pok Pok", 2, "5", "1", "website", 2);
     $name = "Bob";
     $id = null;
     $rating = 3;
     $review_text = "B";
     $review_date = "2015-10-10";
     $restaurant_id = $restaurant->getId();
     $test_Review = new Review($name, $id, $rating, $review_text, $review_date, $restaurant_id);
     $test_Review->save();
     $result = Review::getAll();
     $this->assertEquals($test_Review, $result[0]);
 }
 public static function populate($con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(BookPeer::DATABASE_NAME);
     }
     $con->beginTransaction();
     // Add publisher records
     // ---------------------
     $scholastic = new Publisher();
     $scholastic->setName("Scholastic");
     // do not save, will do later to test cascade
     $morrow = new Publisher();
     $morrow->setName("William Morrow");
     $morrow->save($con);
     $morrow_id = $morrow->getId();
     $penguin = new Publisher();
     $penguin->setName("Penguin");
     $penguin->save();
     $penguin_id = $penguin->getId();
     $vintage = new Publisher();
     $vintage->setName("Vintage");
     $vintage->save($con);
     $vintage_id = $vintage->getId();
     $rowling = new Author();
     $rowling->setFirstName("J.K.");
     $rowling->setLastName("Rowling");
     // no save()
     $stephenson = new Author();
     $stephenson->setFirstName("Neal");
     $stephenson->setLastName("Stephenson");
     $stephenson->save($con);
     $stephenson_id = $stephenson->getId();
     $byron = new Author();
     $byron->setFirstName("George");
     $byron->setLastName("Byron");
     $byron->save($con);
     $byron_id = $byron->getId();
     $grass = new Author();
     $grass->setFirstName("Gunter");
     $grass->setLastName("Grass");
     $grass->save($con);
     $grass_id = $grass->getId();
     $phoenix = new Book();
     $phoenix->setTitle("Harry Potter and the Order of the Phoenix");
     $phoenix->setISBN("043935806X");
     $phoenix->setAuthor($rowling);
     $phoenix->setPublisher($scholastic);
     $phoenix->setPrice(10.99);
     $phoenix->save($con);
     $phoenix_id = $phoenix->getId();
     $qs = new Book();
     $qs->setISBN("0380977427");
     $qs->setTitle("Quicksilver");
     $qs->setPrice(11.99);
     $qs->setAuthor($stephenson);
     $qs->setPublisher($morrow);
     $qs->save($con);
     $qs_id = $qs->getId();
     $dj = new Book();
     $dj->setISBN("0140422161");
     $dj->setTitle("Don Juan");
     $dj->setPrice(12.99);
     $dj->setAuthor($byron);
     $dj->setPublisher($penguin);
     $dj->save($con);
     $dj_id = $dj->getId();
     $td = new Book();
     $td->setISBN("067972575X");
     $td->setTitle("The Tin Drum");
     $td->setPrice(13.99);
     $td->setAuthor($grass);
     $td->setPublisher($vintage);
     $td->save($con);
     $td_id = $td->getId();
     $r1 = new Review();
     $r1->setBook($phoenix);
     $r1->setReviewedBy("Washington Post");
     $r1->setRecommended(true);
     $r1->setReviewDate(time());
     $r1->save($con);
     $r1_id = $r1->getId();
     $r2 = new Review();
     $r2->setBook($phoenix);
     $r2->setReviewedBy("New York Times");
     $r2->setRecommended(false);
     $r2->setReviewDate(time());
     $r2->save($con);
     $r2_id = $r2->getId();
     $blob_path = _LOB_SAMPLE_FILE_PATH . '/tin_drum.gif';
     $clob_path = _LOB_SAMPLE_FILE_PATH . '/tin_drum.txt';
     $m1 = new Media();
     $m1->setBook($td);
     $m1->setCoverImage(file_get_contents($blob_path));
     // CLOB is broken in PDO OCI, see http://pecl.php.net/bugs/bug.php?id=7943
     if (get_class(Propel::getDB()) != "DBOracle") {
         $m1->setExcerpt(file_get_contents($clob_path));
     }
     $m1->save($con);
     // Add book list records
     // ---------------------
     // (this is for many-to-many tests)
     $blc1 = new BookClubList();
     $blc1->setGroupLeader("Crazyleggs");
     $blc1->setTheme("Happiness");
     $brel1 = new BookListRel();
     $brel1->setBook($phoenix);
     $brel2 = new BookListRel();
     $brel2->setBook($dj);
     $blc1->addBookListRel($brel1);
     $blc1->addBookListRel($brel2);
     $blc1->save();
     $bemp1 = new BookstoreEmployee();
     $bemp1->setName("John");
     $bemp1->setJobTitle("Manager");
     $bemp2 = new BookstoreEmployee();
     $bemp2->setName("Pieter");
     $bemp2->setJobTitle("Clerk");
     $bemp2->setSupervisor($bemp1);
     $bemp2->save($con);
     $bemp3 = new BookstoreCashier();
     $bemp3->setName("Tim");
     $bemp3->setJobTitle("Cashier");
     $bemp3->save($con);
     $role = new AcctAccessRole();
     $role->setName("Admin");
     $bempacct = new BookstoreEmployeeAccount();
     $bempacct->setBookstoreEmployee($bemp1);
     $bempacct->setAcctAccessRole($role);
     $bempacct->setLogin("john");
     $bempacct->setPassword("johnp4ss");
     $bempacct->save($con);
     // Add bookstores
     $store = new Bookstore();
     $store->setStoreName("Amazon");
     $store->setPopulationServed(5000000000);
     // world population
     $store->setTotalBooks(300);
     $store->save($con);
     $store = new Bookstore();
     $store->setStoreName("Local Store");
     $store->setPopulationServed(20);
     $store->setTotalBooks(500000);
     $store->save($con);
     $summary = new BookSummary();
     $summary->setSummarizedBook($phoenix);
     $summary->setSummary("Harry Potter does some amazing magic!");
     $summary->save();
     $con->commit();
 }
Пример #19
0
 /**
  * Adds a review to this note.
  * @param Review $review    the review object
  * @param integer $studentId the reviewer id
  */
 public function addReview($review, $studentId)
 {
     $review->note_id = $this->id;
     $review->student_id = $studentId;
     $review->timestamp = date('Y-m-d H:i:s');
     return $review->save();
 }
Пример #20
0
 public function run()
 {
     DB::table('reviews')->delete();
     $faker = Faker\Factory::create();
     for ($i = 1; $i <= 10; $i++) {
         $review = new Review();
         $review->job_id = $i;
         $review->rating = rand(1, 5);
         $review->comment = $faker->sentence(50);
         $review->save();
     }
     //end of for loop
 }
Пример #21
0
 function test_getAll()
 {
     //cuisine
     $name = "Japanese";
     $id = null;
     $test_cuisine = new Cuisine($name, $id);
     $test_cuisine->save();
     //restaurant
     $name = "Good Fortune";
     $description = "very tasty.";
     $address = "1111 SW 11th Ave";
     $cuisine_id = $test_cuisine->getId();
     $test_restaurant = new Restaurant($name, $id, $cuisine_id, $description, $address);
     $test_restaurant->save();
     //review1
     $username = "******";
     $date = '0000-00-00';
     $rating = 5;
     $comment = "good one.";
     $restaurant_id = $test_restaurant->getId();
     $test_review = new Review($username, $date, $rating, $comment, $restaurant_id, $id);
     $test_review->save();
     //review2
     $username2 = "Jen";
     $date2 = '1111-00-00';
     $rating2 = 2;
     $comment2 = "Bad one.";
     $restaurant_id = $test_restaurant->getId();
     $test_review2 = new Review($username2, $date2, $rating2, $comment2, $restaurant_id, $id);
     $test_review2->save();
     $result = Review::getAll();
     $this->assertEquals([$test_review, $test_review2], $result);
 }
Пример #22
0
 function test_update()
 {
     //Arrange
     $rating = 1;
     $comment = "This place sucks!";
     $id = null;
     $test_review = new Review($rating, $comment, $id);
     $test_review->save();
     $new_comment = "This place REALLY sucks!!";
     //Act
     $test_review->updateReview($new_comment);
     //Assert
     $this->assertEquals("This place REALLY sucks!!", $test_review->getComment());
 }
Пример #23
0
 /**
  * Test the type sensitivity of the resturning columns.
  *
  */
 public function testTypeSensitive()
 {
     $book = BookPeer::doSelectOne(new Criteria());
     $r = new Review();
     $r->setReviewedBy("testTypeSensitive Tester");
     $r->setReviewDate(time());
     $r->setBook($book);
     $r->setRecommended(true);
     $r->save();
     $id = $r->getId();
     unset($r);
     // clear the instance cache to force reload from database.
     ReviewPeer::clearInstancePool();
     BookPeer::clearInstancePool();
     // reload and verify that the types are the same
     $r2 = ReviewPeer::retrieveByPK($id);
     $this->assertType('integer', $r2->getId(), "Expected getId() to return an integer.");
     $this->assertType('string', $r2->getReviewedBy(), "Expected getReviewedBy() to return a string.");
     $this->assertType('boolean', $r2->getRecommended(), "Expected getRecommended() to return a boolean.");
     $this->assertType('Book', $r2->getBook(), "Expected getBook() to return a Book.");
     $this->assertType('float', $r2->getBook()->getPrice(), "Expected Book->getPrice() to return a float.");
     $this->assertType('DateTime', $r2->getReviewDate(null), "Expected Book->getReviewDate() to return a DateTime.");
 }
Пример #24
0
 public function testSpeed()
 {
     // Add publisher records
     // ---------------------
     $scholastic = new Publisher();
     $scholastic->setName("Scholastic");
     // do not save, will do later to test cascade
     $morrow = new Publisher();
     $morrow->setName("William Morrow");
     $morrow->save();
     $morrow_id = $morrow->getId();
     $penguin = new Publisher();
     $penguin->setName("Penguin");
     $penguin->save();
     $penguin_id = $penguin->getId();
     $vintage = new Publisher();
     $vintage->setName("Vintage");
     $vintage->save();
     $vintage_id = $vintage->getId();
     // Add author records
     // ------------------
     $rowling = new Author();
     $rowling->setFirstName("J.K.");
     $rowling->setLastName("Rowling");
     // no save()
     $stephenson = new Author();
     $stephenson->setFirstName("Neal");
     $stephenson->setLastName("Stephenson");
     $stephenson->save();
     $stephenson_id = $stephenson->getId();
     $byron = new Author();
     $byron->setFirstName("George");
     $byron->setLastName("Byron");
     $byron->save();
     $byron_id = $byron->getId();
     $grass = new Author();
     $grass->setFirstName("Gunter");
     $grass->setLastName("Grass");
     $grass->save();
     $grass_id = $grass->getId();
     // Add book records
     // ----------------
     $phoenix = new Book();
     $phoenix->setTitle("Harry Potter and the Order of the Phoenix");
     $phoenix->setISBN("043935806X");
     // cascading save (Harry Potter)
     $phoenix->setAuthor($rowling);
     $phoenix->setPublisher($scholastic);
     $phoenix->save();
     $phoenix_id = $phoenix->getId();
     $qs = new Book();
     $qs->setISBN("0380977427");
     $qs->setTitle("Quicksilver");
     $qs->setAuthor($stephenson);
     $qs->setPublisher($morrow);
     $qs->save();
     $qs_id = $qs->getId();
     $dj = new Book();
     $dj->setISBN("0140422161");
     $dj->setTitle("Don Juan");
     $dj->setAuthor($byron);
     $dj->setPublisher($penguin);
     $dj->save();
     $dj_id = $qs->getId();
     $td = new Book();
     $td->setISBN("067972575X");
     $td->setTitle("The Tin Drum");
     $td->setAuthor($grass);
     $td->setPublisher($vintage);
     $td->save();
     $td_id = $td->getId();
     // Add review records
     // ------------------
     $r1 = new Review();
     $r1->setBook($phoenix);
     $r1->setReviewedBy("Washington Post");
     $r1->setRecommended(true);
     $r1->setReviewDate(time());
     $r1->save();
     $r1_id = $r1->getId();
     $r2 = new Review();
     $r2->setBook($phoenix);
     $r2->setReviewedBy("New York Times");
     $r2->setRecommended(false);
     $r2->setReviewDate(time());
     $r2->save();
     $r2_id = $r2->getId();
     // Perform a "complex" search
     // --------------------------
     $crit = new Criteria();
     $crit->add(BookPeer::TITLE, 'Harry%', Criteria::LIKE);
     $results = BookPeer::doSelect($crit);
     $crit2 = new Criteria();
     $crit2->add(BookPeer::ISBN, array("0380977427", "0140422161"), Criteria::IN);
     $results = BookPeer::doSelect($crit2);
     // Perform a "limit" search
     // ------------------------
     $crit = new Criteria();
     $crit->setLimit(2);
     $crit->setOffset(1);
     $crit->addAscendingOrderByColumn(BookPeer::TITLE);
     $results = BookPeer::doSelect($crit);
     // Perform a lookup & update!
     // --------------------------
     $qs_lookup = BookPeer::retrieveByPk($qs_id);
     $new_title = "Quicksilver (" . crc32(uniqid(rand())) . ")";
     $qs_lookup->setTitle($new_title);
     $qs_lookup->save();
     $qs_lookup2 = BookPeer::retrieveByPk($qs_id);
     // Test some basic DATE / TIME stuff
     // ---------------------------------
     // that's the control timestamp.
     $control = strtotime('2004-02-29 00:00:00');
     // should be two in the db
     $r = ReviewPeer::doSelectOne(new Criteria());
     $r_id = $r->getId();
     $r->setReviewDate($control);
     $r->save();
     $r2 = ReviewPeer::retrieveByPk($r_id);
     // Testing the DATE/TIME columns
     // -----------------------------
     // that's the control timestamp.
     $control = strtotime('2004-02-29 00:00:00');
     // should be two in the db
     $r = ReviewPeer::doSelectOne(new Criteria());
     $r_id = $r->getId();
     $r->setReviewDate($control);
     $r->save();
     $r2 = ReviewPeer::retrieveByPk($r_id);
     // Testing the column validators
     // -----------------------------
     $bk1 = new Book();
     $bk1->setTitle("12345");
     // min length is 10
     $ret = $bk1->validate();
     // Unique validator
     $bk2 = new Book();
     $bk2->setTitle("Don Juan");
     $ret = $bk2->validate();
     // Now trying some more complex validation.
     $auth1 = new Author();
     $auth1->setFirstName("Hans");
     // last name required; will fail
     $bk1->setAuthor($auth1);
     $rev1 = new Review();
     $rev1->setReviewDate("08/09/2001");
     // will fail: reviewed_by column required
     $bk1->addReview($rev1);
     $ret2 = $bk1->validate();
     $bk2 = new Book();
     $bk2->setTitle("12345678901");
     // passes
     $auth2 = new Author();
     $auth2->setLastName("Blah");
     //passes
     $auth2->setEmail("*****@*****.**");
     //passes
     $auth2->setAge(50);
     //passes
     $bk2->setAuthor($auth2);
     $rev2 = new Review();
     $rev2->setReviewedBy("Me!");
     // passes
     $rev2->setStatus("new");
     // passes
     $bk2->addReview($rev2);
     $ret3 = $bk2->validate();
     // Testing doCount() functionality
     // -------------------------------
     $c = new Criteria();
     $count = BookPeer::doCount($c);
     // Testing many-to-many relationships
     // ----------------------------------
     // init book club list 1 with 2 books
     $blc1 = new BookClubList();
     $blc1->setGroupLeader("Crazyleggs");
     $blc1->setTheme("Happiness");
     $brel1 = new BookListRel();
     $brel1->setBook($phoenix);
     $brel2 = new BookListRel();
     $brel2->setBook($dj);
     $blc1->addBookListRel($brel1);
     $blc1->addBookListRel($brel2);
     $blc1->save();
     // init book club list 2 with 1 book
     $blc2 = new BookClubList();
     $blc2->setGroupLeader("John Foo");
     $blc2->setTheme("Default");
     $brel3 = new BookListRel();
     $brel3->setBook($phoenix);
     $blc2->addBookListRel($brel3);
     $blc2->save();
     // re-fetch books and lists from db to be sure that nothing is cached
     $crit = new Criteria();
     $crit->add(BookPeer::ID, $phoenix->getId());
     $phoenix = BookPeer::doSelectOne($crit);
     $crit = new Criteria();
     $crit->add(BookClubListPeer::ID, $blc1->getId());
     $blc1 = BookClubListPeer::doSelectOne($crit);
     $crit = new Criteria();
     $crit->add(BookClubListPeer::ID, $blc2->getId());
     $blc2 = BookClubListPeer::doSelectOne($crit);
     $relCount = $phoenix->countBookListRels();
     $relCount = $blc1->countBookListRels();
     $relCount = $blc2->countBookListRels();
     // Removing books that were just created
     // -------------------------------------
     $hp = BookPeer::retrieveByPk($phoenix_id);
     $c = new Criteria();
     $c->add(BookPeer::ID, $hp->getId());
     // The only way for cascading to work currently
     // is to specify the author_id and publisher_id (i.e. the fkeys
     // have to be in the criteria).
     $c->add(AuthorPeer::ID, $hp->getId());
     $c->add(PublisherPeer::ID, $hp->getId());
     $c->setSingleRecord(true);
     BookPeer::doDelete($c);
     // Attempting to delete books by complex criteria
     $c = new Criteria();
     $cn = $c->getNewCriterion(BookPeer::ISBN, "043935806X");
     $cn->addOr($c->getNewCriterion(BookPeer::ISBN, "0380977427"));
     $cn->addOr($c->getNewCriterion(BookPeer::ISBN, "0140422161"));
     $c->add($cn);
     BookPeer::doDelete($c);
     $td->delete();
     AuthorPeer::doDelete($stephenson_id);
     AuthorPeer::doDelete($byron_id);
     $grass->delete();
     PublisherPeer::doDelete($morrow_id);
     PublisherPeer::doDelete($penguin_id);
     $vintage->delete();
     // These have to be deleted manually also since we have onDelete
     // set to SETNULL in the foreign keys in book. Is this correct?
     $rowling->delete();
     $scholastic->delete();
     $blc1->delete();
     $blc2->delete();
 }
Пример #25
0
    $td_id = $td->getId();
    print "Added book \"The Tin Drum\" [id = {$dj_id}].\n";
} catch (Exception $e) {
    die("Error saving book: " . $e->__toString());
}
// Add review records
// ------------------
try {
    print "\nAdding some book reviews to the list\n";
    print "------------------------------------\n\n";
    $r1 = new Review();
    $r1->setBook($phoenix);
    $r1->setReviewedBy("Washington Post");
    $r1->setRecommended(true);
    $r1->setReviewDate(time());
    $r1->save();
    $r1_id = $r1->getId();
    print "Added Washington Post book review  [id = {$r1_id}].\n";
    $r2 = new Review();
    $r2->setBook($phoenix);
    $r2->setReviewedBy("New York Times");
    $r2->setRecommended(false);
    $r2->setReviewDate(time());
    $r2->save();
    $r2_id = $r2->getId();
    print "Added New York Times book review  [id = {$r2_id}].\n";
} catch (Exception $e) {
    die("Error saving book review: " . $e->__toString());
}
// Perform a "complex" search
// --------------------------
Пример #26
0
 function test_findReview()
 {
     //Arrange
     $beer_id = 1;
     $user_id = 1;
     $review = "Great beer";
     $date = "2015-10-08";
     $id = 3;
     $test_review = new Review($beer_id, $user_id, $review, $date, $id);
     $test_review->save();
     $beer_id = 2;
     $user_id = 2;
     $review = "Bad beer";
     $date = "2015-10-09";
     $id = 3;
     $test_review2 = new Review($beer_id, $user_id, $review, $date, $id);
     $test_review2->save();
     //Act
     $search_beer_id = $test_review2->getBeerId();
     $search_user_id = $test_review2->getUserId();
     $result = Review::findReview($search_beer_id, $search_user_id);
     //Assert
     $this->assertEquals([$test_review2], $result);
 }
 public function testFindWithLeftJoinWithManyToOneAndNullObject()
 {
     BookPeer::clearInstancePool();
     AuthorPeer::clearInstancePool();
     ReviewPeer::clearInstancePool();
     $review = new Review();
     $review->save($this->con);
     $c = new ModelCriteria('bookstore', 'Review');
     $c->setFormatter(ModelCriteria::FORMAT_ARRAY);
     $c->leftJoinWith('Review.Book');
     $c->leftJoinWith('Book.Author');
     // should not raise a notice
     $reviews = $c->find($this->con);
     $this->assertTrue(true);
 }
Пример #28
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      PropelPDO $con
  * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws     PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aSeries !== null) {
             if ($this->aSeries->isModified() || $this->aSeries->isNew()) {
                 $affectedRows += $this->aSeries->save($con);
             }
             $this->setSeries($this->aSeries);
         }
         if ($this->aReview !== null) {
             if ($this->aReview->isModified() || $this->aReview->isNew()) {
                 $affectedRows += $this->aReview->save($con);
             }
             $this->setReview($this->aReview);
         }
         if ($this->aScore !== null) {
             if ($this->aScore->isModified() || $this->aScore->isNew()) {
                 $affectedRows += $this->aScore->save($con);
             }
             $this->setScore($this->aScore);
         }
         if ($this->isNew()) {
             $this->modifiedColumns[] = ModelPeer::ID;
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = ModelPeer::doInsert($this, $con);
                 $affectedRows += 1;
                 // we are assuming that there is only 1 row per doInsert() which
                 // should always be true here (even though technically
                 // BasePeer::doInsert() can insert multiple rows).
                 $this->setId($pk);
                 //[IMV] update autoincrement primary key
                 $this->setNew(false);
             } else {
                 $affectedRows += ModelPeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         if ($this->collConfigs !== null) {
             foreach ($this->collConfigs as $referrerFK) {
                 if (!$referrerFK->isDeleted()) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->collReviews !== null) {
             foreach ($this->collReviews as $referrerFK) {
                 if (!$referrerFK->isDeleted()) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->collScores !== null) {
             foreach ($this->collScores as $referrerFK) {
                 if (!$referrerFK->isDeleted()) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->collUserMetas !== null) {
             foreach ($this->collUserMetas as $referrerFK) {
                 if (!$referrerFK->isDeleted()) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
 public function testScenarioUsingQuery()
 {
     // Add publisher records
     // ---------------------
     try {
         $scholastic = new Publisher();
         $scholastic->setName("Scholastic");
         // do not save, will do later to test cascade
         $morrow = new Publisher();
         $morrow->setName("William Morrow");
         $morrow->save();
         $morrow_id = $morrow->getId();
         $penguin = new Publisher();
         $penguin->setName("Penguin");
         $penguin->save();
         $penguin_id = $penguin->getId();
         $vintage = new Publisher();
         $vintage->setName("Vintage");
         $vintage->save();
         $vintage_id = $vintage->getId();
         $this->assertTrue(true, 'Save Publisher records');
     } catch (Exception $e) {
         $this->fail('Save publisher records');
     }
     // Add author records
     // ------------------
     try {
         $rowling = new Author();
         $rowling->setFirstName("J.K.");
         $rowling->setLastName("Rowling");
         // do not save, will do later to test cascade
         $stephenson = new Author();
         $stephenson->setFirstName("Neal");
         $stephenson->setLastName("Stephenson");
         $stephenson->save();
         $stephenson_id = $stephenson->getId();
         $byron = new Author();
         $byron->setFirstName("George");
         $byron->setLastName("Byron");
         $byron->save();
         $byron_id = $byron->getId();
         $grass = new Author();
         $grass->setFirstName("Gunter");
         $grass->setLastName("Grass");
         $grass->save();
         $grass_id = $grass->getId();
         $this->assertTrue(true, 'Save Author records');
     } catch (Exception $e) {
         $this->fail('Save Author records');
     }
     // Add book records
     // ----------------
     try {
         $phoenix = new Book();
         $phoenix->setTitle("Harry Potter and the Order of the Phoenix");
         $phoenix->setISBN("043935806X");
         $phoenix->setAuthor($rowling);
         $phoenix->setPublisher($scholastic);
         $phoenix->save();
         $phoenix_id = $phoenix->getId();
         $this->assertFalse($rowling->isNew(), 'saving book also saves related author');
         $this->assertFalse($scholastic->isNew(), 'saving book also saves related publisher');
         $qs = new Book();
         $qs->setISBN("0380977427");
         $qs->setTitle("Quicksilver");
         $qs->setAuthor($stephenson);
         $qs->setPublisher($morrow);
         $qs->save();
         $qs_id = $qs->getId();
         $dj = new Book();
         $dj->setISBN("0140422161");
         $dj->setTitle("Don Juan");
         $dj->setAuthor($byron);
         $dj->setPublisher($penguin);
         $dj->save();
         $dj_id = $qs->getId();
         $td = new Book();
         $td->setISBN("067972575X");
         $td->setTitle("The Tin Drum");
         $td->setAuthor($grass);
         $td->setPublisher($vintage);
         $td->save();
         $td_id = $td->getId();
         $this->assertTrue(true, 'Save Book records');
     } catch (Exception $e) {
         $this->fail('Save Author records');
     }
     // Add review records
     // ------------------
     try {
         $r1 = new Review();
         $r1->setBook($phoenix);
         $r1->setReviewedBy("Washington Post");
         $r1->setRecommended(true);
         $r1->setReviewDate(time());
         $r1->save();
         $r1_id = $r1->getId();
         $r2 = new Review();
         $r2->setBook($phoenix);
         $r2->setReviewedBy("New York Times");
         $r2->setRecommended(false);
         $r2->setReviewDate(time());
         $r2->save();
         $r2_id = $r2->getId();
         $this->assertTrue(true, 'Save Review records');
     } catch (Exception $e) {
         $this->fail('Save Review records');
     }
     // Perform a "complex" search
     // --------------------------
     $results = BookQuery::create()->filterByTitle('Harry%')->find();
     $this->assertEquals(1, count($results));
     $results = BookQuery::create()->where('Book.ISBN IN ?', array("0380977427", "0140422161"))->find();
     $this->assertEquals(2, count($results));
     // Perform a "limit" search
     // ------------------------
     $results = BookQuery::create()->limit(2)->offset(1)->orderByTitle()->find();
     $this->assertEquals(2, count($results));
     // we ordered on book title, so we expect to get
     $this->assertEquals("Harry Potter and the Order of the Phoenix", $results[0]->getTitle());
     $this->assertEquals("Quicksilver", $results[1]->getTitle());
     // Perform a lookup & update!
     // --------------------------
     // Updating just-created book title
     // First finding book by PK (=$qs_id) ....
     $qs_lookup = BookQuery::create()->findPk($qs_id);
     $this->assertNotNull($qs_lookup, 'just-created book can be found by pk');
     $new_title = "Quicksilver (" . crc32(uniqid(rand())) . ")";
     // Attempting to update found object
     $qs_lookup->setTitle($new_title);
     $qs_lookup->save();
     // Making sure object was correctly updated: ";
     $qs_lookup2 = BookQuery::create()->findPk($qs_id);
     $this->assertEquals($new_title, $qs_lookup2->getTitle());
     // Test some basic DATE / TIME stuff
     // ---------------------------------
     // that's the control timestamp.
     $control = strtotime('2004-02-29 00:00:00');
     // should be two in the db
     $r = ReviewQuery::create()->findOne();
     $r_id = $r->getId();
     $r->setReviewDate($control);
     $r->save();
     $r2 = ReviewQuery::create()->findPk($r_id);
     $this->assertEquals(new Datetime('2004-02-29 00:00:00'), $r2->getReviewDate(null), 'ability to fetch DateTime');
     $this->assertEquals($control, $r2->getReviewDate('U'), 'ability to fetch native unix timestamp');
     $this->assertEquals('2-29-2004', $r2->getReviewDate('n-j-Y'), 'ability to use date() formatter');
     // Handle BLOB/CLOB Columns
     // ------------------------
     $blob_path = dirname(__FILE__) . '/../../etc/lob/tin_drum.gif';
     $blob2_path = dirname(__FILE__) . '/../../etc/lob/propel.gif';
     $clob_path = dirname(__FILE__) . '/../../etc/lob/tin_drum.txt';
     $m1 = new Media();
     $m1->setBook($phoenix);
     $m1->setCoverImage(file_get_contents($blob_path));
     $m1->setExcerpt(file_get_contents($clob_path));
     $m1->save();
     $m1_id = $m1->getId();
     $m1_lookup = MediaQuery::create()->findPk($m1_id);
     $this->assertNotNull($m1_lookup, 'Can find just-created media item');
     $this->assertEquals(md5(file_get_contents($blob_path)), md5(stream_get_contents($m1_lookup->getCoverImage())), 'BLOB was correctly updated');
     $this->assertEquals(file_get_contents($clob_path), (string) $m1_lookup->getExcerpt(), 'CLOB was correctly updated');
     // now update the BLOB column and save it & check the results
     $m1_lookup->setCoverImage(file_get_contents($blob2_path));
     $m1_lookup->save();
     $m2_lookup = MediaQuery::create()->findPk($m1_id);
     $this->assertNotNull($m2_lookup, 'Can find just-created media item');
     $this->assertEquals(md5(file_get_contents($blob2_path)), md5(stream_get_contents($m2_lookup->getCoverImage())), 'BLOB was correctly overwritten');
     // Test Validators
     // ---------------
     require_once 'tools/helpers/bookstore/validator/ISBNValidator.php';
     $bk1 = new Book();
     $bk1->setTitle("12345");
     // min length is 10
     $ret = $bk1->validate();
     $this->assertFalse($ret, 'validation failed');
     $failures = $bk1->getValidationFailures();
     $this->assertEquals(1, count($failures), '1 validation message was returned');
     $el = array_shift($failures);
     $this->assertContains("must be more than", $el->getMessage(), 'Expected validation message was returned');
     $bk2 = new Book();
     $bk2->setTitle("Don Juan");
     $ret = $bk2->validate();
     $this->assertFalse($ret, 'validation failed');
     $failures = $bk2->getValidationFailures();
     $this->assertEquals(1, count($failures), '1 validation message was returned');
     $el = array_shift($failures);
     $this->assertContains("Book title already in database.", $el->getMessage(), 'Expected validation message was returned');
     //Now trying some more complex validation.
     $auth1 = new Author();
     $auth1->setFirstName("Hans");
     // last name required; will fail
     $bk1->setAuthor($auth1);
     $rev1 = new Review();
     $rev1->setReviewDate("08/09/2001");
     // will fail: reviewed_by column required
     $bk1->addReview($rev1);
     $ret2 = $bk1->validate();
     $this->assertFalse($ret2, 'validation failed');
     $failures2 = $bk1->getValidationFailures();
     $this->assertEquals(3, count($failures2), '3 validation messages were returned');
     $expectedKeys = array(AuthorPeer::LAST_NAME, BookPeer::TITLE, ReviewPeer::REVIEWED_BY);
     $this->assertEquals($expectedKeys, array_keys($failures2), 'correct columns failed');
     $bk2 = new Book();
     $bk2->setTitle("12345678901");
     // passes
     $auth2 = new Author();
     $auth2->setLastName("Blah");
     //passes
     $auth2->setEmail("*****@*****.**");
     //passes
     $auth2->setAge(50);
     //passes
     $bk2->setAuthor($auth2);
     $rev2 = new Review();
     $rev2->setReviewedBy("Me!");
     // passes
     $rev2->setStatus("new");
     // passes
     $bk2->addReview($rev2);
     $ret3 = $bk2->validate();
     $this->assertTrue($ret3, 'complex validation can pass');
     // Testing doCount() functionality
     // -------------------------------
     // old way
     $c = new Criteria();
     $records = BookPeer::doSelect($c);
     $count = BookPeer::doCount($c);
     $this->assertEquals($count, count($records), 'correct number of results');
     // new way
     $count = BookQuery::create()->count();
     $this->assertEquals($count, count($records), 'correct number of results');
     // Test many-to-many relationships
     // ---------------
     // init book club list 1 with 2 books
     $blc1 = new BookClubList();
     $blc1->setGroupLeader("Crazyleggs");
     $blc1->setTheme("Happiness");
     $brel1 = new BookListRel();
     $brel1->setBook($phoenix);
     $brel2 = new BookListRel();
     $brel2->setBook($dj);
     $blc1->addBookListRel($brel1);
     $blc1->addBookListRel($brel2);
     $blc1->save();
     $this->assertNotNull($blc1->getId(), 'BookClubList 1 was saved');
     // init book club list 2 with 1 book
     $blc2 = new BookClubList();
     $blc2->setGroupLeader("John Foo");
     $blc2->setTheme("Default");
     $brel3 = new BookListRel();
     $brel3->setBook($phoenix);
     $blc2->addBookListRel($brel3);
     $blc2->save();
     $this->assertNotNull($blc2->getId(), 'BookClubList 2 was saved');
     // re-fetch books and lists from db to be sure that nothing is cached
     $crit = new Criteria();
     $crit->add(BookPeer::ID, $phoenix->getId());
     $phoenix = BookPeer::doSelectOne($crit);
     $this->assertNotNull($phoenix, "book 'phoenix' has been re-fetched from db");
     $crit = new Criteria();
     $crit->add(BookClubListPeer::ID, $blc1->getId());
     $blc1 = BookClubListPeer::doSelectOne($crit);
     $this->assertNotNull($blc1, 'BookClubList 1 has been re-fetched from db');
     $crit = new Criteria();
     $crit->add(BookClubListPeer::ID, $blc2->getId());
     $blc2 = BookClubListPeer::doSelectOne($crit);
     $this->assertNotNull($blc2, 'BookClubList 2 has been re-fetched from db');
     $relCount = $phoenix->countBookListRels();
     $this->assertEquals(2, $relCount, "book 'phoenix' has 2 BookListRels");
     $relCount = $blc1->countBookListRels();
     $this->assertEquals(2, $relCount, 'BookClubList 1 has 2 BookListRels');
     $relCount = $blc2->countBookListRels();
     $this->assertEquals(1, $relCount, 'BookClubList 2 has 1 BookListRel');
     // Cleanup (tests DELETE)
     // ----------------------
     // Removing books that were just created
     // First finding book by PK (=$phoenix_id) ....
     $hp = BookQuery::create()->findPk($phoenix_id);
     $this->assertNotNull($hp, 'Could find just-created book');
     // Attempting to delete [multi-table] by found pk
     $c = new Criteria();
     $c->add(BookPeer::ID, $hp->getId());
     // The only way for cascading to work currently
     // is to specify the author_id and publisher_id (i.e. the fkeys
     // have to be in the criteria).
     $c->add(AuthorPeer::ID, $hp->getAuthor()->getId());
     $c->add(PublisherPeer::ID, $hp->getPublisher()->getId());
     $c->setSingleRecord(true);
     BookPeer::doDelete($c);
     // Checking to make sure correct records were removed.
     $this->assertEquals(3, AuthorPeer::doCount(new Criteria()), 'Correct records were removed from author table');
     $this->assertEquals(3, PublisherPeer::doCount(new Criteria()), 'Correct records were removed from publisher table');
     $this->assertEquals(3, BookPeer::doCount(new Criteria()), 'Correct records were removed from book table');
     // Attempting to delete books by complex criteria
     BookQuery::create()->filterByISBN("043935806X")->orWhere('Book.ISBN = ?', "0380977427")->orWhere('Book.ISBN = ?', "0140422161")->delete();
     // Attempting to delete book [id = $td_id]
     $td->delete();
     // Attempting to delete authors
     AuthorQuery::create()->filterById($stephenson_id)->delete();
     AuthorQuery::create()->filterById($byron_id)->delete();
     $grass->delete();
     // Attempting to delete publishers
     PublisherQuery::create()->filterById($morrow_id)->delete();
     PublisherQuery::create()->filterById($penguin_id)->delete();
     $vintage->delete();
     // These have to be deleted manually also since we have onDelete
     // set to SETNULL in the foreign keys in book. Is this correct?
     $rowling->delete();
     $scholastic->delete();
     $blc1->delete();
     $blc2->delete();
     $this->assertEquals(array(), AuthorPeer::doSelect(new Criteria()), 'no records in [author] table');
     $this->assertEquals(array(), PublisherPeer::doSelect(new Criteria()), 'no records in [publisher] table');
     $this->assertEquals(array(), BookPeer::doSelect(new Criteria()), 'no records in [book] table');
     $this->assertEquals(array(), ReviewPeer::doSelect(new Criteria()), 'no records in [review] table');
     $this->assertEquals(array(), MediaPeer::doSelect(new Criteria()), 'no records in [media] table');
     $this->assertEquals(array(), BookClubListPeer::doSelect(new Criteria()), 'no records in [book_club_list] table');
     $this->assertEquals(array(), BookListRelPeer::doSelect(new Criteria()), 'no records in [book_x_list] table');
 }
Пример #30
0
function processPendingReviewsNotifications()
{
    // Check if it is time to process notifications
    if (!isset($_REQUEST['force']) && !canProcessNotifications()) {
        return;
    }
    // process pending journal notifications
    $pendingReviews = Review::getReviewsWithPendingJournalNotifications();
    if ($pendingReviews !== false && count($pendingReviews) > 0) {
        echo "<br/>Processing " . count($pendingReviews) . " reviews.";
        foreach ($pendingReviews as $review) {
            $tReview = new Review();
            $tReview->loadById($review['reviewer_id'], $review['reviewee_id']);
            if ($tReview->journal_notified == 0) {
                Utils::sendReviewNotification($tReview->reviewee_id, 'update', $tReview->getReviews($tReview->reviewee_id, $tReview->reviewer_id, ' AND r.reviewer_id=' . $tReview->reviewer_id));
            } else {
                Utils::sendReviewNotification($tReview->reviewee_id, 'new', $tReview->getReviews($tReview->reviewee_id, $tReview->reviewer_id, ' AND r.reviewer_id=' . $tReview->reviewer_id));
            }
            $tReview->journal_notified = 1;
            $tReview->save('reviewer_id', 'reviewee_id');
            usleep(4000000);
        }
    } else {
        echo "<br />Processed. No pending Reviews.";
    }
    resetCronFile();
}