update
This commit is contained in:
132
modules/x13gpsr/classes/XGpsrResponsibleManufacturer.php
Normal file
132
modules/x13gpsr/classes/XGpsrResponsibleManufacturer.php
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
class XGpsrResponsibleManufacturer extends ObjectModel
|
||||
{
|
||||
public $id;
|
||||
public $id_x13gpsr_responsible_manufacturer;
|
||||
public $name;
|
||||
public $private_name;
|
||||
public $id_country;
|
||||
public $address;
|
||||
public $postcode;
|
||||
public $city;
|
||||
public $phone;
|
||||
public $email;
|
||||
public $active = 1;
|
||||
public $deleted = 0;
|
||||
public $date_add;
|
||||
public $date_upd;
|
||||
public $extra_note;
|
||||
|
||||
public static $definition = [
|
||||
'table' => 'x13gpsr_responsible_manufacturer',
|
||||
'primary' => 'id_x13gpsr_responsible_manufacturer',
|
||||
'multilang' => true,
|
||||
'fields' => [
|
||||
'name' => ['type' => self::TYPE_STRING, 'required' => true, 'size' => 255],
|
||||
'private_name' => ['type' => self::TYPE_STRING, 'required' => true, 'size' => 255],
|
||||
'id_country' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true],
|
||||
'address' => ['type' => self::TYPE_STRING, 'size' => 255, 'required' => true],
|
||||
'postcode' => ['type' => self::TYPE_STRING, 'size' => 32, 'required' => true],
|
||||
'city' => ['type' => self::TYPE_STRING,'size' => 64, 'required' => true],
|
||||
'phone' => ['type' => self::TYPE_STRING, 'size' => 64],
|
||||
'email' => ['type' => self::TYPE_STRING, 'required' => true, 'size' => 128],
|
||||
'active' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool'],
|
||||
'deleted' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool'],
|
||||
'date_add' => ['type' => self::TYPE_DATE, 'validate' => 'isDate'],
|
||||
'date_upd' => ['type' => self::TYPE_DATE, 'validate' => 'isDate'],
|
||||
'extra_note' => ['type' => self::TYPE_HTML, 'lang' => true],
|
||||
],
|
||||
];
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$result = true;
|
||||
$result &= Db::getInstance()->delete('x13gpsr_responsible_manufacturer_product', 'id_x13gpsr_responsible_manufacturer = ' . (int) $this->id);
|
||||
$result &= Db::getInstance()->delete('x13gpsr_responsible_manufacturer_brand', 'id_x13gpsr_responsible_manufacturer = ' . (int) $this->id);
|
||||
$result &= parent::delete();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get brands assigned to a responsible person
|
||||
*
|
||||
* @param int $idResponsible
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getAssignedBrands($idResponsible)
|
||||
{
|
||||
$brandsQuery = new DbQuery();
|
||||
$brandsQuery->select('m.id_manufacturer AS id_brand, m.name')
|
||||
->from('manufacturer', 'm')
|
||||
->innerJoin('x13gpsr_responsible_manufacturer_brand', 'rb', 'rb.id_brand = m.id_manufacturer')
|
||||
->where('rb.id_x13gpsr_responsible_manufacturer = ' . (int) $idResponsible);
|
||||
|
||||
return Db::getInstance()->executeS($brandsQuery);
|
||||
}
|
||||
|
||||
public static function getResponsibleManufacturerForBrand($brandId)
|
||||
{
|
||||
$query = new DbQuery();
|
||||
$query->select('id_x13gpsr_responsible_manufacturer')
|
||||
->from('x13gpsr_responsible_manufacturer_brand')
|
||||
->where('id_brand = ' . (int) $brandId);
|
||||
|
||||
return Db::getInstance()->getValue($query);
|
||||
}
|
||||
|
||||
public static function assignBrands($idResponsible, $brands)
|
||||
{
|
||||
$result = true;
|
||||
$result &= Db::getInstance()->delete('x13gpsr_responsible_manufacturer_brand', 'id_x13gpsr_responsible_manufacturer = ' . (int) $idResponsible);
|
||||
|
||||
foreach ($brands as $idBrand) {
|
||||
Db::getInstance()->insert('x13gpsr_responsible_manufacturer_brand', [
|
||||
'id_x13gpsr_responsible_manufacturer' => (int) $idResponsible,
|
||||
'id_brand' => (int) $idBrand,
|
||||
]);
|
||||
}
|
||||
|
||||
return (bool) $result;
|
||||
}
|
||||
|
||||
public static function getAll($langId = null)
|
||||
{
|
||||
$langId = (int) $langId ?: (int) Context::getContext()->language->id;
|
||||
$query = new DbQuery();
|
||||
$query->select('r.*, rl.extra_note')
|
||||
->from('x13gpsr_responsible_manufacturer', 'r')
|
||||
->leftJoin('x13gpsr_responsible_manufacturer_lang', 'rl', 'r.id_x13gpsr_responsible_manufacturer = rl.id_x13gpsr_responsible_manufacturer AND rl.id_lang = ' . (int) $langId);
|
||||
|
||||
return Db::getInstance()->executeS($query);
|
||||
}
|
||||
|
||||
public static function deleteByProductId($productId)
|
||||
{
|
||||
$result = true;
|
||||
$result &= Db::getInstance()->delete('x13gpsr_responsible_manufacturer_product', 'id_product = ' . (int) $productId);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function deleteByBrandId($brandId)
|
||||
{
|
||||
$result = true;
|
||||
$result &= Db::getInstance()->delete('x13gpsr_responsible_manufacturer_brand', 'id_brand = ' . (int) $brandId);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function checkIfPrivateNameExistsForId($manufacturerId, $privateName)
|
||||
{
|
||||
$query = new DbQuery();
|
||||
$query->select('id_x13gpsr_responsible_manufacturer')
|
||||
->from('x13gpsr_responsible_manufacturer')
|
||||
->where('private_name = "' . pSQL($privateName) . '"')
|
||||
->where('id_x13gpsr_responsible_manufacturer != ' . (int) $manufacturerId);
|
||||
|
||||
return Db::getInstance()->getValue($query);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user