Initial commit
This commit is contained in:
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
class AttributeField {
|
||||
public string $name;
|
||||
public array $params;
|
||||
public $content = "";
|
||||
|
||||
public function __construct($params = array())
|
||||
{
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
public function set_content($content)
|
||||
{
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
public function set_name($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function render_edit()
|
||||
{
|
||||
global $b;
|
||||
$item_id = $_GET["item_id"];
|
||||
if(!isset($item_id)) {
|
||||
echo "Редактировать атрибуты можно только после создания объекта.";
|
||||
return;
|
||||
}
|
||||
$item = $b->get_item_by_id($item_id);
|
||||
|
||||
$search = new Search(array(
|
||||
"class" => "Attribute",
|
||||
));
|
||||
|
||||
$items = $search->collect();
|
||||
$attributes = $item->get_parent_items("Attribute");
|
||||
$ai = $item->get_child_items("Attribute_Item");
|
||||
?>
|
||||
|
||||
<?php if(count($attributes)) { ?>
|
||||
<div class="bive-attributes">
|
||||
<?php foreach ($attributes as $arg => $attribute) { ?>
|
||||
<div class="bive-attributes_row">
|
||||
<div class="bive-attributes__wrapper">
|
||||
<div class="bive-attributes__title">
|
||||
<?= $attribute->get_item_name(); ?>
|
||||
</div>
|
||||
<div class="bive-attributes__items">
|
||||
<?php foreach ($ai as $key => $a) { ?>
|
||||
<?php if($a->parent_id != $attribute->get_item_id()) continue; ?>
|
||||
<div class="bive-attributes__item">
|
||||
<div class="bive-attributes__item-text"><?= $a->get_item_name(); ?></div>
|
||||
<button type="submit" class="bive-attributes__item-remove" name="<?= $this->name . "[" . $attribute->get_item_id() . "][remove]"; ?>" value="<?= $a->get_item_id(); ?>">x</button>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<div class="bive-attributes__item-new">
|
||||
<input class="bive-attributes__item-input" type="text" name="<?= $this->name . "[" . $attribute->get_item_id() . "][new]"; ?>" placeholder="Новый атрибут">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="bive-attributes__remove" name="<?= $this->name . "[remove]"; ?>" value="<?= $attribute->get_item_id(); ?>">X</button>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div>
|
||||
<select class="bive-select" name="<?= $this->name . "[new][attribute]"; ?>">
|
||||
<?php foreach ($items as $arg => $item) { ?>
|
||||
<option value="<?= $item->get_item_id(); ?>"><?= $item->get_item_name(); ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
<button type="submit" class="btn btn-primary mb-1 ml-1 mt-1" name="<?= $this->name . "[new][button]"; ?>" value="1">Добавить</button>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
public function render_value()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
public function render_db_value()
|
||||
{
|
||||
global $b;
|
||||
$item_id = $_GET["item_id"];
|
||||
if(!isset($item_id)) return "";
|
||||
$item = $b->get_item_by_id($item_id);
|
||||
if (is_array($this->content)) {
|
||||
foreach ($this->content as $key => $data) {
|
||||
if ((string) $key == "new" && isset($data["button"])) {
|
||||
$item->set_parent($data["attribute"], false);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((string) $key == "remove") {
|
||||
$item->clear_parent($data);
|
||||
continue;
|
||||
}
|
||||
|
||||
if((string) $data["new"] !== "") {
|
||||
$parent_id = $key;
|
||||
$slug = $this->translit_sef($data["new"]);
|
||||
$search = new Search(array(
|
||||
"class" => "Attribute_Item",
|
||||
"terms" => array("item_slug" => $slug),
|
||||
"parent_id" => $parent_id
|
||||
));
|
||||
$items = $search->collect();
|
||||
if(!$items) {
|
||||
$ai = new Attribute_Item(0);
|
||||
$ai->create($data["new"], "");
|
||||
$ai->set_field("item_slug", $slug);
|
||||
$ai->set_parent($parent_id, true);
|
||||
$ai->set_parent($item_id);
|
||||
} else {
|
||||
$items[0]->set_parent($item_id);
|
||||
}
|
||||
}
|
||||
|
||||
if((string) $data["remove"] !== "") {
|
||||
$parent = $b->get_item_by_id($data["remove"]);
|
||||
$parent->clear_parent($item_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private function translit_sef($value)
|
||||
{
|
||||
$converter = array(
|
||||
'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd',
|
||||
'е' => 'e', 'ё' => 'e', 'ж' => 'zh', 'з' => 'z', 'и' => 'i',
|
||||
'й' => 'y', 'к' => 'k', 'л' => 'l', 'м' => 'm', 'н' => 'n',
|
||||
'о' => 'o', 'п' => 'p', 'р' => 'r', 'с' => 's', 'т' => 't',
|
||||
'у' => 'u', 'ф' => 'f', 'х' => 'h', 'ц' => 'c', 'ч' => 'ch',
|
||||
'ш' => 'sh', 'щ' => 'sch', 'ь' => '', 'ы' => 'y', 'ъ' => '',
|
||||
'э' => 'e', 'ю' => 'yu', 'я' => 'ya',
|
||||
);
|
||||
|
||||
$value = mb_strtolower($value);
|
||||
$value = strtr($value, $converter);
|
||||
$value = mb_ereg_replace('[^-0-9a-z]', '-', $value);
|
||||
$value = mb_ereg_replace('[-]+', '-', $value);
|
||||
$value = trim($value, '-');
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
class Bigtext {
|
||||
public string $name;
|
||||
public array $params;
|
||||
public $content = "";
|
||||
|
||||
public function __construct($params = array())
|
||||
{
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
public function set_content($content)
|
||||
{
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
public function set_name($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function render_edit()
|
||||
{
|
||||
$bive_textarea_dom = new DOM("div");
|
||||
$bive_textarea_dom->setAttribute("class", "bive-textarea mb-1");
|
||||
|
||||
$bive_textarea_content_dom = new DOM("textarea", true);
|
||||
$bive_textarea_content_dom->setAttribute("type", "text");
|
||||
$bive_textarea_content_dom->setAttribute("class", "bive-textarea__content");
|
||||
$bive_textarea_content_dom->setAttribute("id", $this->name);
|
||||
$bive_textarea_content_dom->setAttribute("name", $this->name);
|
||||
$bive_textarea_content_dom->append($this->content);
|
||||
|
||||
$bive_textarea_dom->append($bive_textarea_content_dom);
|
||||
$bive_textarea_dom->view();
|
||||
}
|
||||
|
||||
public function render_value()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
public function render_db_value()
|
||||
{
|
||||
if(!$this->content) return "";
|
||||
return $this->content;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
class Date {
|
||||
public string $name;
|
||||
public array $params;
|
||||
public $content = "";
|
||||
|
||||
public function __construct($params = array())
|
||||
{
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
public function set_content($content)
|
||||
{
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
public function set_name($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function render_edit()
|
||||
{
|
||||
$input_dom = new DOM("input");
|
||||
$input_dom->setAttribute("type", "text");
|
||||
$input_dom->setAttribute("name", $this->name);
|
||||
$input_dom->setAttribute("value", $this->content);
|
||||
$input_dom->view();
|
||||
}
|
||||
|
||||
public function render_value()
|
||||
{
|
||||
return date("H:m:s d.m.Y", $this->content);
|
||||
}
|
||||
|
||||
public function render_db_value()
|
||||
{
|
||||
if(!$this->content) return time();
|
||||
return $this->content;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
class Image {
|
||||
public string $name;
|
||||
public array $params;
|
||||
public $content = "";
|
||||
|
||||
public function __construct($params = array())
|
||||
{
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
public function set_content($content)
|
||||
{
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
public function set_name($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function render_edit()
|
||||
{
|
||||
global $b;
|
||||
|
||||
if($this->content) {
|
||||
$box_dom = new DOM("div");
|
||||
$box_dom->setAttribute("class", "image-field__preview");
|
||||
|
||||
$preview_link_dom = new DOM("a");
|
||||
$preview_link_dom->setAttribute("href", $b->file_get_link($this->content));
|
||||
$preview_link_dom->setAttribute("target", "_blank");
|
||||
|
||||
$preview_dom = new DOM("img");
|
||||
$preview_dom->setAttribute("src", $b->file_get_link($this->content));
|
||||
$preview_dom->setAttribute("class", "image-field__preview-image");
|
||||
$preview_link_dom->append($preview_dom);
|
||||
$box_dom->append($preview_link_dom);
|
||||
|
||||
$hidden_dom = new DOM("input");
|
||||
$hidden_dom->setAttribute("type", "hidden");
|
||||
$hidden_dom->setAttribute("name", $this->name . "[file_id]");
|
||||
$hidden_dom->setAttribute("value", $this->content);
|
||||
$box_dom->append($hidden_dom);
|
||||
|
||||
$label_dom = new DOM("label");
|
||||
$label_dom->setAttribute("class", "image-field__delete-label");
|
||||
|
||||
$p_dom = new DOM("p");
|
||||
$p_dom->setAttribute("class", "image-field__delete-text");
|
||||
$p_dom->append("Удалить");
|
||||
|
||||
$label_dom->append($p_dom);
|
||||
|
||||
$checkbox_dom = new DOM("input");
|
||||
$checkbox_dom->setAttribute("type", "checkbox");
|
||||
$checkbox_dom->setAttribute("class", "image-field__delete-checkbox");
|
||||
$checkbox_dom->setAttribute("name", $this->name . "[delete]");
|
||||
$label_dom->prepend($checkbox_dom);
|
||||
|
||||
$box_dom->append($label_dom);
|
||||
$box_dom->view();
|
||||
} else {
|
||||
$input_dom = new DOM("input");
|
||||
$input_dom->setAttribute("type", "file");
|
||||
$input_dom->setAttribute("name", $this->name);
|
||||
$input_dom->view();
|
||||
}
|
||||
}
|
||||
|
||||
public function render_value()
|
||||
{
|
||||
global $b;
|
||||
return $b->file_get_link($this->content);
|
||||
}
|
||||
|
||||
public function render_db_value()
|
||||
{
|
||||
global $b;
|
||||
|
||||
if (is_array($this->content)) {
|
||||
if($this->content["delete"])
|
||||
return "";
|
||||
if($this->content["file_id"])
|
||||
return $this->content["file_id"];
|
||||
return $b->files_save($this->content);
|
||||
} else {
|
||||
return $this->content;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
class Link {
|
||||
public string $name;
|
||||
public array $params;
|
||||
public $content = "";
|
||||
|
||||
public function __construct($params = array())
|
||||
{
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
public function set_content($content)
|
||||
{
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
public function set_name($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function render_edit()
|
||||
{
|
||||
global $b;
|
||||
$input_dom = new DOM("input", false);
|
||||
$input_dom->setAttribute("type", "text");
|
||||
$input_dom->setAttribute("name", $this->name);
|
||||
$input_dom->setAttribute("placeholder", "Укажите абсолютную или относительную ссылку");
|
||||
$input_dom->setAttribute("value", $b->get_view($this->content));
|
||||
$input_dom->view();
|
||||
}
|
||||
|
||||
public function render_value()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
public function render_db_value()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
class Multifield {
|
||||
public string $name;
|
||||
public array $params;
|
||||
public $content = "";
|
||||
|
||||
public function __construct($params = array())
|
||||
{
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
public function set_content($content)
|
||||
{
|
||||
if(is_array($content)) {
|
||||
$this->content = $content;
|
||||
return;
|
||||
}
|
||||
if(!$content) $content = "[]";
|
||||
$this->content = json_decode(trim($content), true);
|
||||
}
|
||||
|
||||
public function set_name($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function render_edit()
|
||||
{
|
||||
global $b;
|
||||
|
||||
?><div class="bive-multifield"><?php
|
||||
|
||||
?><div class="bive-multifield__wrapper" data-level="<?= $this->name; ?>"><?php
|
||||
foreach ($this->content as $key => $data)
|
||||
{
|
||||
?><div class="bive-multifield__row"><?php
|
||||
?><div class="input-number"><?= $key; ?></div><?php
|
||||
|
||||
?><div class="input-row"><?php
|
||||
foreach ($this->params["fields"] as $arg => $field)
|
||||
{
|
||||
?><div class="input-group"><?php
|
||||
?><div class="input-label">
|
||||
<p class="input-label__inner"><?= $field[1]; ?></p>
|
||||
<p class="input-label__background"><?= $arg;?></p>
|
||||
</div><?php
|
||||
|
||||
?><div class="input-edit"><?php
|
||||
$b->field_render_edit($field[0], $this->name . "[$key][$arg]", $data[$arg]);
|
||||
?></div><?php
|
||||
?></div><?php
|
||||
}
|
||||
?></div><?php
|
||||
|
||||
?><button type="submit" class="btn-remove" name="<?= $this->name . "[$key]"; ?>" value="remove">X</button>
|
||||
</div><?php
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="bive-multifield__buttons">
|
||||
<button type="submit" class="btn btn-primary mb-1 ml-1 mt-1" name="<?= $this->name . "[new]"; ?>" value="1">Добавить ещё</button>
|
||||
<span class="bive-multifield__hide">Скрыть</span>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
||||
?></div><?php
|
||||
}
|
||||
|
||||
public function render_value()
|
||||
{
|
||||
global $b;
|
||||
$array = array();
|
||||
foreach ($this->content as $key => $data) {
|
||||
foreach ($this->params["fields"] as $arg => $field) {
|
||||
$array[$key][$arg] = $b->field_render_value($field[0], $this->name . "[$key][$arg]", $data[$arg]);
|
||||
}
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
public function render_db_value()
|
||||
{
|
||||
global $b;
|
||||
|
||||
foreach ($this->content as $key => $data) {
|
||||
if ((string) $data == "remove") {
|
||||
unset($this->content[$key]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((string) $key == "new") {
|
||||
unset($this->content[$key]);
|
||||
$array = array();
|
||||
foreach ($this->params["fields"] as $arg => $field)
|
||||
$array[$arg] = $b->field_render_db_value($field[0], $this->name . "[$key][$arg]", "");
|
||||
$this->content[] = $array;
|
||||
}
|
||||
}
|
||||
foreach ($this->content as $key => $data) {
|
||||
foreach ($this->params["fields"] as $arg => $field)
|
||||
$this->content[$key][$arg] = $b->field_render_db_value($field[0], $this->name . "[$key][$arg]", $data[$arg]);
|
||||
}
|
||||
return json_encode(array_values($this->content));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
class Password {
|
||||
public string $name;
|
||||
public array $params;
|
||||
public $content = "";
|
||||
|
||||
public function __construct($params = array())
|
||||
{
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
public function set_content($content)
|
||||
{
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
public function set_name($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function render_edit()
|
||||
{
|
||||
global $b;
|
||||
$input_dom = new DOM("input");
|
||||
$input_dom->setAttribute("type", "password");
|
||||
$input_dom->setAttribute("name", $this->name);
|
||||
$input_dom->setAttribute("placeholder", "Оставьте пустым чтобы не вносить изменения");
|
||||
$input_dom->setAttribute("value", $b->get_view($this->content));
|
||||
$input_dom->view();
|
||||
}
|
||||
|
||||
public function render_value()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
public function render_db_value($old_value)
|
||||
{
|
||||
if($this->content == "ЗАШИФРОВАНО") return $old_value;
|
||||
return password_hash($this->content, PASSWORD_DEFAULT);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
class Separator {
|
||||
public string $name;
|
||||
public array $params;
|
||||
public $content = "";
|
||||
|
||||
public function __construct($params = array())
|
||||
{
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
public function set_content($content)
|
||||
{
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
public function set_name($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
public function render_edit()
|
||||
{
|
||||
global $b;
|
||||
$input_dom = new DOM("div");
|
||||
$input_dom->setAttribute("type", "text");
|
||||
$input_dom->setAttribute("class", "bive-separator");
|
||||
$input_dom->setAttribute("value", $b->get_view($this->content));
|
||||
$input_dom->view();
|
||||
}
|
||||
|
||||
public function render_value()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
public function render_db_value()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
class Text {
|
||||
public string $name;
|
||||
public array $params;
|
||||
public $content = "";
|
||||
|
||||
public function __construct($params = array())
|
||||
{
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
public function set_content($content)
|
||||
{
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
public function set_name($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function render_edit()
|
||||
{
|
||||
global $b;
|
||||
$input_dom = new DOM("input");
|
||||
$input_dom->setAttribute("type", "text");
|
||||
$input_dom->setAttribute("name", $this->name);
|
||||
$input_dom->setAttribute("value", $b->get_view($this->content));
|
||||
$input_dom->view();
|
||||
}
|
||||
|
||||
public function render_value()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
public function render_db_value()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
class Text_Readonly {
|
||||
public string $name;
|
||||
public array $params;
|
||||
public $content = "";
|
||||
|
||||
public function __construct($params = array())
|
||||
{
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
public function set_content($content)
|
||||
{
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
public function set_name($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
public function render_edit()
|
||||
{
|
||||
global $b;
|
||||
$input_dom = new DOM("input");
|
||||
$input_dom->setAttribute("type", "text");
|
||||
$input_dom->setAttribute("class", "bive-readonly");
|
||||
$input_dom->setAttribute("value", $b->get_view($this->content));
|
||||
$input_dom->setAttribute("readonly", "readonly");
|
||||
$input_dom->view();
|
||||
}
|
||||
|
||||
public function render_value()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
public function render_db_value()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user