| | |
| | | <?php |
| | | namespace JVBase\rest\routes; |
| | | |
| | | use JVBase\JVB; |
| | | use JVBase\managers\Emails; |
| | | use JVBase\managers\Errors; |
| | | use JVBase\managers\ImageGenerator; |
| | | use JVBase\managers\NotificationManager; |
| | | use JVBase\managers\queue\Queue; |
| | | use JVBase\managers\UploadManager; |
| | | use JVBase\registrar\Registrar; |
| | | use JVBase\rest\RestRouteManager; |
| | |
| | | $operationID = $data['id']; |
| | | unset($data['id']); |
| | | |
| | | $data = json_encode($data); |
| | | |
| | | $queue->queueOperation( |
| | | 'shop_update', |
| | |
| | | $shop_name = get_term($shopID, BASE . 'shop')->name; |
| | | |
| | | // Notify each manager |
| | | foreach ($owners as $owner) { |
| | | NotificationManager::getInstance()->addNotification( |
| | | $owner, |
| | | 'artist_request', |
| | | [ |
| | | 'artist_id' => $artistID, |
| | | 'artist_name' => $artist_name, |
| | | 'user_id' => $userID, |
| | | 'shop_id' => $shopID, |
| | | 'shop_name' => $shop_name |
| | | ] |
| | | ); |
| | | } |
| | | //TODO |
| | | // foreach ($owners as $owner) { |
| | | // NotificationManager::getInstance()->addNotification( |
| | | // $owner, |
| | | // 'artist_request', |
| | | // [ |
| | | // 'artist_id' => $artistID, |
| | | // 'artist_name' => $artist_name, |
| | | // 'user_id' => $userID, |
| | | // 'shop_id' => $shopID, |
| | | // 'shop_name' => $shop_name |
| | | // ] |
| | | // ); |
| | | // } |
| | | } |
| | | |
| | | /** |
| | |
| | | $invitation_id = $wpdb->insert_id; |
| | | |
| | | // If user exists, send notification through the system |
| | | if ($existing_user_id) { |
| | | NotificationManager::getInstance()->addNotification( |
| | | $existing_user_id, |
| | | 'artist_invitation', |
| | | $manager_id, |
| | | sprintf('You have been invited to join %s', get_term($shop_id, BASE . 'shop')->name), |
| | | $invitation_id, |
| | | 'invitation' |
| | | ); |
| | | } |
| | | //TODO |
| | | // if ($existing_user_id) { |
| | | // NotificationManager::getInstance()->addNotification( |
| | | // $existing_user_id, |
| | | // 'artist_invitation', |
| | | // $manager_id, |
| | | // sprintf('You have been invited to join %s', get_term($shop_id, BASE . 'shop')->name), |
| | | // $invitation_id, |
| | | // 'invitation' |
| | | // ); |
| | | // } |
| | | |
| | | // Send email invitation |
| | | $this->sendInvitationEmail($artist_email, $artist_name, $manager_id, $shop_id, $token); |
| | |
| | | |
| | | // If invitation was for an existing user, notify them |
| | | $user_id = email_exists($invitation->email); |
| | | if ($user_id) { |
| | | NotificationManager::getInstance()->addNotification( |
| | | $user_id, |
| | | 'invitation_revoked', |
| | | $manager_id, |
| | | sprintf('Your invitation to %s has been revoked', get_term($shop_id, BASE . 'shop')->name), |
| | | $shop_id, |
| | | BASE . 'shop' |
| | | ); |
| | | } |
| | | //TODO |
| | | // if ($user_id) { |
| | | // NotificationManager::getInstance()->addNotification( |
| | | // $user_id, |
| | | // 'invitation_revoked', |
| | | // $manager_id, |
| | | // sprintf('Your invitation to %s has been revoked', get_term($shop_id, BASE . 'shop')->name), |
| | | // $shop_id, |
| | | // BASE . 'shop' |
| | | // ); |
| | | // } |
| | | |
| | | return new WP_REST_Response([ |
| | | 'success' => true, |
| | |
| | | |
| | | // Notify the artist |
| | | $notification_type = $status === 'accepted' ? 'shop_accepted' : 'shop_rejected'; |
| | | NotificationManager::getInstance()->addNotification( |
| | | $request->user_id, |
| | | $notification_type, |
| | | [ |
| | | 'shop_id' => $request->shop_id, |
| | | 'shop_name' => get_term($request->shop_id, BASE . 'shop')->name, |
| | | 'notes' => $notes |
| | | ] |
| | | ); |
| | | //TODO |
| | | // NotificationManager::getInstance()->addNotification( |
| | | // $request->user_id, |
| | | // $notification_type, |
| | | // [ |
| | | // 'shop_id' => $request->shop_id, |
| | | // 'shop_name' => get_term($request->shop_id, BASE . 'shop')->name, |
| | | // 'notes' => $notes |
| | | // ] |
| | | // ); |
| | | |
| | | return new WP_REST_Response([ |
| | | 'success' => true, |
| | |
| | | } |
| | | |
| | | // Notify inviters |
| | | $inviters = json_decode($invitation['inviters'], true); |
| | | if (!empty($inviters)) { |
| | | foreach ($inviters as $inviter_id) { |
| | | NotificationManager::getInstance()->addNotification( |
| | | $inviter_id, |
| | | 'invitation_accepted', |
| | | [ |
| | | 'artist_id' => $user_id, |
| | | 'artist_name' => jvbGetUsername($user_id), |
| | | 'shop_id' => $invitation['to_shop'] |
| | | ] |
| | | ); |
| | | } |
| | | } |
| | | //TODO |
| | | // $inviters = json_decode($invitation['inviters'], true); |
| | | // if (!empty($inviters)) { |
| | | // foreach ($inviters as $inviter_id) { |
| | | // NotificationManager::getInstance()->addNotification( |
| | | // $inviter_id, |
| | | // 'invitation_accepted', |
| | | // [ |
| | | // 'artist_id' => $user_id, |
| | | // 'artist_name' => jvbGetUsername($user_id), |
| | | // 'shop_id' => $invitation['to_shop'] |
| | | // ] |
| | | // ); |
| | | // } |
| | | // } |
| | | |
| | | $wpdb->query('COMMIT'); |
| | | return true; |
| | |
| | | [ |
| | | 'user_id' => $user_id, |
| | | 'invitation' => $invitation |
| | | ], |
| | | 'error' |
| | | ] |
| | | ); |
| | | |
| | | return false; |
| | |
| | | ); |
| | | |
| | | // Notify inviters |
| | | $inviters = json_decode($invitation['inviters'], true); |
| | | if (!empty($inviters)) { |
| | | foreach ($inviters as $inviter_id) { |
| | | NotificationManager::getInstance()->addNotification( |
| | | $inviter_id, |
| | | 'invitation_declined', |
| | | [ |
| | | 'artist_id' => $user_id, |
| | | 'artist_name' => jvbGetUsername($user_id), |
| | | 'shop_id' => $invitation['to_shop'] |
| | | ] |
| | | ); |
| | | } |
| | | } |
| | | //TODO |
| | | // $inviters = json_decode($invitation['inviters'], true); |
| | | // if (!empty($inviters)) { |
| | | // foreach ($inviters as $inviter_id) { |
| | | // NotificationManager::getInstance()->addNotification( |
| | | // $inviter_id, |
| | | // 'invitation_declined', |
| | | // [ |
| | | // 'artist_id' => $user_id, |
| | | // 'artist_name' => jvbGetUsername($user_id), |
| | | // 'shop_id' => $invitation['to_shop'] |
| | | // ] |
| | | // ); |
| | | // } |
| | | // } |
| | | |
| | | return true; |
| | | } catch (Exception $e) { |
| | |
| | | [ |
| | | 'user_id' => $user_id, |
| | | 'invitation' => $invitation |
| | | ], |
| | | 'error' |
| | | ] |
| | | ); |
| | | |
| | | return false; |
| | |
| | | $shop_meta = Meta::forTerm($shop_id); |
| | | $owners = $shop_meta->getAll(['owner', 'managers']); |
| | | $owners = array_unique(array_merge(explode(',', $owners['owner']),explode(',', $owners['managers']))); |
| | | |
| | | foreach ($owners as $owner_id) { |
| | | if (!empty($owner_id)) { |
| | | NotificationManager::getInstance()->addNotification( |
| | | $owner_id, |
| | | 'artist_left', |
| | | $user_id, |
| | | sprintf('%s has left %s', jvbGetUsername($user_id), $shop_name), |
| | | $shop_id, |
| | | BASE . 'shop' |
| | | ); |
| | | } |
| | | } |
| | | // TODO |
| | | // foreach ($owners as $owner_id) { |
| | | // if (!empty($owner_id)) { |
| | | // NotificationManager::getInstance()->addNotification( |
| | | // $owner_id, |
| | | // 'artist_left', |
| | | // $user_id, |
| | | // sprintf('%s has left %s', jvbGetUsername($user_id), $shop_name), |
| | | // $shop_id, |
| | | // BASE . 'shop' |
| | | // ); |
| | | // } |
| | | // } |
| | | |
| | | return true; |
| | | } catch (Exception $e) { |
| | |
| | | [ |
| | | 'user_id' => $user_id, |
| | | 'shop_id' => $shop_id |
| | | ], |
| | | 'error' |
| | | ] |
| | | ); |
| | | |
| | | return false; |