public function presentAllLevels()
 {
     $levels = [];
     foreach ($this->data as $rate) {
         $levels[$rate->level] = ['rate' => $rate->rate];
     }
     for ($i = 1; $i <= Setting::get('max-level'); $i++) {
         if (!isset($levels[$i])) {
             $levels[$i] = ['rate' => isset($levels[Setting::get('max-level')]) ? $this->percentageService->estimateRate($i, $levels[Setting::get('max-level')]->rate) : null, 'rate_estimate' => true];
         }
     }
     ksort($levels);
     return $levels;
 }
 /**
  * If values are missing, estimate them
  * @param object $dragon
  */
 protected function setEstimatesForMax(&$dragon)
 {
     if ($dragon['collect_time'] === null) {
         if ($dragon['max_collect_time']) {
             $dragon['collect_time'] = $this->percentageService->estimateTime(Auth::user()->academyLevel->max_dragon_level, $dragon['max_collect_time']);
             $dragon['collect_time_estimate'] = true;
         }
     }
     if ($dragon['wood_rate'] === null) {
         if ($dragon['max_wood_rate']) {
             $dragon['wood_rate'] = $this->percentageService->estimateRate(Auth::user()->academyLevel->max_dragon_level, $dragon['max_wood_rate']);
             $dragon['wood_rate_estimate'] = true;
             $dragon['wood_user_collect_estimate'] = true;
         }
     }
     if ($dragon['fish_rate'] === null) {
         if ($dragon['max_fish_rate']) {
             $dragon['fish_rate'] = $this->percentageService->estimateRate(Auth::user()->academyLevel->max_dragon_level, $dragon['max_fish_rate']);
             $dragon['fish_rate_estimate'] = true;
             $dragon['fish_user_collect_estimate'] = true;
         }
     }
 }
Exemplo n.º 3
0
 public function allLevelsRate(&$levels, $attribute, $key, $startLevel)
 {
     foreach ($attribute->data as $wRate) {
         $levels[$wRate->level][$key] = $wRate->rate;
         $levels[$wRate->level][$key . '_updated_at'] = $wRate->updated_at;
     }
     $fillTo = $startLevel !== null ? $startLevel : Setting::get('max-level') + 1;
     for ($i = 1; $i < $fillTo; $i++) {
         $levels[$i][$key] = 0;
         $levels[$i][$key . '_updated_at'] = null;
     }
     foreach ($levels as $level => &$data) {
         if ($data[$key] === null) {
             $data[$key] = $this->percentageService->estimateRate($level, $levels[Setting::get('max-level')][$key]);
             $data[$key . '_estimate'] = true;
         }
     }
 }