FIX: no se podia cargar imagenes

This commit is contained in:
2020-05-31 11:59:40 -04:00
parent cb08e0af64
commit 26bd5207f3
3 changed files with 16 additions and 15 deletions

View File

@ -285,7 +285,7 @@ class Productos {
$status = $producto->addImagen($file); $status = $producto->addImagen($file);
$output = [ $output = [
'informacion' => $id, 'informacion' => $producto->id,
'estado' => $status 'estado' => $status
]; ];
$response->getBody()->write(json_encode($output)); $response->getBody()->write(json_encode($output));

View File

@ -105,11 +105,11 @@
<div class="fields"> <div class="fields">
<div class="field"> <div class="field">
<label>Tamaño M&iacute;nimo</label> <label>Tamaño M&iacute;nimo</label>
<input type="text" name="tamaño_min" value="{{(property_exists($producto, 'tamaños')) ? explode(' - ', rtrim($producto->tamaños, ' m²'))[0] : ''}}" /> <input type="text" name="tamaño_min" value="{{(property_exists($producto, 'tamaños') and is_array($producto->tamaños)) ? explode(' - ', rtrim($producto->tamaños, ' m²'))[0] : ''}}" />
</div> </div>
<div class="field"> <div class="field">
<label>Tamaño M&aacute;ximo</label> <label>Tamaño M&aacute;ximo</label>
<input type="text" name="tamaño_max" value="{{(property_exists($producto, 'tamaños')) ? explode(' - ', rtrim($producto->tamaños, ' m²'))[1] : ''}}" /> <input type="text" name="tamaño_max" value="{{(property_exists($producto, 'tamaños') and is_array($producto->tamaños)) ? explode(' - ', rtrim($producto->tamaños, ' m²'))[1] : ''}}" />
</div> </div>
</div> </div>
</div> </div>
@ -202,6 +202,9 @@
}, },
formatInput: false, formatInput: false,
onChange: function(a, b) { onChange: function(a, b) {
if (typeof a == 'undefined') {
a = new Date()
}
$(this).find('input').val(('0' + (a.getMonth() + 1)).slice(-2) + '/' + a.getFullYear()) $(this).find('input').val(('0' + (a.getMonth() + 1)).slice(-2) + '/' + a.getFullYear())
} }
}) })

View File

@ -77,20 +77,18 @@ class Producto extends Model {
public function imagenes() { public function imagenes() {
if ($this->imagenes === null) { if ($this->imagenes === null) {
$folder = $this->image_folder; $folder = $this->image_folder;
$this->imagenes = [];
if (!file_exists($folder)) { if (!file_exists($folder)) {
$this->imagenes = []; return $this->imagenes;
return [];
} }
if (file_exists($folder)) { $files = new \DirectoryIterator($folder);
$files = new \DirectoryIterator($folder); foreach ($files as $file) {
foreach ($files as $file) { if ($file->isDir()) {
if ($file->isDir()) { continue;
continue;
}
$this->imagenes []= $file->getFilename();
} }
sort($this->imagenes); $this->imagenes []= $file->getFilename();
} }
sort($this->imagenes);
} }
return $this->imagenes; return $this->imagenes;
} }
@ -112,14 +110,14 @@ class Producto extends Model {
public function deleteImagen(string $file) { public function deleteImagen(string $file) {
$filename = implode(DIRECTORY_SEPARATOR, [ $filename = implode(DIRECTORY_SEPARATOR, [
$this->image_folder, $this->image_folder,
$imagen $file
]); ]);
if (!file_exists($filename)) { if (!file_exists($filename)) {
return false; return false;
} }
$status = unlink($filename); $status = unlink($filename);
if (count(scandir($dir)) == 2) { if (count(scandir($this->image_folder)) == 2) {
rmdir($this->image_folder); rmdir($this->image_folder);
} }
return $status; return $status;