Ejemplo n.º 1
0
 /**
  * Get list of teams.
  *
  * @return array
  */
 public static function getTeamList()
 {
     $params = $_REQUEST;
     if (isset($params['parent_id'])) {
         // requesting child groups for a given parent
         $params['page'] = 1;
         $params['rp'] = 0;
         $groups = self::getTeamListSelector($params);
         CRM_Utils_JSON::output($groups);
     } else {
         $sortMapper = array(0 => 'groups.title', 1 => 'count', 2 => 'createdBy.sort_name', 3 => '', 4 => 'groups.group_type', 5 => 'groups.visibility');
         $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
         $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
         $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
         $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL;
         $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
         if ($sort && $sortOrder) {
             $params['sortBy'] = $sort . ' ' . $sortOrder;
         }
         $params['page'] = $offset / $rowCount + 1;
         $params['rp'] = $rowCount;
         $params['group_type'] = teamGroupType();
         // restrict to teams logged in user may access
         $contact = billing_contact_get();
         //@todo remove for admin
         if (!CRM_Core_Permission::check('edit all contacts')) {
             $params['created_by'] = $contact['sort_name'];
         }
         // get team list
         $groups = self::getTeamListSelector($params);
         // if no groups found with parent-child hierarchy and logged in user say can view child groups only (an ACL case),
         // go ahead with flat hierarchy
         if (empty($groups)) {
             $groupsAccessible = CRM_Core_PseudoConstant::group();
             $parentsOnly = CRM_Utils_Array::value('parentsOnly', $params);
             if (!empty($groupsAccessible) && $parentsOnly) {
                 // recompute group list with flat hierarchy
                 $params['parentsOnly'] = 0;
                 $groups = self::getTeamListSelector($params);
             }
         }
         $iFilteredTotal = $iTotal = count($groups);
         //$params['total'];
         $selectorElements = array('group_name', 'count', 'created_by', 'group_description', 'group_type', 'visibility', 'org_info', 'links', 'class');
         if (empty($params['showOrgInfo'])) {
             unset($selectorElements[6]);
         }
         //add setting so this can be tested by unit test
         //@todo - ideally the portion of this that retrieves the groups should be extracted into a function separate
         // from the one which deals with web inputs & outputs so we have a properly testable & re-usable function
         if (!empty($params['is_unit_test'])) {
             return array($groups, $iFilteredTotal);
         }
         header('Content-Type: application/json');
         echo CRM_Utils_JSON::encodeDataTableSelector($groups, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
         CRM_Utils_System::civiExit();
     }
 }
Ejemplo n.º 2
0
/**
 * Implements hook_civicrm_navigationMenu().
 *
 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_navigationMenu
 */
function tournament_civicrm_navigationMenu(&$menu)
{
    $domain = array('domain' => domain());
    $path = path();
    $name = $path;
    // This inserts a menu at the end the bar. TODO: How to insert at beginning?
    _tournament_civix_insert_navigation_menu($menu, NULL, array('label' => ts('Tournament', $domain), 'name' => $name, 'url' => ''));
    $path = $name;
    $name = 'tournament_dashboard';
    _tournament_civix_insert_navigation_menu($menu, $path, array('label' => ts('Dashboard', $domain), 'name' => $name, 'url' => 'civicrm', 'permission' => 'access Contact Dashboard'));
    $name = 'individual_profile';
    $billing_contact = billing_contact_get();
    $billing_contact_id = $billing_contact["id"];
    $record = named_profile_get("Billing Individual Profile");
    $gid = $record["id"];
    $delim = '?';
    $HREF = contact_profile_HREF_data($billing_contact, $record, $delim);
    $label = $HREF['title'];
    $url = $HREF['relativeURL'];
    _tournament_civix_insert_navigation_menu($menu, $path, array('label' => ts($label, $domain), 'name' => $name, 'url' => $url, 'permission' => 'edit my contact'));
    $name = 'organization_profile';
    _tournament_civix_insert_navigation_menu($menu, $path, array('label' => ts("Organizations", $domain), 'name' => $name, 'url' => ''));
    $path .= "/{$name}";
    $profile = named_profile_get("Billing Organization Profile");
    $billing_organizations = billing_organizations_get($billing_contact_id);
    if (count($billing_organizations) > 0) {
        foreach ($billing_organizations as $org) {
            $HREF = contact_profile_HREF_data($org, $profile, $delim);
            $label = $HREF['title'];
            $url = $HREF['relativeURL'];
            _tournament_civix_insert_navigation_menu($menu, $path, array('label' => ts($label, $domain), 'name' => "{$name}_{$organization_name}", 'url' => $url, 'permission' => 'access contact reference fields'));
        }
    }
    $path = path();
    $name = 'Profiles';
    _tournament_civix_insert_navigation_menu($menu, $path, array('label' => ts('Your players, coaches, etc.', $domain), 'name' => $name, 'permission' => 'profile edit', 'separator' => 1));
    $path .= "/{$name}";
    // add a menu item for each of the session billing contact's profiles
    $registrationProfiles = get_registrationProfiles($billing_contact_id);
    if (count($registrationProfiles) > 0) {
        foreach ($registrationProfiles as $profile) {
            $id = $profile["id"];
            $title = $profile["title"];
            _tournament_civix_insert_navigation_menu($menu, $path, array('label' => ts("{$title}", array('domain' => $domain)), 'name' => "{$name}_{$id}", 'permission' => 'profile edit'));
            _tournament_civix_insert_navigation_menu($menu, "{$path}/{$name}_{$id}", array('label' => ts("Find Contacts", array('domain' => $domain)), 'name' => "{$name}_{$id}_list", 'url' => "civicrm/profile?gid={$id}&reset=1&force=1", 'permission' => 'profile edit'));
            _tournament_civix_insert_navigation_menu($menu, "{$path}/{$name}_{$id}", array('label' => ts("New Contact", array('domain' => $domain)), 'name' => "{$name}_{$id}_add", 'url' => "civicrm/profile/create?gid={$id}&reset=1", 'permission' => 'profile create'));
        }
    }
    $path = path();
    _tournament_civix_insert_navigation_menu($menu, $path, array('label' => ts('Register Contacts for Tournament', $domain), 'name' => 'registration', 'permission' => 'edit event participants', 'separator' => 1));
    _tournament_civix_insert_navigation_menu($menu, "{$path}/registration", array('label' => ts('Register a contact', $domain), 'name' => 'registerParticipant', 'url' => registrationRelativeURL("?"), 'permission' => 'edit event participants'));
    _tournament_civix_insert_navigation_menu($menu, "{$path}/registration", array('label' => ts('List/edit contacts already registered', $domain), 'name' => 'participantList', 'url' => registrationReportRelativeURL("?"), 'permission' => 'edit event participants'));
    $path = path();
    _tournament_civix_insert_navigation_menu($menu, $path, array('label' => ts('Team Builder', array('domain' => $domain)), 'name' => "teamBuilder", 'permission' => 'edit groups', 'separator' => 1));
    _tournament_civix_insert_navigation_menu($menu, "{$path}/teamBuilder", array('label' => ts('New Team', array('domain' => $domain)), 'name' => 'NewTeam', 'url' => "civicrm/tournament/team/add?reset=1", 'permission' => 'edit groups'));
    _tournament_civix_insert_navigation_menu($menu, "{$path}/teamBuilder", array('label' => ts('List/edit existing teams', array('domain' => $domain)), 'name' => 'teamList', 'url' => "civicrm/tournament/team/search", 'permission' => 'edit groups'));
    $path = path();
    _tournament_civix_insert_navigation_menu($menu, $path, array('label' => ts('Advanced Operations', $domain), 'name' => 'bulkOperations', 'permission' => 'edit event participants', 'url' => bulkOperationsRelativeURL("?"), 'separator' => 1));
    $path = null;
    $name = "TournamentAdmin";
    _tournament_civix_insert_navigation_menu($menu, $path, array('label' => ts('Tournament Admins', array('domain' => $domain)), 'name' => $name, 'permission' => 'edit all contacts'));
    $path = $name;
    $record = named_profile_get("Billing Organization Profile");
    $id = $record["id"];
    _tournament_civix_insert_navigation_menu($menu, $path, array('label' => ts('Billing Organizations', array('domain' => $domain)), 'name' => 'BillingOrganizations', 'url' => "civicrm/profile?gid={$id}", 'permission' => 'view all contacts'));
    $record = named_report_get("Preliminary Estimates Summary");
    $id = $record["id"];
    _tournament_civix_insert_navigation_menu($menu, "{$path}/BillingOrganizations", array('label' => ts('Preliminary Estimates', array('domain' => $domain)), 'name' => 'PreliminaryEstimates', 'url' => "civicrm/report/instance/{$id}?reset=1", 'permission' => 'view all contacts'));
    $record = named_group_get("Billing Contacts");
    $id = $record["id"];
    _tournament_civix_insert_navigation_menu($menu, $path, array('label' => ts('Billing Individuals', array('domain' => $domain)), 'name' => 'BillingContacts', 'url' => "civicrm/group/search?context=smog&gid={$id}&reset=1&force=1", 'permission' => 'view all contacts'));
    _tournament_civix_navigationMenu($menu);
}