Game-Jaming/Backend/Controllers/keyWord/NewKeyWord.php

48 lines
1.5 KiB
PHP

<?php
require_once "../../../bootstrap.php";
require_once "../Group/Group.php";
use Backend\Models\Group;
use Backend\Models\KeyWord;
session_start();
if (isLogin()) {
if(isset($_POST['submitKeyWord'])){
//Find the group id
$group = groupViaToken($_SESSION['token']);
//if statement to find out if the group have use all their keyWords
if(KeyWord::where('group_id', $group->id)->count()<$group->group_amount){
//Make a new keyword[Only to be used if you need to make a new of something]
$keyword = new KeyWord();
//Take the keyWord the user typed and set it equal to the keyword valuable
$keyword->key_word = $_POST['key_word'];
//Make foreign key from the groups table to the keyWords table
$keyword->group()->associate($group);
//Try to save it
if(!$keyword->save()){
header("location: ../../../Frontend/index.html?error=FailedToSave");
exit();
}else{
header("location: ../../../Frontend/index.html?success=KeyWordSaved");
exit();
}
}else{
header("location: ../../../Frontend/index.html?error=YouCantSubmitAnyMoreKeyWords");
exit();
}
}else{
header("location: ../../../Frontend/index.html?error=CouldNotSubmitKeyWord");
exit();
}
}else{
header("location: ../../../Frontend/index.html?error=NotLogin");
exit();
}