Skip to content

Instantly share code, notes, and snippets.

@lshulyay
Created July 25, 2014 18:52
Show Gist options
  • Save lshulyay/73178e34a08b8e8e1089 to your computer and use it in GitHub Desktop.
Save lshulyay/73178e34a08b8e8e1089 to your computer and use it in GitHub Desktop.
Having an issue updating a record...it seems to be ignoring $propertiesToUpdate and trying to update properties that are set after model load and are NOT in the db. Error message: [2014-07-25 18:36:04] local.ERROR: exception 'Illuminate\Database\QueryException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'racePos' in 'fi…
<?php
function depleteEnergy($interval) {
Log::info('depleting snail energy. Snail ID: ' . $this->snailID);
// convert calories to Joules
// CurrentRMR is in JOULES
// Here we convert the target RMR (which is Joules to deplete PER HOUR) to Carbohydrates, Fat, and Protein. Then we multiply that by the Interval at which this job runs after converting it to hours.
$carbsToDeplete = Utility::JoulesToCarbs(Utility::CalcTargetPercentageValue($this->carbohydratesIdealPercentage, $this->currentRMR)) * Utility::SecondsToHours($interval);
$fatToDeplete = Utility::JoulesToFat(Utility::CalcTargetPercentageValue($this->fatIdealPercentage, $this->currentRMR)) * Utility::SecondsToHours($interval);
$proteinToDeplete = Utility::JoulesToProtein(Utility::CalcTargetPercentageValue($this->proteinIdealPercentage, $this->currentRMR)) * Utility::SecondsToHours($interval);
// Deplete the actual macros from the current values
$this->carbohydratesCurrent -= $carbsToDeplete;
$this->fatCurrent -= $fatToDeplete;
$this->proteinCurrent -= $proteinToDeplete;
// Update these values in the DB
$propertiesToUpdate = array(
"carbohydratesCurrent" => $this->carbohydratesCurrent,
"fatCurrent" => $this->fatCurrent,
"proteinCurrent" => $this->proteinCurrent
);
$this->updateSnail($propertiesToUpdate);
// Convert each macro BACK to joules
$totalJoulesDepleted = Utility::CarbsToJoules($carbsToDeplete) + Utility::FatToJoules($fatToDeplete) + Utility::FatToJoules($proteinToDeplete);
// Count total daily depleted joules (including things like races or other events where depleted Joules are recorded) and create an event log for this.
$this->CountDailyDepleted($totalJoulesDepleted);
}
function updateSnail($propertiesToUpdate) {
$this->update($propertiesToUpdate);
$currentJarID = array_get($propertiesToUpdate, 'currentJarID');
if (isset($currentJarID)) {
$jarController = new JarController();
$jarController->findJar($currentJarID)->checkBreedingJar();
}
return true;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment