33namespace okapi \services \lists \create ;
44
55use okapi \core \Db ;
6+ use okapi \core \Exception \InvalidParam ;
67use okapi \core \Okapi ;
78use okapi \core \Request \OkapiRequest ;
89use okapi \Settings ;
9- use okapi \core \Exception \InvalidParam ;
1010
1111class WebService
1212{
@@ -28,66 +28,67 @@ public static function call(OkapiRequest $request)
2828 {
2929 $ user_id = $ request ->token ->user_id ;
3030
31- $ listName = $ request ->get_parameter ('list_name ' );
32- $ listDescription = $ request ->get_parameter ('list_description ' );
33- $ listStatus = $ request ->get_parameter ('list_status ' );
34- $ isWatched = $ request ->get_parameter ('is_watched ' );
35- $ listPassword = $ request ->get_parameter ('list_password ' );
31+ $ list_name = $ request ->get_parameter ('list_name ' );
32+ $ list_description = $ request ->get_parameter ('list_description ' );
33+ $ list_status = $ request ->get_parameter ('list_status ' );
34+ $ is_watched = $ request ->get_parameter ('is_watched ' );
35+ $ list_password = $ request ->get_parameter ('list_password ' );
3636
37- if (empty ($ listName )) {
37+ if (empty ($ list_name )) {
3838 throw new InvalidParam ('list_name ' , 'list_name is mandatory and must not be empty. ' );
3939 }
4040
41- $ insertFields = array (
42- 'name ' => Db::escape_string ($ listName ),
41+ $ insert_fields = array (
42+ 'name ' => Db::escape_string ($ list_name ),
4343 'user_id ' => Db::escape_string ($ user_id )
4444 );
4545
46- if (!empty ($ listDescription )) {
47- $ insertFields ['description ' ] = Db::escape_string ($ listDescription );
46+ if (!empty ($ list_description )) {
47+ $ insert_fields ['description ' ] = Db::escape_string ($ list_description );
4848 }
4949
50- if ($ listStatus !== null && $ listStatus !== '' ) {
51- $ listStatus = (int )$ listStatus ;
52- if (!in_array ($ listStatus , [0 , 2 , 3 ])) {
50+ if ($ list_status !== null && $ list_status !== '' ) {
51+ $ list_status = (int )$ list_status ;
52+ if (!in_array ($ list_status , [0 , 2 , 3 ])) {
5353 throw new InvalidParam ('list_status ' , 'list_status must be a valid value (0, 2, 3). ' );
5454 }
55- $ insertFields ['is_public ' ] = $ listStatus ;
55+ $ insert_fields ['is_public ' ] = $ list_status ;
5656
5757 // Handle list_password only if list_status is 0 (private)
58- if ($ listStatus == 0 ) {
59- if (isset ($ listPassword ) && $ listPassword !== '' ) {
60- $ insertFields ['password ' ] = substr ( Db::escape_string ($ listPassword ) , 0 , 16 );
58+ if ($ list_status == 0 ) {
59+ if (isset ($ list_password ) && $ list_password !== '' ) {
60+ $ insert_fields ['password ' ] = Db::escape_string (substr ( $ list_password , 0 , 16 ) );
6161 }
6262 }
6363 }
6464
65- $ columns = implode (', ' , array_keys ($ insertFields ));
66- $ values = "' " . implode ("', ' " , $ insertFields ) . "' " ;
65+ $ columns = implode (', ' , array_keys ($ insert_fields ));
66+ $ values = "' " . implode ("', ' " , $ insert_fields ) . "' " ;
6767
68- $ insertQuery = "INSERT INTO cache_lists ( $ columns) VALUES ( $ values) " ;
69- Db::query ($ insertQuery );
68+ $ insert_query = "INSERT INTO cache_lists ( $ columns) VALUES ( $ values) " ;
69+ Db::query ($ insert_query );
7070
71- $ listId = Db::last_insert_id ();
71+ $ list_id = Db::last_insert_id ();
7272
7373 // Handle is_watched
74- if ($ isWatched !== null && $ isWatched !== '' ) {
75- $ isWatched = (int )$ isWatched ;
76- if (!in_array ($ isWatched , [0 , 1 ])) {
74+ if ($ is_watched !== null && $ is_watched !== '' ) {
75+ $ is_watched = (int )$ is_watched ;
76+ if (!in_array ($ is_watched , [0 , 1 ])) {
7777 throw new InvalidParam ('is_watched ' , 'is_watched must be a valid value (0, 1). ' );
7878 }
7979
80- // Insert a new record
81- Db::query ("INSERT INTO cache_list_watches (cache_list_id, user_id, is_watched) VALUES (LAST_INSERT_ID(), ' $ user_id', $ isWatched) " );
80+ Db::query ("
81+ INSERT INTO cache_list_watches (cache_list_id, user_id, is_watched)
82+ VALUES (' " .Db::escape_string ($ list_id )."', ' " .Db::escape_string ($ user_id )."', ' " .Db::escape_string ($ is_watched )."')
83+ " );
8284 }
8385
8486 $ result = array (
8587 'success ' => true ,
8688 'message ' => 'Cache list created successfully. ' ,
87- 'list_id ' => $ listId
89+ 'list_id ' => $ list_id
8890 );
8991 }
9092 return Okapi::formatted_response ($ request , $ result );
9193 }
9294}
93-
0 commit comments