1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2025-02-23 14:57:46 +01:00

Registrazione utente check

This commit is contained in:
Thomas Zilio 2019-07-30 17:44:15 +02:00
parent db91453a20
commit ca39c354c3
4 changed files with 18 additions and 6 deletions

View File

@ -174,7 +174,7 @@ elseif (filter('op') == 'toggle_check') {
$check = Check::find($check_id);
if (!empty($check) && $check->assignedUsers->pluck('id')->search($user->id) !== false) {
$check->toggleCheck();
$check->toggleCheck($user);
} else {
flash()->error(tr('Impossibile cambiare lo stato del check!'));
}

View File

@ -10,7 +10,7 @@ function renderChecklist($check, $level = 0)
<input type="checkbox" value="'.(!empty($check->checked_at) ? '1' : '0').'" '.(!empty($check->checked_at) ? 'checked' : '').'>
<span class="text">'.$check->content.'</span>
<span class="badge">'.(!empty($check->checked_at) ? timestampFormat($check->checked_at).' - '.$check->user->username : '').'</span>';
<span class="badge">'.(!empty($check->checked_at) ? timestampFormat($check->checked_at).' - '.$check->checkUser->username : '').'</span>';
if ($level == 0) {
$result .= '
@ -20,11 +20,14 @@ function renderChecklist($check, $level = 0)
</span>';
}
$result .= '
if (empty($check->user) || $check->user->id == $user->id) {
$result .= '
<div class="tools">
<i class="fa fa-trash-o check-delete"></i>
</div>
</div>';
}
$result .= '
<ul class="todo-list">';
$children = $check->children;

View File

@ -52,16 +52,18 @@ class Check extends Model
return $model;
}
public function toggleCheck()
public function toggleCheck(User $user)
{
$checked_at = $this->checked_at ? null : date('Y-m-d H:i:s');
$this->checked_at = $checked_at;
$this->checkUser()->associate($user);
$this->save();
$children = $this->children;
while (!$children->isEmpty()) {
$child = $children->shift();
$child->checked_at = $checked_at;
$child->checkUser()->associate($user);
$child->save();
$children = $children->merge($child->children);
@ -113,6 +115,11 @@ class Check extends Model
return $this->belongsTo(User::class, 'created_by');
}
public function checkUser()
{
return $this->belongsTo(User::class, 'checked_by');
}
public function assignedUsers()
{
return $this->belongsToMany(User::class, 'zz_check_user', 'id_check', 'id_utente');

View File

@ -213,6 +213,7 @@ CREATE TABLE IF NOT EXISTS `zz_checks` (
`id_plugin` int(11),
`id_record` int(11) NOT NULL,
`created_by` int(11) NOT NULL,
`checked_by` int(11) ,
`checked_at` TIMESTAMP NULL,
`content` TEXT,
`id_parent` int(11),
@ -221,6 +222,7 @@ CREATE TABLE IF NOT EXISTS `zz_checks` (
FOREIGN KEY (`id_module`) REFERENCES `zz_modules`(`id`) ON DELETE CASCADE,
FOREIGN KEY (`id_plugin`) REFERENCES `zz_plugins`(`id`) ON DELETE CASCADE,
FOREIGN KEY (`created_by`) REFERENCES `zz_users`(`id`) ON DELETE CASCADE,
FOREIGN KEY (`checked_by`) REFERENCES `zz_users`(`id`) ON DELETE CASCADE,
FOREIGN KEY (`id_parent`) REFERENCES `zz_checks`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB;