private function duration($quantity, $unite, $segmentId, $resellerId) { switch ($unite) { case 'heure': return $quantity * 3600; case 'minute': return $quantity * 60; default: $row = Model::Conversion()->where(['reseller_id', '=', (int) $resellerId])->where(['to', '=', 'hour'])->where(['from', '=', (string) $unite])->where(['segment_id', '=', (int) $segmentId])->first(true); if ($row) { $value = $row->value; if (!is_array($quantity)) { return $quantity * $value * 3600; } else { $duration = 0; foreach ($quantity as $index => $nb) { $val = isset($value[$index]) ? $value[$index] : 0; $duration += $nb * $val * 3600; } return $duration; } } } return 0; }