i have 4 columns: assignment, student, user, cycle
the student exist in a cycle
the user (having a type: admin, assistant or teacher) is responsible on one or more cycle(s)
an assignment is made by a user to a student.
in the views/assignment/admin.php: i need to display the list of the assignments in the cgrid columns based on the cycle’s logged in user.
if a user is responsible of the cycle1 and cycle2, display the student that exist only in the cycle 1 and 2.
this is my code:
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$type = Yii::app()->user->getType();
$criteria=new CDbCriteria;
$criteria->with = array('student');
// $type represent the user type
// if type is assistant or teacher, display the student and the assignment information of the student exists in the same user's cycles.
if(($type == 'Assistant')or($type == 'Teacher')) {
// the cycle of the user
$usercycles = Cycle::model()->GetCycleOfUser(Yii::app()->user->getID());
foreach($usercycles as $usercycle){
$studentCycle = Student::model()->find('Group_Code=\'' . $usercycle['Group_Code'] .'\'');
}
// $studentCycle is the list of students having the same cycle of the logged in user
foreach($studentCycle as $cyc){
$criteria->addSearchCondition('CONCAT('. $cyc->E_Child_Name . ',' . $cyc->E_Family_Name . ')',$this->studentID);
}
}else{
$criteria->addSearchCondition('CONCAT(E_Child_Name,E_Family_Name)',$this->studentID);
}
...
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
I think you’re thinking wrong. If you want to do this, you should use User model, User controller and User views. This is because in your User model all relationships already exists, then everything will be eassier.
A user have one or more cycles, a cycle one or more students and a student one or more assignments.
You fill the CGridview with function "search" from your model "Assigment", right?
Then in your function "search" you have to write the necessary condition to show only logged user assigments (Understanding that the "userID" property exists in Yii::app()->user. You must create it.).