Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/Models/V2/Projects/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class Project extends Model implements MediaModel, AuditableContract, EntityMode
'elp_project',
'consortium',
'landowner_agreement',
'nursery_seedlings_goal',
];

public $fileConfiguration = [
Expand Down
1 change: 1 addition & 0 deletions app/Models/V2/Sites/SiteReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class SiteReport extends Model implements MediaModel, AuditableContract, ReportM
'survival_description',
'maintenance_activities',
'planting_status',
'anr_practices',

// virtual (see HasDemographics trait)
'other_workdays_description',
Expand Down
2 changes: 2 additions & 0 deletions config/wri/linked-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@
'pro-elp-project' => ['property' => 'elp_project', 'label' => 'Early Learning Program project', 'input_type' => 'boolean'],
'pro-consortium' => ['property' => 'consortium', 'label' => 'Consortium information', 'input_type' => 'long-text'],
'pro-landowner-agreement' => ['property' => 'landowner_agreement', 'label' => 'Prior agreement with landowner', 'input_type' => 'select', 'multichoice' => false, 'option_list_key' => 'landowner-collection'],
'pro-nursery-seedlings-goal' => ['property' => 'nursery_seedlings_goal', 'label' => 'Nursery seedlings goal', 'input_type' => 'number'],
],
'file-collections' => [
'pro-col-media' => ['property' => 'media', 'label' => 'Media', 'input_type' => 'file', 'multichoice' => true],
Expand Down Expand Up @@ -1347,6 +1348,7 @@
'site-rep-survival-calculation' => ['property' => 'survival_calculation', 'label' => 'Description of Survival Rate Calculation', 'input_type' => 'long-text'],
'site-rep-survival-description' => ['property' => 'survival_description', 'label' => 'Explanation of Survival Rate', 'input_type' => 'long-text'],
'site-rep-maintenance-activities' => ['property' => 'maintenance_activities', 'label' => 'Maintenance Activities', 'input_type' => 'long-text'],
'site-rep-anr-practices' => ['property' => 'anr_practices', 'label' => 'ANR Practices', 'input_type' => 'select', 'multichoice' => true, 'option_list_key' => 'anr-practices'],
],
'file-collections' => [
'site-rep-col-media' => ['property' => 'media', 'label' => 'Media', 'input_type' => 'file', 'multichoice' => true],
Expand Down
33 changes: 33 additions & 0 deletions database/migrations/2026_02_25_210000_add_new_fields.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class () extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('v2_site_reports', function (Blueprint $table) {
$table->string('anr_practices')->nullable();
});
Schema::table('v2_projects', function (Blueprint $table) {
$table->tinyInteger('nursery_seedlings_goal')->nullable();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('v2_site_reports', function (Blueprint $table) {
$table->dropColumn('anr_practices');
});
Schema::table('v2_projects', function (Blueprint $table) {
$table->dropColumn('nursery_seedlings_goal');
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

use App\Models\V2\Forms\FormOptionList;
use App\Models\V2\Forms\FormOptionListOption;
use App\Models\V2\Forms\FormQuestion;
use App\Models\V2\Forms\FormQuestionOption;
use App\Models\V2\I18n\I18nItem;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Str;

return new class () extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
$linkedFields = [
'land-use-systems' => [
'linked_field_key' => ['site-land-use-types', 'pro-land-use-types', 'pro-pit-rst-inv-types', 'pro-pit-land-systems', 'pro-pit-land-use-types', 'pro-pit-land-use-type-distribution', 'org-land-systems'],
'new_options' => ['open-natural-ecosystem'],
],
'land-tenures' => [
'linked_field_key' => ['pro-land-tenure-proj-area', 'site-land-tenures'],
'new_options' => ['state-land'],
],
];

foreach ($linkedFields as $key => $items) {
$formOptionList = FormOptionList::where('key', $key)->first();

if (! $formOptionList) {
continue;
}

foreach ($items['new_options'] as $newOption) {
FormOptionListOption::firstOrCreate([
'form_option_list_id' => $formOptionList->id,
'label' => $newOption,
'slug' => Str::slug($newOption),
]);

$formQuestionIds = FormQuestion::whereIn('linked_field_key', $items['linked_field_key'])->pluck('id');
foreach ($formQuestionIds as $formQuestionId) {
FormQuestionOption::firstOrCreate([
'form_question_id' => $formQuestionId,
'label' => $newOption,
'slug' => Str::slug($newOption),
]);
}
}


}

foreach (FormOptionListOption::all() as $option) {
$option->label_id = $this->generateIfMissingI18nItem($option, 'label');
$option->save();
}
}

private function generateIfMissingI18nItem(Model $target, string $property): ?int
{
$value = trim(data_get($target, $property, false));
$short = strlen($value) <= 256;
if ($value && data_get($target, $property . '_id', true)) {
$i18nItem = I18nItem::create([
'type' => $short ? 'short' : 'long',
'status' => I18nItem::STATUS_DRAFT,
'short_value' => $short ? $value : null,
'long_value' => $short ? null : $value,
]);

return $i18nItem->id;
}

return data_get($target, $property . '_id');
}
};
Loading