1+ <?php
2+ namespace ide \doc \account \api ;
3+
4+ use ide \account \api \AbstractService ;
5+ use ide \account \api \ServiceException ;
6+ use ide \account \api \ServiceInvalidResponseException ;
7+ use ide \account \api \ServiceNotAvailableException ;
8+ use ide \account \api \ServiceResponse ;
9+ use ide \account \api \ServiceResponseFuture ;
10+ use ide \utils \Tree ;
11+
12+ /**
13+ * Class DocService
14+ * @package ide\doc\account\api
15+ *
16+ * @method ServiceResponseFuture categoryTreeAsync(callable $callback = null)
17+ * @method ServiceResponseFuture categoryAsync($id, callable $callback = null)
18+ * @method ServiceResponseFuture categoriesAsync($parentCategoryId, callable $callback = null)
19+ * @method ServiceResponseFuture allCategoriesAsync(callable $callback = null)
20+ * @method ServiceResponseFuture entryAsync($id, callable $callback = null)
21+ * @method ServiceResponseFuture entriesAsync($categoryId, $offset, $limit, callable $callback = null)
22+ * @method ServiceResponseFuture allEntriesAsync($sort, $offset, $limit, callable $callback = null)
23+ * @method ServiceResponseFuture saveEntryAsync($data, callable $callback = null)
24+ * @method ServiceResponseFuture saveCategoryAsync($data, callable $callback = null)
25+ * @method ServiceResponseFuture deletedEntryAsync($id, callable $callback = null)
26+ * @method ServiceResponseFuture restoreEntryAsync($id, callable $callback = null)
27+ * @method ServiceResponseFuture deleteCategoryAsync($id, callable $callback = null)
28+ * @method ServiceResponseFuture restoreCategoryAsync($id, callable $callback = null)
29+ */
30+ class DocService extends AbstractService
31+ {
32+ /**
33+ * Return full tree of categories.
34+ */
35+ public function categoryTree ()
36+ {
37+ $ response = $ this ->allCategories ();
38+
39+ if ($ response ->isSuccess ()) {
40+ $ data = $ response ->data ();
41+
42+ return new ServiceResponse ([
43+ 'status ' => $ response ->status (),
44+ 'message ' => $ response ->message (),
45+ 'data ' => new Tree ($ data , 'id ' , 'parentId ' )
46+ ]);
47+ } else {
48+ return $ response ;
49+ }
50+ }
51+
52+ public function category ($ id )
53+ {
54+ return $ this ->execute ('doc/category ' , ['id ' => $ id ]);
55+ }
56+
57+ public function categories ($ parentCategoryId = null )
58+ {
59+ return $ this ->execute ('doc/categories ' , ['parentId ' => $ parentCategoryId ]);
60+ }
61+
62+ public function allCategories ()
63+ {
64+ return $ this ->execute ('doc/all-categories ' , []);
65+ }
66+
67+ public function entry ($ id )
68+ {
69+ return $ this ->execute ('doc/entry ' , ['id ' => $ id ]);
70+ }
71+
72+ public function entries ($ categoryId , $ offset = 0 , $ limit = 40 )
73+ {
74+ return $ this ->execute ('doc/entries ' , ['categoryId ' => $ categoryId , 'offset ' => $ offset , 'limit ' => $ limit ]);
75+ }
76+
77+ public function allEntries ($ sort = 'UPDATED_AT ' , $ offset = 0 , $ limit = 40 )
78+ {
79+ return $ this ->execute ('doc/entries ' , ['categoryId ' => $ sort , 'offset ' => $ offset , 'limit ' => $ limit ]);
80+ }
81+
82+ public function saveEntry ($ data )
83+ {
84+ return $ this ->execute ('doc/save-entry ' , $ data );
85+ }
86+
87+ public function saveCategory ($ data )
88+ {
89+ return $ this ->execute ('doc/save-category ' , $ data );
90+ }
91+
92+ public function deleteEntry ($ id )
93+ {
94+ return $ this ->saveEntry (['id ' => $ id , 'deleted ' => true ]);
95+ }
96+
97+ public function restoreEntry ($ id )
98+ {
99+ return $ this ->saveEntry (['id ' => $ id , 'deleted ' => false ]);
100+ }
101+
102+ public function deleteCategory ($ id )
103+ {
104+ return $ this ->saveCategory (['id ' => $ id , 'deleted ' => true ]);
105+ }
106+
107+ public function restoreCategory ($ id )
108+ {
109+ return $ this ->saveCategory (['id ' => $ id , 'deleted ' => false ]);
110+ }
111+ }
0 commit comments