@@ -127,7 +127,12 @@ function createUserRole(array $roles, int $user_id) : String
127127 {
128128 $ role = \Obrainwave \AccessTree \Models \Role::where ('id ' , $ role )->first ();
129129 if ($ role )
130- {
130+ {
131+ $ check_role = \Obrainwave \AccessTree \Models \UserRole::where ('role_id ' , $ role ->id )->where ('user_id ' , $ user_id )->first ();
132+ if ($ check_role )
133+ {
134+ continue ;
135+ }
131136 $ user_role = new \Obrainwave \AccessTree \Models \UserRole ();
132137 $ user_role ->user_id = $ user_id ;
133138 $ user_role ->role_id = $ role ->id ;
@@ -285,4 +290,72 @@ function fetchUserRoles(int $user_id) : Object
285290 }
286291
287292 return $ user_roles ;
293+ }
294+
295+ function importFile ($ request )
296+ {
297+ $ fileMimes = array (
298+ 'text/x-comma-separated-values ' ,
299+ 'text/comma-separated-values ' ,
300+ 'application/octet-stream ' ,
301+ 'application/vnd.ms-excel ' ,
302+ 'application/x-csv ' ,
303+ 'text/x-csv ' ,
304+ 'text/csv ' ,
305+ 'application/csv ' ,
306+ 'application/excel ' ,
307+ 'application/vnd.msexcel ' ,
308+ 'text/plain '
309+ );
310+
311+ // if (!empty($_FILES['file']['name']) && in_array($_FILES['file']['type'], $fileMimes))
312+ // {
313+
314+ // // Open uploaded CSV file with read-only mode
315+ // $csvFile = fopen($_FILES['file']['tmp_name'], 'r');
316+
317+ // // Skip the first line
318+ // fgetcsv($csvFile);
319+
320+ // // Parse data from CSV file line by line
321+ // while (($getData = fgetcsv($csvFile, 10000, ",")) !== FALSE)
322+ // {
323+ // // Get row data
324+ // $name = $getData[0];
325+ // $email = $getData[1];
326+
327+ // // If user already exists in the database with the same email
328+ // $query = "SELECT id FROM users WHERE email = '" . $getData[1] . "'";
329+
330+ // $check = mysqli_query($con, $query);
331+
332+ // if ($check->num_rows > 0)
333+ // {
334+ // mysqli_query($conn, "UPDATE users SET name = '" . $name . "', created_at = NOW() WHERE email = '" . $email . "'");
335+ // }
336+ // else
337+ // {
338+ // mysqli_query($con, "INSERT INTO users (name, email, created_at, updated_at) VALUES ('" . $name . "', '" . $email . "', NOW(), NOW())");
339+ // }
340+ // }
341+
342+ // // Close opened CSV file
343+ // fclose($csvFile);
344+
345+ // header("Location: index.php");
346+ // }else{
347+ // echo "Please select valid file";
348+ // }
349+ $ file = $ request ->file ('file ' );
350+ $ fileContents = file ($ file ->getPathname ());
351+
352+ foreach ($ fileContents as $ line ) {
353+ $ data = str_getcsv ($ line );
354+
355+ // Product::create([
356+ // 'name' => $data[0],
357+ // 'price' => $data[1],
358+ // // Add more fields as needed
359+ // ]);
360+ }
288361}
0 commit comments