Add getActiveBatteries function. #733

This commit is contained in:
Korina Cordero 2023-02-06 10:39:30 +00:00
parent 6e9e56b1be
commit 765b3a99b9
5 changed files with 56 additions and 64 deletions

View file

@ -823,11 +823,9 @@ class APIController extends Controller implements LoggedController
// batteries // batteries
$batt_list = []; $batt_list = [];
$batts = $vehicle->getBatteries(); // $batts = $vehicle->getBatteries();
$batts = $vehicle->getActiveBatteries();
foreach ($batts as $batt) foreach ($batts as $batt)
{
// check if battery is active
if ($batt->isActive())
{ {
// TODO: Add warranty_tnv to battery information // TODO: Add warranty_tnv to battery information
$batt_list[] = [ $batt_list[] = [
@ -844,7 +842,6 @@ class APIController extends Controller implements LoggedController
'image_url' => $this->getBatteryImageURL($req, $batt), 'image_url' => $this->getBatteryImageURL($req, $batt),
]; ];
} }
}
// data // data
$data = [ $data = [

View file

@ -45,11 +45,9 @@ class BatteryController extends APIController
// batteries // batteries
$batt_list = []; $batt_list = [];
$batts = $vehicle->getBatteries(); // $batts = $vehicle->getBatteries();
$batts = $vehicle->getActiveBatteries();
foreach ($batts as $batt) foreach ($batts as $batt)
{
// check if battery is active
if ($batt->isActive())
{ {
// TODO: Add warranty_tnv to battery information // TODO: Add warranty_tnv to battery information
$batt_list[] = [ $batt_list[] = [
@ -66,7 +64,6 @@ class BatteryController extends APIController
'image_url' => $this->getBatteryImageURL($req, $batt), 'image_url' => $this->getBatteryImageURL($req, $batt),
]; ];
} }
}
// data // data
$data = [ $data = [

View file

@ -495,10 +495,8 @@ class VehicleController extends Controller
$battery_index = []; $battery_index = [];
// get compatible batteries from selected manufacturer // get compatible batteries from selected manufacturer
foreach ($vobj->getBatteries() as $battery) // foreach ($vobj->getBatteries() as $battery)
{ foreach ($vobj->getActiveBatteries() as $battery)
// need to check if battery is active
if ($battery->isActive())
{ {
$batteries[] = [ $batteries[] = [
'id' => $battery->getID(), 'id' => $battery->getID(),
@ -512,7 +510,6 @@ class VehicleController extends Controller
]; ];
$battery_index[$battery->getID()] = 1; $battery_index[$battery->getID()] = 1;
} }
}
// add all other batteries, because they want options // add all other batteries, because they want options
foreach ($all_batts as $battery) foreach ($all_batts as $battery)

View file

@ -4,6 +4,8 @@ namespace App\Entity;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Criteria;
use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Constraints as Assert;
/** /**
@ -177,4 +179,12 @@ class Vehicle
{ {
return $this->cust_vehicles; return $this->cust_vehicles;
} }
public function getActiveBatteries()
{
$crit = Criteria::create();
$crit->where(Criteria::expr()->eq('flag_active', true));
return $this->batteries->matching($crit);
}
} }

View file

@ -233,14 +233,13 @@ $(function() {
var batteryIds = []; var batteryIds = [];
var battMfgModelSize = [] var battMfgModelSize = []
{% for batt in obj.getBatteries %} {% for batt in obj.getActiveBatteries %}
trow = { trow = {
id: "{{ batt.getID }}", id: "{{ batt.getID }}",
manufacturer: "{{ batt.getManufacturer.getName|default('') }} ", manufacturer: "{{ batt.getManufacturer.getName|default('') }} ",
model: "{{ batt.getModel.getName|default('') }}", model: "{{ batt.getModel.getName|default('') }}",
size: "{{ batt.getSize.getName|default('') }}", size: "{{ batt.getSize.getName|default('') }}",
sell_price: "{{ batt.getSellingPrice }}", sell_price: "{{ batt.getSellingPrice }}",
flag_active: "{{ batt.isActive }}"
}; };
battRows.push(trow); battRows.push(trow);
@ -342,14 +341,6 @@ $(function() {
layout: { layout: {
scroll: true scroll: true
}, },
rows: {
beforeTemplate: function(row, data, index) {
var is_active = data.flag_active;
if (is_active == false) {
$(row).addClass('hide');
}
}
},
columns: [ columns: [
{ {
field: 'id', field: 'id',