name = $form_model->getItem("name"); $model->version = $form_model->getItem("version"); $model->description = $form_model->getItem("description"); $model->author = $form_model->getItem("author"); $model->status = $form_model->getItem("status"); $model->path_to_archive = $form_model->getItem("path_to_archive"); $model->dependence = $form_model->getItem("dependence"); $model->slug = $form_model->getItem("slug"); $model->type = $form_model->getItem("type"); if ($model->save()) { return $model; } return false; } public function update(FormModel $form_model, ModuleShop $model): false|ModuleShop { $model->name = $form_model->getItem("name"); $model->version = $form_model->getItem("version"); $model->description = $form_model->getItem("description"); $model->author = $form_model->getItem("author"); $model->status = $form_model->getItem("status"); $model->path_to_archive = $form_model->getItem("path_to_archive"); $model->dependence = $form_model->getItem("dependence"); $model->slug = $form_model->getItem("slug"); $model->type = $form_model->getItem("type"); if ($model->save()) { return $model; } return false; } public static function getAllDependencies(string $slug, array $depArr = []): array { $query = ModuleShop::query(); $query->select('ms1.*') ->from('module_shop as ms1') ->leftJoin('module_shop as ms2', function ($join) { $join->on('ms1.slug', '=', 'ms2.slug') ->on('ms1.id', '<', 'ms2.id'); }) ->where('ms2.slug', '=', null); $query->where('ms1.slug', $slug); $module = $query->first(); if ($module){ if ($module->dependence !== null){ $moduleDependencies = explode(",", $module->dependence); foreach ($moduleDependencies as $dependency){ if (!in_array($dependency, $depArr)){ $depArr[] = $dependency; $depArrTmp = self::getAllDependencies($dependency, $depArr); foreach ($depArrTmp as $item){ if (!in_array($item, $depArr)){ $depArr[] = $item; } } } } } } return array_diff($depArr, [$slug]); } }