Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
category.php
1<?php
3
5use \Bitrix\Main\Type\DateTime;
7
8Loc::loadMessages(__FILE__);
9
44class CategoryTable extends Entity\DataManager
45{
46 public static function getFilePath()
47 {
48 return __FILE__;
49 }
50
51 public static function getTableName()
52 {
53 return 'b_sale_tp_ebay_cat';
54 }
55
56 public static function getMap()
57 {
58 return array(
59 'ID' => array(
60 'data_type' => 'integer',
61 'primary' => true,
62 'autocomplete' => true,
63 'title' => Loc::getMessage('TRADING_PLATFORM_EBAY_GENERAL_METADATA_ENTITY_ID_FIELD'),
64 ),
65 'NAME' => array(
66 'data_type' => 'string',
67 'validation' => array(__CLASS__, 'validateName'),
68 'required' => true,
69 'title' => Loc::getMessage('TRADING_PLATFORM_EBAY_GENERAL_METADATA_ENTITY_NAME_FIELD'),
70 ),
71 'CATEGORY_ID' => array(
72 'data_type' => 'integer',
73 'required' => true,
74 'title' => Loc::getMessage('TRADING_PLATFORM_EBAY_GENERAL_METADATA_ENTITY_CATEGORY_ID_FIELD'),
75 ),
76 'PARENT_ID' => array(
77 'data_type' => 'integer',
78 'required' => true,
79 'title' => Loc::getMessage('TRADING_PLATFORM_EBAY_GENERAL_METADATA_ENTITY_PARENT_ID_FIELD'),
80 ),
81 'LEVEL' => array(
82 'data_type' => 'integer',
83 'required' => true,
84 'title' => Loc::getMessage('TRADING_PLATFORM_EBAY_GENERAL_METADATA_ENTITY_LEVEL_FIELD'),
85 ),
86 'LAST_UPDATE' => array(
87 'data_type' => 'datetime',
88 'required' => false,
89 'default_value' => DateTime::createFromTimestamp(time()),
90 'title' => Loc::getMessage('TRADING_PLATFORM_EBAY_GENERAL_METADATA_ENTITY_LAST_UPDATE_FIELD'),
91 ),
92 );
93 }
94
99 public static function getCategoryParents($ebayCategoryId)
100 {
101 $result = array();
102
103 do
104 {
105 $categoryRes = self::getList(array(
106 'select' =>array('CATEGORY_ID', 'NAME', 'PARENT_ID', 'LEVEL'),
107 'filter'=> array(
108 'CATEGORY_ID' => $ebayCategoryId
109 ),
110 ));
111
112 if($category = $categoryRes->fetch())
113 {
114 $result[$category["LEVEL"]] = $category;
115 $ebayCategoryId = $category["PARENT_ID"];
116 }
117 else
118 {
119 break;
120 }
121 }
122 while($category["LEVEL"] > 1 || $category["PARENT_ID"] != $category["CATEGORY_ID"]);
123
124 return array_reverse($result, true);
125 }
126
133 public static function update($primary, array $data)
134 {
135 $data["LAST_UPDATE"] = DateTime::createFromTimestamp(time());
136 return parent::update($primary, $data);
137 }
138
139 public static function validateName()
140 {
141 return array(
142 new Entity\Validator\Length(null, 255),
143 );
144 }
145}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static createFromTimestamp($timestamp)
Definition datetime.php:246
static update($primary, array $data)
Definition category.php:133