Backend\Modules\Profiles\Engine\Model::getGroupsForDropDown PHP Method

getGroupsForDropDown() public static method

Get profile groups for dropdown not yet linked to a profile
public static getGroupsForDropDown ( integer $profileId, integer $includeId = null ) : array
$profileId integer Profile id.
$includeId integer Group id to always include.
return array
    public static function getGroupsForDropDown($profileId, $includeId = null)
    {
        // init db
        $db = BackendModel::getContainer()->get('database');
        // get groups already linked but don't include the includeId
        if ($includeId !== null) {
            $groupIds = (array) $db->getColumn('SELECT group_id
                 FROM profiles_groups_rights
                 WHERE profile_id = ? AND id != ?', array($profileId, $includeId));
        } else {
            $groupIds = (array) $db->getColumn('SELECT group_id
                 FROM profiles_groups_rights
                 WHERE profile_id = ?', (int) $profileId);
        }
        // get groups not yet linked
        return (array) $db->getPairs('SELECT id, name
             FROM profiles_groups
             WHERE id NOT IN(\'' . implode('\',\'', $groupIds) . '\')');
    }

Usage Example

Example #1
0
 /**
  * Load the form
  */
 private function loadForm()
 {
     // get group values for dropdown
     $ddmValues = BackendProfilesModel::getGroupsForDropDown($this->id);
     // create form and elements
     $this->frm = new BackendForm('import');
     $this->frm->addDropdown('group', $ddmValues);
     $this->frm->addFile('file');
     $this->frm->addCheckbox('overwrite_existing');
 }
All Usage Examples Of Backend\Modules\Profiles\Engine\Model::getGroupsForDropDown