I have a File-model, for which I restrict access. The access is provided through membership of groups having access - rather complex and not relevant for here. Anyway, I have a function in my model called checkAccess() which checks the access of the current user (Yii::app()->user) for the current File-model and returns true or false.
My question: I want to search models and display only the models which are available/accessable for the current user, thus returning true on checkAccess(). Whether the user has access, is no direct (in-database) model property, so I don’t know how to search on it. It cannot be searched by sql-criteria. I’ve tried things with CDbCriteria and model-scopes, but I can’t find a solution.
Thanks in advance for helping!
class File extends CActiveRecord
{
...
public function checkAccess()
{
if( < --- check the permission here --- > ) {
return true;
}
return false;
}
public function search()
{
$criteria=new CDbCriteria;
...
// how to add the result of the above checkAccess function
// as a criteria here?
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
}
— Is there anyone who can help me here?