Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
storedocumentspecifictable.php
1<?php
2
4
11
12/*
13 * This class' children are meant to be used to work with a specific document type.
14 * Each document type has its own user fields set, so they need to have their own separate ORM classes.
15 * If you need to select all documents/a set of documents regardless of their type,
16 * use \Bitrix\Catalog\StoreDocumentTable; however, do note that it doesn't support user fields.
17 */
19{
20 abstract public static function getType(): string;
21
22 public static function getUfId()
23 {
24 return 'CAT_STORE_DOCUMENT_' . static::getType();
25 }
26
27 public static function setDefaultScope($query)
28 {
29 $query->where('DOC_TYPE', static::getType());
30 }
31
32 public static function add(array $data)
33 {
34 $data['DOC_TYPE'] = static::getType();
35 return parent::add($data);
36 }
37
38 public static function update($primary, array $data)
39 {
40 $result = new UpdateResult();
41
42 $documentType = self::getByPrimary($primary, ['select' => ['DOC_TYPE']])->fetch();
43 if (!$documentType)
44 {
45 $result->addError(new Error(Loc::getMessage('STORE_DOCUMENT_SPECIFIC_TABLE_DOC_NOT_FOUND_ERROR')));
46
47 return $result;
48 }
49
50 if ($documentType['DOC_TYPE'] !== static::getType())
51 {
52 $result->addError(new Error(Loc::getMessage('STORE_DOCUMENT_SPECIFIC_TABLE_WRONG_DOC_TYPE_ERROR')));
53
54 return $result;
55 }
56
57 if (isset($data['DOC_TYPE']))
58 {
59 unset($data['DOC_TYPE']);
60 }
61
62 return parent::update($primary, $data);
63 }
64
65 public static function delete($primary)
66 {
67 $result = new DeleteResult();
68
69 $documentType = self::getByPrimary($primary, ['select' => ['DOC_TYPE']])->fetch();
70 if (!$documentType)
71 {
72 $result->addError(new Error(Loc::getMessage('STORE_DOCUMENT_SPECIFIC_TABLE_DOC_NOT_FOUND_ERROR')));
73
74 return $result;
75 }
76
77 if ($documentType['DOC_TYPE'] !== static::getType())
78 {
79 $result->addError(new Error(Loc::getMessage('STORE_DOCUMENT_SPECIFIC_TABLE_WRONG_DOC_TYPE_ERROR')));
80
81 return $result;
82 }
83
84 return parent::delete($primary);
85 }
86}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static getByPrimary($primary, array $parameters=array())