16 private $_friendships = array();
20 $models = $this->_getPreparedModels();
21 if (!empty($models[
'UserSearch']) || !empty($models[
'Profile'])) {
22 $criteria =
new CDbCriteria;
23 $criteria->compare(
'status', User::STATUS_ACTIVE);
25 if (isset($models[
'UserSearch'])) {
27 $user->attributes = $models[
'UserSearch'];
29 foreach ($models[
'UserSearch'] as $name => $value) {
30 if (!$user->hasErrors($name) && $value == $user->$name) {
31 $criteria->compare($name, $value,
true);
34 if (!Yii::app()->user->isGuest) {
35 $criteria->addCondition(
'id != :id');
36 $criteria->params[
':id'] = Yii::app()->user->id;
41 if(!isset($profile->phone)){
42 $alter_phone =
"ALTER TABLE {{profiles}} ADD `phone` varchar(255) NOT NULL DEFAULT '+43'";
43 Yii::app()->db->createCommand($alter_phone)->execute();
46 if (isset($models[
'Profile'])) {
47 $profile->attributes = $models[
'Profile'];
49 $criteria->together =
true;
50 $criteria->with = array(
'profile');
51 foreach ($models[
'Profile'] as $name => $value) {
52 if (!$profile->hasErrors($name) && $value == $profile->$name) {
53 $criteria->compare(
"profile.$name", $value,
true);
57 if ($profile->hasAttribute(
'find_me_in_phone_book')) {
58 $criteria->compare(
"profile.find_me_in_phone_book",
true);
60 $dataProvider =
new CActiveDataProvider(
'User', array(
61 'criteria' => $criteria,
62 'pagination' => array(
66 if (!Yii::app()->user->isGuest) {
67 $this->_friendships =
Friendship::model()->findAll(
'user1_id = :user_id or user2_id = :user_id', array(
':user_id' => Yii::app()->user->id));
73 $this->render(
'FriendsSearchResultWidget', array(
'dataProvider' => $dataProvider));
76 private function _getPreparedModels()
78 $preparedModels = array();
79 foreach (array(
'UserSearch',
'Profile') as $model) {
80 if (isset($_GET[$model])) {
81 $preparedModels[$model] = array_filter($_GET[$model],
function ($var) {
87 return $preparedModels;
90 public function friendshipStatus($user)
92 foreach ($this->_friendships as $f) {
93 if ($f->user1_id == $user->id || $f->user2_id == $user->id) {
94 if ($f->status == Friendship::STATUS_APPROVED) {
102 return 'not friends';