<?php class AssignedJudgesGetListProcessor extends modObjectGetListProcessor { public $classKey = 'modUser'; public $languageTopics = array('user'); public $permission = 'view_user'; public $defaultSortField = 'email'; public function initialize() { $initialized = parent::initialize(); $this->setDefaultProperties(array( 'usergroup' => false, 'query' => '', )); if ($this->getProperty('sort') == 'username_link') $this->setProperty('sort','username'); if ($this->getProperty('sort') == 'id') $this->setProperty('sort','modUser.id'); return $initialized; } public function prepareQueryBeforeCount(xPDOQuery $c) { $c->leftJoin('modUserProfile','Profile'); $query = $this->getProperty('query',''); if (!empty($query)) { $c->where(array('modUser.username:LIKE' => '%'.$query.'%')); $c->orCondition(array('Profile.fullname:LIKE' => '%'.$query.'%')); $c->orCondition(array('Profile.email:LIKE' => '%'.$query.'%')); } $userGroup = $this->getProperty('usergroup',0); if (!empty($userGroup)) { $c->innerJoin('modUserGroupMember','UserGroupMembers'); $c->where(array( 'UserGroupMembers.user_group' => $userGroup, )); } /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! I tried adding this but I'm not really sure what I'm doing...obviously not working :) */ $userGroupName = 'Judges#'.$this->getProperty('galleryId'); if(!empty($galleryId)) { $c->where(array( 'UserGroupMembers.user_group' => $userGroupName, )); } return $c; } public function prepareQueryAfterCount(xPDOQuery $c) { $c->select($this->modx->getSelectColumns('modUser','modUser')); $c->select($this->modx->getSelectColumns('modUserProfile','Profile','',array('fullname','email','blocked'))); //$this->setProperty('username', $this->getProperty('email')); return $c; } /** * Prepare the row for iteration * @param xPDOObject $object * @return array */ public function prepareRow(xPDOObject $object) { $objectArray = $object->toArray(); $objectArray['blocked'] = $object->get('blocked') ? true : false; $objectArray['cls'] = 'pupdate premove pcopy'; unset($objectArray['password'],$objectArray['cachepwd'],$objectArray['salt']); return $objectArray; } } return 'AssignedJudgesGetListProcessor';
This question has been answered by Bruno17. See the first response.
$judgesGroup = 'JudgesGallery#'.$this->getProperty('galleryId'); if(!empty($judgesGroup)) { $c->innerJoin('modUserGroup', 'PrimaryGroup'); $c->where(array('PrimaryGroup.name' => $judgesGroup)); }
if ($usergroup = $this->modx->getObject('modUserGroup',array('name' => $judgesGroup))){ if ($usercollection = $usergroup->getUsersIn()){ foreach ($usercollection as $userobject){ //do something with the userobject } } }
why does it need to be a modObjectGetListProcessor?
public function getData() { $data = array(); $limit = intval($this->getProperty('limit')); $start = intval($this->getProperty('start')); $userCollection = array(); $judgesGroup = 'JudgesGallery#'.$this->getProperty('galleryId'); if ($userGroup = $this->modx->getObject('modUserGroup',array('name' => $judgesGroup))) { $userCollection = $userGroup->getUsersIn(); } /* query for chunks */ $c = $this->modx->newQuery($this->classKey); $c = $this->prepareQueryBeforeCount($c); //$data['total'] = $this->modx->getCount($this->classKey,$c); $data['total'] = sizeof($userCollection); $c = $this->prepareQueryAfterCount($c); $sortClassKey = $this->getSortClassKey(); $sortKey = $this->modx->getSelectColumns($sortClassKey,$this->getProperty('sortAlias',$sortClassKey),'',array($this->getProperty('sort'))); if (empty($sortKey)) $sortKey = $this->getProperty('sort'); $c->sortby($sortKey,$this->getProperty('dir')); if ($limit > 0) { $c->limit($limit,$start); } //$data['results'] = $this->modx->getCollection($this->classKey,$c); $data['results'] = $userCollection; return $data; }
{"total":"2","results": [{"id":45,"username":"user1","class_key":"modUser","active":true,"remote_key":null,"remote_data":null,"hash_class":"hashing.modPBKDF2","p rimary_group":0,"session_stale":null,"sudo":false,"role":"Judge","role_name":"Judge","blocked":false,"cls":"pupdate premove pcopy"}, {"id":46,"username":"user2","class_key":"modUser","active":true,"remote_key":null,"remote_data":null,"hash_class":"hashing.modPBKDF2"," primary_group":0,"session_stale":null,"sudo":false,"role":"Judge","role_name":"Judge","blocked":false,"cls":"pupdate premove pcopy"}]}
public function getData() { $data = array(); $userCollection = array(); $judgesGroup = 'JudgesGallery#'.$this->getProperty('galleryId'); if ($userGroup = $this->modx->getObject('modUserGroup',array('name' => $judgesGroup))) { $userCollection = $userGroup->getUsersIn(); foreach ($userCollection as $userObject) { $username = $userObject->get('username'); $this->modx->log(modX::LOG_LEVEL_DEBUG, 'The current value of username : ' . $username); $profile = $userObject->getOne('Profile'); $this->modx->log(modX::LOG_LEVEL_DEBUG, 'The current value of fullname : ' . $profile->fullname); } } $data['total'] = sizeof($userCollection); $data['results'] = $userCollection; return $data; }
$userCollection->leftJoin('modUserProfile', 'Profile');
class SingleJudgeCreateProcessor extends modObjectProcessor { public $object; public function process() { // gets the id of current gallery $galleryId = $this->getProperty('galleryId'); // creates a group using the gallery id if one doesn't already exist if (!$group = $this->modx->getObject('modUserGroup', array('name' => 'JudgesGallery#'.$galleryId))) { $group = $this->modx->newObject('modUserGroup', array('name' => 'JudgesGallery#'.$galleryId)); $group->save(); } // creates the appropriate role for the user if it doesn't already exist if (!$role = $this->modx->getObject('modUserGroupRole', array('name' => 'Judge'))) { $role = $this->modx->newObject('modUserGroupRole', array('name' => 'Judge', 'authority' => '7')); $role->save(); } // creates the user account with all the fields the judge will need if(!$user = $this->modx->getObject('modUserProfile', array('email' => $this->getProperty('email')))) { $user = $this->modx->newObject('modUser', array('username' => $this->getProperty('email'))); $user->set('primary_group', $group->get('id')); // here's the bit I wasn't doing!! $user->set('password', md5($this->getProperty('password'))); $profile = $this->modx->newObject('modUserProfile'); $profile->set('fullname', $this->getProperty('fullname')); $profile->set('email', $this->getProperty('email')); $profile->save(); $user->addOne($profile); $success = $user->save(); } else { $success = false; } // Assign the user both a group and a role $joinSuccess = $user->joinGroup($group->get('id'), $role->get('id')); if ($success && $joinSuccess) { $this->modx->log(modX::LOG_LEVEL_ERROR,'Profile Created: '.print_r($_POST,true)); return $this->success(); } else { $this->modx->log(modX::LOG_LEVEL_ERROR,'Profile Denied: '.print_r($_POST,true)); return $this->failure(); } } } return 'SingleJudgeCreateProcessor';
class AssignedJudgeGetListProcessor extends modObjectGetListProcessor { public $classKey = 'modUser'; public $languageTopics = array('user'); public $permission = 'view_user'; public $defaultSortField = 'username'; public function initialize() { $initialized = parent::initialize(); $this->setDefaultProperties(array( 'usergroup' => false, 'query' => '', )); if ($this->getProperty('sort') == 'username_link') $this->setProperty('sort','username'); if ($this->getProperty('sort') == 'id') $this->setProperty('sort','modUser.id'); return $initialized; } public function prepareQueryBeforeCount(xPDOQuery $c) { $c->leftJoin('modUserProfile','Profile'); $query = $this->getProperty('query',''); if (!empty($query)) { $c->where(array('modUser.username:LIKE' => '%'.$query.'%')); $c->orCondition(array('Profile.fullname:LIKE' => '%'.$query.'%')); $c->orCondition(array('Profile.email:LIKE' => '%'.$query.'%')); } $userGroup = $this->getProperty('usergroup',0); if (!empty($userGroup)) { $c->innerJoin('modUserGroupMember','UserGroupMembers'); $c->where(array( 'UserGroupMembers.user_group' => $userGroup, )); } // This bit here is all that needed to be added after assigning a value to 'primary_group' $userGroupName = $this->getProperty('usergroupname',0); if (!empty($userGroupName)) { $c->innerJoin('modUserGroup','PrimaryGroup'); $c->where(array( 'PrimaryGroup.name' => $userGroupName, )); } return $c; } public function prepareQueryAfterCount(xPDOQuery $c) { $c->select($this->modx->getSelectColumns('modUser','modUser')); $c->select($this->modx->getSelectColumns('modUserProfile','Profile','',array('fullname','email','blocked'))); return $c; } /** * Prepare the row for iteration * @param xPDOObject $object * @return array */ public function prepareRow(xPDOObject $object) { $objectArray = $object->toArray(); $objectArray['blocked'] = $object->get('blocked') ? true : false; $objectArray['cls'] = 'pupdate premove pcopy'; unset($objectArray['password'],$objectArray['cachepwd'],$objectArray['salt']); return $objectArray; } } return 'AssignedJudgeGetListProcessor';