3030use phpMyFAQ \Helper \FaqHelper ;
3131use phpMyFAQ \Instance \Elasticsearch ;
3232use phpMyFAQ \Language \Plurals ;
33+ use stdClass ;
3334
3435/*
3536 * Query type definitions
@@ -454,18 +455,15 @@ public function renderFaqsByCategoryId(int $categoryId, string $orderBy = 'id',
454455 /**
455456 * This function returns all not expired records from the given record ids.
456457 *
457- * @param int[] $faqIds Array of record ids
458+ * @param int[] $faqIds Array of record ids
458459 * @param string $orderBy Order by
459- * @param string $sortBy Sort by
460+ * @param string $sortBy Sort by
461+ * @throws CommonMarkException
460462 */
461- public function renderFaqsByFaqIds (array $ faqIds , string $ orderBy = 'fd.id ' , string $ sortBy = 'ASC ' ): string
463+ public function renderFaqsByFaqIds (array $ faqIds , string $ orderBy = 'fd.id ' , string $ sortBy = 'ASC ' ): array
462464 {
463- global $ sids ;
464-
465465 $ records = implode (', ' , $ faqIds );
466466 $ page = Filter::filterInput (INPUT_GET , 'seite ' , FILTER_VALIDATE_INT , 1 );
467- $ taggingId = Filter::filterInput (INPUT_GET , 'tagging_id ' , FILTER_VALIDATE_INT );
468- $ output = '' ;
469467
470468 $ now = date ('YmdHis ' );
471469 $ queryHelper = new QueryHelper ($ this ->user , $ this ->groups );
@@ -474,7 +472,8 @@ public function renderFaqsByFaqIds(array $faqIds, string $orderBy = 'fd.id', str
474472 SELECT
475473 fd.id AS id,
476474 fd.lang AS lang,
477- fd.thema AS thema,
475+ fd.thema AS question,
476+ fd.content AS answer,
478477 fcr.category_id AS category_id,
479478 fv.visits AS visits
480479 FROM
@@ -530,29 +529,19 @@ public function renderFaqsByFaqIds(array $faqIds, string $orderBy = 'fd.id', str
530529
531530 $ num = $ this ->configuration ->getDb ()->numRows ($ result );
532531 $ numberPerPage = $ this ->configuration ->get ('records.numberOfRecordsPerPage ' );
533- $ pages = ceil ($ num / $ numberPerPage );
534532
535533 if ($ page == 1 ) {
536534 $ first = 0 ;
537535 } else {
538536 $ first = ($ page * $ numberPerPage ) - $ numberPerPage ;
539537 }
540538
539+ $ searchResults = [];
541540 if ($ num > 0 ) {
542- if ($ pages > 1 ) {
543- $ output .= sprintf (
544- '<p><strong>%s %s %s</strong></p> ' ,
545- Translation::get ('msgPage ' ) . $ page ,
546- Translation::get ('msgVoteFrom ' ),
547- $ pages . Translation::get ('msgPages ' )
548- );
549- }
550-
551- $ output .= '<ul class="phpmyfaq_ul"> ' ;
552541 $ counter = 0 ;
553542 $ displayedCounter = 0 ;
554-
555543 $ lastFaqId = 0 ;
544+ $ faqHelper = new FaqHelper ($ this ->configuration );
556545 while (($ row = $ this ->configuration ->getDb ()->fetchObject ($ result )) && $ displayedCounter < $ numberPerPage ) {
557546 ++$ counter ;
558547 if ($ counter <= $ first ) {
@@ -565,68 +554,34 @@ public function renderFaqsByFaqIds(array $faqIds, string $orderBy = 'fd.id', str
565554 continue ; // Don't show multiple FAQs
566555 }
567556
568- $ visits = empty ( $ row -> visits ) ? 0 : $ row -> visits ;
557+ $ rowResult = new stdClass () ;
569558
570- $ title = $ row ->thema ;
559+ $ title = $ row ->question ;
571560 $ url = sprintf (
572- '%sindex.php?%saction =faq& cat=%d& id=%d& artlang=%s ' ,
561+ '%sindex.php?action =faq&cat=%d&id=%d&artlang=%s ' ,
573562 $ this ->configuration ->getDefaultUrl (),
574- $ sids ,
575563 $ row ->category_id ,
576564 $ row ->id ,
577565 $ row ->lang
578566 );
567+
579568 $ oLink = new Link ($ url , $ this ->configuration );
580- $ oLink ->itemTitle = $ row ->thema ;
569+ $ oLink ->itemTitle = $ row ->question ;
581570 $ oLink ->text = $ title ;
582571 $ oLink ->tooltip = $ title ;
583- $ listItem = sprintf (
584- '<li>%s<br><small>(%s)</small></li> ' ,
585- $ oLink ->toHtmlAnchor (),
586- $ this ->plurals ->GetMsg ('plmsgViews ' , $ visits )
587- );
588572
589- $ output .= $ listItem ;
573+ $ rowResult ->renderedScore = 0 ;
574+ $ rowResult ->question = Utils::chopString ($ title , 15 );
575+ $ rowResult ->path = '' ;
576+ $ rowResult ->url = $ oLink ->toString ();
577+ $ rowResult ->answerPreview = $ faqHelper ->renderAnswerPreview ($ row ->answer , 20 );
590578
591579 $ lastFaqId = $ row ->id ;
580+ $ searchResults [] = $ rowResult ;
592581 }
593-
594- $ output .= '</ul><span id="totFaqRecords" style="display: none;"> ' . $ num . '</span> ' ;
595- } else {
596- return '' ;
597- }
598-
599- if ($ num > $ this ->configuration ->get ('records.numberOfRecordsPerPage ' )) {
600- $ output .= '<p class="text-center"><strong> ' ;
601- if (!isset ($ page )) {
602- $ page = 1 ;
603- }
604-
605- $ vor = $ page - 1 ;
606- $ next = $ page + 1 ;
607- if ($ vor != 0 ) {
608- $ url = $ sids . '&action=search&tagging_id= ' . $ taggingId . '&seite= ' . $ vor ;
609- $ oLink = new Link ($ this ->configuration ->getDefaultUrl () . '? ' . $ url , $ this ->configuration );
610- $ oLink ->itemTitle = 'tag ' ;
611- $ oLink ->text = Translation::get ('msgPrevious ' );
612- $ oLink ->tooltip = Translation::get ('msgPrevious ' );
613- $ output .= '[ ' . $ oLink ->toHtmlAnchor () . ' ] ' ;
614- }
615-
616- $ output .= ' ' ;
617- if ($ next <= $ pages ) {
618- $ url = $ sids . '&action=search&tagging_id= ' . $ taggingId . '&seite= ' . $ next ;
619- $ oLink = new Link ($ this ->configuration ->getDefaultUrl () . '? ' . $ url , $ this ->configuration );
620- $ oLink ->itemTitle = 'tag ' ;
621- $ oLink ->text = Translation::get ('msgNext ' );
622- $ oLink ->tooltip = Translation::get ('msgNext ' );
623- $ output .= '[ ' . $ oLink ->toHtmlAnchor () . ' ] ' ;
624- }
625-
626- $ output .= '</strong></p> ' ;
627582 }
628583
629- return $ output ;
584+ return $ searchResults ;
630585 }
631586
632587 /**
0 commit comments