/** * The main function for executing the command. */ public function execute() { // Retrieve the logs from the database $logs = \AppSync\LogEntryFactory::getOrderedLogEntries(); $response = array(); // For each logEntry create a row in the response array. foreach ($logs as $logEntry) { $row = array('occurredOn' => date('m/d/Y h:m:s a', $logEntry->getOccurredOn()), 'username' => $logEntry->getUsername(), 'desc' => $logEntry->getDescription()); $response[] = $row; } // Echo the json encoded data back to the front end. echo json_encode($response); exit; }
/** * The main function for executing the command. */ public function execute() { // Retrieve the values from the request $id = $_REQUEST['logId']; $action = $_REQUEST['logAction']; $category = $_REQUEST['logCategory']; // Set the variable to 'to' initially $toFrom = 'to'; // Retrieve the username $username = \Current_User::getUsername(); // If the action is set as removing then switch the variable to from if ($action == 'Removing') { $toFrom = 'from'; } // Create a new logEntry with the values $logEntry = new \AppSync\LogEntry(null, $action . ' students ' . $toFrom . ' ' . $category . ' with ' . $category . ' id ' . $id, $username, time()); \AppSync\LogEntryFactory::save($logEntry); // Send a confirmation back to the front end echo json_encode('logged'); exit; }
/** * Place a user or users into a group. User can be a single user id or and array of ids * * @param int $user_id (can be array of user id's), int $group_id (groups id) * @return boolean (success or not) */ public function removeGroupAccount($user_id, $group_id) { // Use the UtilityFunctions to retrieve the info to be passed to the API $key = \AppSync\UtilityFunctions::getOrgSyncKey(); $base_url = \AppSync\UtilityFunctions::getOrgSyncURL(); $id = \AppSync\UtilityFunctions::getIDFromUsername($user_id); // Create the url $import_url = $base_url . "groups/{$group_id}/accounts/remove"; // Initialize curl $curl = curl_init(); curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $import_url, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => "ids={$id}&key={$key}")); // Execute the curl request and store the result $result = curl_exec($curl); // Close curl curl_close($curl); // Check to make sure the result was valid if ($result) { $result = json_decode($result); if (is_object($result) && $result->success == "true") { return TRUE; } else { // Log that an attempt to interact with the API failed $logEntry = new \AppSync\LogEntry(null, 'Attempted to from user from group in Orgsync API via removeGroupAccount function, response was ' . $result->message, \Current_User::getUsername(), time()); \AppSync\LogEntryFactory::save($logEntry); return FALSE; } } else { // Log that an attempt to interact with the API failed $logEntry = new \AppSync\LogEntry(null, 'Attempted to from user from group in Orgsync API via removeGroupAccount function, response was ' . $result->message, \Current_User::getUsername(), time()); \AppSync\LogEntryFactory::save($logEntry); return FALSE; } }
/** * Retrieves the Id for a user from orgsync * @return id */ public static function getIDFromUsername($username) { // Retrieve the orgsync url values using the static functions in this class $key = self::getOrgSyncKey(); $base_url = self::getOrgSyncURL(); // Initialize curl $curl = curl_init(); curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $base_url . "accounts/username/{$username}?key={$key}")); // Execute the curl request and store its result $result = curl_exec($curl); // Close curl curl_close($curl); // Check to see if the result is valid if ($result) { $result = json_decode($result); if (!empty($result->id)) { return $result->id; } } // Log that an attempt to interact with the API failed $logEntry = new \AppSync\LogEntry(null, 'Attempted to retrieve Id from Orgsync API via getIDFromUsername function, response was ' . $result->message, \Current_User::getUsername(), time()); \AppSync\LogEntryFactory::save($logEntry); return false; }