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");
?>
$attribute) { ?>
= $attribute->get_item_name(); ?>
$a) { ?>
parent_id != $attribute->get_item_id()) continue; ?>
= $a->get_item_name(); ?>
get_item_id() . "][new]"; ?>" placeholder="Новый атрибут">
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;
}
}