Last active
August 1, 2019 17:22
-
-
Save walison17/544ef5bc112d557fa4328662688f6ea9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function distribuirLotes($resultSet) | |
{ | |
$lotes = []; | |
foreach ($resultSet as $row) { | |
$lotes = array_merge($lotes, $this->organizarIntervalos($row)); | |
} | |
return $lotes; | |
} | |
private function organizarIntervalos($row) | |
{ | |
$sequencias = $row->sequencias; | |
sort($sequencias); | |
$ranges = []; | |
$lastIndex = $sequencias[count($sequencias) - 1]; | |
$temp = []; | |
for ($i = $sequencias[0]; $i <= $lastIndex; $i++) { | |
if (in_array($i, $sequencias)) { | |
$temp[] = $i; | |
} | |
if ((! in_array($i, $sequencias) || $i == $lastIndex) && ! empty($temp)) { | |
$ranges[] = [ | |
'evento_tipo_id' => $row->evento_tipo_id, | |
'evento_tipo' => $row->evento_tipo, | |
'lote_inicial' => $temp[0], | |
'lote_final' => end($temp) | |
]; | |
$temp = []; | |
} | |
} | |
return $ranges; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function findRanges($numbers) | |
{ | |
sort($numbers); | |
$ranges = []; | |
$lastIndex = $numbers[count($numbers) - 1]; | |
$temp = []; | |
for ($i = $numbers[0]; $i <= $lastIndex; $i++) { | |
if (in_array($i, $numbers)) { | |
$temp[] = $i; | |
} | |
if ((! in_array($i, $numbers) || $i == $lastIndex) && ! empty($temp)) { | |
$ranges[] = ['min' => $temp[0], 'max' => end($temp)]; | |
$temp = []; | |
} | |
} | |
return $ranges; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment