chcreaimagetype.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. class Chcreaimagetypeclass extends ObjectModel
  3. {
  4. public $id;
  5. public $id_chcrea_image_type;
  6. public $name;
  7. public $width;
  8. public $height;
  9. public $id_shop;
  10. public $active;
  11. public static $definition = array(
  12. 'table' => 'chcrea_image_type',
  13. 'primary' => 'id_image_type',
  14. 'multilang' => false,
  15. 'fields' => array(
  16. 'name' => array('type' => self::TYPE_STRING, 'validate' => 'isString'),
  17. 'width' => array('type' => self::TYPE_INT, 'validate' => 'isunsignedInt'),
  18. 'height' => array('type' => self::TYPE_INT, 'validate' => 'isunsignedInt'),
  19. 'id_shop' =>array('type' => self::TYPE_INT, 'validate' => 'isunsignedInt'),
  20. 'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
  21. ),
  22. );
  23. public function __construct($id = null, $id_lang = null, $id_shop = null)
  24. {
  25. parent::__construct($id, $id_lang, $id_shop);
  26. }
  27. public function update($null_values = false)
  28. {
  29. if(!parent::update($null_values))
  30. return false;
  31. return true;
  32. }
  33. public function add($autodate = true, $null_values = false)
  34. {
  35. $this->id_shop = (int)Context::getContext()->shop->id;
  36. if(!parent::add($autodate, $null_values) || !Validate::isLoadedObject($this))
  37. return false;
  38. return true;
  39. }
  40. public static function GetAllImageTypes($prefix = null)
  41. {
  42. $id_shop = (int)Context::getContext()->shop->id;
  43. $sql = 'SELECT * FROM `'._DB_PREFIX_.'chcrea_image_type` ';
  44. $sql .= ' WHERE id_shop = '.(int)$id_shop;
  45. if ( $prefix != null ) {
  46. $sql .= ' AND `name` like "%'.$prefix.'%"';
  47. }
  48. $queryexec = Db::getInstance()->executeS($sql);
  49. if(isset($queryexec) && !empty($queryexec)){
  50. return $queryexec;
  51. }else{
  52. $sql2 = 'SELECT * FROM `'._DB_PREFIX_.'chcrea_image_type` ';
  53. $sql2 .= ' WHERE 1';
  54. $queryexec2 = Db::getInstance()->executeS($sql2);
  55. return $queryexec2;
  56. }
  57. }
  58. }