Bitrix-D7  20.5.0
delivery/requests/shipment.php
См. документацию.
1 <?php
3 
6 
7 Loc::loadMessages(__FILE__);
8 
9 /**
10  * Class ShipmentTable
11  *
12  * Fields:
13  * <ul>
14  * <li> ID int mandatory
15  * <li> SHIPMENT_ID int mandatory *
16  * <li> REQUEST_ID int optional
17  * <li> EXTERNAL_ID int optional
18  * <li> ERROR_DESCRIPTION string
19  * </ul>
20  *
21  * @package Bitrix\Sale\Delivery\Requests
22  **/
23 
24 class ShipmentTable extends Entity\DataManager
25 {
26  /**
27  * Returns DB table name for entity.
28  *
29  * @return string
30  */
31  public static function getTableName()
32  {
33  return 'b_sale_delivery_req_shp';
34  }
35 
36  /**
37  * Returns entity map definition.
38  *
39  * @return array
40  */
41  public static function getMap()
42  {
43  return array(
44  'ID' => array(
45  'data_type' => 'integer',
46  'primary' => true,
47  'autocomplete' => true,
48  'title' => Loc::getMessage('SALE_DLVR_REQ_SHP_TBL_ID_FIELD'),
49  ),
50  'SHIPMENT_ID' => array(
51  'data_type' => 'integer',
52  'required' => true,
53  'title' => Loc::getMessage('SALE_DLVR_REQ_SHP_TBL_SHIPMENT_ID_FIELD'),
54  ),
55  'REQUEST_ID' => array(
56  'data_type' => 'integer',
57  'title' => Loc::getMessage('SALE_DLVR_REQ_SHP_TBL_REQUEST_ID_FIELD'),
58  ),
59  'EXTERNAL_ID' => array(
60  'data_type' => 'string',
61  'validation' => array(__CLASS__, 'validateType'),
62  'title' => Loc::getMessage('SALE_DLVR_REQ_SHP_TBL_EXTERNAL_ID_FIELD'),
63  ),
64  'ERROR_DESCRIPTION' => array(
65  'data_type' => 'string',
66  'validation' => array(__CLASS__, 'validateErrorDescription'),
67  'title' => Loc::getMessage('SALE_DLVR_REQ_SHP_TBL_ERROR_DESCRIPTION_FIELD'),
68  ),
69  'SHIPMENT' => array(
70  'data_type' => '\Bitrix\Sale\Internals\ShipmentTable',
71  'reference' => array('=this.SHIPMENT_ID' => 'ref.ID'),
72  ),
73  'REQUEST' => array(
74  'data_type' => '\Bitrix\Sale\Delivery\Requests\RequestTable',
75  'reference' => array('=this.REQUEST_ID' => 'ref.ID'),
76  )
77  );
78  }
79 
80  /**
81  * @return array
82  */
83  public static function validateType()
84  {
85  return array(
86  new Entity\Validator\Length(null, 50),
87  );
88  }
89 
90  /**
91  * @return array
92  */
93  public static function validateErrorDescription()
94  {
95  return array(
96  new Entity\Validator\Length(null, 2048),
97  );
98  }
99 
100  public static function setShipment(array $fields)
101  {
102  $res = self::getList(array('filter' => array('=SHIPMENT_ID' => $fields['SHIPMENT_ID'])));
103 
104  if($row = $res->fetch())
105  $result = self::update($row['ID'], $fields);
106  else
107  $result = self::add($fields);
108 
109  return $result;
110  }
111 }
static loadMessages($file)
Loads language messages for specified file in a lazy way.
Definition: loc.php:67
static getMessage($code, $replace=null, $language=null)
Returns translation by message code.
Definition: loc.php:29
static getMap()
Returns entity map definition.
static getTableName()
Returns DB table name for entity.