Ejemplo n.º 1
0
 /**
  * import matches from CSV file
  *
  * @param string $file
  * @param string $delimiter
  */
 function importMatches($file, $delimiter)
 {
     global $leaguemanager;
     $handle = @fopen($file, "r");
     if ($handle) {
         if ("TAB" == $delimiter) {
             $delimiter = "\t";
         }
         // correct tabular delimiter
         $league = $leaguemanager->getLeague($this->league_id);
         $matches = $home_points = $away_points = $home_teams = $away_teams = $custom = array();
         $i = $x = 0;
         while (!feof($handle)) {
             $buffer = fgets($handle, 4096);
             $line = explode($delimiter, $buffer);
             // ignore header and empty lines
             if ($i > 0 && $line) {
                 $date = !empty($line[6]) ? $line[0] . " " . $line[6] : $line[0] . " 00:00";
                 $season = $this->season = $line[1];
                 $match_day = $line[2];
                 $date = trim($date);
                 $location = $line[5];
                 $home_team = $this->getTeamID($line[3]);
                 $away_team = $this->getTeamID($line[4]);
                 $group = $line[7];
                 $match_id = $this->addMatch($date, $home_team, $away_team, $match_day, $location, $this->league_id, $season, $group, '', array());
                 $matches[$match_id] = $match_id;
                 $home_teams[$match_id] = $this->getTeamID($line[3]);
                 $away_teams[$match_id] = $this->getTeamID($line[4]);
                 $score = explode("-", $line[8]);
                 $home_points[$match_id] = $score[0];
                 $away_points[$match_id] = $score[1];
                 $custom = apply_filters('leaguemanager_import_matches_' . $league->sport, $custom, $line, $match_id);
                 $x++;
             }
             $i++;
         }
         $this->updateResults($league->id, $matches, $home_points, $away_points, $home_teams, $away_teams, $custom, false);
         fclose($handle);
         parent::setMessage(sprintf(__('%d Matches imported', 'leaguemanager'), $x));
     }
 }
Ejemplo n.º 2
0
 /**
  * save match statistics
  *
  * The first parameter is simply the match ID. The second is a multidimensional array holding all statistics.
  *
  * @param int $match_id
  * @param array $stats
  * @return string
  */
 function save($match_id, $stats)
 {
     global $wpdb, $leaguemanager;
     $match = $leaguemanager->getMatch($match_id);
     $custom = $match->custom;
     foreach ((array) $stats as $stat => $data) {
         $custom[$stat] = array_values($data);
     }
     $custom['hasStats'] = true;
     $wpdb->query($wpdb->prepare("UPDATE {$wpdb->leaguemanager_matches} SET `custom` = '%s' WHERE `id` = '%s'", maybe_serialize($custom), $match_id));
     parent::setMessage(__('Saved Statstics', 'leaguemanager'));
     parent::printMessage();
 }
Ejemplo n.º 3
0
 /**
  * Load template for user display. First the current theme directory is checked for a template
  * before defaulting to the plugin
  *
  * @param string $template Name of the template file (without extension)
  * @param array $vars Array of variables name=>value available to display code (optional)
  * @return the content
  */
 function loadTemplate($template, $vars = array())
 {
     global $leaguemanager, $lmStats, $championship;
     extract($vars);
     ob_start();
     if (file_exists(get_template_directory() . "/leaguemanager/{$template}.php")) {
         include get_template_directory() . "/leaguemanager/{$template}.php";
     } elseif (file_exists(LEAGUEMANAGER_PATH . "/templates/" . $template . ".php")) {
         include LEAGUEMANAGER_PATH . "/templates/" . $template . ".php";
     } else {
         parent::setMessage(sprintf(__('Could not load template %s.php', 'leaguemanager'), $template), true);
         parent::printMessage();
     }
     $output = ob_get_contents();
     ob_end_clean();
     return $output;
 }