openstamanager/modules/checklists/src/ChecklistItem.php

69 lines
1.8 KiB
PHP
Raw Normal View History

2019-07-26 18:05:19 +02:00
<?php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
2021-01-20 15:08:51 +01:00
* Copyright (C) DevCode s.r.l.
2020-09-07 15:04:06 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2019-07-26 18:05:19 +02:00
2019-07-29 13:16:55 +02:00
namespace Modules\Checklists;
2019-07-26 18:05:19 +02:00
use Common\SimpleModelTrait;
use Illuminate\Database\Eloquent\Model;
2019-07-26 18:05:19 +02:00
use Traits\HierarchyTrait;
2019-07-29 13:16:55 +02:00
class ChecklistItem extends Model
2019-07-26 18:05:19 +02:00
{
use SimpleModelTrait;
2019-07-26 18:05:19 +02:00
use HierarchyTrait;
protected static $parent_identifier = 'id_parent';
protected $table = 'zz_checklist_items';
/**
* Crea un nuovo elemento della checklist.
*
* @param string $contenuto
* @param int $id_parent
2019-07-26 18:05:19 +02:00
*
* @return self
*/
public static function build(Checklist $checklist, $contenuto, $id_parent = null)
{
$model = new static();
2019-07-26 18:05:19 +02:00
$model->checklist()->associate($checklist);
$model->id_parent = $id_parent;
$model->content = $contenuto;
2019-07-30 16:50:10 +02:00
$model->findOrder();
2019-07-26 18:05:19 +02:00
$model->save();
return $model;
}
/* Relazioni Eloquent */
public function checklist()
{
return $this->belongsTo(Checklist::class, 'id_checklist');
}
2019-07-30 16:50:10 +02:00
protected function findOrder()
{
$this->order = orderValue($this->table, 'id_checklist', $this->id_checklist);
}
2019-07-26 18:05:19 +02:00
}