/** * @return \yii\db\ActiveQuery */ public function getShopImages() { return $this->hasMany(ShopImage::className(), ['product_id' => 'id']); }
function shop_delete_images() { global $xoopsSecurity, $xoopsModule; $ids = rmc_server_var($_REQUEST, 'ids', 0); $id = rmc_server_var($_REQUEST, 'id', 0); $page = rmc_server_var($_REQUEST, 'page', 0); $bname = rmc_server_var($_REQUEST, 'bname', 0); $ruta = "action=images&page={$page}&id={$id}&bname={$bname}"; //Verificamos que nos hayan proporcionado una imagen para eliminar if (!is_array($ids)) { redirectMsg('products.php?' . $ruta, __('You must select an image to delete!', 'shop'), 1); die; } if (!$xoopsSecurity->check()) { redirectMsg('products.php?' . $ruta, __('Session token expired!', 'shop'), 1); die; } $errors = ''; foreach ($ids as $k) { //Verificamos si la imagen es válida if ($k <= 0) { $errors .= sprintf(__('Image ID "%s" is not valid!', 'shop'), $k); continue; } //Verificamos si la imagen existe $img = new ShopImage($k); if ($img->isNew()) { $errors .= sprintf(__('Image with ID "%s" does not exists!', 'shop'), $k); continue; } if (!$img->delete()) { $errors .= sprintf(__('Image "%s" could not be deleted!', 'shop'), $img->getVar('title')); } } if ($errors != '') { redirectMsg('products.php?' . $ruta, __('Errors ocurred while trying to delete images', 'shop') . '<br />' . $errors, 1); die; } else { redirectMsg('products.php?' . $ruta, __('Images deleted successfully!', 'shop'), 0); die; } }