Skip to content

Instantly share code, notes, and snippets.

@jorgesanabria
Last active October 18, 2019 12:36
Show Gist options
  • Save jorgesanabria/6b213c3dd5d0a7a74d857f9941a08cc9 to your computer and use it in GitHub Desktop.
Save jorgesanabria/6b213c3dd5d0a7a74d857f9941a08cc9 to your computer and use it in GitHub Desktop.
asasas
<?php
public function copiarPlan($idPlan, $idEntrenado) {
if (empty($idEntrenado)) $idEntrenado = 'null';
$strQuery = "CALL SP_copiarPlan($idPlan, $idEntrenado)";
$db = $this->getDb();
if ( !$db->query($strQuery) )
$this->setLastError($db->getErrorString());
try {
$idPlanNew = $db->next_record()["idPlan"];
$db->close();
$db = $this->getDb();
//mover los archivos de cada ejercicio
//obtener la lista de ids donde puede haber archivos
$strQuery = "CALL SP_obtenerIdsWorkoutExercise($idPlan)";
$idsEjercicios = array();
$idEjerciciosNuevos = array();
if ($db->query($strQuery)) {
if (!file_exists($this->directorioArchivos)) {
mkdir($this->directorioArchivos, 0777, true);
}
while ($objRecord = $db->next_record()) {
$idsEjercicios[] = $objRecord["idWorkoutExercise"];
}
$db->close();
$db = $this->getDb();
$strQuery = "CALL SP_obtenerIdsWorkoutExercise($idPlanNew)";
if ($db->query($strQuery)) {
while ($objRecord = $db->next_record()) {
$idEjerciciosNuevos[] = $objRecord["idWorkoutExercise"];
}
foreach ($idsEjercicios as $key=>$value) {
$dir = $this->directorioArchivos . "/$value";
$dirNew = $this->directorioArchivos . "/" . $idEjerciciosNuevos[$key];
if (file_exists($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if ($file==".") continue;
if ($file=="..") continue;
if (!file_exists($dirNew)) {
mkdir($dirNew, 0777, true);
}
copy("$dir/$file","$dirNew/$file");
}
closedir($dh);
}
}
}
} else {
$this->setLastError($db->getErrorString());
}
} else {
$this->setLastError($db->getErrorString());
}
if (!file_exists($this->directorioDocs)) {
mkdir($this->directorioDocs, 0777, true);
}
chmod("{$this->directorioDocs}", 0777);
if ($idEntrenado != 'null') {
$strQuery = "CALL SP_idPTidTRPorPlan($idPlan)";
$db->close();
$db = $this->getDb();
if ($db->query($strQuery)) {
$record = $db->next_record();
$idPT = $record["idUserPT"];
$idTR = $record["idUserTR"];
$dir = "{$this->directorioDocs}/$idPT/$idTR";
$dirNew = "{$this->directorioDocs}/$idPT/$idEntrenado";
chmod("{$this->directorioDocs}/$idPT", 0777);
if (file_exists($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if ($file==".") continue;
if ($file=="..") continue;
if (!file_exists($dirNew)) {
mkdir($dirNew, 0777, true);
}
copy("$dir/$file","$dirNew/$file");
}
closedir($dh);
}
}
} else {
$this->setLastError($db->getErrorString());
}
}
} catch (Exception $e) {
$this->setLastError($e->getMessage());
}
return !$this->getBlnLastError();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment