/** * Tests grant right to write testimonial. */ public function testGrant() { $student = $this->students('student2'); $testimonial = new Testimonial(); $this->assertTrue($testimonial->grantTo($student)); $newTestimonial = Testimonial::model()->findByPk($testimonial->id); $this->assertNotNull($newTestimonial); $this->assertTrue($newTestimonial instanceof Testimonial); $this->assertEquals(Testimonial::STATUS_NEW, $newTestimonial->status); $this->assertNotEquals('0000-00-00 00:00:00', $newTestimonial->timestamp); $this->assertEquals($student->id, $newTestimonial->student_id); }
/** * Displays the form for granting testimonial privilege. */ public function actionGrant() { $model = new Testimonial(); if (isset($_POST['Testimonial'])) { $username = $_POST['Testimonial']['student_id']; $student = Student::model()->findByAttributes(array('username' => $username)); if ($student === null) { Yii::app()->user->setNotification('danger', 'Mahasiswa ' . $username . ' tidak terdaftar.'); } else { if ($model->grantTo($student)) { Yii::app()->user->setNotification('success', 'Hak berhasil diberikan.'); $model->student_id = null; } else { Yii::app()->user->setFlash('danger', 'Hak tidak berhasil diberikan.'); } } } $students = Student::model()->findAll(); $usernames = array(); foreach ($students as $student) { $usernames[] = $student->username; } $this->render('grant', array('model' => $model, 'usernames' => $usernames)); }