2019-10-04 17:00:53 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Modules\CategorieDocumentali;
|
|
|
|
|
|
|
|
use Common\Model;
|
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
|
|
|
|
class Categoria extends Model
|
|
|
|
{
|
|
|
|
use SoftDeletes;
|
|
|
|
|
|
|
|
protected $table = 'do_categorie';
|
|
|
|
|
|
|
|
public static function build($descrizione)
|
|
|
|
{
|
|
|
|
$model = parent::build();
|
|
|
|
$model->descrizione = $descrizione;
|
|
|
|
|
|
|
|
$model->save();
|
|
|
|
|
|
|
|
$gruppi = database()->fetchArray('SELECT `id` FROM `zz_groups`');
|
2019-12-19 13:37:10 +01:00
|
|
|
foreach($gruppi as $array) {
|
|
|
|
foreach($array as $k=>$v) {
|
|
|
|
$newArray[$k] = $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$model->syncPermessi($newArray);
|
2019-10-04 17:00:53 +02:00
|
|
|
|
|
|
|
return $model;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function syncPermessi(array $groups)
|
|
|
|
{
|
|
|
|
$groups[] = 1;
|
2019-12-19 13:37:10 +01:00
|
|
|
|
2019-10-04 17:00:53 +02:00
|
|
|
$database = database();
|
|
|
|
$database->sync('do_permessi', ['id_categoria' => $this->id], [
|
|
|
|
'id_gruppo' => $groups,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|