118 lines
4.3 KiB
PHP
118 lines
4.3 KiB
PHP
<?php
|
|
|
|
class XGpsrResponsiblePerson extends ObjectModel
|
|
{
|
|
public $id;
|
|
public $id_x13gpsr_responsible_person;
|
|
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_person',
|
|
'primary' => 'id_x13gpsr_responsible_person',
|
|
'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_person_product', 'id_x13gpsr_responsible_person = ' . (int) $this->id);
|
|
$result &= Db::getInstance()->delete('x13gpsr_responsible_person_brand', 'id_x13gpsr_responsible_person = ' . (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_person_brand', 'rb', 'rb.id_brand = m.id_manufacturer')
|
|
->where('rb.id_x13gpsr_responsible_person = ' . (int) $idResponsible);
|
|
|
|
return Db::getInstance()->executeS($brandsQuery);
|
|
}
|
|
|
|
public static function getResponsiblePersonForBrand($brandId)
|
|
{
|
|
$query = new DbQuery();
|
|
$query->select('id_x13gpsr_responsible_person')
|
|
->from('x13gpsr_responsible_person_brand')
|
|
->where('id_brand = ' . (int) $brandId);
|
|
|
|
return Db::getInstance()->getValue($query);
|
|
}
|
|
|
|
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_person', 'r')
|
|
->leftJoin('x13gpsr_responsible_person_lang', 'rl', 'r.id_x13gpsr_responsible_person = rl.id_x13gpsr_responsible_person AND rl.id_lang = ' . (int) $langId);
|
|
|
|
return Db::getInstance()->executeS($query);
|
|
}
|
|
|
|
public static function deleteByProductId($productId)
|
|
{
|
|
$result = true;
|
|
$result &= Db::getInstance()->delete('x13gpsr_responsible_person_product', 'id_product = ' . (int) $productId);
|
|
|
|
return $result;
|
|
}
|
|
|
|
public static function deleteByBrandId($brandId)
|
|
{
|
|
$result = true;
|
|
$result &= Db::getInstance()->delete('x13gpsr_responsible_person_brand', 'id_brand = ' . (int) $brandId);
|
|
|
|
return $result;
|
|
}
|
|
|
|
public static function checkIfPrivateNameExistsForId($manufacturerId, $privateName)
|
|
{
|
|
$query = new DbQuery();
|
|
$query->select('id_x13gpsr_responsible_person')
|
|
->from('x13gpsr_responsible_person')
|
|
->where('id_x13gpsr_responsible_person != ' . (int) $manufacturerId)
|
|
->where('private_name = "' . pSQL($privateName) . '"');
|
|
|
|
return Db::getInstance()->getValue($query);
|
|
}
|
|
}
|