| 37 | | class QuestionHelper extends AbstractHelper |
| 38 | | { |
| 39 | | |
| 40 | | |
| 41 | | |
| 42 | | public function generateSmartAnswer(SearchResultSet $searchResultSet): string |
| 43 | | { |
| 44 | | $plurals = new Plurals(); |
| 45 | | $smartAnswer = sprintf('<h5>%s</h5>', $plurals->get( |
| 46 | | key: 'plmsgSearchAmount', |
| 47 | | number: $searchResultSet->getNumberOfResults(), |
| 48 | | )); |
| 49 | | |
| 50 | | $smartAnswer .= '<ul>'; |
| 51 | | foreach ($searchResultSet->getResultSet() as $result) { |
| 52 | | $question = (string) ($result->question ?? ''); |
| 53 | | $url = sprintf( |
| 54 | | '%scontent/%d/%d/%s/%s.html', |
| 55 | | $this->configuration->getDefaultUrl(), |
| 56 | | (int) ($result->category_id ?? 0), |
| 57 | | (int) ($result->id ?? 0), |
| 58 | | (string) ($result->lang ?? ''), |
| 59 | | TitleSlugifier::slug($question), |
| 60 | | ); |
| 61 | | $link = new Link($url, $this->configuration); |
| 62 | | $link->text = Utils::chopString($question, 15); |
| 63 | | $link->setTitle($question); |
| 64 | | |
| 65 | | $faqHelper = new FaqHelper($this->configuration); |
| 66 | | $smartAnswer .= sprintf( |
| 67 | | '<li>%s<br><small class="pmf-search-preview">%s...</small></li>', |
| 68 | | $link->toHtmlAnchor(), |
| 69 | | $faqHelper->renderAnswerPreview((string) ($result->answer ?? ''), 10), |
| 70 | | ); |
| 71 | | } |
| 72 | | |
| 73 | | return $smartAnswer . '</ul>'; |
| 74 | | } |
| 75 | | |
| 76 | | public function getOpenQuestions(): stdClass |
| 77 | | { |
| 78 | | $date = new Date($this->configuration); |
| 79 | | $mail = new Mail($this->configuration); |
| 80 | | $db = $this->configuration->getDb(); |
| 81 | | $language = $db->escape($this->configuration->getLanguage()->getLanguage()); |
| 82 | | |
| 83 | | $query = sprintf( |
| 84 | | "SELECT COUNT(id) AS num FROM %sfaqquestions WHERE lang = '%s' AND is_visible != 'Y'", |
| 85 | | Database::getTablePrefix(), |
| 86 | | $language, |
| 87 | | ); |
| 88 | | |
| 89 | | $result = $db->query($query); |
| 90 | | $row = $db->fetchObject($result); |
| 91 | | |
| 92 | | $openQuestions = new stdClass(); |
| 93 | | $openQuestions->numberInvisibleQuestions = $row instanceof \stdClass ? (int) $row->num : 0; |
| 94 | | |
| 95 | | $query = sprintf( |
| 96 | | "SELECT * FROM %sfaqquestions WHERE lang = '%s' AND is_visible = 'Y' ORDER BY created ASC", |
| 97 | | Database::getTablePrefix(), |
| 98 | | $language, |
| 99 | | ); |
| 100 | | |
| 101 | | $result = $db->query($query); |
| 102 | | |
| 103 | | if ($result !== false && $this->configuration->getDb()->numRows($result) > 0) { |
| 104 | | $openQuestions->numberQuestions = $this->configuration->getDb()->numRows($result); |
| 105 | | $questions = []; |
| 106 | | while (true) { |
| 107 | | $row = $this->configuration->getDb()->fetchObject($result); |
| 108 | | if (!$row instanceof \stdClass) { |
| 109 | | break; |
| 110 | | } |
| 111 | | |
| 112 | | $question = new stdClass(); |
| 113 | | $question->id = (int) $row->id; |
| 114 | | $question->lang = (string) $row->lang; |
| 115 | | $question->date = $date->format(Date::createIsoDate((string) $row->created)); |
| 116 | | $question->email = $mail->safeEmail((string) $row->email); |
| 117 | | $question->userName = (string) $row->username; |
| 118 | | $question->categoryId = (int) $row->category_id; |
| 119 | | $question->categoryName = $this->getCategory()->getCategoryName((int) $row->category_id); |
| 120 | | $question->question = (string) $row->question; |
| 121 | | $question->answerId = (int) $row->answer_id; |
| 122 | | $question->slug = TitleSlugifier::slug($question->question); |
| 123 | | |
| 124 | | $questions[] = $question; |
| 125 | | } |
| 126 | | |
| 127 | | $openQuestions->questions = $questions; |
| 128 | | } |
| 129 | | |
| 130 | | return $openQuestions; |
| 131 | | } |
| 132 | | } |