/** * Get registration profiles for $contactID registration groups * * @param $contact_id long * @return array */ function get_registrationProfiles($contact_id) { $aclGroups = get_aclGroups($contact_id); $registrationGroups = get_registrationGroups($aclGroups); if (count($registrationGroups) > 0) { foreach ($registrationGroups as $group) { $group_id = $group["id"]; $apiParams = array("add_to_group_id" => $group_id, "limit_listings_group_id" => $group_id, "group_type" => "Individual", "is_active" => 1, 'options' => array('sort' => 'created_date DESC', 'limit' => 1)); $entity_name = "uf_group"; $result = civicrm_api3_get($entity_name, $apiParams, 'getsingle'); $profiles[$result["id"]] = $result; } } return $profiles; }
private function findEligiblePlayers() { // Retrieve registration groups available to current user $contact_id = user_id_get(); $aclGroups = get_aclGroups($contact_id); $registrationGroups = get_registrationGroups($aclGroups); if (!CRM_Core_Permission::check('edit all contacts')) { $groups = "("; foreach ($registrationGroups as $group) { $groups .= "{$group["id"]},"; } $groups = rtrim($groups, ","); $groups .= ")"; $groupWhere = " group_id IN {$groups}"; } // Retrieve team games $query = "SELECT entity_id AS ID, equations_21 AS E, on_sets_22 AS O, linguishtik_23 AS L, propaganda_24 AS P, presidents_25 AS M, world_events_26 AS A, wff_n_proof_27 AS W FROM civicrm_value_team_data_7 AS team_games WHERE `entity_id` = %1"; $params = array(1 => array($this->_id, 'Integer')); $teamGames = CRM_Core_DAO::executeQuery($query, $params); $teamGames->fetch(); //@todo don't hard code game codes $this->_teamGameText = ""; if (strlen($teamGames->E) > 0) { $this->_teamGameText .= 'E'; } if (strlen($teamGames->O) > 0) { $this->_teamGameText .= 'O'; } if (strlen($teamGames->L) > 0) { $this->_teamGameText .= 'L'; } if (strlen($teamGames->P) > 0) { $this->_teamGameText .= 'P'; } if (strlen($teamGames->M) > 0) { $this->_teamGameText .= 'M'; } if (strlen($teamGames->A) > 0) { $this->_teamGameText .= 'A'; } if (strlen($teamGames->W) > 0) { $this->_teamGameText .= 'W'; } $this->assign("teamGameText", $this->_teamGameText); $gamesWhere = ""; $gamesWhere = $this->gamesWhere($gamesWhere, $teamGames->E, "equations_11"); $gamesWhere = $this->gamesWhere($gamesWhere, $teamGames->O, "on_sets_12"); $gamesWhere = $this->gamesWhere($gamesWhere, $teamGames->L, "linguishtik_13"); $gamesWhere = $this->gamesWhere($gamesWhere, $teamGames->P, "propaganda_14"); $gamesWhere = $this->gamesWhere($gamesWhere, $teamGames->M, "presidents_15"); $gamesWhere = $this->gamesWhere($gamesWhere, $teamGames->A, "world_events_16"); $gamesWhere = $this->gamesWhere($gamesWhere, $teamGames->W, "wff_n_proof_17"); // Select players matching team criteria $query = "\n \tSELECT player.contact_id AS PlayerID, person.sort_name AS Name\n \t, group_id AS DistrictID, District.title AS DistrictName\n \t, equations_11 AS E, on_sets_12 AS O, linguishtik_13 AS L, propaganda_14 AS P, presidents_15 AS M, world_events_16 AS A, wff_n_proof_17 AS W\n \tFROM civicrm_value_games_registration_5 AS player_games\n \tJOIN civicrm_participant AS player ON player.id = player_games.entity_id\n \tJOIN civicrm_contact AS person ON player.contact_id = person.id\n \tJOIN civicrm_group_contact AS DistrictPlayer ON DistrictPlayer.contact_id = person.id\n \tJOIN civicrm_group AS District ON DistrictPlayer.group_id = District.ID\n \tWHERE player.event_id = %1 AND player.status_id = %2 AND player.role_id LIKE %3 AND is_test = 0\n \tAND status LIKE 'Added' AND is_active = 1 AND District.group_type LIKE %4\n \t"; if (strlen($gamesWhere) > 0) { $query .= " AND {$gamesWhere}"; } if (strlen($groupWhere) > 0) { $query .= " AND {$groupWhere}"; } $eventID = 1; $activeStatus = 1; $playerRole = '1'; $groupType = '%4%'; //@todo $params = array(1 => array($eventID, 'Integer'), 2 => array($activeStatus, 'Integer'), 3 => array($playerRole, 'String'), 4 => array($groupType, 'String')); $playerRecords = CRM_Core_DAO::executeQuery($query, $params); while ($playerRecords->fetch()) { //@todo don't include players already on a team $playerID = $playerRecords->PlayerID; $teamID = $this->_id; unset($errors); self::checkTeamPlayer($teamID, $playerID, $errors); if (!isset($errors)) { $displayText = "{$playerRecords->Name} ({$playerRecords->DistrictName})"; //@todo don't hard code game codes $gameText = ""; if (strlen($playerRecords->E) > 0) { $gameText .= 'E'; } if (strlen($playerRecords->O) > 0) { $gameText .= 'O'; } if (strlen($playerRecords->L) > 0) { $gameText .= 'L'; } if (strlen($playerRecords->P) > 0) { $gameText .= 'P'; } if (strlen($playerRecords->M) > 0) { $gameText .= 'M'; } if (strlen($playerRecords->A) > 0) { $gameText .= 'A'; } if (strlen($playerRecords->W) > 0) { $gameText .= 'W'; } if (strlen($gameText) > 0) { $displayText .= " ({$gameText})"; } $this->_eligiblePlayers[$playerRecords->PlayerID] = $displayText; } } }