/**
  * Callback to render the 'family' entry type part of the 'Name' metabox.
  * Called from self::name()
  *
  * @access private
  * @since  0.8
  *
  * @param  cnEntry $entry An instance of the cnEntry object.
  * @param  array   $atts  The metabox attributes array set in self::register(). Passed from self::name().
  *
  * @return void
  */
 public static function family($entry, $atts)
 {
     // Grab an instance of the Connections object.
     $instance = Connections_Directory();
     $html = '';
     $id = $entry->getId();
     $ckey = $entry->getId() ? 'relative_select_entry_' . $id : 'relative_select_user_' . $instance->currentUser->getID();
     if (FALSE !== ($cache = cnCache::get($ckey, 'transient'))) {
         echo $cache;
         return;
     }
     // Retrieve all the entries of the "individual" entry type that the user is permitted to view and is approved.
     $individuals = cnRetrieve::individuals();
     // Get the core entry relations.
     $options = $instance->options->getDefaultFamilyRelationValues();
     $html .= '<div class="cn-metabox" id="cn-metabox-section-family">';
     // --> Start template for Family <-- \\
     $html .= '<textarea id="cn-relation-template" style="display: none">';
     $html .= cnHTML::select(array('class' => 'family-member-name', 'id' => 'family_member[::FIELD::][entry_id]', 'default' => __('Select Entry', 'connections'), 'options' => $individuals, 'enhanced' => TRUE, 'return' => TRUE));
     $html .= cnHTML::select(array('class' => 'family-member-relation', 'id' => 'family_member[::FIELD::][relation]', 'default' => __('Select Relation', 'connections'), 'options' => $options, 'enhanced' => TRUE, 'return' => TRUE));
     $html .= '</textarea>';
     // --> End template for Family <-- \\
     $html .= '<label for="family_name">' . __('Family Name', 'connections') . ':</label>';
     $html .= '<input type="text" name="family_name" value="' . $entry->getFamilyName() . '" />';
     $html .= '<ul id="cn-relations">';
     if ($relations = $entry->getFamilyMembers()) {
         foreach ($relations as $relationData) {
             $token = str_replace('-', '', cnUtility::getUUID());
             if (array_key_exists($relationData['entry_id'], $individuals)) {
                 $html .= '<li id="relation-row-' . $token . '" class="cn-relation"><i class="fa fa-sort"></i> ';
                 $html .= cnHTML::select(array('class' => 'family-member-name', 'id' => 'family_member[' . $token . '][entry_id]', 'default' => __('Select Entry', 'connections'), 'options' => $individuals, 'enhanced' => TRUE, 'return' => TRUE), $relationData['entry_id']);
                 $html .= cnHTML::select(array('class' => 'family-member-relation', 'id' => 'family_member[' . $token . '][relation]', 'default' => __('Select Relation', 'connections'), 'options' => $options, 'enhanced' => TRUE, 'return' => TRUE), $relationData['relation']);
                 $html .= '<a href="#" class="cn-remove cn-button button cn-button-warning" data-type="relation" data-token="' . $token . '">' . __('Remove', 'connections') . '</a>';
                 $html .= '</li>';
             }
         }
     }
     $html .= '</ul>';
     $html .= '<p class="add"><a id="add-relation" class="button">' . __('Add Relation', 'connections') . '</a></p>';
     $html .= '</div>';
     cnCache::set($ckey, $html, YEAR_IN_SECONDS, 'transient');
     echo $html;
 }
Beispiel #2
0
<?php

/**
 * Team edit form extension for selecting players.
 */
// Get an array of individuals from connections
$individuals = cnRetrieve::individuals();
foreach ($individuals as $id => $name) {
    $parts = explode(', ', $name);
    $individuals[$id] = trim($parts[1] . ' ' . $parts[0]);
}
uasort($individuals, function ($a, $b) {
    return strcasecmp($a, $b);
});
// Get the list of existing players
$players = array_keys($Team->listPlayers());
?>
<tr>
    <th scope='row'><?php 
_e('Players', 'my5280');
?>
</th>
    <td>
        <?php 
