commands/XmlSoccerController.php
public function actionImportLeagues()
    {
        $client = new Client([
            'apiKey' => $this->apiKey
        ]);

        $leagues = $client->getAllLeagues();
        $count = 0;
        foreach ($leagues as $league) {
            $dbLeague = Yii::createObject([
                'class' => $this->leagueClass,
                'interface_id' => ArrayHelper::getValue($league, 'Id'),
                'name' => ArrayHelper::getValue($league, 'Name'),
                'country' => ArrayHelper::getValue($league, 'Country'),
                'historical_data' => constant(
                    '\drsdre\yii\xmlsoccer\models\League::HISTORICAL_DATA_' .
                    strtoupper(ArrayHelper::getValue($league, 'Historical_Data', 'no'))
                ),
                'fixtures' => filter_var(
                    strtolower(ArrayHelper::getValue($league, 'Fixtures', 'no')),
                    FILTER_VALIDATE_BOOLEAN
                ),
                'livescore' => filter_var(
                    strtolower(ArrayHelper::getValue($league, 'Livescore', 'no')),
                    FILTER_VALIDATE_BOOLEAN
                ),
                'number_of_matches' => ArrayHelper::getValue($league, 'NumberOfMatches', 0),
                'latest_match' => ArrayHelper::getValue($league, 'LatestMatch'),
                'is_cup' => filter_var(
                    strtolower(ArrayHelper::getValue($league, 'IsCup', 'no')),
                    FILTER_VALIDATE_BOOLEAN
                )
            ]);
            /* @var $dbLeague \drsdre\yii\xmlsoccer\models\League */

            if (!$dbLeague->save()) {
                $this->stderr("Failed to import league '{$dbLeague->name}': ", Console::FG_RED);
                $this->stderr("\n");
                foreach ($dbLeague->errors as $attribute => $errors) {
                    foreach ($errors as $error) {
                        $this->stderr("$attribute: $error", Console::BG_YELLOW, Console::FG_BLACK);
                        $this->stderr("\n");
                    }
                }
                $this->stderr("\n");
            } else {
                $count++;
                $this->stdout("League '{$dbLeague->name}' inserted\n");
            }
        }

        $this->stdout("\n");
        $this->stdout("$count leagues imported", Console::FG_GREEN);
        $this->stdout("\n");

        return ExitCode::OK;
    }
public function actionImportLeagues()
    {
        $client = new Client([
            'apiKey' => $this->apiKey
        ]);

        $leagues = $client->getAllLeagues();
        $count = 0;
        foreach ($leagues as $league) {
            $dbLeague = Yii::createObject([
                'class' => $this->leagueClass,
                'interface_id' => ArrayHelper::getValue($league, 'Id'),
                'name' => ArrayHelper::getValue($league, 'Name'),
                'country' => ArrayHelper::getValue($league, 'Country'),
                'historical_data' => constant(
                    '\drsdre\yii\xmlsoccer\models\League::HISTORICAL_DATA_' .
                    strtoupper(ArrayHelper::getValue($league, 'Historical_Data', 'no'))
                ),
                'fixtures' => filter_var(
                    strtolower(ArrayHelper::getValue($league, 'Fixtures', 'no')),
                    FILTER_VALIDATE_BOOLEAN
                ),
                'livescore' => filter_var(
                    strtolower(ArrayHelper::getValue($league, 'Livescore', 'no')),
                    FILTER_VALIDATE_BOOLEAN
                ),
                'number_of_matches' => ArrayHelper::getValue($league, 'NumberOfMatches', 0),
                'latest_match' => ArrayHelper::getValue($league, 'LatestMatch'),
                'is_cup' => filter_var(
                    strtolower(ArrayHelper::getValue($league, 'IsCup', 'no')),
                    FILTER_VALIDATE_BOOLEAN
                )
            ]);
            /* @var $dbLeague \drsdre\yii\xmlsoccer\models\League */

            if (!$dbLeague->save()) {
                $this->stderr("Failed to import league '{$dbLeague->name}': ", Console::FG_RED);
                $this->stderr("\n");
                foreach ($dbLeague->errors as $attribute => $errors) {
                    foreach ($errors as $error) {
                        $this->stderr("$attribute: $error", Console::BG_YELLOW, Console::FG_BLACK);
                        $this->stderr("\n");
                    }
                }
                $this->stderr("\n");
            } else {
                $count++;
                $this->stdout("League '{$dbLeague->name}' inserted\n");
            }
        }

        $this->stdout("\n");
        $this->stdout("$count leagues imported", Console::FG_GREEN);
        $this->stdout("\n");

        return ExitCode::OK;
    }
public function actionImportLeagues ( ) { $ client = new Client ( [ 'apiKey' => $ this -> apiKey ] ) ; $ leagues = $ client -> getAllLeagues ( ) ; $ count = 0 ; foreach ( $ leagues as $ league ) { $ dbLeague = Yii :: createObject ( [ 'class' => $ this -> leagueClass , 'interface_id' => ArrayHelper :: getValue ( $ league , 'Id' ) , 'name' => ArrayHelper :: getValue ( $ league , 'Name' ) , 'country' => ArrayHelper :: getValue ( $ league , 'Country' ) , 'historical_data' => constant ( '\drsdre\yii\xmlsoccer\models\League::HISTORICAL_DATA_' . strtoupper ( ArrayHelper :: getValue ( $ league , 'Historical_Data' , 'no' ) ) ) , 'fixtures' => filter_var ( strtolower ( ArrayHelper :: getValue ( $ league , 'Fixtures' , 'no' ) ) , FILTER_VALIDATE_BOOLEAN ) , 'livescore' => filter_var ( strtolower ( ArrayHelper :: getValue ( $ league , 'Livescore' , 'no' ) ) , FILTER_VALIDATE_BOOLEAN ) , 'number_of_matches' => ArrayHelper :: getValue ( $ league , 'NumberOfMatches' , 0 ) , 'latest_match' => ArrayHelper :: getValue ( $ league , 'LatestMatch' ) , 'is_cup' => filter_var ( strtolower ( ArrayHelper :: getValue ( $ league , 'IsCup' , 'no' ) ) , FILTER_VALIDATE_BOOLEAN ) ] ) ; /* @var $dbLeague \drsdre\yii\xmlsoccer\models\League */ if ( ! $ dbLeague -> save ( ) ) { $ this -> stderr ( "Failed to import league '{$dbLeague->name}': " , Console :: FG_RED ) ; $ this -> stderr ( "\n" ) ; foreach ( $ dbLeague -> errors as $ attribute => $ errors ) { foreach ( $ errors as $ error ) { $ this -> stderr ( "$attribute: $error" , Console :: BG_YELLOW , Console :: FG_BLACK ) ; $ this -> stderr ( "\n" ) ; } } $ this -> stderr ( "\n" ) ; } else { $ count ++ ; $ this -> stdout ( "League '{$dbLeague->name}' inserted\n" ) ; } } $ this -> stdout ( "\n" ) ; $ this -> stdout ( "$count leagues imported" , Console :: FG_GREEN ) ; $ this -> stdout ( "\n" ) ; return ExitCode :: OK ; }
Import all leagues from XMLSoccer interface
@return integer Exit code
@throws \yii\base\InvalidConfigException
Import all leagues from XMLSoccer interface