public function getItems() { $db =& JFactory::getDbo(); $items = parent::getItems(); $cmd = $this->getState(strtolower($this->model_key) . '.cmd'); switch ($cmd) { case 'subscription': foreach ($items as $item) { $query = $db->getQuery(true)->select('h.vin')->from('fleet_trip as h')->leftJoin('#__fleet_trip_subscription as b on b.trip_id = h.id')->where('b.subscription_id = ' . $item->id)->order('h.id desc limit 1'); $db->setQuery($query); //var_dump((string)$query); //var_dump($vin); $vin = $db->loadResult(); if (!$vin) { $item->match = "N/A"; } else { $item->match = $db->loadResult() == $item->vin ? 'Yes' : 'No'; //var_dump($item->vin); } $query = $db->getQuery(true)->select('min(DATE(h.start_date)) as start, max(DATE(h.end_date)) as end')->from('fleet_trip as h')->leftJoin('#__fleet_trip_subscription as b on b.trip_id = h.id')->where('b.subscription_id = ' . $item->id); $db->setQuery($query); //var_dump((string)$query); $ret = $db->loadObject(); if (!$ret) { $item->date_range = 'N/A'; } else { $item->date_range = sprintf("%s <br> %s", $ret->start, $ret->end); } } break; case 'batchfileload': break; } return $items; }
protected function populateState() { $app = JFactory::getApplication(); $trend = JRequest::getCmd('trend', 'overall'); $this->setState(strtolower($this->model_key) . '.trend', $trend); parent::populateState(); }
public function getItems() { $items = parent::getItems(); $cmd = $this->getState(strtolower($this->model_key) . '.cmd'); $window = $this->getState(strtolower($this->model_key) . '.window'); $trend = $this->getState(strtolower($this->model_key) . '.trend'); switch ($cmd) { case 'vehicle': foreach ($items as &$item) { $ret = $this->getVehicleFuelUsage($item, $window); #var_dump($ret); $item->gallons = $ret[0]; $item->mpg = $ret[1]; } break; case 'driverdetail': foreach ($items as &$item) { #$item->gallons = $this->getVehicleFuelUsage($item, $window); #$item->mpg = $this->calcMPG($item); $item->accel_score = $this->getDriverAccelScore($item, $window, 'yes', 'x'); $item->decel_score = $this->getDriverAccelScore($item, $window, 'no', 'x'); $item->hard_turns = $this->getDriverAccelScore($item, $window, 'both', 'y'); $item->speed_score = $this->getDriverSpeedScore($item, $window); $item->overall = $this->getOverall($item); } break; case 'vehicletrend': foreach ($items as &$item) { $item->mpg = $this->getMpgArray($item, $window); } $this->reduce_to_scope($items, 'mpg'); break; case 'drivertrend': #TODO: remove when drop downs are complete foreach ($items as &$item) { $item->gallons = $this->getVehicleFuelUsage($item, $window); #$item->mpg = $this->calcMPG($item); if ($trend == "accel" || $trend == "overall") { $item->accel_score = $this->getDriverAccelArray($item, $window, 'yes', 'x'); } if ($trend == 'decel' || $trend == 'overall') { $item->decel_score = $this->getDriverAccelArray($item, $window, 'no', 'x'); } if ($trend == 'hard_turns' || $trend == 'overall') { $item->hard_turns = $this->getDriverAccelArray($item, $window, 'both', 'y'); } if ($trend == 'speed' || $trend == 'overall') { $item->speed_score = $this->getDriverSpeedArray($item, $window); } } if ($trend == 'overall') { #foreach (array('accel', 'decel', 'hard_turns', 'speed') as $context) { # $this->reduce_to_scope($items, $context); #} $this->getOverallArray($items); } else { $this->reduce_to_scope($items); } break; } return $items; }
public function getItems() { $items = parent::getItems(); $cmd = $this->getState(strtolower($this->model_key) . '.cmd'); $window = $this->getState(strtolower($this->model_key) . '.window'); $windowtwo = $this->getState(strtolower($this->model_key) . '.windowtwo'); $trend = $this->getState(strtolower($this->model_key) . '.trend'); $company = JRequest::getInt('company', 0); if (!$company && sizeof($GLOBALS['user_companies']) == 1) { $company = (int) $GLOBALS['user_companies']; } $group = JRequest::getInt('group', 0); if (!$group && sizeof($GLOBALS['user_groups']) == 1) { $group = (int) $GLOBALS['user_groups']; } $vehicle = JRequest::getInt('vehicle', 0); $driver = JRequest::getInt('driver', 0); $idletime = JRequest::getInt('idletime', 0); $diffDays = JRequest::getInt('diffDays', 0); switch ($cmd) { case 'vehicle': foreach ($items as &$item) { $ret = $this->getVehicleFuelUsage($item, $window); #var_dump($ret); // $item->gallons = $ret[0]; // $item->mpg = $ret[1]; $item->disconnects = $this->getDisconnects($item, $window); $item->not_connected = $this->not_connected($item, $window); } break; case 'tendency': foreach ($items as &$item) { #$item->gallons = $this->getVehicleFuelUsage($item, $window); #$item->mpg = $this->calcMPG($item); $item->accel_score = $this->calculator->getDriverAccelScore($item, $window, 'accel'); $item->decel_score = $this->calculator->getDriverAccelScore($item, $window, 'decel'); $item->hard_turns = $this->calculator->getDriverAccelScore($item, $window, 'hard_turns'); // $item->speed_score = $this->calculator->getDriverSpeedScore($item, $window); // $item->overall_score = $this->calculator->getOverall($item); } // echo "<pre>"; print_r($items); break; case 'totalscore': foreach ($items as &$item) { $item->total_score = $this->calculator->getDriverTotalScore($item, 'totalScore', $diffDays); $item->aggressive_score = $this->calculator->getDriverTotalScore($item, 'aggressiveScore', $diffDays); $item->distraction_score = $this->calculator->getDriverTotalScore($item, 'distractionScore', $diffDays); $item->company_group_name = $this->calculator->getCompanyGroupName($company, $group); $company_group_score = $this->calculator->getCompanyGroupTotalScore($item, $diffDays, $company, $group, '7'); $item->company_group_total_score = count($company_group_score) > 0 ? $company_group_score[0]->total_score : 0; $item->company_group_aggressive_score = count($company_group_score) > 0 ? $company_group_score[0]->aggressive_score : 0; $item->company_group_distraction_score = count($company_group_score) > 0 ? $company_group_score[0]->distraction_score : 0; } break; case 'vehicletrend': foreach ($items as &$item) { $item->mpg = $this->calculator->getMpgArray($item, $window); } // echo "<pre>"; echo "before reduce to average"; print_r($items); // $this->reduce_to_scope($items, 'mpg'); // $items = $this->reduce_to_average($items, $company, $group, 0, $vehicle, 'vehicle_name'); // $items = $this->reduce_to_average($items, $company, $group, $driver, 0); // echo "<pre>"; echo "after reduce to average"; print_r($items); // $items = $this->reduce_to_average($items, $company, $group, $driver, 0); // echo "<pre>"; print_r($items); break; case 'drivertrend': #TODO: remove when drop downs are complete // echo "<pre>"; print_r($items); foreach ($items as &$item) { #$item->gallons = $this->getVehicleFuelUsage($item, $window); #$item->mpg = $this->calcMPG($item); if ($trend == "accel" || $trend == "overall" || $trend == "all") { $item->accel_score = $this->calculator->getDriverAccelArray($item, $window, 'accel'); // echo "<pre>"; print_r($item->accel_score); } if ($trend == 'decel' || $trend == 'overall' || $trend == "all") { $item->decel_score = $this->calculator->getDriverAccelArray($item, $window, 'decel'); //echo "<pre>"; print_r($item->decel_score); } if ($trend == 'hard_turns' || $trend == 'overall' || $trend == "all") { $item->hard_turns = $this->calculator->getDriverAccelArray($item, $window, 'hard_turns'); //echo "<pre>"; print_r($item->hard_turns); } // if ($trend == 'speed' || $trend == 'overall' || $trend=="all") { // $item->speed_score = $this->calculator->getDriverSpeedArray($item, $window); // //echo "<pre>"; print_r($item->speed_score); // } } if ($trend == 'overall' || $trend == 'all') { foreach (array('accel', 'decel', 'hard_turns') as $context) { // $this->reduce_to_scope($items, $context); $this->cap_to_zero($items, $context); } $this->calculator->getOverallArray($items); } else { // echo "in else"; echo "<pre>"; print_r($items); // $this->reduce_to_scope($items); } // echo "after else"; echo "<pre>"; print_r($items); // $items = $this->reduce_to_average($items, $company, $group, $driver, 0); // echo "after reduce to average"; echo "<pre>"; print_r($items); break; } return $items; }