You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.3 KiB
PHTML

14 years ago
<?php
use Engelsystem\Models\Question;
/**
* @return string
*/
8 years ago
function questions_title()
{
return __('Ask the Heaven');
}
/**
* @return string
*/
8 years ago
function user_questions()
{
$user = auth()->user();
$request = request();
8 years ago
if (!$request->has('action')) {
$open_questions = $user->questionsAsked()
->whereNull('answerer_id')
->orderByDesc('created_at')
->get();
$answered_questions = $user->questionsAsked()
->whereNotNull('answerer_id')
->orderByDesc('answered_at')
->get();
8 years ago
return Questions_view(
$open_questions->all(),
$answered_questions->all(),
page_link_to('user_questions', ['action' => 'ask'])
);
8 years ago
} else {
switch ($request->input('action')) {
8 years ago
case 'ask':
$question = request()->get('question');
if (!empty($question) && $request->hasPostData('submit')) {
Question::create([
'user_id' => $user->id,
'text' => $question,
]);
success(__('You question was saved.'));
throw_redirect(page_link_to('user_questions'));
8 years ago
} else {
return page_with_title(questions_title(), [
error(__('Please enter a question!'), true)
8 years ago
]);
}
break;
case 'delete':
if (
$request->has('id')
&& preg_match('/^\d{1,11}$/', $request->input('id'))
&& $request->hasPostData('submit')
) {
$question_id = $request->input('id');
8 years ago
} else {
return error(__('Incomplete call, missing Question ID.'), true);
8 years ago
}
$question = Question::find($question_id);
if (!empty($question) && $question->user_id == $user->id) {
$question->delete();
throw_redirect(page_link_to('user_questions'));
8 years ago
} else {
return page_with_title(questions_title(), [
error(__('No question found.'), true)
8 years ago
]);
}
break;
}
8 years ago
}
return '';
14 years ago
}