/** * Lists all notes. */ public function actionIndex() { $model = new Note('search'); if (isset($_GET['Note'])) { $model->attributes = $_GET['Note']; $dataProvider = $model->search(); } else { $dataProvider = new CActiveDataProvider('Note', array('criteria' => array('order' => 'upload_timestamp DESC'))); } $dataProvider->setPagination(array('pageSize' => 16)); $students = Student::model()->findAll(); $usernames = array(); foreach ($students as $student) { $usernames[] = $student->username; } $this->render('index', array('model' => $model, 'dataProvider' => $dataProvider, 'usernames' => $usernames)); }
/** * Tests search action. */ public function testSearch() { // search by title $note = new Note(); $note->title = '1'; $this->assertEquals(1, $note->search()->totalItemCount); // search by type $note = new Note(); $note->type = 0; $this->assertEquals(1, $note->search()->totalItemCount); // search by faculty $note = new Note(); $note->faculty_id = 1; $this->assertEquals(2, $note->search()->totalItemCount); // search by course $note = new Note(); $note->course_id = 1; $this->assertEquals(1, $note->search()->totalItemCount); // search by uploader $note = new Note(); $note->uploader = '1'; $this->assertEquals(2, $note->search()->totalItemCount); }
function search_notes() { $data = array('title' => 'Search' . ($search ? ": {$search}" : ''), 'results' => Note::search(rtrim($_GET['search']))); echo template('search_template', $data, 'layout'); }