| | |
| | | use JVBase\Instance; |
| | | use JVBase\managers\Cache; |
| | | use JVBase\managers\CustomTable; |
| | | use JVBase\managers\Emails; |
| | | use JVBase\managers\Favourites; |
| | | use JVBase\managers\NotificationManager; |
| | | use JVBase\managers\queue\Queue; |
| | | use JVBase\registrar\Registrar; |
| | | use JVBase\rest\PermissionHandler; |
| | | use JVBase\rest\Response; |
| | |
| | | return ['added' => $added, 'errors' => $errors]; |
| | | |
| | | } catch (Exception $e) { |
| | | $this->logError('addItemsToList', [ |
| | | 'error' => $e->getMessage(), |
| | | $this->logError($e->getMessage(),'addItemsToList', [ |
| | | 'user_id' => $user_id, |
| | | 'list_id' => $list_id, |
| | | ]); |
| | |
| | | // Get list items |
| | | $items = $this->listItems |
| | | ->where(['list_id' => $list_id]) |
| | | ->orderBy('added_at', 'DESC') |
| | | ->orderBy('added_at') |
| | | ->getResults(); |
| | | |
| | | // Format items - convert to favourite-like objects |
| | |
| | | |
| | | // Get shared users if owner |
| | | $shared_users = []; |
| | | $is_owner = false;//TODO |
| | | if ($is_owner) { |
| | | $shares = $this->listShares |
| | | ->where(['list_id' => $list_id]) |
| | | ->orderBy('created_at', 'DESC') |
| | | ->orderBy('created_at') |
| | | ->getResults(); |
| | | |
| | | foreach ($shares as $share_item) { |
| | |
| | | $shared_users[] = $shared_user; |
| | | } |
| | | } |
| | | |
| | | $list = []; //TODO: check this |
| | | return [ |
| | | 'success' => true, |
| | | 'list' => [ |
| | |
| | | ]; |
| | | |
| | | } catch (Exception $e) { |
| | | $this->logError('getListDetails', [ |
| | | 'error' => $e->getMessage(), |
| | | $this->logError($e->getMessage(), 'getListDetails', [ |
| | | 'user_id' => $user_id, |
| | | 'list_id' => $list_id |
| | | ]); |
| | |
| | | ]; |
| | | |
| | | } catch (Exception $e) { |
| | | $this->logError('updateList', [ |
| | | 'error' => $e->getMessage(), |
| | | $this->logError($e->getMessage(),'updateList', [ |
| | | 'user_id' => $user_id, |
| | | 'list_id' => $list_id |
| | | ]); |
| | |
| | | ]; |
| | | |
| | | } catch (Exception $e) { |
| | | $this->logError('removeFromList', [ |
| | | 'error' => $e->getMessage(), |
| | | $this->logError($e->getMessage(), 'removeFromList', [ |
| | | 'user_id' => $user_id, |
| | | 'list_id' => $list_id |
| | | ]); |
| | |
| | | ]); |
| | | |
| | | // Send notification |
| | | NotificationManager::getInstance()->addNotification( |
| | | $share_user->ID, |
| | | 'list_shared', |
| | | $user_id, |
| | | sprintf('%s shared a favorites list with you: "%s"', $owner_name, $list->name), |
| | | $list_id, |
| | | 'favourites_list', |
| | | [ |
| | | 'list_id' => $list_id, |
| | | 'list_name' => $list->name, |
| | | 'permission_type' => $permission_type |
| | | ] |
| | | ); |
| | | // TODO This should be handled by the Favourites:: manager |
| | | // NotificationManager::getInstance()->addNotification( |
| | | // $share_user->ID, |
| | | // 'list_shared', |
| | | // $user_id, |
| | | // sprintf('%s shared a favorites list with you: "%s"', $owner_name, $list->name), |
| | | // $list_id, |
| | | // 'favourites_list', |
| | | // [ |
| | | // 'list_id' => $list_id, |
| | | // 'list_name' => $list->name, |
| | | // 'permission_type' => $permission_type |
| | | // ] |
| | | // ); |
| | | |
| | | return [ |
| | | 'success' => true, |
| | |
| | | ]; |
| | | |
| | | } catch (Exception $e) { |
| | | $this->logError('unshareList', [ |
| | | 'error' => $e->getMessage(), |
| | | $this->logError($e->getMessage(),'unshareList', [ |
| | | 'user_id' => $user_id, |
| | | 'list_id' => $list_id, |
| | | 'email' => $email |
| | |
| | | ]; |
| | | |
| | | } catch (Exception $e) { |
| | | $this->logError('acceptListInvitation', [ |
| | | 'error' => $e->getMessage(), |
| | | $this->logError($e->getMessage(),'acceptListInvitation', [ |
| | | 'token' => $token, |
| | | 'email' => $email |
| | | ]); |
| | |
| | | // For posts |
| | | if (str_contains($type, 'post') || in_array($type, array_keys($this->valid_types))) { |
| | | $post = get_post($target_id); |
| | | return $post ? $post->post_author : null; |
| | | return $post?->post_author; |
| | | } |
| | | |
| | | // For terms (shops, etc.) |
| | |
| | | }; |
| | | |
| | | if (!$operation_type) { |
| | | return $this->error('Invalid action', 'invalid_action', 400); |
| | | return $this->error('Invalid action', 'invalid_action'); |
| | | } |
| | | |
| | | Queue::getInstance()->queueOperation( |