/** * Retrieves student objects from banner * @return student */ public static function getStudentByBanner($banner) { // Retrieve the url for Banner from the database $base_url = \AppSync\SettingFactory::getSetting('banner_url')->getValue(); // Initialize curl $curl = curl_init(); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_URL, $base_url . 'Student'); // Execute the curl request and store its result $studentList = json_decode(curl_exec($curl)); // Loop through the student list and retrieve the student with the given banner id foreach ($studentList as $student) { if ($student->{'ID'} == $banner) { return $student; } } }
/** * The main function for executing the command. */ public function execute() { // Make sure the user has the appropriate permissions to access settings. // Basically only deities will have access to settings. if (!\Current_User::isDeity()) { echo json_encode('user does not have permission to retrieve live state'); exit; } // Set the variables to base values $liveUrl = ''; $testUrl = ''; $key = ''; $bannerUrl = ''; // Retrieve the settings from the database $liveUrlSetting = \AppSync\SettingFactory::getSetting('orgsync_live_url'); $testUrlSetting = \AppSync\SettingFactory::getSetting('orgsync_test_url'); $keySetting = \AppSync\SettingFactory::getSetting('orgsync_key'); $bannerUrlSetting = \AppSync\SettingFactory::getSetting('banner_url'); // If the settings are non null then set the variables, otherwise leave them empty if ($liveUrlSetting) { $liveUrl = $liveUrlSetting->getValue(); } if ($testUrlSetting) { $testUrl = $testUrlSetting->getValue(); } if ($keySetting) { $key = $keySetting->getValue(); } if ($bannerUrlSetting) { $bannerUrl = $bannerUrlSetting->getValue(); } // If the state is not set it, set it to LIVE and use that as the state, // otherwise use the current state. if ($_SESSION['state'] != null) { $state = $_SESSION['state']; } else { $state = 'LIVE'; $_SESSION['state'] = 'LIVE'; } // Echo the values back to the front end after encoding them. echo json_encode(array('state' => $state, 'liveUrl' => $liveUrl, 'testUrl' => $testUrl, 'key' => $key, 'bannerUrl' => $bannerUrl)); exit; }
/** * The main function for executing the command. */ public function execute() { // Make sure the user has the appropriate permissions to make changes to the permissions settings. // Basically only deities will have access to permissions. if (!\Current_User::isDeity()) { echo json_encode('user does not have permission to set live state'); exit; } // Retrieve the input values from the request $newState = $_REQUEST['state']; $newLiveUrl = $_REQUEST['liveUrl']; $newTestUrl = $_REQUEST['testUrl']; $newKey = $_REQUEST['key']; $newBannerUrl = $_REQUEST['bannerUrl']; // If the newLiveUrl is not empty set the value in the database to the new value if ($newLiveUrl != '') { $liveUrlSetting = \AppSync\SettingFactory::getSetting('orgsync_live_url'); if (!$liveUrlSetting) { $liveUrlSetting = new \AppSync\Setting(NULL, 'orgsync_live_url', $newLiveUrl); } else { $liveUrlSetting->setValue($newLiveUrl); } \AppSync\SettingFactory::save($liveUrlSetting); } // If the newTestUrl is not empty, set the value in the database to the new value if ($newTestUrl != '') { $testUrlSetting = \AppSync\SettingFactory::getSetting('orgsync_test_url'); if (!$testUrlSetting) { $testUrlSetting = new \AppSync\Setting(NULL, 'orgsync_test_url', $newTestUrl); } else { $testUrlSetting->setValue($newTestUrl); } \AppSync\SettingFactory::save($testUrlSetting); } // If the newKey is not empty, set the value in the database to the new value if ($newKey != '') { $keySetting = \AppSync\SettingFactory::getSetting('orgsync_key'); if (!$keySetting) { $keySetting = new \AppSync\Setting(NULL, 'orgsync_key', $newKey); } else { $keySetting->setValue($newKey); } \AppSync\SettingFactory::save($keySetting); } // If the newBannerUrl is not empty, set the value in the database to the new value if ($newBannerUrl != '') { $bannerUrlSetting = \AppSync\SettingFactory::getSetting('banner_url'); if (!$bannerUrlSetting) { $bannerUrlSetting = new \AppSync\Setting(NULL, 'banner_url', $newBannerUrl); } else { $bannerUrlSetting->setValue($newBannerUrl); } \AppSync\SettingFactory::save($bannerUrlSetting); } // If the newState is 'LIVE' set the session to 'LIVE', if it is 'TEST' // set it to 'TEST', otherwise throw an error if ($newState == 'LIVE') { $_SESSION['state'] = 'LIVE'; } else { if ($newState == 'TEST') { $_SESSION['state'] = 'TEST'; } else { echo json_encode(array('type' => 'error', 'message' => 'input does not match a valid server type: ' . $newState)); exit; } } echo json_encode(array('type' => 'success', 'message' => 'Changes saved successfully.')); exit; }