[Space::USERGROUP_OWNER, Space::USERGROUP_ADMIN]]]; } public function actionIndex() { $subNav = null; if (class_exists(RescueSettingsMenu::class)) { $subNav = RescueSettingsMenu::widget(['space' => $this->contentContainer]); } $fieldSettingsForm = new FieldDefinitionSettingsForm(); $fieldSettingsForm->loadRows(); $displaySettingsForm = new DisplaySettingsForm([ 'contentContainer' => $this->contentContainer, ]); $displaySettingsForm->loadValues(); if (Yii::$app->request->post('DisplaySettingsForm') !== null) { if ($displaySettingsForm->load(Yii::$app->request->post()) && $displaySettingsForm->save()) { $this->view->success(Yii::t('AnimalManagementModule.base', 'Display settings saved.')); return $this->redirect($this->contentContainer->createUrl('/animal_management/settings')); } } if (Yii::$app->request->post('FieldDefinitionSettingsForm') !== null) { if ($fieldSettingsForm->load(Yii::$app->request->post()) && $fieldSettingsForm->save()) { $this->view->success(Yii::t('AnimalManagementModule.base', 'Field settings saved.')); return $this->redirect($this->contentContainer->createUrl('/animal_management/settings')); } } $animalCount = Animal::find()->where(['contentcontainer_id' => $this->contentContainer->contentcontainer_id])->count(); return $this->render('index', [ 'subNav' => $subNav, 'animalCount' => (int)$animalCount, 'fieldSettingsForm' => $fieldSettingsForm, 'displaySettingsForm' => $displaySettingsForm, 'space' => $this->contentContainer, ]); } public function actionSetup() { if (!Yii::$app->request->isPost) { throw new BadRequestHttpException('Invalid request method.'); } if (!$this->contentContainer instanceof Space) { $this->view->error(Yii::t('AnimalManagementModule.base', 'Setup can only be run inside a space.')); return $this->redirect($this->contentContainer->createUrl('/animal_management/settings')); } try { $result = ModuleSetupService::runForSpace($this->contentContainer); $appliedCount = count($result['applied'] ?? []); if ($appliedCount > 0) { $this->view->success(Yii::t('AnimalManagementModule.base', 'Setup completed. Applied {count} migration(s).', [ 'count' => $appliedCount, ])); } else { $this->view->success(Yii::t('AnimalManagementModule.base', 'Setup completed. No pending migrations were found.')); } } catch (\Throwable $e) { Yii::error($e, 'animal_management.setup'); $this->view->error(Yii::t('AnimalManagementModule.base', 'Setup failed. Please check logs and try again.')); } return $this->redirect($this->contentContainer->createUrl('/animal_management/settings')); } }