Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 33 additions & 31 deletions application/controllers/EnrollmentForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ function __construct()
log_message('debug', "-- from IP address: " . $this->input->ip_address());
}

public function test() {
$this->load->model("Repository_Model");
$this->Repository_Model->initClass(MEMBERSHIP_SPREADSHEET_ID, MEMBERSHIP_SHEET_NAME, REGISTRATION_SPREADSHEET_ID);
public function test()
{
$this->load->model("Repository_Model");
$this->Repository_Model->initClass(MEMBERSHIP_SPREADSHEET_ID, MEMBERSHIP_SHEET_NAME, REGISTRATION_SPREADSHEET_ID);
// $event = new Event(
// "id3",
// "name",
Expand All @@ -55,7 +56,7 @@ public function test() {
// );

print_r("This is a test function."/*$this->Repository_Model->getOrganisation("1")*/);
}
}

/**
* The "home" page.
Expand Down Expand Up @@ -85,14 +86,16 @@ public function validate()

$this->load->model('Verification_Model');

$member = $this->Repository_Model->getMemberByEmail($emailAddress);

// If the email is of invalid format, return 412 error
if (!isset($emailAddress) || !$this->Verification_Model->isValidEmail($emailAddress)) {
$this->createResponse(412, 'Error: Format of email is invalid');
return;
}

// If the email does not exist or is not on the membership spreadsheet, return 404 error
if (!$this->Verification_Model->isEmailOnSheet($emailAddress, MEMBERSHIP_SPREADSHEET_ID, MEMBERSHIP_SHEET_NAME)) {
if ($member === null) {
$this->createResponse(404, 'Error: Email incorrect or not found on sheet');
return;
}
Expand All @@ -104,14 +107,12 @@ public function validate()
}

// If membership payment status is checked, and user's membership fee has not been paid, return 403 error
if (CHECK_MEMBERSHIP_PAYMENT && !$this->Verification_Model->hasUserPaidMembership($emailAddress)) {
if (CHECK_MEMBERSHIP_PAYMENT && !$member->feePaid) {
$this->createResponse(403, "Error: signed up but not paid");
return;
}

[$fullName, $UPI] = $this->Verification_Model->getMemberInfo($emailAddress);

$this->createResponse(200, "Success", $fullName);
$this->createResponse(200, "Success", $member->fullName);
}

/**
Expand All @@ -124,30 +125,27 @@ public function makeStripePayment()
$this->load->model('Verification_Model');

// Receive data from form, method=POST
$data['email'] = $this->input->post('email');
[$data['name'], $data['upi']] = $this->Verification_Model->getMemberInfo($data["email"]);
$memberEmail = $this->input->post('email');
$member = $this->Repository_Model->getMemberByEmail($memberEmail);

// Stopping direct access to this method
if (!isset($data['name']) || !isset($data['email'])) {
show_error("Sorry, this page you are requesting is either not found or you don't have permission to access this page. Error Code:001",
"404");
if (!isset($member->fullName) || !isset($member->email)) {
show_error("Sorry, this page you are requesting is either not found or you don't have permission to access this page. Error Code:001", "404");
}

if (CHECK_MEMBERSHIP_PAYMENT) {
$paid_member = ($this->Verification_Model->hasUserPaidMembership($data['email']));
if (!$paid_member) {
show_error("Something went wrong, your email was not found in the ASPA member list or haven't paid. Error Code: 002", "500");
}
if (CHECK_MEMBERSHIP_PAYMENT && !$member->feePaid) {
show_error("Something went wrong, your email was not found in the ASPA member list or haven't paid. Error Code: 002", "500");
}

// Only record if the email is not found
if (!($this->Verification_Model->isEmailOnSheet($data['email'], REGISTRATION_SPREADSHEET_ID, $this->eventData['gsheet_name']))) {
$this->GoogleSheets_Model->addNewRecord($data['email'], $data['name'], $data['upi'], 'Stripe');
//TODO: WE NEED TO PASS THE PROPER EVENT ID
if ($this->Repository_Model->getRecord($member->email, '') === null) {
$this->GoogleSheets_Model->addNewRecord($member->email, $member->fullName, $member->upi, 'Stripe');
} else {
// Email is found, so find the cell
// Then edit the "How would you like your payment" to be of Stripe payment
// Get the row of the specific email from google sheets
$cell = $this->GoogleSheets_Model->getCellCoordinate($data['email'], 'B');
$cell = $this->GoogleSheets_Model->getCellCoordinate($member->email, 'B');
if (!isset($cell)) {
show_error("Something went wrong, your email was not found in the ASPA member list.Error Code: 002", "500");
}
Expand All @@ -160,10 +158,15 @@ public function makeStripePayment()

// Generate the stripe session ID
$this->load->model('Stripe_Model');
$data['session_id'] = $this->Stripe_Model->generateNewSessionId($data['email'], $this->eventData);
$stripeSessionId = $this->Stripe_Model->generateNewSessionId($member->email, $this->eventData);

// Initiate the stripe payment
$this->load->view('stripe.php', $data);
$this->load->view('stripe.php', [
'email' => $member->email,
'name' => $member->fullName,
'upi' => $member->upi,
'session_id' => $stripeSessionId
]);
}

/**
Expand All @@ -172,25 +175,24 @@ public function makeStripePayment()
public function makeOfflinePayment()
{
$this->load->model("GoogleSheets_Model");
$this->load->model("Verification_Model");
$this->load->model('Email_Model');
log_message('debug', "-- makeOfflinePayment function called");

$this->load->model("GoogleSheets_Model");
$this->load->model("Verification_Model");
$this->load->model('Email_Model');

$data['has_paid'] = false;
$data["email"] = $this->input->post("email");
$data['paymentMethod'] = $this->input->post("paymentMethod");
[$data['name'], $data['upi']] = $this->Verification_Model->getMemberInfo($data["email"]);
$member = $this->Repository_Model->getMemberByEmail($data["email"]);
// [$data['name'], $data['upi']] = $this->Verification_Model->getMemberInfo($data["email"]);
$data['name'] = $member->fullName;
$data['upi'] = $member->upi;

if (!isset($data['name']) || !isset($data["email"]) || !isset($data['paymentMethod'])) {
show_error("Something went wrong. Please contact uoa.wdcc@gmail.com. Error Code: 001", "500");
}

// Only record if the email is not found
if (!($this->Verification_Model->isEmailOnSheet($data['email'], REGISTRATION_SPREADSHEET_ID, $this->eventData['gsheet_name']))) {
//TODO: WE NEED TO PASS THE PROPER EVENT ID
if ($this->Repository_Model->getRecord($member->email, '') === null) {
$this->GoogleSheets_Model->addNewRecord($data['email'], $data['name'], $data['upi'], ucfirst($data['paymentMethod']));
} else {
// Email is found, so find the cell then edit the "How would you like your payment" to be of Offline payment
Expand Down
6 changes: 2 additions & 4 deletions application/core/ASPA_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function __construct()
parent::__construct();
$this->load->model("Repository_Model");
$this->load->model("GoogleSheets_Model");

$this->Repository_Model->initClass(MEMBERSHIP_SPREADSHEET_ID, MEMBERSHIP_SHEET_NAME, REGISTRATION_SPREADSHEET_ID);
$this->eventData = $this->loadEventData();
$this->orgData = $this->Repository_Model->getOrganisation("")->toArray();
}
Expand Down Expand Up @@ -62,8 +62,8 @@ private function loadEventData(): array

// Get event details from spreadsheet from range A2 to size of spreadsheet
$this->GoogleSheets_Model->setCurrentSheetName("CurrentEventDetails");
$data = $this->GoogleSheets_Model->getCellContents('A2', 'C' . ($this->GoogleSheets_Model->getNumberOfRecords() + 2));

$data = $this->GoogleSheets_Model->getCellContents('A2', 'C');
// Important variables we care about
$elements = ['time', 'date', 'location', 'title', 'tagline', 'price', 'acc_num', 'desc', 'gsheet_name', 'form_enabled'];

Expand All @@ -82,6 +82,4 @@ private function loadEventData(): array
}
return $eventTemp;
}

}

81 changes: 42 additions & 39 deletions application/models/Repository_Model.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

defined('BASEPATH') OR exit('No direct script access allowed');
defined('BASEPATH') or exit('No direct script access allowed');

require('vendor/autoload.php');
require('./application/models/entities/Event.php');
Expand Down Expand Up @@ -30,10 +30,10 @@ public function initClass(String $membershipSpreadsheetId, String $membershipShe

// Get all the events
$this->GoogleSheets_Model->setCurrentSheetName("Events");
$records = $this->GoogleSheets_Model->getNumberOfRecords();
$array2d = $this->GoogleSheets_Model->getCellContents("A2", "J" . ($records + 2));

for ($i = 0; $i < $records; $i++) {
$array2d = $this->GoogleSheets_Model->getCellContents("A2", "J");

for ($i = 0; $i < sizeof($array2d); $i++) {
$current = $array2d[$i];
$id = $current[0];
$name = $current[1];
Expand Down Expand Up @@ -65,11 +65,9 @@ public function initClass(String $membershipSpreadsheetId, String $membershipShe

$this->GoogleSheets_Model->setCurrentSheetName($membershipSheetName);

$records = $this->GoogleSheets_Model->getNumberOfRecords();

$array2d = $this->GoogleSheets_Model->getCellContents("A2", "I" . ($records + 2));
$array2d = $this->GoogleSheets_Model->getCellContents("A2", "I");

for ($i = 0; $i < $records; $i++) {
for ($i = 0; $i < sizeof($array2d); $i++) {
$current = $array2d[$i];

$signUpDate = intval($current[0]);
Expand All @@ -89,71 +87,74 @@ public function initClass(String $membershipSpreadsheetId, String $membershipShe
* @param string the email of the member
* @return Member the member object
*/
public function getMemberByEmail(string $memberEmail) {
return $this->members[$memberEmail];
public function getMemberByEmail(string $memberEmail)
{
return array_key_exists($memberEmail, $this->members) ? $this->members[$memberEmail] : null;
}

/**
* @return Member[] a list of all members
*/
public function getMembers() {
public function getMembers()
{
return $this->members;
}

/**
* @return Event the event object that corrosponds to the event ID
*/
public function getEventById(string $eventId) {
public function getEventById(string $eventId)
{
return $this->events[$eventId];
}

/**
* Gets an organization
*/
// TODO: Replace this to return the actual organisation.
public function getOrganisation(string $orgId) {
return new Organisation(
"ASPA",
"01-0129-0469512-00",
$orgId,
"-",
"-",
"Auckland Students Pool Association",
"uoapool@gmail.com",
);
public function getOrganisation(string $orgId)
{
return new Organisation(
"ASPA",
"01-0129-0469512-00",
$orgId,
"-",
"-",
"Auckland Students Pool Association",
"uoapool@gmail.com",
);
}

/**
* Get a member's record from an event using their email and the event id
* @return Record the member's record, or NULL
*/
public function getRecord(string $memberEmail, string $eventId) {
public function getRecord(string $memberEmail, string $eventId)
{
$records = $this->getRecordsByEvent($eventId);

if (array_key_exists($memberEmail, $records)) {
return $records[$memberEmail];
}
else {
} else {
return NULL;
}
}

/**
* Get all the records for an event
* @return Record[] a list of all records for an event
* @return Record[] returns an map of Records where the member's email is the key.
*/
public function getRecordsByEvent(string $eventId) {
$this->GoogleSheets_Model->setCurrentSheetName($eventId);

$records = $this->GoogleSheets_Model->getNumberOfRecords();
public function getRecordsByEvent(string $eventId)
{
$this->GoogleSheets_Model->setCurrentSheetName($eventId);

$array2d = $this->GoogleSheets_Model->getCellContents("A2","K" . ($records + 2));
$array2d = $this->GoogleSheets_Model->getCellContents("A2", "K");

$allRecords = [];
$allRecords = [];

for ($i = 0; $i < $records; $i++) {
$allRecords[$array2d[$i][1]] = new Record($array2d[$i][1], $eventId, $array2d[$i][0], $array2d[$i][2], $array2d[$i][4], $array2d[$i][5], $array2d[$i][10], $array2d[$i][9], isset($array2d[$i][6]));
}
for ($i = 0; $i < sizeof($array2d); $i++) {
$allRecords[$array2d[$i][1]] = new Record($array2d[$i][1], $eventId, $array2d[$i][0], $array2d[$i][2], $array2d[$i][4], $array2d[$i][5], $array2d[$i][10], $array2d[$i][9], isset($array2d[$i][6]));
}

return $allRecords;
}
Expand All @@ -162,7 +163,8 @@ public function getRecordsByEvent(string $eventId) {
* Save an event to the database.
* @param event the event to save to the database.
*/
public function saveEvent(Event $event): Event {
public function saveEvent(Event $event): Event
{
$this->GoogleSheets_Model->saveEvent($event->id, EVENT_SHEET_ID_COLUMN, $event->toArray());

return $event;
Expand All @@ -172,9 +174,10 @@ public function saveEvent(Event $event): Event {
* Save a record to the database.
* @param record the record to save to the database.
*/
public function saveRecord(Record $record) {
$this->GoogleSheets_Model->saveRecord($record->eventID, $record->email, REGISTRATIONS_SHEET_ID_COLUMN, $record->toArray());
public function saveRecord(Record $record)
{
$this->GoogleSheets_Model->saveRecord($record->eventID, $record->email, REGISTRATIONS_SHEET_ID_COLUMN, $record->toArray());

return $record;
return $record;
}
}
Loading