-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormIblockEntity.php
More file actions
executable file
·77 lines (73 loc) · 1.86 KB
/
Copy pathFormIblockEntity.php
File metadata and controls
executable file
·77 lines (73 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
namespace Msvdev\Bitrix\Forms;
//MAKEME: сделать вывод ошибок сохранения формы
abstract class FormIblockEntity implements FormEntityInterface
{
/**
* @var integer
*/
protected $id;
/**
* @var integer
*/
protected $iblockId;
/**
* @return integer
*/
abstract protected function getIblockId();
/**
* @return string
*/
abstract protected function getElementName();
/**
* Before save event
* @return bool
*/
public function beforeSave(){
return true;
}
/**
* After save event
*/
public function afterSave(){
}
/**
* Save entity to bitrix Iblock
* @return bool
*/
public function save(){
\CModule::IncludeModule("iblock");
$fields = [];
$arFields = [
"ACTIVE" => "Y",
"IBLOCK_ID" => $this->getIblockId(),
"NAME" => $this->getElementName()
];
if(!$this->beforeSave()){
return false;
}
foreach ($this->fieldMapping() as $property => $field){
$method = "get{$property}";
if(method_exists($this,$method)){
$value = $this->$method();
}
else{
$value = $this->$property;
}
if($field == 'PREVIEW_TEXT' || $field == 'DETAIL_TEXT' || $field == 'IBLOCK_SECTION_ID'){
$arFields[$field] = $value;
} else {
$fields[$field] = $value;
}
}
$arFields['PROPERTY_VALUES'] = $fields;
$oElement = new \CIBlockElement();
$idElement = $oElement->Add($arFields, false, false, true);
if($idElement){
$this->id = $idElement;
$this->afterSave();
return true;
}
return false;
}
}