/home/sharedstore/public_html/prestashop.sharedstore.ma/classes
NameSizeModeActions
assets/-0755rm
cache/-0755rm
checkout/-0755rm
container/-0755rm
controller/-0755rm
db/-0755rm
exception/-0755rm
form/-0755rm
helper/-0755rm
lang/-0755rm
log/-0755rm
module/-0755rm
order/-0755rm
pdf/-0755rm
product/-0755rm
proxy/-0755rm
range/-0755rm
shop/-0755rm
Smarty/-0755rm
stock/-0755rm
tax/-0755rm
tree/-0755rm
webservice/-0755rm
.htaccess1700644editdlrm
Access.php135730644editdlrm
Address.php230160644editdlrm
AddressChecksumCore.php18510644editdlrm
AddressFormat.php251250644editdlrm
Alias.php51060644editdlrm
Attachment.php115570644editdlrm
AttributeGroup.php134880644editdlrm
Carrier.php656660644editdlrm
Cart.php2211920644editdlrm
CartRule.php927650644editdlrm
Category.php891710644editdlrm
Chart.php41770644editdlrm
ChecksumInterface.php12460644editdlrm
CMS.php117250644editdlrm
CMSCategory.php241480644editdlrm
CMSRole.php18220644editdlrm
Combination.php180120644editdlrm
Configuration.php271560644editdlrm
ConfigurationKPI.php91260644editdlrm
ConfigurationTest.php123090644editdlrm
Connection.php102620644editdlrm
ConnectionsSource.php49260644editdlrm
Contact.php39540644editdlrm
Context.php183720644editdlrm
Cookie.php178060644editdlrm
Country.php167230644editdlrm
CSV.php31100644editdlrm
Currency.php371670644editdlrm
Curve.php29930644editdlrm
Customer.php535760644editdlrm
CustomerAddress.php12950644editdlrm
CustomerMessage.php58900644editdlrm
CustomerSession.php27180644editdlrm
CustomerThread.php98480644editdlrm
Customization.php137540644editdlrm
CustomizationField.php29150644editdlrm
DateRange.php25320644editdlrm
Delivery.php33170644editdlrm
Dispatcher.php488100644editdlrm
Employee.php240620644editdlrm
EmployeeSession.php27180644editdlrm
Feature.php116560644editdlrm
FeatureFlag.php32260644editdlrm
FeatureValue.php82490644editdlrm
FileUploader.php38200644editdlrm
Gender.php28760644editdlrm
Group.php153230644editdlrm
GroupReduction.php90250644editdlrm
Guest.php85290644editdlrm
Hook.php509090644editdlrm
Image.php324180644editdlrm
ImageManager.php325490644editdlrm
ImageType.php71550644editdlrm
index.php13720644editdlrm
Language.php635470644editdlrm
Link.php638140644editdlrm
LocalizationPack.php236040644editdlrm
Mail.php343120644editdlrm
Manufacturer.php217450644editdlrm
ManufacturerAddress.php13110644editdlrm
Media.php330210644editdlrm
Message.php66260644editdlrm
Meta.php185770644editdlrm
Notification.php84700644editdlrm
ObjectModel.php837730644editdlrm
Pack.php263320644editdlrm
Page.php45980644editdlrm
PaymentFree.php13620644editdlrm
PaymentModule.php611970644editdlrm
PhpEncryption.php32910644editdlrm
PhpEncryptionEngine.php39490644editdlrm
PrestaShopAutoload.php97990644editdlrm
PrestaShopBackup.php117020644editdlrm
PrestaShopCollection.php217900644editdlrm
PrestaShopLogger.php85230644editdlrm
Product.php3180560644editdlrm
ProductAssembler.php68950644editdlrm
ProductAttribute.php138080644editdlrm
ProductDownload.php102940644editdlrm
ProductPresenterFactory.php39830644editdlrm
ProductSale.php130000644editdlrm
ProductSupplier.php85370644editdlrm
Profile.php85230644editdlrm
QqUploadedFileForm.php53170644editdlrm
QqUploadedFileXhr.php58250644editdlrm
QuickAccess.php64020644editdlrm
RequestSql.php214530644editdlrm
Risk.php24190644editdlrm
Search.php592290644editdlrm
SearchEngine.php28790644editdlrm
SpecificPrice.php332120644editdlrm
SpecificPriceRule.php143740644editdlrm
State.php79560644editdlrm
Store.php63940644editdlrm
Supplier.php183390644editdlrm
SupplierAddress.php12990644editdlrm
Tab.php222230644editdlrm
Tag.php135580644editdlrm
Tools.php1409030644editdlrm
Translate.php120590644editdlrm
TranslatedConfiguration.php47920644editdlrm
Upgrader.php118590644editdlrm
Uploader.php111040644editdlrm
Validate.php398010644editdlrm
ValidateConstraintTranslator.php26110644editdlrm
WarehouseAddress.php13020644editdlrm
Zone.php35000644editdlrm
Edit: /home/sharedstore/public_html/prestashop.sharedstore.ma/classes/Attachment.php (11557B)
* @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) */ /** * Class AttachmentCore. */ class AttachmentCore extends ObjectModel { public $file; public $file_name; public $file_size; public $name; public $mime; public $description; /** @var int position Position */ public $position; /** * @see ObjectModel::$definition */ public static $definition = [ 'table' => 'attachment', 'primary' => 'id_attachment', 'multilang' => true, 'fields' => [ 'file' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 40], 'mime' => ['type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'required' => true, 'size' => 128], 'file_name' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 128], 'file_size' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId'], /* Lang fields */ 'name' => ['type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 32], 'description' => ['type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCleanHtml', 'size' => 4194303], ], 'associations' => [ 'products' => ['type' => self::HAS_MANY, 'field' => 'id_product', 'object' => 'Product', 'association' => 'product_attachment'], ], ]; protected $webserviceParameters = [ 'objectNodeNames' => 'attachments', 'hidden_fields' => [], 'fields' => [ 'file' => [], 'file_name' => [], 'file_size' => [], 'mime' => [], ], 'associations' => [ 'products' => [ 'resource' => 'product', 'api' => 'products', 'fields' => [ 'id' => ['required' => true], ], ], ], ]; /** * @see ObjectModel::add() */ public function add($autoDate = true, $nullValues = false) { if (file_exists(_PS_DOWNLOAD_DIR_ . $this->file)) { $this->file_size = filesize(_PS_DOWNLOAD_DIR_ . $this->file); } return parent::add($autoDate, $nullValues); } /** * @see ObjectModel::update() */ public function update($nullValues = false) { if (file_exists(_PS_DOWNLOAD_DIR_ . $this->file)) { $this->file_size = filesize(_PS_DOWNLOAD_DIR_ . $this->file); } return parent::update($nullValues); } /** * @see ObjectModel::delete() */ public function delete() { if (file_exists(_PS_DOWNLOAD_DIR_ . $this->file)) { @unlink(_PS_DOWNLOAD_DIR_ . basename($this->file)); } $sql = new DbQuery(); $sql->select('pa.`id_product`'); $sql->from('product_attachment', 'pa'); $sql->where('pa.`id_attachment` = ' . (int) $this->id); $products = Db::getInstance()->executeS($sql); Db::getInstance()->delete( 'product_attachment', '`id_attachment` = ' . (int) $this->id ); foreach ($products as $product) { Product::updateCacheAttachment((int) $product['id_product']); } return parent::delete(); } /** * Delete selection of attachments. * * @param array $attachments Attachments * * @return bool|int Whether the selection has been successfully deleted * @todo: Find out if $return can be initialized with true. (breaking change) */ public function deleteSelection($attachments) { $return = 1; foreach ($attachments as $idAttachment) { $attachment = new Attachment((int) $idAttachment); $return &= $attachment->delete(); } return $return; } /** * Get attachments. * * @param int $idLang Language ID * @param int $idProduct Product ID * @param bool $include Whether the attachments are included or excluded from the Product ID * * @return array|false|mysqli_result|PDOStatement|resource|null Database query result */ public static function getAttachments($idLang, $idProduct, $include = true) { return Db::getInstance()->executeS( ' SELECT * FROM ' . _DB_PREFIX_ . 'attachment a LEFT JOIN ' . _DB_PREFIX_ . 'attachment_lang al ON (a.id_attachment = al.id_attachment AND al.id_lang = ' . (int) $idLang . ') WHERE a.id_attachment ' . ($include ? 'IN' : 'NOT IN') . ' ( SELECT pa.id_attachment FROM ' . _DB_PREFIX_ . 'product_attachment pa WHERE id_product = ' . (int) $idProduct . ' )' ); } /** * Unassociate all products from the current object * * @param bool $updateAttachmentCache [default=true] If set to false attachment cache will not be updated * * @return bool Deletion result */ public function deleteAttachments(bool $updateAttachmentCache = true): bool { if (0 >= (int) $this->id) { // Can not delete attachement without id return false; } $res = Db::getInstance()->execute( 'DELETE FROM `' . _DB_PREFIX_ . 'product_attachment` ' . 'WHERE `id_attachment` = ' . (int) $this->id ); if ($updateAttachmentCache === true) { $productIds = Db::getInstance()->executeS( 'SELECT `id_product` FROM `' . _DB_PREFIX_ . 'product_attachment` ' . 'WHERE `id_attachment` = ' . (int) $this->id ); foreach ($productIds as $productId) { Product::updateCacheAttachment((int) $productId); } } return $res; } /** * Delete Product attachments for the given Product ID. * * @param int $idProduct Product ID * * @return bool */ public static function deleteProductAttachments($idProduct) { $res = Db::getInstance()->execute(' DELETE FROM ' . _DB_PREFIX_ . 'product_attachment WHERE id_product = ' . (int) $idProduct); Product::updateCacheAttachment((int) $idProduct); return $res; } /** * Associate $id_product to the current object. * * @param int $idProduct id of the product to associate * * @return bool true if success */ public function attachProduct($idProduct) { return static::associateProductAttachment((int) $idProduct, (int) $this->id); } /** * @param int $productId * @param int $attachmentId * * @return bool true if success */ public static function associateProductAttachment(int $productId, int $attachmentId): bool { $res = Db::getInstance()->execute(' INSERT INTO ' . _DB_PREFIX_ . 'product_attachment (id_attachment, id_product) VALUES (' . $attachmentId . ', ' . $productId . ')'); Product::updateCacheAttachment($productId); return $res; } /** * Associate an array of id_attachment $array to the product $id_product * and remove eventual previous association. * * @param int $idProduct Product ID * @param mixed $array Attachment IDs * * @return bool Whether the attachments have been successfully associated with the Product */ public static function attachToProduct($idProduct, $array) { $result1 = Attachment::deleteProductAttachments($idProduct); if (is_array($array)) { $ids = []; foreach ($array as $idAttachment) { if ((int) $idAttachment > 0) { $ids[] = ['id_product' => (int) $idProduct, 'id_attachment' => (int) $idAttachment]; } } if (!empty($ids)) { $result2 = Db::getInstance()->insert('product_attachment', $ids); } } Product::updateCacheAttachment((int) $idProduct); if (is_array($array)) { return $result1 && (!isset($result2) || $result2); } return $result1; } /** * Get Attachment IDs for the given Product within the given range of attachment IDs. * * @param int $idLang Language ID * @param array $list List of attachment IDs in which to search * * @return array|bool List of attachment IDs found. False if nothing found. */ public static function getProductAttached($idLang, $list) { if (!is_array($list)) { return false; } $idsAttachments = array_column($list, 'id_attachment'); $sql = 'SELECT * FROM `' . _DB_PREFIX_ . 'product_attachment` pa ' . 'LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (pa.`id_product` = pl.`id_product`' . Shop::addSqlRestrictionOnLang('pl') . ') ' . 'WHERE `id_attachment` IN (' . implode(',', array_map('intval', $idsAttachments)) . ') ' . 'AND pl.`id_lang` = ' . (int) $idLang; $tmp = Db::getInstance()->executeS($sql); $productAttachments = []; foreach ($tmp as $t) { $productAttachments[$t['id_attachment']][] = $t['name']; } return $productAttachments; } /** * Get attachment products ids of current attachment for association. * * @return array An array of product ids */ public function getWsProducts(): array { return Db::getInstance()->executeS( 'SELECT p.`id_product` AS id ' . 'FROM `' . _DB_PREFIX_ . 'product_attachment` pa ' . 'INNER JOIN `' . _DB_PREFIX_ . 'product` p ON (p.id_product = pa.id_product) ' . '' . Shop::addSqlAssociation('product', 'p') . ' ' . 'WHERE pa.`id_attachment` = ' . (int) $this->id ); } /** * Set products ids of current attachment for association. * * @param array $products Products ids * * @return bool */ public function setWsProducts(array $products): bool { $this->deleteAttachments(true); foreach ($products as $product) { Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'product_attachment` (`id_product`, `id_attachment`) VALUES (' . (int) $product['id'] . ', ' . (int) $this->id . ')'); Product::updateCacheAttachment((int) $product['id']); } return true; } }