Created
April 21, 2014 12:48
-
-
Save max107/11141801 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$user_qs = User::objects()->filter([ | |
'group__permission__code__in' => [ | |
'can_create' => true, | |
'can_update' => true, | |
'can_delete' => false | |
], | |
'is_active__isnull' => false, | |
'cart__price__gte' => 10000, | |
]); | |
$pages = Pages::objects()->filter([ | |
'pages__author_id' => $user_qs->select('id') | |
])->all(); | |
assert(is_array($pages)); | |
// Yii | |
$criteria = new CDbCriteria(); | |
$criteria->with = ['group', 'cart']; | |
$criteria->together = true; | |
$criteria->join = "LEFT JOIN group grp ON grp.user_id = user.id LEFT JOIN group_link grp_link ON grp_link.group_id = group.id LEFT JOIN group_permission perm"; | |
$criteria->alias = 'user'; | |
$criteria->condition = "cart.price > :price AND user.is_active NOT NULL"; | |
$criteria->addInCondition('perm.code', [ | |
'can_create' => true, | |
'can_update' => true, | |
'can_delete' => false | |
]); | |
$users = User::model()->findAll($criteria); | |
$ids = []; | |
foreach($users as $user) { | |
$ids[] = $user->id; | |
} | |
$pages = Pages::model()->with(['pages'])->findAllByAttributes(['pages.author_id' => $ids]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment