diff --git a/.idea/workspace.xml b/.idea/workspace.xml index e8b72b2..de8f11a 100755 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -21,6 +21,9 @@ <component name="ChangeListManager"> <list default="true" id="fc13552d-b118-4828-b78f-fc8714e0cfdc" name="Default Changelist" comment="Final COMMIT!!!"> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/controller/FaqController.class.inc.php" beforeDir="false" afterPath="$PROJECT_DIR$/controller/FaqController.class.inc.php" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/model/FaqModel.class.inc.php" beforeDir="false" afterPath="$PROJECT_DIR$/model/FaqModel.class.inc.php" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/templates/faq.tmpl.html" beforeDir="false" afterPath="$PROJECT_DIR$/templates/faq.tmpl.html" afterDir="false" /> <change beforePath="$PROJECT_DIR$/vendor/js/faq.js" beforeDir="false" afterPath="$PROJECT_DIR$/vendor/js/faq.js" afterDir="false" /> </list> <option name="SHOW_DIALOG" value="false" /> @@ -32,7 +35,7 @@ <execution /> </component> <component name="DarkyenusTimeTracker"> - <option name="totalTimeSeconds" value="73933" /> + <option name="totalTimeSeconds" value="76591" /> <option name="gitIntegration" value="true" /> <option name="naggedAbout" value="1" /> </component> @@ -77,7 +80,8 @@ <option name="presentableId" value="Default" /> <updated>1601618466935</updated> <workItem from="1601618467981" duration="36776000" /> - <workItem from="1601809534320" duration="1018000" /> + <workItem from="1601809534320" duration="1558000" /> + <workItem from="1601811106543" duration="2864000" /> </task> <task id="LOCAL-00001" summary="Initial commit"> <created>1601618764031</created> @@ -170,7 +174,14 @@ <option name="project" value="LOCAL" /> <updated>1601810048772</updated> </task> - <option name="localTasksCounter" value="14" /> + <task id="LOCAL-00014" summary="Done issue #5 and #3"> + <created>1601810664354</created> + <option name="number" value="00014" /> + <option name="presentableId" value="LOCAL-00014" /> + <option name="project" value="LOCAL" /> + <updated>1601810664354</updated> + </task> + <option name="localTasksCounter" value="15" /> <servers /> </component> <component name="TypeScriptGeneratedFilesManager"> @@ -200,7 +211,8 @@ <MESSAGE value=" Updating database-conf" /> <MESSAGE value="Final COMMIT!!!" /> <MESSAGE value="Fix issue #1" /> - <option name="LAST_COMMIT_MESSAGE" value="Fix issue #1" /> + <MESSAGE value="Done issue #5 and #3" /> + <option name="LAST_COMMIT_MESSAGE" value="Done issue #5 and #3" /> </component> <component name="WindowStateProjectService"> <state x="728" y="326" width="800" height="683" key="#com.intellij.execution.impl.EditConfigurationsDialog" timestamp="1601632929047"> @@ -239,10 +251,10 @@ <screen x="0" y="34" width="1920" height="1046" /> </state> <state x="441" y="192" width="1037" height="736" key="SettingsEditor/0.34.1920.1046@0.34.1920.1046" timestamp="1601632853044" /> - <state x="555" y="292" width="800" height="535" key="Vcs.Push.Dialog.v2" timestamp="1601810051854"> + <state x="555" y="292" width="800" height="535" key="Vcs.Push.Dialog.v2" timestamp="1601810665321"> <screen x="0" y="34" width="1920" height="1046" /> </state> - <state x="555" y="292" width="800" height="535" key="Vcs.Push.Dialog.v2/0.34.1920.1046@0.34.1920.1046" timestamp="1601810051854" /> + <state x="555" y="292" width="800" height="535" key="Vcs.Push.Dialog.v2/0.34.1920.1046@0.34.1920.1046" timestamp="1601810665321" /> <state x="809" y="122" width="639" height="876" key="com.intellij.database.view.ui.AbstractDbRefactoringDialog" timestamp="1601632983240"> <screen x="0" y="34" width="1920" height="1046" /> </state> diff --git a/controller/FaqController.class.inc.php b/controller/FaqController.class.inc.php index bb6c484..677cc95 100644 --- a/controller/FaqController.class.inc.php +++ b/controller/FaqController.class.inc.php @@ -62,8 +62,9 @@ class FaqController extends DefaultController $FAQModel = new FaqModel(); $room = $FAQModel->getRoom(); $question = Api::getVar( 'question' ); + $nickname = APi::getVar( 'nickname' ); - if( empty( $question ) || strlen( $question ) > 500 || strlen( $question ) < 10 ) + if( empty( $question ) || empty( $nickname) || strlen( $question ) > 500 || strlen( $question ) < 10 || strlen( $nickname) < 3 || strlen( $nickname ) > 20 ) { $view->setSuccess( false ); $view->setHeaderCode( 903 ); @@ -71,7 +72,7 @@ class FaqController extends DefaultController } try { - $FAQModel->addQuestion( $room['id'], $question ); + $FAQModel->addQuestion( $room['id'], $question, $nickname ); } catch( Exception $e ) { $view->setSuccess( false ); diff --git a/model/FaqModel.class.inc.php b/model/FaqModel.class.inc.php index c2d79c1..0ff1e6e 100644 --- a/model/FaqModel.class.inc.php +++ b/model/FaqModel.class.inc.php @@ -75,10 +75,15 @@ class FaqModel return $result['id']; } - public function addQuestion(int $room_id, string $question) + /** + * @param int $room_id + * @param string $question + * @param string $nickname + */ + public function addQuestion(int $room_id, string $question, string $nickname ) { $stmnt = Database::getConnection()->prepare( 'INSERT INTO questions ( room_id, question, created_by ) VALUES ( :room_id, :question, :created_by )' ); - $stmnt->execute( array( 'room_id' => $room_id, 'question' => htmlspecialchars( $question ), 'created_by' => 'Anonymous' ) ); + $stmnt->execute( array( 'room_id' => $room_id, 'question' => htmlspecialchars( $question ), 'created_by' => $nickname ) ); } diff --git a/templates/faq.tmpl.html b/templates/faq.tmpl.html index b7ef587..d9b07ad 100755 --- a/templates/faq.tmpl.html +++ b/templates/faq.tmpl.html @@ -68,11 +68,11 @@ <div class="modal-body"> <span class="text-danger" id="askErrorMsg"></span> <div class="form-group"> - <label for="name" class="col-form-label">Name</label><br> - <input type="text" class="form-control" maxlength="15" id="name"> + <label for="nickname" class="col-form-label">Name</label><br> + <input type="text" class="form-control" maxlength="20" minlength="3" id="nickname"> <br> <label for="question" class="col-form-label">Question</label> - <textarea name="question" class="form-control" id="question" maxlength="500" rows="4"></textarea> + <textarea name="question" class="form-control" id="question" minlength="10" maxlength="500" rows="4"></textarea> </div> </div> <div class="modal-footer"> @@ -96,7 +96,7 @@ <span class="text-danger" id="answerErrorMsg"></span> <div class="form-group"> <label for="answer" class="col-form-label">Answer</label> - <textarea name="answer" class="form-control" id="answer" maxlength="500" rows="4"></textarea> + <textarea name="answer" class="form-control" id="answer" minlength="5" maxlength="1000" rows="4"></textarea> </div> </div> <div class="modal-footer"> diff --git a/vendor/js/faq.js b/vendor/js/faq.js index 7bb0837..9e05f59 100644 --- a/vendor/js/faq.js +++ b/vendor/js/faq.js @@ -13,6 +13,7 @@ answerErrorMsg = $('#answerErrorMsg' ); questions = $( '#questions' ) question = $('#question' ); askButton = $('#askBtn' ); +nickname = $('#nickname' ); function request( a_uri, a_data, a_successhandler, a_errorhandler ) { @@ -56,6 +57,19 @@ function askQuestion() askButton.prop( 'disabled', false ); return; } + if ( !nickname.val() ) + { + askErrorMsg.html( 'Please enter a name first!' ); + askButton.prop( 'disabled', false ); + return; + } + + if( nickname.val().length > 20 || nickname.val().length < 3 ) + { + askErrorMsg.html( 'The name should be 3-20 characters long.' ); + askButton.prop( 'disabled', false ); + return; + } if( question.val().length > 500 || question.val().length < 10 ) { @@ -64,7 +78,7 @@ function askQuestion() return; } - request( 'addQuestion', {"question":question.val()}, + request( 'addQuestion', {"question":question.val(),"nickname":nickname.val()}, function( result ){ askErrorMsg.html( '' ); askButton.prop( 'disabled', false ); @@ -79,7 +93,7 @@ function askQuestion() askErrorMsg.html( "Something wrong happened. We don't know why...<br>Try again later please!" ); break; case 903: - askErrorMsg.html( "The question should contain at least 10 up to 500 characters!<br>Just not romans, but also not just 'help'." ); + askErrorMsg.html( "The question should contain at least 10 up to 500 characters!<br>The nickname should contain at least 3 up to 20 characters!" ); break; default: $('.modal').modal('hide'); @@ -122,13 +136,13 @@ function openReadMoreModal( id ) let answer_id = 0; function openAnswerModal( id ) { - answerModalTitle.html( 'Answer ' + 'Anonymous' + " question" ); + answerModalTitle.html( 'Answer ' + 'XXX' + " question" ); answerErrorMsg.html( '' ); answerModal.modal( 'show' ); request( 'getQuestion', {"question_id":id}, function( result ) { - readMoreModalTitle.html( 'Answer ' + result.data.created_by + " question" ); + answerModalTitle.html( 'Answer ' + result.data.created_by + "'s question" ); if( result.data.answer !== null && result.data.answer.length > 5 ) { answerText.val( result.data.answer ); @@ -147,9 +161,9 @@ function answer() return; } - if( answerText.val().length < 5 || answerText.val().length > 500 ) + if( answerText.val().length < 5 || answerText.val().length > 1000 ) { - answerErrorMsg.html( 'The answer should contain 10-500 characters!' ); + answerErrorMsg.html( 'The answer should contain 10-1000 characters!' ); return; } @@ -183,7 +197,7 @@ function getQuestions() { questions.append( '<div class="col-sm-6 col-lg-4 col-md-5"><div class="card" id="q_' + result.data.questions[i].id + '" style=" margin-bottom: 10px;">' + ' <div class="card-body">' + - ' <h5 class="card-title">Question</h5>' + + ' <h5 class="card-title text-warning">Question</h5>' + ' <h6 class="card-subtitle mb-2 text-muted">From ' + result.data.questions[i].created_by + '</h6>' + ' <p class="card-text">'+ result.data.questions[i].question + '</p>' + ' <a href="#" onclick="openReadMoreModal(\''+ result.data.questions[i].id + '\');" class="card-link">Read more</a>' + @@ -193,6 +207,11 @@ function getQuestions() '</div> ' ) } else if ( $( '#qa_' + result.data.questions[i].id ).length < 1 && result.data.questions[i].answer !== null && result.data.questions[i].answer.length > 5 ) + { + $('#q_' + result.data.questions[i].id + ' p' ).html( result.data.questions[i].question + '<hr><span id="qa_' + result.data.questions[i].id + '">' + result.data.questions[i].answer + '</span>' ); + $('#q_' + result.data.questions[i].id + ' h5').addClass( 'text-info' ).removeClass( 'text-warning' ); + } + else if ( result.data.questions[i].answer !== $('#qa_' + result.data.questions[i].id ).html() ) { $('#q_' + result.data.questions[i].id + ' p' ).html( result.data.questions[i].question + '<hr><span id="qa_' + result.data.questions[i].id + '">' + result.data.questions[i].answer + '</span>' ); }