Código fuente wiki de Macros for the Blog Categories

Última modificación por Administrator el 2014/10/29 07:38

Mostrar los últimos autores
1 {{include reference="Blog.BlogCode"/}}
2
3 {{velocity output="false"}}
4 ##
5 ##
6 ##
7 #**
8 * Retrieves the list of blog entries from a given category. Entries belonging to subcategories
9 * are not returned.
10 *
11 * @param category The name of the category (XDocument full name, for example 'MyBlog.Fishing').
12 * @param articles Return parameter, where the list of entries is placed.
13 * @param total Return parameter, where the total number of entries belonging to this category is
14 * placed. Useful for a paginated view.
15 *###
16 #macro(getEntriesForCategory $category $entries $totalEntries)
17 #set ($entries = $NULL)
18 #set ($totalEntries = $NULL)
19 #if ("$!{blogCategoryEntriesCache.containsKey($!{category})}" == 'true')
20 #setVariable ("$entries" $blogCategoryEntriesCache.get($!{category}).get(0))
21 #setVariable ("$totalEntries" $blogCategoryEntriesCache.get($!{category}).get(1))
22 #preparePagedViewParams ($totalEntries 10)
23 #else
24 #getCategoriesHierarchy ('' $tree)
25 #set ($subcategories = [])
26 #getSubcategories ($tree $category $subcategories)
27 #set ($categories = [${category}])
28 #set ($discard = $categories.addAll(${subcategories}))
29 #set ($parameters = '?')
30 #foreach ($subcategory in $subcategories)
31 #set ($parameters = $parameters.concat(', ?'))
32 #end
33 #getBlogEntriesBaseQuery ($query)
34 #set ($query = ", DBStringListProperty as categories join categories.list as category${query} and obj.id = categories.id.id and categories.id.name='category' and category in (${parameters})")
35 #set ($totalResult = $services.query.hql($query).bindValues($categories).count())
36 #preparePagedViewParams ($totalResult 10)
37 #set ($result = $services.query.hql("${query} order by publishDate.value desc").setLimit($itemsPerPage).setOffset($startAt).bindValues($categories).execute())
38 #if ("$!{blogCategoryEntriesCache.containsKey($!{category})}" == '')
39 #set ($blogCategoryEntriesCache = {})
40 #end
41 #set ($discard = $blogCategoryEntriesCache.put("$!{category}", [$result, $totalResult]))
42 #setVariable ("$entries" $result)
43 #setVariable ("$totalEntries" $totalResult)
44 #end
45 #end
46 #macro(getSubcategories $tree $category $subcategories)
47 #if(!$subcategories.contains($category))
48 #foreach($subcategory in $tree.get($category))
49 #set($discard = $subcategories.add($subcategory))
50 #getSubcategories($tree $subcategory $subcategories)
51 #end
52 #end
53 #end
54 ##
55 ##
56 ##
57 #**
58 * Builds a tree of categories, respecting the parent<->subcategory relation. Each node holds the
59 * full name of the category's document. The root of the tree is 'Blog.Categories'.
60 *
61 * @param space The space where to search for categories. If this parameter is an emptry string or
62 * null, all the categories in the wiki are returned.
63 * @param tree Return parameter, HashMap<String, List<String>> structure holding the categories
64 * hierarchy, where the key is the name of a category, and the value contains the names of
65 * all its subcategories. To obtain the full hierarchy, start with the key 'Blog.Categories'.
66 *###
67 #macro(getCategoriesHierarchy $space $tree)
68 #set ($tree = $NULL)
69 #if ("$!{blogCategoriesHierarchyCache.containsKey($!{space})}" == 'true')
70 #setVariable ("$tree" $blogCategoriesHierarchyCache.get($!{space}))
71 #else
72 #set ($result = {})
73 #set($query = ', BaseObject obj where ')
74 #if("$!space" != '')
75 #set($query = "${query}doc.space = '${space}' and ")
76 #end
77 #set($query = "${query}obj.name = doc.fullName and obj.className = '${blogCategoryClassname}' order by doc.name")
78 #foreach($category in $services.query.hql($query).execute())
79 #set($categoryDoc = $xwiki.getDocument($category))
80 #set($categoryParent = "$!categoryDoc.parent")
81 #if($categoryParent == '')
82 #set($categoryParent = $defaultCategoryParent)
83 #end
84 #if(!$result.containsKey($categoryParent))
85 #set($discard = $result.put($categoryParent, []))
86 #end
87 #set($discard = $result.get($categoryParent).add($category))
88 #end
89 #if ("$!{blogCategoriesHierarchyCache.containsKey($!{space})}" == '')
90 #set ($blogCategoriesHierarchyCache = {})
91 #end
92 #set ($discard = $blogCategoriesHierarchyCache.put("$!{space}", $result))
93 #setVariable ("$tree" $result)
94 #end
95 #end
96 ##
97 ##
98 ##
99 #**
100 * Displays the category hierarchy held in the <tt>tree</tt> parameter.
101 *
102 * @param tree The category hierarchy, a HashMap<String, List<String>> structure, where the key
103 * is the name of a category, and the value contains the names of all its subcategories.
104 * @param displayMethod Selects how to display the category tree. Possible values are:
105 * <ul>
106 * <li><em>"simple"</em>: tree with links to the category pages.</li>
107 * <li><em>"selectable"</em>: each category name in the tree is preceded by a checkbox.</li>
108 * <li><em>"option"</em>: wraps each category name in an &lt;option&gt; element, to be used
109 * in a select box.</li>
110 * <li><em>"editable"</em>: displays links to delete and edit each category, if the rights
111 * allow such actions.</li>
112 * </ul>
113 * For any other value, the default ("simple") is considered.
114 *###
115 #macro(displayCategoriesHierarchy $tree $displayMethod)
116 #set($processedCategories = [])
117 #displayCategoriesHierarchyRecursive($tree $defaultCategoryParent 1 $displayMethod)
118 #end
119 ##
120 ##
121 ##
122 #**
123 * Displays recursively the category hierarchy held in the <tt>tree</tt> parameter, starting at
124 * the node indicated by the <tt>root</tt> parameter, which is on the <tt>level</tt>th level in
125 * the tree.
126 *
127 * @param tree The category hierarchy HashMap<String, List<String>> structure, where the key
128 * is the name of a category, and the value contains the names of all its subcategories.
129 * @param root The full name of the document containing the category that is to be considered the
130 * root of the displayed subtree.
131 * @param level The current depth of the tree, used for proper indentation.
132 * @param displayMethod Selects how to display the category tree. Possible values are:
133 * <ul>
134 * <li><em>"simple"</em>: tree with links to the category pages.</li>
135 * <li><em>"selectable"</em>: each category name in the tree is preceded by a checkbox.</li>
136 * <li><em>"option"</em>: wraps each category name in an &lt;option&gt; element, to be used
137 * in a select box.</li>
138 * <li><em>"editable"</em>: displays links to delete and edit each category, if the rights
139 * allow such actions.</li>
140 * </ul>
141 * For any other value, the default ("simple") is considered.
142 *###
143 #macro(displayCategoriesHierarchyRecursive $tree $root $level $displayMethod)
144 #if(!$processedCategories)
145 #set($processedCategories = [])
146 #end
147 #foreach($item in $tree.get($root))
148 #if(!$processedCategories.contains($item))
149 #set($discard = $processedCategories.add($item))
150 #displayCategory($item $level $displayMethod)
151 #displayCategoriesHierarchyRecursive($tree $item $mathtool.add($level, 1) $displayMethod)
152 #end
153 #end
154 #if($displayMethod == "selectable")
155 <input type="hidden" name="${blogPostClassname}_$!{entryObj.number}_category" value="" />
156 #end
157 #end
158 ##
159 ##
160 ##
161 #**
162 * Displays a category as part of a category hierarchy.
163 *
164 * @param name The full name of the document containing the category to be displayed.
165 * @param level The depth where this category is in the tree, used for proper indentation.
166 * @param displayMethod Selects how to display the category tree. Possible values are:
167 * <ul>
168 * <li><em>"simple"</em>: tree with links to the category pages.</li>
169 * <li><em>"selectable"</em>: each category name in the tree is preceded by a checkbox.</li>
170 * <li><em>"option"</em>: wraps each category name in an &lt;option&gt; element, to be used
171 * in a select box.</li>
172 * <li><em>"editable"</em>: displays links to delete and edit each category, if the rights
173 * allow such actions.</li>
174 * </ul>
175 * For any other value, the default ("simple") is considered.
176 *###
177 #macro(displayCategory $name $level $displayMethod)
178 #if("$!displayMethod" == "option")
179 #displayOptionCategory($name $level)
180 #elseif("$!displayMethod" == "selectable")
181 #displaySelectableCategory($name $level)
182 #elseif("$!displayMethod" == "editable")
183 #displayEditableCategory($name $level)
184 #else
185 #displaySimpleCategory($name $level)
186 #end
187 #end
188 ##
189 ##
190 ##
191 #**
192 * Displays a category as part of a category hierarchy, preceded by a checkbox that allows choosing
193 * this category for a blog entry.
194 *
195 * @param name The full name of the document containing the category to be displayed.
196 * @param level The depth where this category is in the tree, used for proper indentation.
197 *###
198 #macro(displaySelectableCategory $name $level)
199 #set($categoryDoc = $xwiki.getDocument($name))
200 #set($addCategURL = $doc.getURL('view', $escapetool.url({
201 'xaction': 'showAddCategory',
202 'parentCategory' : $name
203 })))
204 #set($addEntryParams = false)
205 #if($isBlogPost)
206 #set($entry = $xwiki.getDocument($doc.fullName))
207 #set($entryObj = $isBlogPost)
208 #set($addEntryParams = true)
209 #elseif("$!request.entry" != '' && "$!request.entryObjNb" != '')
210 #set($entry = $xwiki.getDocument($request.entry))
211 #set($entryObj = $entry.getObject($blogPostClassname, $mathtool.toInteger($request.entryObjNb)))
212 #set($addEntryParams = true)
213 #end
214 #if($isBlogPost || $addEntryParams)
215 ## parentCategory must be the last param
216 #set($addCategURL = $doc.getURL('view', $escapetool.url({
217 'xaction': 'showAddCategory',
218 'entry': $entry.fullName,
219 'entryObjNb': $entryObj.number,
220 'parentCategory': $name
221 })))
222 #end
223 #foreach($i in [1..$level])*#end ##
224 <span class="blog-category-level"><span class="blog-category">##
225 <label id='blog_category_${escapetool.xml($name)}' title="#getCategoryDescription($categoryDoc)"><input name="${blogPostClassname}_$!{entryObj.number}_category" value="${escapetool.xml($name)}" type="checkbox"#if($entryObj.getProperty('category').getValue().contains($name)) checked="checked" #end/> #getCategoryName($categoryDoc)</label>##
226 </span>##
227 #if($xwiki.hasAccessLevel('edit', $xcontext.user, $doc.fullName) && ("$!{request.xaction}" != "showAddCategory" || "$!{request.parentCategory}" != $name))
228 <span class="blog-category-tools">##
229 <a href="$escapetool.xml($addCategURL)" class="tool add-subcategory">#toolImage('chart_organisation_add' 'Add a subcategory ')</a>##
230 </span>##
231 #end
232 </span>
233 #end
234 ##
235 ##
236 ##
237 #**
238 * Displays a form for creating a new category. If a parentCategory parameter is present in the
239 * query string, the parent category is set accordingly. Otherwise, the form provides a selection
240 * control for choosing the parent category among existing categories.
241 *###
242 ## DO NOT CHANGE INDENTATION
243 #macro(addCategoryForm) #set($addCategURL = $doc.getURL()) #if("$!request.entry" != '') #set($addCategURL = "${addCategURL}?entry=$escapetool.url($request.entry)&amp;entryObjNb=$escapetool.url($!request.entryObjNb)")#end<form action="${addCategURL}" method="post" class="category-add-form"><div class='create-category'> <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" /> <input type="hidden" name="xaction" value="create"/> <label>$services.localization.render('xe.blog.categories.new')<br/> <input type="text" name="newCategoryName" class="category-name-input" /></label><br/>#if("$!{request.parentCategory}" == "")<label>#* $services.localization.render('xe.blog.categories.parent')*# Subcategory of:<br/> <select name="newCategoryParent" id="blog_category_selectBox" class="category-add-input"> <option value="${defaultCategoryParent}" selected="selected">None</option> $!processedCategories.clear() #displayCategoriesHierarchy($tree 'option') </select> <br/></label>#else<input type="hidden" name="newCategoryParent" value="${escapetool.xml($request.parentCategory)}"/>#end<span class="buttonwrapper"><input class="button" type="submit" value="Add" /></span> <a href="$doc.getURL()">Cancel</a> </div></form> #end
244 ##
245 ##
246 ##
247 #**
248 * Displays a form for renaming a category.
249 *###
250 ## DO NOT CHANGE INDENTATION
251 #macro(renameCategoryForm)##
252 <form action="$doc.getURL()" method="post" class="category-rename-form"><div class='rename-category'>##
253 <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" />
254 <input type="hidden" name="xaction" value="rename"/>##
255 <input type="hidden" name="category" value="${escapetool.xml($request.category)}"/>##
256 <label>$services.localization.render('xe.blog.categories.newName')<br/> <input type="text" name="newCategoryName" class="category-name-input" /></label><br/>##
257 <span class="buttonwrapper"><input class="button" type="submit" value="Rename" /></span> ##
258 <a href="$doc.getURL()">Cancel</a>##
259 </div></form>##
260 #end
261 ##
262 ##
263 ##
264 #**
265 * Displays a category as part of a category hierarchy, followed by links for editing and deleting
266 * this category, if the current user has the rights to perform these actions.
267 *
268 * @param name The full name of the document containing the category to be displayed.
269 * @param level The depth where this category is in the tree, used for proper indentation.
270 *###
271 ## DO NOT CHANGE INDENTATION
272 #macro(displayEditableCategory $name $level)
273 #getEntriesForCategory($name $discard $totalEntries)
274 #set($nameUrl = $escapetool.url($name))
275 #foreach($i in [1..$level])*#end ##
276 <span class="blog-category-level"><span class="blog-category">##
277 <a href="$xwiki.getURL('Blog.CategoryRss', 'view', "xpage=plain&amp;category=$nameUrl")" title="RSS"><img class="icon icon-manage" src="$xwiki.getSkinFile('icons/xwiki/rss-medium.png')" alt="[RSS]"/></a>##
278 [[#getCategoryName($xwiki.getDocument($name)) (% class="itemCount" %)($totalEntries)(%%)>>${name}]]</span> ##
279 <span class="blog-category-tools">##
280 #if($xwiki.hasAccessLevel('delete', $xcontext.user, $name) && ("$!{request.xaction}" != 'showRenameCategory' || "$!{request.category}" != $name))<a href="$xwiki.getURL('Blog.ManageCategories', 'view', "xaction=showRenameCategory&amp;category=$nameUrl")" class="tool rename">#toolImage('pencil' 'Rename ')</a>#end ##
281 #if($xwiki.hasAccessLevel('edit', $xcontext.user, $doc.fullName) && ("$!{request.xaction}" != "showAddCategory" || "$!{request.parentCategory}" != $name))<a href="$xwiki.getURL('Blog.ManageCategories', 'view', "xaction=showAddCategory&amp;parentCategory=$nameUrl")" class="tool add-subcategory">#toolImage('chart_organisation_add' 'Add a subcategory ')</a> #end ##
282 #if($xwiki.hasAccessLevel('delete', $xcontext.user, $name)) <a href="$xwiki.getURL('Blog.ManageCategories', 'view', "xaction=delete&amp;category=$nameUrl&amp;form_token=$!{services.csrf.getToken()}")" class="tool delete">#toolImage('cross' 'Delete ')</a>#end ##
283 </span>##
284 #if($xwiki.hasAccessLevel('edit', $xcontext.user, $doc.fullName) && "$!{request.xaction}" == "showRenameCategory" && "$!{request.category}" == $name) #renameCategoryForm() #end##
285 #if($xwiki.hasAccessLevel('edit', $xcontext.user, $doc.fullName) && "$!{request.xaction}" == "showAddCategory" && "$!{request.parentCategory}" == $name) #addCategoryForm() #end##
286 </span>
287 #end
288 ##
289 ##
290 ##
291 #**
292 * Displays a category as part of a category hierarchy, wrapped in an &lt;option&gt; element, to
293 * be used in a select box.
294 *
295 * @param name The full name of the document containing the category to be displayed.
296 * @param level The depth where this category is in the tree, used for proper indentation.
297 *###
298 #macro(displayOptionCategory $name $level)
299 <option id="blog_category_${escapetool.xml($name)}_option" value="${escapetool.xml($name)}">#if($level > 1)#foreach($i in [2..$level])&nbsp;&nbsp;#end#end#getCategoryName($xwiki.getDocument($name))</option>
300 #end
301 ##
302 ##
303 ##
304 #**
305 * Displays a category as part of a category hierarchy, wrapped in a link.
306 *
307 * @param name The full name of the document containing the category to be displayed.
308 * @param level The depth where this category is in the tree, used for proper indentation.
309 *###
310 #macro(displaySimpleCategory $name $level)
311 #getEntriesForCategory($name $discard $totalEntries)
312 #set($nameUrl = $escapetool.url($name))
313 #foreach($i in [1..$level])*#end <span class="blog-category-level"><a href="$xwiki.getURL('Blog.CategoryRss', 'view', "xpage=plain&amp;category=$nameUrl")" title="RSS">#toolImage('bullet_feed', '[RSS]')</a> <a href="$xwiki.getURL($name)">#getCategoryName($xwiki.getDocument($name))</a> <span class="itemCount"> ($totalEntries)</span></span>
314 #end
315 ##
316 ##
317 ##
318 #**
319 * Prints the name of a category, indicated by its document.
320 * The result is XML-escaped
321 *
322 * @param categoryDoc The document containing the category to be displayed.
323 *###
324 #macro(getCategoryName $categoryDoc)
325 ## Don't indent!
326 #set($result = "$!categoryDoc.getObject(${blogCategoryClassname}).getProperty('name').value.trim()")##
327 #if($result == '')
328 #set($result = $categoryDoc.name)
329 #end
330 $escapetool.xml($result)##
331 #end
332 ##
333 ##
334 ##
335 #**
336 * Prints the description of a category, indicated by its document.
337 * The result is XML-escaped
338 *
339 * @param categoryDoc The document containing the category to be displayed.
340 *###
341 #macro(getCategoryDescription $categoryDoc)
342 ## Don't indent!
343 $escapetool.xml($!categoryDoc.getObject(${blogCategoryClassname}).getProperty('description').value.trim())##
344 #end
345 ##
346 ##
347 ##
348 #**
349 * Generates a form for creating a new category. The form allows to enter the name of the new
350 * category, and select a parent category from the existing ones.
351 *
352 * @param tree The category hierarchy, a HashMap<String, List<String>> structure, where the key
353 * is the name of a category, and the value contains the names of all its subcategories.
354 * @todo When javascript is disabled, a link to "Manage categories" should be displayed instead.
355 * This "form" should be created from javascript.
356 *###
357 #macro(showCreateCategoryBoxWithForm $tree)
358 <form action="" method="post">
359 #showCreateCategoryBox($tree)
360 </form>
361 #end
362 #**
363 * Generates a box for creating a new category. This allows to enter the name of the new
364 * category, and select a parent category from the existing ones. Note that this does not create
365 * a HTML form element, but requires one to be defined already as its ancestor.
366 *
367 * @param tree The category hierarchy HashMap<String, List<String>> structure, where the key
368 * is the name of a category, and the value contains the names of all its subcategories.
369 * @todo When javascript is disabled, a link to "Manage categories" should be displayed instead.
370 * This "form" should be created from javascript.
371 *###
372 #macro(showCreateCategoryBox $tree)
373 <div class='create-category'>
374 <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" />
375 <input type="hidden" name="xaction" value="create"/>
376 <label>$services.localization.render('xe.blog.categories.new') <input type="text" name="newCategoryName" /></label>
377 <label>$services.localization.render('xe.blog.categories.parent')
378 <select name="newCategoryParent" id="blog_category_selectBox">
379 <option value="${defaultCategoryParent}" selected="selected">None</option>
380 $!processedCategories.clear()##
381 #displayCategoriesHierarchy($tree 'option')
382 </select>
383 </label>
384 <span class="buttonwrapper"><input class="button" type="button" value="Add" id="blog_AddCategoryButton" /></span>
385 </div>
386 #end
387 ##
388 ##
389 ##
390 #macro(displayCategoryManagementTree $space $displayType)
391 <div class="blog-categories-list">
392 #getCategoriesHierarchy("$!{space}" $tree)
393 #displayCategoriesHierarchy($tree $displayType)
394 #if($xwiki.hasAccessLevel('edit', $xcontext.user, $doc.fullName))
395 #set($addCategURL = $doc.getURL('view', $escapetool.url({
396 'xaction' : 'showAddCategory',
397 'parentCategory' : ''
398 })))
399 #if($isBlogPost || ("$!request.entry" != '' && "$!request.entryObjNb" != ''))
400 #set($entryParam = $!doc.fullName)
401 #set($entryObjNbParam = $!entryObj.number)
402 #if(!$isBlogPost)
403 #set($entryParam = $!request.entry)
404 #set($entryObjNbParam = $!request.entryObjNb)
405 #end
406 #set($addCategURL = $doc.getURL('view', $escapetool.url({
407 'xaction' : 'showAddCategory',
408 'parentCategory' : '',
409 'entry' : $entryParam,
410 'entryObjNb' : $entryObjNbParam
411 })))
412 #end
413 * <span class="blog-add-category-label"><a href="$escapetool.xml($addCategURL)">$services.localization.render('xe.blog.categories.addcategory')</a></span>
414 #if("$!{request.xaction}" == "showAddCategory" && "$!{request.parentCategory}" == "") #addCategoryForm() #end
415 #end
416
417
418 </div>
419 #end
420 ##
421 ##
422 ##
423 #**
424 * Deletes a category, moving all the subcategories to its parent and removing this category from
425 * all existing blog entries.
426 *
427 * @param category The full name of the document containing the category to be deleted.
428 *###
429 #macro(deleteCategory $category)
430 #set($categoryDoc = $xwiki.getDocument($category))
431 #set($categoryParent = "$!categoryDoc.parent")
432 #if($categoryParent == '')
433 #set($categoryParent = "{$defaultCategoryParent}"))
434 #end
435 #set($parameterValues = ["$!{category}"])
436 #set($query = ', BaseObject obj where ')
437 #if($space != '')
438 #set($query = "${query}doc.space = '${space}' and ")
439 #end
440 #set($query = "${query}obj.name = doc.fullName and obj.className = '${blogCategoryClassname}' and doc.fullName <> 'Blog.CategoryTemplate' and doc.parent = ? order by doc.name")
441
442 #foreach($item in $services.query.hql($query).bindValues($parameterValues).execute())
443 #if($xwiki.hasAccessLevel('edit', $xcontext.user, $item) && $!{services.csrf.isTokenValid("$!{request.getParameter('form_token')}")})
444 #set($subcategoryDoc = $xwiki.getDocument($item))
445 $subcategoryDoc.setParent($categoryParent)
446 $subcategoryDoc.save($services.localization.render('xe.blog.manageCategories.comment.updatedParent'), true)
447 #end
448 #end
449 #set($query = ', BaseObject obj, DBStringListProperty categories join categories.list as category where ')
450 #if($space != '')
451 #set($query = "${query}doc.space = '${space}' and ")
452 #end
453 #set($query = "${query}obj.name = doc.fullName and obj.className = '${blogPostClassname}' and doc.fullName <> 'Blog.BlogPostTemplate' and categories.id.id = obj.id and categories.id.name = 'category' and category = ? order by doc.name")
454 #foreach($item in $services.query.hql($query).bindValues($parameterValues).execute())
455 #if($xwiki.hasAccessLevel('edit', $xcontext.user, $item) && $!{services.csrf.isTokenValid("$!{request.getParameter('form_token')}")})
456 #set($blogEntryDoc = $xwiki.getDocument($item))
457 #set($discard = $blogEntryDoc.getObject(${blogPostClassname}).getProperty('category').value.remove($category))
458 $blogEntryDoc.save($services.localization.render('xe.blog.manageCategories.comment.removedDeletedCategory'), true)
459 #end
460 #end
461 $categoryDoc.delete()
462 #end
463 ##
464 ##
465 ##
466 #**
467 * Renames a category, updating all the subcategories and all existing blog entries.
468 *
469 * @param category The full name of the document containing the category to be renamed.
470 * @param newCategoryName The new name of the category.
471 *###
472 #macro(renameCategory $category $newCategoryName)
473 #set($categoryDoc = $xwiki.getDocument($category))
474 #set($newCategoryDoc = $xwiki.getDocument($newCategoryName))
475 #set($parameterValues = ["$!{category}"])
476 #set($query = ', BaseObject obj where ')
477 #set($query = "${query}obj.name = doc.fullName and obj.className = '${blogCategoryClassname}' and doc.fullName <> 'Blog.CategoryTemplate' and doc.parent = ? order by doc.name")
478 #foreach($item in $services.query.hql($query).bindValues($parameterValues).execute())
479 #if($xwiki.hasAccessLevel('edit', $xcontext.user, $item) && $!{services.csrf.isTokenValid("$!{request.getParameter('form_token')}")})
480 #set($subcategoryDoc = $xwiki.getDocument($item))
481 $subcategoryDoc.setParent($newCategoryDoc.fullName)
482 $subcategoryDoc.save($services.localization.render('xe.blog.manageCategories.comment.updatedParent'), true)
483 #end
484 #end
485 #set($query = ', BaseObject obj, DBStringListProperty categories join categories.list as category where ')
486 #set($query = "${query}obj.name = doc.fullName and obj.className = '${blogPostClassname}' and doc.fullName <> 'Blog.BlogPostTemplate' and categories.id.id = obj.id and categories.id.name = 'category' and category = ? order by doc.name")
487 #foreach($item in $services.query.hql($query).bindValues($parameterValues).execute())
488 #if($xwiki.hasAccessLevel('edit', $xcontext.user, $item) && $!{services.csrf.isTokenValid("$!{request.getParameter('form_token')}")})
489 #set($blogEntryDoc = $xwiki.getDocument($item))
490 #set($discard = $blogEntryDoc.getObject(${blogPostClassname}).getProperty('category').value.remove($category))
491 #set($discard = $blogEntryDoc.getObject(${blogPostClassname}).getProperty('category').value.add($newCategoryDoc.fullName))
492 $blogEntryDoc.save($services.localization.render('xe.blog.manageCategories.comment.updatedRenamedCategory'), true)
493 #end
494 #end
495 #if ($!{services.csrf.isTokenValid("$!{request.getParameter('form_token')}")})
496 $categoryDoc.getObject('Blog.CategoryClass').set('name', $newCategoryName)
497 $categoryDoc.save($services.localization.render('xe.blog.manageCategories.comment.updatedCategory'), true)
498 $categoryDoc.rename($newCategoryName)
499 #end
500 #end
501 {{/velocity}}