Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
lists.php
1<?php
3
5
6class Lists
7{
8 private $categoryCodes = array();
9 private $categoryNames = array();
10 private $sections = array();
11 private $items = array();
12
13
14 public function addItem($categoryCode = "", $item = array())
15 {
16 $this->createCategory($categoryCode);
17 $this->items[$categoryCode][] = $item;
18 }
19 public function addItems($categoryCode = "", $items = array())
20 {
21 $this->createCategory($categoryCode);
22 foreach ($items as $item)
23 {
24 $this->items[$categoryCode][] = $item;
25 }
26 }
27
28 public function addSection($categoryCode = "", $sectionCode, $sectionName)
29 {
30 $this->createCategory($categoryCode);
31
32 $this->sections[$categoryCode][] = array(
33 "ID"=> $sectionCode,
34 "NAME"=>$sectionName
35 );
36
37 }
38
39 public function setCategoryName($categoryCode = "", $name = "")
40 {
41 $this->categoryNames[$categoryCode] = $name;
42 }
43
44 private function createCategory($categoryCode)
45 {
46 if(!array_key_exists($categoryCode,$this->categoryCodes))
47 {
48 $this->categoryCodes[$categoryCode] = array();
49 $this->sections[$categoryCode] = array();
50 $this->categoryNames[$categoryCode] = "";
51
52 }
53 }
54
55
56 public function showJSON()
57 {
61 global $APPLICATION;
62
63 $listData = array(
64 "data" => $this->items,
65 "sections" => $this->sections,
66 "names" => $this->categoryNames,
67 );
68
69 if(SITE_CHARSET != "UTF8")
70 {
71 $listData = Encoding::convertEncodingArray($listData, SITE_CHARSET, "UTF8");
72 }
73 header("Content-Type: application/x-javascript");
74 echo json_encode($listData);
75 }
76
77
78}
setCategoryName($categoryCode="", $name="")
Definition lists.php:39
addItem($categoryCode="", $item=array())
Definition lists.php:14
addItems($categoryCode="", $items=array())
Definition lists.php:19
addSection($categoryCode="", $sectionCode, $sectionName)
Definition lists.php:28