Пример #1
0
 public function testStatistics()
 {
     $this->PDO->exec('INSERT INTO `' . PREFIX . 'training` (`distance`, `s`, `accountid`) VALUES (10, 3600, 1)');
     $firstActivity = $this->PDO->lastInsertId();
     $this->PDO->exec('INSERT INTO `' . PREFIX . 'activity_equipment` (`activityid`, `equipmentid`) VALUES (' . $firstActivity . ', ' . $this->EquipmentIDs[0] . ')');
     $this->PDO->exec('INSERT INTO `' . PREFIX . 'activity_equipment` (`activityid`, `equipmentid`) VALUES (' . $firstActivity . ', ' . $this->EquipmentIDs[1] . ')');
     $this->PDO->exec('INSERT INTO `' . PREFIX . 'training` (`distance`, `s`, `accountid`) VALUES (20, 7200, 1)');
     $this->PDO->exec('INSERT INTO `' . PREFIX . 'activity_equipment` (`activityid`, `equipmentid`) VALUES (' . $this->PDO->lastInsertId() . ', ' . $this->EquipmentIDs[1] . ')');
     $Updater = new StatisticsUpdater($this->PDO, 1);
     $this->assertEquals(3, $Updater->run());
     $this->assertEquals(array(10, 3600), $this->PDO->query('SELECT `distance`, `time` FROM `' . PREFIX . 'equipment` WHERE `id`=' . $this->EquipmentIDs[0])->fetch(PDO::FETCH_NUM));
     $this->assertEquals(array(30, 10800), $this->PDO->query('SELECT `distance`, `time` FROM `' . PREFIX . 'equipment` WHERE `id`=' . $this->EquipmentIDs[1])->fetch(PDO::FETCH_NUM));
     $this->assertEquals(array(0, 0), $this->PDO->query('SELECT `distance`, `time` FROM `' . PREFIX . 'equipment` WHERE `id`=' . $this->EquipmentIDs[2])->fetch(PDO::FETCH_NUM));
 }
Пример #2
0
 /**
  * Recalculate equipment statistics
  */
 protected function recalculateEquipmentStatistics()
 {
     $Updater = new Equipment\StatisticsUpdater(\DB::getInstance(), \SessionAccountHandler::getId());
     $num = $Updater->run();
     if ($num === false) {
         $this->addMessage(__('There was a problem while recalculating your equipment statistics'));
     } else {
         $this->addMessage(sprintf(__('Statistics have been recalculated for all <strong>%s</strong> pieces of equipment.'), $num));
     }
 }