2019-07-26 18:05:19 +02:00
|
|
|
<?php
|
|
|
|
|
2019-07-29 13:16:55 +02:00
|
|
|
namespace Modules\Checklists;
|
2019-07-26 18:05:19 +02:00
|
|
|
|
|
|
|
use Common\Model;
|
|
|
|
use Traits\HierarchyTrait;
|
|
|
|
|
2019-07-29 13:16:55 +02:00
|
|
|
class ChecklistItem extends Model
|
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.
|
|
|
|
*
|
2019-07-29 13:16:55 +02:00
|
|
|
* @param Checklist $checklist
|
2019-07-26 18:05:19 +02:00
|
|
|
* @param string $contenuto
|
|
|
|
* @param int $id_parent
|
|
|
|
*
|
|
|
|
* @return self
|
|
|
|
*/
|
|
|
|
public static function build(Checklist $checklist, $contenuto, $id_parent = null)
|
|
|
|
{
|
|
|
|
$model = parent::build();
|
|
|
|
|
|
|
|
$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
|
|
|
}
|