Example #1
0
 /**
  * Adds meta boxes
  * @link https://github.com/gizburdt/cuztom/wiki/Meta-Boxes
  */
 public function add_meta_boxes()
 {
     $apiHandler = WP_SUAPI_API_Handler::GET_INITIALIZED_API_HANDLER();
     $this->post_types['team']->add_meta_box('su_meta', 'swiss unihockey Meta Data', array(array('name' => 'showsuhvdetails', 'label' => __('swiss unihockey ranking and fixtures', 'wp-suapi'), 'description' => __('Show swiss unihockey ranking and fixtures', 'wp-suapi'), 'type' => 'yesno'), array('name' => 'suhvteamid', 'label' => __('swiss unihockey Team ID', 'wp-suapi'), 'description' => __('Needed for API at swissunihockey.ch', 'wp-suapi'), 'type' => 'select', 'options' => array_reduce($apiHandler->getTeamsForClub(new Club(get_option("wp-suapi_api-club"), "EMPTY_CLUB_CALL")), function ($result, $item) {
         $result[$item->getTeamId()] = $item->getTeamName();
         return $result;
     }, array()), 'show_admin_column' => true, 'admin_column_sortable' => true, 'admin_column_filter' => true)));
     $this->post_types['team']->add_meta_box('team_meta', 'Team Meta', array(array('name' => 'showplayerdetails', 'label' => __('Link to player profiles', 'wp-suapi'), 'description' => __('Show detailed player profiles', 'wp-suapi'), 'type' => 'yesno'), array('name' => 'newscategory', 'label' => __('Select Category', 'wp-suapi'), 'description' => __('Select which news category should be assigned to this team', 'wp-suapi'), 'type' => 'term_select', 'args' => array('taxonomy' => 'category')), array('name' => 'emailkontakt', 'label' => 'E-Mail Kontakt', 'description' => 'E-Mail Kontakt', 'type' => 'text', 'show_admin_column' => false, 'admin_column_sortable' => false, 'admin_column_filter' => false), array('name' => 'agegroup', 'label' => 'Jahrgänge', 'description' => 'Jahrgänge für das Team', 'type' => 'text', 'show_admin_column' => false, 'admin_column_sortable' => false, 'admin_column_filter' => false)));
 }
 public function rankingTable($atts)
 {
     $a = shortcode_atts(array('year' => 0, 'team' => 0, 'type' => 1, 'highlight' => 1), $atts);
     if ($a['year'] == 0 || $a['team'] == 0) {
         return "";
     }
     $apiHandler = \WP_SUAPI\WP_SUAPI_API_Handler::GET_INITIALIZED_API_HANDLER();
     $apiHandler->setYearForQuery($a['year']);
     $rankingsTable = $apiHandler->getRankingForTeam(new Team($a['team'], ''));
     $args = array('rankings' => $rankingsTable->getRankings());
     if ($a['highlight'] == 1) {
         $args = array_merge($args, array('team' => $apiHandler->getTeamById($a['team'])));
     }
     switch ($a['type']) {
         case 1:
             return $this->twig->render('wp-suapi-rankingtable-1.twig.html', $args);
         case 2:
             return $this->twig->render('wp-suapi-rankingtable-2.twig.html', $args);
         case 3:
             return $this->twig->render('wp-suapi-rankingtable-3.twig.html', $args);
         default:
             return "";
     }
 }
 /**
  * Build settings fields
  * @return array Fields to be displayed on settings page
  */
 private function settings_fields()
 {
     $settings['apiconnection'] = array('title' => __('API Connection', 'wp-suapi'), 'description' => __('swiss unihockey API Connection', 'wp-suapi'), 'fields' => array(array('id' => 'api-url', 'label' => __('API URL', 'wp-suapi'), 'description' => __('URL to the swiss unihockey API.', 'wp-suapi'), 'type' => 'text', 'default' => 'https://api-v2.swissunihockey.ch/api', 'placeholder' => __('https://api-v2.swissunihockey.ch/api', 'wp-suapi')), array('id' => 'api-key', 'label' => __('API Key', 'wp-suapi'), 'description' => __('Key to the API', 'wp-suapi'), 'type' => 'text', 'default' => '', 'placeholder' => __('Your personal key', 'wp-suapi')), array('id' => 'api-version', 'label' => __('API Version', 'wp-suapi'), 'description' => __('Select the API Version', 'wp-suapi'), 'type' => 'select', 'options' => array('v1' => 'V1', 'v2' => 'V2'), 'default' => 'v2')));
     if ($this->check_api_connection_setup()) {
         try {
             $apiHandler = WP_SUAPI_API_Handler::GET_INITIALIZED_API_HANDLER();
             if ($apiHandler->isConnected()) {
                 $allClubs = array_reduce($apiHandler->getClubs(), function (&$result, $item) {
                     $result[$item->getClubId()] = $item->getClubName();
                     return $result;
                 }, array());
                 $settings['apiconnection']['fields'][] = array('id' => 'api-club', 'label' => __('swiss unihockey Club', 'wp-suapi'), 'description' => __('Select the swiss unihockey Club', 'wp-suapi'), 'type' => 'select', 'options' => $allClubs, 'default' => '');
             } else {
                 $settings['apiconnection']['fields'][] = array('id' => 'api-club', 'label' => __('swiss unihockey Club', 'wp-suapi'), 'description' => __('Select the swiss unihockey Club', 'wp-suapi'), 'type' => 'select', 'options' => array('noConnection' => 'No Connection'), 'default' => 'noConnection');
             }
         } catch (\GuzzleHttp\Exception\RequestException $e) {
             new Cuztom_Notice($this->_token . " RequestException: " . $e->getMessage() . " - " . $e->getResponse()->getReasonPhrase(), 'error');
         }
     }
     $settings['extra'] = array('title' => __('Extra', 'wp-suapi'), 'description' => __('WP SUAPI Plugin settings', 'wp-suapi'), 'fields' => array(array('id' => 'extra-usecache', 'label' => __('Use cache', 'wp-suapi'), 'description' => __('Cache the API results', 'wp-suapi'), 'type' => 'checkbox', 'default' => 'checked')));
     $settings = apply_filters($this->parent->_token . '_settings_fields', $settings);
     return $settings;
 }
 /**
  * Test fixture list for team query from api handler
  * @return void
  */
 public function testGetFixtureListForLigaTeam()
 {
     self::$apiHandler->setYearForQuery(2015);
     $fixtureList = self::$apiHandler->getFixtureListForTeam(new Team(428988, "Herren 3. Liga Gruppe 10"));
     $this->assertInstanceOf('WP_SUAPI\\Object\\Fixture', $fixtureList->getFixtures()[0]);
 }