public function process()
 {
     $this->resource = $this->getResource();
     if (!is_object($this->resource) || !$this->resource instanceof modResource) {
         return $this->failure($this->resource);
     }
     /* setup default properties */
     $isLimit = $this->getProperty('limit') > 0;
     $resourceGroupList = $this->resource->getGroupsList(array($this->getProperty('sort') => $this->getProperty('dir')), $isLimit ? $this->getProperty('limit') : 0, $this->getProperty('start'));
     $resourceGroups = $resourceGroupList['collection'];
     $parentGroups = array();
     $mode = $this->getProperty('mode');
     $parent = $this->getProperty('parent', 0);
     $token = $this->getProperty('token', '');
     // see if this request is in the context of a resource reload
     if (!empty($token)) {
         $rgs = $this->getRGReloadData($token);
     } else {
         if (!empty($parent) && $mode == 'create') {
             $parent = $this->modx->getObject('modResource', $parent);
             /** @var modResource $parent */
             if ($parent) {
                 $parentResourceGroups = $parent->getMany('ResourceGroupResources');
                 /** @var modResourceGroupResource $parentResourceGroup */
                 foreach ($parentResourceGroups as $parentResourceGroup) {
                     $parentGroups[] = $parentResourceGroup->get('document_group');
                 }
                 $parentGroups = array_unique($parentGroups);
             }
         }
     }
     $list = array();
     /** @var modResourceGroup $resourceGroup */
     foreach ($resourceGroups as $resourceGroup) {
         $resourceGroupArray = $resourceGroup->toArray();
         $resourceGroupArray['access'] = (bool) $resourceGroupArray['access'];
         if (!empty($parent) && $mode == 'create') {
             $resourceGroupArray['access'] = in_array($resourceGroupArray['id'], $parentGroups) ? true : false;
         }
         if (is_array($rgs) && count($rgs) > 0) {
             $name = $resourceGroup->get('name');
             if (array_key_exists($name, $rgs)) {
                 $resourceGroupArray['access'] = (bool) $rgs[$name]->get('access');
             }
         }
         $list[] = $resourceGroupArray;
     }
     return $this->outputArray($list, $resourceGroupList['total']);
 }
 public function getResourceGroups()
 {
     $parentGroups = array();
     if ($this->resource->get('id') == 0) {
         $parent = $this->modx->getObject('modResource', $this->resource->get('parent'));
         /** @var modResource $parent */
         if ($parent) {
             $parentResourceGroups = $parent->getMany('ResourceGroupResources');
             /** @var modResourceGroupResource $parentResourceGroup */
             foreach ($parentResourceGroups as $parentResourceGroup) {
                 $parentGroups[] = $parentResourceGroup->get('document_group');
             }
             $parentGroups = array_unique($parentGroups);
         }
     }
     $this->resourceArray['resourceGroups'] = array();
     $resourceGroups = $this->resource->getGroupsList(array('name' => 'ASC'), 0, 0);
     /** @var modResourceGroup $resourceGroup */
     foreach ($resourceGroups['collection'] as $resourceGroup) {
         $access = (bool) $resourceGroup->get('access');
         if (!empty($parent) && $this->resource->get('id') == 0) {
             $access = in_array($resourceGroup->get('id'), $parentGroups) ? true : false;
         }
         $resourceGroupArray = array($resourceGroup->get('id'), $resourceGroup->get('name'), $access);
         $this->resourceArray['resourceGroups'][] = $resourceGroupArray;
     }
     return $this->resourceArray['resourceGroups'];
 }
 public function process()
 {
     $this->resource = $this->getResource();
     if (!is_object($this->resource) || !$this->resource instanceof modResource) {
         return $this->failure($this->resource);
     }
     /* setup default properties */
     $isLimit = $this->getProperty('limit') > 0;
     $resourceGroupList = $this->resource->getGroupsList(array($this->getProperty('sort') => $this->getProperty('dir')), $isLimit ? $this->getProperty('limit') : 0, $this->getProperty('start'));
     $resourceGroups = $resourceGroupList['collection'];
     $parentGroups = array();
     $mode = $this->getProperty('mode');
     $parent = $this->getProperty('parent', 0);
     if (!empty($parent) && $mode == 'create') {
         $parent = $this->modx->getObject('modResource', $parent);
         /** @var modResource $parent */
         if ($parent) {
             $parentResourceGroups = $parent->getMany('ResourceGroupResources');
             /** @var modResourceGroupResource $parentResourceGroup */
             foreach ($parentResourceGroups as $parentResourceGroup) {
                 $parentGroups[] = $parentResourceGroup->get('document_group');
             }
             $parentGroups = array_unique($parentGroups);
         }
     }
     $list = array();
     /** @var modResourceGroup $resourceGroup */
     foreach ($resourceGroups as $resourceGroup) {
         $resourceGroupArray = $resourceGroup->toArray();
         $resourceGroupArray['access'] = (bool) $resourceGroupArray['access'];
         if (!empty($parent) && $mode == 'create') {
             $resourceGroupArray['access'] = in_array($resourceGroupArray['id'], $parentGroups) ? true : false;
         }
         $list[] = $resourceGroupArray;
     }
     return $this->outputArray($list, $resourceGroupList['total']);
 }