added roster config

This commit is contained in:
Frank John Begornia
2024-11-05 05:33:47 +08:00
parent c68f28aa11
commit 54278c568d
7 changed files with 750 additions and 258 deletions

View File

@@ -348,14 +348,16 @@ class UserController extends Controller
$newTeamStoreModel = new TeamStoreModel;
$product_array = $newTeamStoreModel->selectTeamStoreProducts('ProductURL', $url);
$roster = $newUserModel->getRoster($product_array[0]->Id);
$thumbnails_array = $newTeamStoreModel->getThumbnails($product_array[0]->Id);
$available_size = explode(",", $product_array[0]->AvailableSizes);
$shipping_cost = $newUserModel->selectShippingCost();
return view('user-layouts.view-store-item')->with('product_array', $product_array)
->with('available_size', $available_size)
->with('thumbnails_array', $thumbnails_array)
->with('shipping_cost', $shipping_cost);
->with('shipping_cost', $shipping_cost)
->with('roster', $roster);
}
@@ -1344,4 +1346,76 @@ class UserController extends Controller
return $array_address_book;
}
}
function roster(Request $request)
{
$UserModel = new UserModel;
$post = $request->all();
$response = $UserModel->insertRoster($post['data']);
if($response) {
return response()->json(array(
'status' => true,
'message' => "Roster is successfully saved."
));
}
return response()->json(array(
'status' => false,
'message' => "Something went wrong. Please try again"
));
}
function deleteRoster(Request $request) {
$UserModel = new UserModel;
$post = $request->all();
$response = $UserModel->deleteRoster($post['data']);
if($response) {
return response()->json(array(
'status' => true,
'message' => "Roster is successfully deleted."
));
}
return response()->json(array(
'status' => false,
'message' => "Something went wrong. Please try again"
));
}
function rosterUpdate(Request $request)
{
$UserModel = new UserModel;
$post = $request->all();
$response = $UserModel->updateRoster($post['data']);
if($response) {
return response()->json(array(
'status' => true,
'message' => "Roster is successfully updated."
));
}
return response()->json(array(
'status' => false,
'message' => "Something went wrong. Please try again"
));
}
function getCurrentRoster(Request $request) {
$productId = $request->query('product-id');
$newUserModel = new UserModel;
$roster = $newUserModel->getRoster($productId);
return response()->json($roster);
}
}

View File

@@ -149,6 +149,11 @@ Route::group(['middleware' => 'normaluser'], function () {
Route::post('user/store-items/personal-design', 'user\UserController@saveNewItemFromDesigner');
Route::post('user/roster', 'user\UserController@roster');
Route::get('user/roster', 'user\UserController@getCurrentRoster');
Route::post('user/roster-delete', 'user\UserController@deleteRoster');
Route::post('user/roster-update', 'user\UserController@rosterUpdate');
});
Route::group(['middleware' => 'auth'], function () {

View File

@@ -425,4 +425,44 @@ class UserModel extends Model
->update($data);
return $i;
}
}
function insertRoster($data) {
$i = DB::table('roster')
->insert($data);
return $i;
}
function getRoster($productId)
{
$i = DB::table('roster')
->where('ProductId', $productId)
->get();
return $i;
}
function deleteRoster($idArray)
{
$deletedRows = DB::table('roster')
->whereIn('Id', $idArray) // Replace 'id' with the actual column name if different
->delete();
return $deletedRows; // Returns the number of rows deleted
}
function updateRoster($data)
{
$updatedRows = 0;
foreach ($data as $item) {
// Assuming each item contains an 'id' and the fields to update
$id = $item['Id'];
unset($item['Id']); // Remove 'id' from the update data
$updatedRows += DB::table('roster')
->where('Id', $id)
->update($item);
}
return $updatedRows; // Returns the total number of rows updated
}
}