for ($i = 0; $i < 10; $i++) {
    ?>
            <div>
                <select name="my5280_players[]">
                    <option value="NONE">(None/No More)</option>
                    <?php 
    foreach ($individuals as $id => $name) {
Beispiel #3
0
 /**
  * show the scoresheet for a league
  *
  * @param array
  * @param bool
  * @return void
  */
 function showScoresheet($atts, $widget = false)
 {
     global $leaguemanager;
     // Extract attributes
     extract(shortcode_atts(array('league_id' => 0, 'league_name' => '', 'season' => false, 'mode' => null, 'title' => null, 'match_id' => isset($_GET['match']) ? $_GET['match'] : null), $atts));
     // Get the league, session, and teams
     $league = $leaguemanager->getLeague($league_id);
     $session = new my5280_Session($league_id, $season);
     $format = $session->getLeagueFormat();
     // Determine the title
     if (!isset($title) || $title === null) {
         $title = $session->getLeagueName() . '<br />' . $session->getName(true);
     }
     // Check for a specific match
     $curMatch = null;
     $helperMatch = null;
     $matches = $session->listMatches(false);
     if (isset($match_id) && $match_id !== null) {
         if (isset($matches[$match_id])) {
             $curMatch = $matches[$match_id];
             $helperMatch = $curMatch;
         } else {
             $helperMatch = array_pop($matches);
         }
     } else {
         $helperMatch = array_pop($matches);
     }
     // Get the home and away teams
     if ($curMatch) {
         // Load format-specific functionality
         $format = $session->getLeagueFormat();
         // Initialize the team array
         $teams = array();
         // Get home team information
         $team = $curMatch->getHomeTeam();
         $players = array();
         foreach ($team->listPlayers() as $player) {
             $players[$player->getId()] = array('id' => $player->getId(), 'name' => $player->getName(), 'handicap' => round($player->getHandicap($curMatch->getDate(), $session->getMaxHandicapGames()), 0), 'sel' => array());
         }
         // Indicate the selected players
         $homeHcp = 0;
         foreach ($curMatch->listHomePlayers() as $index => $player) {
             $id = $player->player_id;
             if ($id) {
                 // Make sure the player is in the list and is selected
                 if (!isset($players[$id])) {
                     $players[$id] = array('id' => $id, 'name' => isset($player->player) ? $player->player->getName() : '(Unknown)', 'handicap' => $player->handicap, 'sel' => array($index));
                 } else {
                     $players[$id]['handicap'] = $player->handicap;
                     $players[$id]['sel'][] = $index;
                 }
                 // Calculate total home handicap
                 $homeHcp += $player->handicap;
             }
         }
         // Get round handicaps
         $roundHandicaps = $curMatch->listRoundHandicaps();
         // Add the home team to the list
         $teams['HOME'] = array('team' => $team, 'players' => $players, 'selPlayers' => $curMatch->listHomePlayers(), 'scores' => $curMatch->listHomeScores(), 'handicap' => $homeHcp, 'hcpPerRound' => 0, 'roundTotals' => array(), 'roundHandicaps' => array(), 'playerTotals' => array(), 'totalHcpPoints' => 0, 'totalPoints' => 0, 'doublesHandicap' => $curMatch instanceof my5280_Match_8BallScotch ? $curMatch->getHomeDoublesHandicap() : null);
         // Get away team information
         $team = $curMatch->getAwayTeam();
         $players = array();
         foreach ($team->listPlayers() as $player) {
             $players[$player->getId()] = array('id' => $player->getId(), 'name' => $player->getName(), 'handicap' => round($player->getHandicap($curMatch->getDate(), $session->getMaxHandicapGames()), 0), 'sel' => array());
         }
         // Indicate the selected players
         $awayHcp = 0;
         foreach ($curMatch->listAwayPlayers() as $index => $player) {
             $id = $player->player_id;
             if ($id) {
                 // Make sure the player is in the list
                 if (!isset($players[$id])) {
                     $players[$id] = array('id' => $id, 'name' => isset($player->player) ? $player->player->getName() : '(Unknown)', 'handicap' => $player->handicap, 'sel' => array($index));
                 } else {
                     $players[$id]['handicap'] = $player->handicap;
                     $players[$id]['sel'][] = $index;
                 }
                 // Calculate total away handicap
                 $awayHcp += $player->handicap;
             }
         }
         // Add the away team to the list
         $teams['AWAY'] = array('team' => $team, 'players' => $players, 'selPlayers' => $curMatch->listAwayPlayers(), 'scores' => $curMatch->listAwayScores(), 'handicap' => $awayHcp, 'hcpPerRound' => 0, 'roundTotals' => array(), 'roundHandicaps' => array(), 'playerTotals' => array(), 'totalHcpPoints' => 0, 'totalPoints' => 0, 'doublesHandicap' => $curMatch instanceof my5280_Match_8BallScotch ? $curMatch->getAwayDoublesHandicap() : null);
         // Process scores
         foreach (array('HOME', 'AWAY') as $key) {
             foreach ($teams[$key]['scores'] as $game => $score) {
                 // Calculate round totals
                 $round = $curMatch->getRoundNumber($game);
                 if (!isset($teams[$key]['roundTotals'][$round])) {
                     // Determine handicap points for the round
                     if (isset($roundHandicaps[$round])) {
                         $hcpPts = $roundHandicaps[$round][$key == 'HOME' ? 0 : 1];
                     } else {
                         $hcpPts = 0;
                     }
                     // Add the handicap points to the round totals, total handicap, and total points for the team
                     $teams[$key]['roundHandicaps'][$round] = $hcpPts;
                     $teams[$key]['roundTotals'][$round] = $hcpPts;
                     $teams[$key]['totalHcpPoints'] += $hcpPts;
                     $teams[$key]['totalPoints'] += $hcpPts;
                 }
                 // Calculate round totals and total points
                 $teams[$key]['roundTotals'][$round] += $score;
                 $teams[$key]['totalPoints'] += $score;
                 // Calculate player totals
                 $player = $key == 'HOME' ? $curMatch->getHomePlayerNumber($game) : $curMatch->getAwayPlayerNumber($game);
                 if (!isset($teams[$key]['playerTotals'][$player])) {
                     $teams[$key]['playerTotals'][$player] = $score;
                 } else {
                     $teams[$key]['playerTotals'][$player] += $score;
                 }
             }
         }
     } else {
         $teams = array('HOME' => null, 'AWAY' => null);
     }
     // Handle flags
     if (!isset($mode) || $mode === null || $curMatch === null) {
         $mode = 'view';
     }
     // Get an array of all players in the system
     $allPlayers = cnRetrieve::individuals();
     foreach (array_keys($allPlayers) as $id) {
         $allPlayers[$id] = my5280::$instance->getPlayer($id);
     }
     uasort($allPlayers, function ($a, $b) {
         return strcasecmp($a->getName(), $b->getName());
     });
     // Determine the path to the template
     $template = null;
     if (isset($league->league_format)) {
         $template = MY5280_PLUGIN_DIR . '/templates/scoresheets/' . $league->league_format . '_' . $mode . '.php';
         if (!file_exists($template)) {
             $template = null;
         }
     }
     // Display the template
     if ($template) {
         include $template;
     } else {
         print "<i>There is no scoresheet for this league.</i>";
     }
 }