1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
storedocumentspecifictable.php
См. документацию.
1<?php
2
3namespace Bitrix\Catalog\Document\Type;
4
5use Bitrix\Catalog\StoreDocumentTable;
6use Bitrix\Main\Error;
7use Bitrix\Main\Localization\Loc;
8use Bitrix\Main\NotImplementedException;
9use Bitrix\Main\ORM\Data\DeleteResult;
10use Bitrix\Main\ORM\Data\UpdateResult;
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}
Определения error.php:15
static getByPrimary($primary, array $parameters=array())
Определения datamanager.php:330
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$query
Определения get_search.php:11