mirror of
https://github.com/grocy/grocy.git
synced 2025-10-12 16:44:55 +00:00
Applied PHP-CS-Fixer rules
This commit is contained in:
@@ -5,23 +5,15 @@ namespace Grocy\Services;
|
||||
class ChoresService extends BaseService
|
||||
{
|
||||
const CHORE_ASSIGNMENT_TYPE_IN_ALPHABETICAL_ORDER = 'in-alphabetical-order';
|
||||
|
||||
const CHORE_ASSIGNMENT_TYPE_NO_ASSIGNMENT = 'no-assignment';
|
||||
|
||||
const CHORE_ASSIGNMENT_TYPE_RANDOM = 'random';
|
||||
|
||||
const CHORE_ASSIGNMENT_TYPE_WHO_LEAST_DID_FIRST = 'who-least-did-first';
|
||||
|
||||
const CHORE_PERIOD_TYPE_DAILY = 'daily';
|
||||
|
||||
const CHORE_PERIOD_TYPE_DYNAMIC_REGULAR = 'dynamic-regular';
|
||||
|
||||
const CHORE_PERIOD_TYPE_MANUALLY = 'manually';
|
||||
|
||||
const CHORE_PERIOD_TYPE_MONTHLY = 'monthly';
|
||||
|
||||
const CHORE_PERIOD_TYPE_WEEKLY = 'weekly';
|
||||
|
||||
const CHORE_PERIOD_TYPE_YEARLY = 'yearly';
|
||||
|
||||
public function CalculateNextExecutionAssignment($choreId)
|
||||
@@ -45,33 +37,29 @@ class ChoresService extends BaseService
|
||||
{
|
||||
$assignedUsers[] = $user;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$nextExecutionUserId = null;
|
||||
|
||||
if ($chore->assignment_type == self::CHORE_ASSIGNMENT_TYPE_RANDOM)
|
||||
{
|
||||
// Random assignment and only 1 user in the group? Well, ok - will be hard to guess the next one...
|
||||
// Random assignment and only 1 user in the group? Well, ok - will be hard to guess the next one...
|
||||
if (count($assignedUsers) == 1)
|
||||
{
|
||||
$nextExecutionUserId = array_shift($assignedUsers)->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Randomness in small groups will likely often result in the same user, so try it as long as this is the case
|
||||
// Randomness in small groups will likely often result in the same user, so try it as long as this is the case
|
||||
while ($nextExecutionUserId == null || $nextExecutionUserId == $lastDoneByUserId)
|
||||
{
|
||||
$nextExecutionUserId = $assignedUsers[array_rand($assignedUsers)]->id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else if ($chore->assignment_type == self::CHORE_ASSIGNMENT_TYPE_IN_ALPHABETICAL_ORDER)
|
||||
elseif ($chore->assignment_type == self::CHORE_ASSIGNMENT_TYPE_IN_ALPHABETICAL_ORDER)
|
||||
{
|
||||
usort($assignedUsers, function ($a, $b)
|
||||
{
|
||||
usort($assignedUsers, function ($a, $b) {
|
||||
return strcmp($a->display_name, $b->display_name);
|
||||
});
|
||||
|
||||
@@ -88,24 +76,21 @@ class ChoresService extends BaseService
|
||||
{
|
||||
$nextRoundMatches = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// If nothing has matched, probably it was the last user in the sorted list -> the first one is the next one
|
||||
// If nothing has matched, probably it was the last user in the sorted list -> the first one is the next one
|
||||
if ($nextExecutionUserId == null)
|
||||
{
|
||||
$nextExecutionUserId = array_shift($assignedUsers)->id;
|
||||
}
|
||||
|
||||
}
|
||||
else if ($chore->assignment_type == self::CHORE_ASSIGNMENT_TYPE_WHO_LEAST_DID_FIRST)
|
||||
elseif ($chore->assignment_type == self::CHORE_ASSIGNMENT_TYPE_WHO_LEAST_DID_FIRST)
|
||||
{
|
||||
$row = $this->getDatabase()->chores_execution_users_statistics()->where('chore_id = :1', $choreId)->orderBy('execution_count')->limit(1)->fetch();
|
||||
if ($row != null)
|
||||
{
|
||||
$nextExecutionUserId = $row->user_id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$chore->update([
|
||||
@@ -217,5 +202,4 @@ class ChoresService extends BaseService
|
||||
$choreRow = $this->getDatabase()->chores()->where('id = :1', $choreId)->fetch();
|
||||
return $choreRow !== null;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user