Exemple #1
0
 /**
  * @param $sub_category
  *
  * @return BetssonCategoryLeague|null|static
  * @throws \BetssonSports\Exception
  */
 protected function StoreCategoryLeague($sub_category)
 {
     // Load or store category
     if (!($BetssonCategory = BetssonCategory::findOne(['CategoryID' => intval($sub_category->CategoryID), 'LanguageCode' => $sub_category->LanguageCode]))) {
         $BetssonCategory = new BetssonCategory();
         $BetssonCategory->CategoryID = intval($sub_category->CategoryID);
         $BetssonCategory->LanguageCode = $sub_category->LanguageCode;
     }
     // TODO: temporary fix to prevent errors when Betsson provides no category name
     $BetssonCategory->CategoryName = $sub_category->CategoryName ? $sub_category->CategoryName : 'Not provided';
     $BetssonCategory->CacheDate = $sub_category->CacheDate;
     $BetssonCategory->CacheExpireDate = $sub_category->CacheExpireDate;
     $BetssonCategory->ErrorMessage = $sub_category->ErrorMessage;
     if (!$this->storeDataRecord($BetssonCategory)) {
         return false;
     }
     // Load or store category league
     if (!($BetssonCategoryLeague = BetssonCategoryLeague::findOne(['LeagueID' => intval($sub_category->SubCategoryID), 'LanguageCode' => $sub_category->LanguageCode]))) {
         $BetssonCategoryLeague = new BetssonCategoryLeague();
         $BetssonCategoryLeague->LeagueID = intval($sub_category->SubCategoryID);
         $BetssonCategoryLeague->LanguageCode = $sub_category->LanguageCode;
     }
     $BetssonCategoryLeague->CategoryID = intval($sub_category->CategoryID);
     $BetssonCategoryLeague->LeagueName = $sub_category->SubCategoryName;
     $BetssonCategoryLeague->LeagueURL = $sub_category->SubCategoryURL;
     $BetssonCategoryLeague->CacheDate = gmdate("Y-m-d H:i:s", strtotime($sub_category->CacheDate));
     $BetssonCategoryLeague->CacheExpireDate = gmdate("Y-m-d H:i:s", strtotime($sub_category->CacheExpireDate));
     $BetssonCategoryLeague->ErrorMessage = $sub_category->ErrorMessage;
     if (!$this->storeDataRecord($BetssonCategoryLeague)) {
         return false;
     }
     return true;
 }
Exemple #2
0
 /**
  * Update the cache
  *
  * @param bool|false|string $force Force full data retrieval, or update or no data update
  * @param bool|false $expire Expire data in the database
  *
  * @return array process statistics
  */
 public function updateCache($force = false, $expire = false)
 {
     $cache = new Cache($this);
     // Init data if force or no existing categories
     if ($force === true || BetssonCategory::find()->count() == 0) {
         $cache->initData();
     } elseif ($force === false) {
         $cache->updateData();
     }
     // Expire data
     if ($expire) {
         $cache->expireData();
     }
     return $cache->getStatistics();
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCategory()
 {
     return $this->hasOne(BetssonCategory::className(), ['CategoryID' => 'CategoryID'])->inverseOf('leagues');
 }