1515
1616namespace Paustian \BookModule \Controller ;
1717
18+ use Symfony \Component \HttpFoundation \JsonResponse ;
1819use Symfony \Contracts \Translation \TranslatorInterface ;
1920use Zikula \Bundle \CoreBundle \Controller \AbstractController ;
2021use Zikula \Bundle \CoreBundle \RouteUrl ;
@@ -58,6 +59,8 @@ public function __construct(
5859 parent ::__construct ($ extension , $ permissionApi , $ variableApi , $ translator );
5960 $ this ->currentUserApi = $ currentUserApi ;
6061 $ this ->textSummarizer = new TextSummarizer ();
62+ //initially don't summarize the text at all.
63+ $ this ->textSummarizer ->setSumLevel (1 , (int )$ this ->getVar ('sumlevel ' ));
6164 }
6265
6366 /**
@@ -171,7 +174,10 @@ public function displayarticle(Request $request,
171174 $ content = $ article ->getContents ();
172175 //Now add the highlights if necessary
173176 $ uid = $ this ->currentUserApi ->get ('uid ' );
174- if ($ uid != "" ) {
177+ $ summarize = $ this ->getVar ('summarize ' );
178+ $ maxLevel = $ this ->getVar ('sumlevel ' );
179+ //Only process highlights if the text summarizing functions are off or the sumLevel is at 5 sentences (max)
180+ if (($ uid != "" ) && (!$ summarize || ($ this ->textSummarizer ->getSumLevel () == 5 ))) {
175181 //procesing the highlights goes here. This way the figure text won't matter
176182 $ content = $ this ->_process_highlights ($ content , $ article ->getAid (), $ this ->currentUserApi );
177183 }
@@ -191,6 +197,8 @@ public function displayarticle(Request $request,
191197 'chnumber ' => $ chnumber ,
192198 'content ' => $ content ,
193199 'return_url ' => $ return_url ,
200+ 'summarize ' => $ summarize ,
201+ 'max_level ' => $ maxLevel ,
194202 'show_internals ' => $ show_internals ])->getContent ();
195203
196204 $ repo = $ this ->getDoctrine ()->getRepository ('PaustianBookModule:BookArticlesEntity ' );
@@ -200,9 +208,7 @@ public function displayarticle(Request $request,
200208 if ($ doglossary ) {
201209 $ return_text = $ this ->_add_glossary_defs ($ return_text );
202210 }
203- //dummy variable for now.
204- $ doSummary = true ;
205- if ($ doSummary ){
211+ if ($ summarize ){
206212 $ return_text = $ this ->textSummarizer ->summarizeText ($ return_text );
207213 }
208214 return new Response ($ return_text );
@@ -363,6 +369,31 @@ public function displayfigure(Request $request, BookFiguresEntity $figure = null
363369 return new Response ($ figureText );
364370 }
365371
372+ /**
373+ * @Route("/sumlevelchange", options={"expose"=true})
374+ * @Method("POST")
375+ *
376+ * Grab all comments associated with this module and item ID and return them to the caller
377+ * The caller is a javascript, see the javascripts in Resources/public/js directory
378+ *
379+ * @param Request $request
380+ * @return JsonResponse|AccessDeniedException
381+ */
382+ public function sumlevelchange (Request $ request ): JsonResponse {
383+ if (!$ this ->hasPermission ($ this ->name . ':: ' , ':: ' , ACCESS_READ )) {
384+ return new AccessDeniedException ($ this ->trans ('Access forbidden since you cannot read this page. ' ));
385+ }
386+ //get the summary level and set it
387+ $ summaryLevel = (int )$ request ->get ('sumLevel ' );
388+ $ this ->textSummarizer ->setSumLevel ($ summaryLevel , (int )$ this ->getVar ('sumlevel ' ));
389+
390+ //now we have to rerender the text. The $request already has the aid of the article
391+ $ response = $ this ->displayarticle ($ request );
392+ $ jsonReply = ['html ' => $ response ->getContent (),
393+ 'sumLevel ' => $ summaryLevel ];
394+ return new JsonResponse ($ jsonReply );
395+ }
396+
366397 /**
367398 * @Route("/displayglossary")
368399 *
0 commit comments