Last active
December 7, 2021 12:22
-
-
Save ojulianos/a25b7a4586a46764fad5e92b8d75c26f to your computer and use it in GitHub Desktop.
This file contains 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 | |
/* | |
* MÉTODO updateData RETORNA A STRING | |
* UPDATE os SET {$p[0]} WHERE {$p[1]} | |
* updateData($p[0], $p[1]); | |
*/ | |
class OSConsulta extends BaseApp | |
{ | |
public function updatePosicao() | |
{ | |
$pos = $_POST['posicao_atual']; | |
$newpos = $_POST['posicao_nova']; | |
$respon_ti = $_POST['respon_ti']; | |
$id = $_POST['order_id_os']; | |
$condicao = " AND id<>'{$id}' AND respon_ti='{$respon_ti}' "; | |
if ($pos != $newpos) { | |
if ($newpos > $pos) { | |
$this->os_item->updateData("posicao_ant=posicao, posicao=posicao-1", "posicao < '$newpos' {$condicao}"); | |
$this->os_item->updateData("posicao_ant=posicao, posicao='$newpos'", "id='{$id}'"); | |
$this->os_item->updateData("posicao_ant=posicao, posicao=posicao+1", "posicao >= '$newpos' {$condicao}"); | |
} else { | |
$this->os_item->updateData("posicao_ant=posicao, posicao=posicao-1", "posicao < '$newpos' {$condicao}"); | |
$this->os_item->updateData("posicao_ant=posicao, posicao=posicao+1", "posicao >= '$newpos' {$condicao}"); | |
} | |
} | |
if ($pos != $newpos || ($pos == null && $newpos == null && $id == null)) { | |
$rs = $this->os_item->getData([ | |
'select' => 'id, posicao', | |
'where' => "respon_ti = $respon_ti", | |
'order_by' => 'posicao asc', | |
]); | |
$p = 0; | |
foreach ($rs as $data) { | |
$p++; | |
$this->os_item->updateData("posicao={$p}", "id='{$data->id}'"); | |
} | |
} | |
die; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment