Skip to content
Open
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
40 changes: 40 additions & 0 deletions controllers/Countries.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace Winter\Test\Controllers;

use Input;
use BackendMenu;
use Backend\Classes\Controller;

Expand All @@ -24,4 +25,43 @@ public function __construct()

BackendMenu::setContext('Winter.Test', 'test', 'countries');
}

public function onGetDangerComputedValue()
{
$rowData = Input::get('rowData');
$dangerScore = 0;

switch ($rowData['type']) {
default:
$dangerScore += 1;
break;
case 'Minor':
$dangerScore += 5;
break;
case 'Major':
$dangerScore += 10;
break;
case 'Capital':
$dangerScore += 20;
break;
}

if (is_numeric($rowData['rating'])) {
$dangerScore += (int) $rowData['rating'];
}

if ($dangerScore >= 30) {
return 'Extremely Dangerous';
} else if ($dangerScore >= 20) {
return 'Dangerous';
} else if ($dangerScore >= 15) {
return 'Maintain Caution';
} else if ($dangerScore >= 10) {
return 'Keep Alert';
} else if ($dangerScore >= 5) {
return 'Low Risk';
} else {
return 'No Risk';
}
}
}
6 changes: 6 additions & 0 deletions models/country/fields.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,18 @@ tabs:
validation:
required:
message: Please select a type
danger:
title: Danger Index
type: computed
dependsOn: [rating, type]
callback: onGetDangerComputedValue
locations:
tab: Related
label: Locations
prompt: Add new location
span: full
type: repeater
minItems: 1
form:
fields:
country:
Expand Down