Ejemplo n.º 1
0
 public static function callService($requestData)
 {
     // --- Variable Declarations  -------------------------------//
     /* Whether or not the command was found.                   */
     $commandFound = True;
     /* @var $serviceResult Array Contains the command results. */
     $serviceResult = NULL;
     /* @var $iCommand The command object to execute.          */
     $iCommand = NULL;
     /* @var $sessionCheckCommand The command to check session*/
     $sessionCheckCommand;
     // --- Main Routine -----------------------------------------//
     // Make sure the serviceID element exists if so execute.
     if ($requestData != NULL && array_key_exists("ServiceID", $requestData) && $requestData["ServiceID"] != NULL) {
         // check session if needed.
         if ($requestData["ServiceID"] != "Login") {
             $sessionCheckCommand = new CheckSessionCommand($requestData);
             $serviceResult = $sessionCheckCommand->executeCommand();
             // Invalid session data flag it.
             if ($serviceResult->getResultType() != "success") {
                 return $serviceResult;
             }
         }
         // Parse for the right command to be displayed.
         switch ($requestData["ServiceID"]) {
             // --- Account Management commands --- //
             case "Login":
                 $iCommand = new LoginCommand($requestData);
                 break;
             case "Logout":
                 $iCommand = new LogoutCommand($requestData);
                 break;
                 // --- Admin panel commands --- //
             // --- Admin panel commands --- //
             case "AddCourse":
                 $iCommand = new AddCourseCommand($requestData);
                 break;
             case "DeleteCourse":
                 $iCommand = new DeleteCourseCommand($requestData);
                 break;
             case "UpdateCourse":
                 $iCommand = new UpdateCourseCommand($requestData);
                 break;
                 // --- Student panel commands --- //
             // --- Student panel commands --- //
             case "SearchCourse":
                 $iCommand = new SearchCourseCommand($requestData);
                 break;
             case "UpdateSchedule":
                 $iCommand = new UpdateScheduleCommand($requestData);
                 break;
             case "GetSchedule":
                 $iCommand = new GetScheduleCommmand($requestData);
                 break;
             case "GetSemesters":
                 $iCommand = new GetSemestersCommand($requestData);
                 break;
             case "GetFacRatings":
                 $iCommand = new GetFacRatingCommand($requestData);
                 break;
             default:
                 // Service requested not found.
                 $commandFound = false;
         }
         // Execute command.
         if ($commandFound) {
             $serviceResult = $iCommand->executeCommand();
         } else {
             $serviceResult = new commandResult("invalidData");
             $serviceResult->addValuePair("Description", "Service requested not found.");
         }
     } else {
         $serviceResult = new commandResult("invalidData");
         $serviceResult->addValuePair("Description", "Improper request format.");
     }
     // give back the result.
     return $serviceResult;
 }
 public function executeCommand()
 {
     // --- Variable Declarations  -------------------------------//
     /* @var $commands (Array) Used to cross check the request.   */
     $commandParams = array("searchPhrase", "semesterID");
     /* @var $commandResult (commandResult) The result model.     */
     $commandResult;
     /* @var $courseList (Array) Used to grab sections data.      */
     $courseList;
     /* @var $result (object) The output of PDO sql executes.     */
     $result = NULL;
     /* @var $sqlQuery (object) The query to execute on service.  */
     $sqlQuery = NULL;
     /* @var $searchPhrase (String) The phrase to do the search.  */
     $searchPhrase = NULL;
     /* @var $resultTable (array) The result table to return data.*/
     $resultTable;
     // --- Main Routine ------------------------------------------//
     // Check if the request contains all necessary parameters.
     if ($this->isValidContent($this->requestContent, $commandParams)) {
         try {
             // Get the search phrase.
             $searchPhrase = $this->requestContent["searchPhrase"];
             // 1. Select the type of data were working with.
             if ($searchPhrase == "*") {
                 // Select everything.
                 $sqlQuery = 'SELECT courseCode FROM course WHERE 1';
                 $sqlParams = array();
             } else {
                 if (preg_match('~^[a-zA-Z]{3} [0-9]{3}$~', $searchPhrase)) {
                     // XXX XXX: CIS 350
                     $sqlQuery = 'SELECT c.courseCode FROM course AS c JOIN department AS d ON d.depName = ? WHERE c.cID = ?';
                     $sqlParams = array(substr($searchPhrase, 0, 3), substr($searchPhrase, 4, 3));
                 } else {
                     if (preg_match('~^[a-zA-Z]{3}$~', $searchPhrase)) {
                         // XXX: CIS
                         $sqlQuery = 'SELECT c.courseCode FROM course AS c JOIN department AS d ON d.depName = ? WHERE c.dNum = d.dID';
                         $sqlParams = array($searchPhrase);
                     } else {
                         if ($searchPhrase != "") {
                             $sqlQuery = "SELECT courseCode FROM course WHERE title LIKE ? OR description LIKE ?";
                             $searchPhrase = "%" . $searchPhrase . "%";
                             $sqlParams = array($searchPhrase, $searchPhrase);
                         } else {
                             $commandResult = new commandResult("failed");
                             $commandResult->addValuePair("Description", "No classes found.");
                             return $commandResult;
                         }
                     }
                 }
             }
             // 2. Run the statement.
             if ($this->dbAccess->executeQuery($sqlQuery, $sqlParams)) {
                 // 3. get the results and make sure we have something to return.
                 $courseList = $this->dbAccess->getResults();
                 if ($courseList != null) {
                     $sqlQuery = "SELECT c.*, d.depName, s.sectionCode, s.sectionID, s.seats,s.seatsOpen,\n                            f.firstName,f.lastName, b.buildingName, l.classroom, t.meetDays, t.creditHours, t.startTime, t.endTime\n                            FROM course AS c\n                                   JOIN department AS d\n                                       ON c.dNum = d.dID\n                                   JOIN section AS s\n                                       ON s.courseCode = c.courseCode AND s.semesterCode = ?\n                                   JOIN faculty AS f\n                                       ON f.facultyID = s.facultyID\n                                   JOIN location AS l\n                                       ON l.locationID = s.locationID\n                                   JOIN building AS b\n                                       ON b.buildingID = l.buildingID\n                                   JOIN timeblock AS t\n                                       ON t.timeblockID = s.timeblockID\n                            WHERE c.courseCode = ?";
                     $courseResults = array();
                     // 4. Per result pull all the sections related to the course.
                     foreach ($courseList as &$courseCode) {
                         // Execute the search query.
                         $sqlParams = array($this->requestContent["semesterID"], $courseCode["courseCode"]);
                         if ($this->dbAccess->executeQuery($sqlQuery, $sqlParams)) {
                             // 5. Check and see if we have sections.
                             $sectionList = $this->dbAccess->getResults();
                             $sectionArray = array();
                             if ($sectionList != null) {
                                 // 6. Per section populate section data.
                                 foreach ($sectionList as &$resSec) {
                                     $section = array();
                                     $section["sectionID"] = $resSec["sectionID"];
                                     $section["sectionCode"] = $resSec["sectionCode"];
                                     $section["profFirst"] = $resSec["firstName"];
                                     $section["profLast"] = $resSec["lastName"];
                                     $section["startTime"] = $resSec["startTime"];
                                     $section["endTime"] = $resSec["endTime"];
                                     $section["meetDays"] = $resSec["meetDays"];
                                     $section["building"] = $resSec["buildingName"];
                                     $section["room"] = $resSec["classroom"];
                                     $section["seats"] = $resSec["seats"];
                                     $section["seatsOpen"] = $resSec["seatsOpen"];
                                     array_push($sectionArray, $section);
                                 }
                                 // Populate the course data.
                                 $course["department"] = $sectionList[0]["depName"];
                                 $course["courseID"] = $sectionList[0]["cID"];
                                 $course["title"] = $sectionList[0]["title"];
                                 $course["Description"] = $sectionList[0]["description"];
                                 $course["creditHours"] = $sectionList[0]["creditHours"];
                                 $course["sections"] = $sectionArray;
                                 array_push($courseResults, $course);
                             }
                             // end if check for null semester result.
                         } else {
                             $commandResult = new commandResult("systemError");
                             $commandResult->addValuePair("Description", "Database failure.");
                         }
                     }
                     // end of for each for course.
                     // Append the data back if we have something.
                     if (count($courseResults) > 0) {
                         $commandResult = new commandResult("success");
                         $commandResult->addValuePair("courseList", $courseResults);
                     } else {
                         $commandResult = new commandResult("failed");
                         $commandResult->addValuePair("Description", "No classes found.");
                     }
                 } else {
                     $commandResult = new commandResult("failed");
                     $commandResult->addValuePair("Description", "No classes found.");
                 }
             } else {
                 $commandResult = new commandResult("systemError");
                 $commandResult->addValuePair("Description", "Database failure.");
             }
         } catch (Exception $e) {
             $commandResult = new commandResult("systemError");
             $commandResult->addValuePair("Description", "Database failure.");
         }
     } else {
         $commandResult = new commandResult("invalidData");
         $commandResult->addValuePair("Description", "Invalid input parameters for SearchCourses service.");
     }
     // Return the command result.
     return $commandResult;
 }
Ejemplo n.º 3
0
 public function executeCommand()
 {
     // --- Variable Declarations  -------------------------------//
     /* @var $commands (Array) Used to cross check the request.   */
     $commandParams = array("studentID", "sessionID");
     /* @var $commandResult (commandResult) The result model.     */
     $commandResult;
     /* @var $result (object) The output of PDO sql executes.     */
     $result = NULL;
     /* @var $sqlQuery (object) The query to execute on service.  */
     $sqlQuery = NULL;
     // --- Main Routine ------------------------------------------//
     // Check if the request contains all necessary parameters.
     if ($this->isValidContent($this->requestContent, $commandParams)) {
         // TODO: 3. Brief Description of what is going to happen.
         try {
             $sqlQuery = 'DELETE FROM session WHERE studentID = ? AND sessionKey = ?';
             $sqlParams = array($this->requestContent["studentID"], $this->requestContent["sessionID"]);
             // Execute and build the login data result.
             if ($this->dbAccess->executeQuery($sqlQuery, $sqlParams)) {
                 $result = $this->dbAccess->getResults();
                 if ($result > 0) {
                     $commandResult = new commandResult("success");
                 } else {
                     $commandResult = new commandResult("failed");
                     $commandResult->addValuePair("Description", "Session already logged out or doesn't exist.");
                 }
             } else {
                 $commandResult = new commandResult("systemError");
                 $commandResult->addValuePair("Description", "Database failure.");
             }
         } catch (Exception $e) {
             $commandResult = new commandResult("systemError");
             $commandResult->addValuePair("Description", "Database failure.");
         }
     } else {
         $commandResult = new commandResult("invalidData");
         $commandResult->addValuePair("Description", "Invalid input parameters for Logout.");
     }
     // Return the command result.
     return $commandResult;
 }
 public function executeCommand()
 {
     // --- Variable Declarations  -------------------------------//
     /* @var $commands (Array) Used to cross check the request.   */
     $commandParams = array("studentID", "semesterID");
     /* @var $commandResult (commandResult) The result model.     */
     $commandResult;
     /* @var $result (object) The output of PDO sql executes.     */
     $result = NULL;
     /* @var $sqlQuery (object) The query to execute on service.  */
     $sqlQuery = NULL;
     /* @var $classList (array) List of classes for user.         */
     $classList = array();
     /* @var $scheduleResult (array) Meta data for schedule.      */
     $scheduleResult = array();
     /* @var $scheduleResult (string) The schedule ID.            */
     $scheduleID;
     /* @var $credits (int) The number of credits scheduled.      */
     $credits;
     // --- Main Routine ------------------------------------------//
     // Check if the request contains all necessary parameters.
     if ($this->isValidContent($this->requestContent, $commandParams)) {
         // Try to match a schedule up to a student and pull it down.
         try {
             // 1. Get schedule meta data if it exists so we can pull details.
             $sqlQuery = 'SELECT scheduleID, creditHours FROM studentschedule WHERE
           studentID = ? AND semesterID = ? LIMIT 1';
             $sqlParams = array($this->requestContent["studentID"], $this->requestContent["semesterID"]);
             // 2. If data could be found pull class data.
             if ($this->dbAccess->executeQuery($sqlQuery, $sqlParams)) {
                 $result = $this->dbAccess->getResults();
                 if ($result != null) {
                     $sqlQuery = "SELECT s.semesterCode,s.sectionCode,s.seats,s.seatsOpen,s.sectionID,\n                                d.depName, f.firstName, f.lastName, b.buildingName, l.classroom, t.meetDays,\n                                t.creditHours, t.startTime, t.endTime, c.title, c.cID, c.courseCode, c.description\n                                FROM scheduleitem AS si\n                                \tJOIN section AS s\n                                    \tON s.sectionCode = si.SectionCode\n                                    JOIN course AS c\n                                    \tON c.courseCode = s.courseCode\n                                \tJOIN department AS d\n                                    \tON d.dID = c.dNum\n                                    JOIN faculty AS f\n                                    \tON f.facultyID = s.facultyID\n                                    JOIN location AS l\n                                    \tON l.locationID = s.locationID\n                                    JOIN building AS b\n                                    \tON b.buildingID = l.buildingID\n                                    JOIN timeblock AS t\n                                    \tON t.timeblockID = s.timeblockID\n                                WHERE si.scheduleID = ?";
                     // fill out meta data used for later.
                     $scheduleID = $result[0]["scheduleID"];
                     $credits = $result[0]["creditHours"];
                     $sqlParams = array($scheduleID);
                     // 3. get the classes and populate the data.
                     if ($this->dbAccess->executeQuery($sqlQuery, $sqlParams)) {
                         $result = $this->dbAccess->getResults();
                         if ($result != null) {
                             foreach ($result as &$resClass) {
                                 $class = array();
                                 $class["courseCode"] = $resClass["courseCode"];
                                 $class["courseID"] = $resClass["cID"];
                                 $class["courseTitle"] = $resClass["title"];
                                 $class["departmentName"] = $resClass["depName"];
                                 $class["courseDescription"] = $resClass["description"];
                                 $class["semesterCode"] = $resClass["semesterCode"];
                                 $class["sectionID"] = $resClass["sectionID"];
                                 $class["sectionCode"] = $resClass["sectionCode"];
                                 $class["profFirst"] = $resClass["firstName"];
                                 $class["profLast"] = $resClass["lastName"];
                                 $class["startTime"] = $resClass["startTime"];
                                 $class["endTime"] = $resClass["endTime"];
                                 $class["meetDays"] = $resClass["meetDays"];
                                 $class["building"] = $resClass["buildingName"];
                                 $class["room"] = $resClass["classroom"];
                                 $class["seats"] = $resClass["seats"];
                                 $class["seatsOpen"] = $resClass["seatsOpen"];
                                 array_push($classList, $class);
                             }
                             // Add all meta data to the list.
                             $scheduleResult["scheduleID"] = $scheduleID;
                             $scheduleResult["creditHours"] = $credits;
                             $scheduleResult["classes"] = $classList;
                             // Return the result.
                             $commandResult = new commandResult("success");
                             $commandResult->addValuePair("scheduleData", $scheduleResult);
                         } else {
                             $commandResult = new commandResult("systemError");
                             $commandResult->addValuePair("Description", "Database failure.");
                         }
                     } else {
                         $commandResult = new commandResult("systemError");
                         $commandResult->addValuePair("Description", "Database failure.");
                     }
                 } else {
                     $commandResult = new commandResult("systemError");
                     $commandResult->addValuePair("Description", "Database failure.");
                 }
             } else {
                 $commandResult = new commandResult("systemError");
                 $commandResult->addValuePair("Description", "Database failure.");
             }
         } catch (Exception $e) {
             $commandResult = new commandResult("systemError");
             $commandResult->addValuePair("Description", "Database failure.");
         }
     } else {
         $commandResult = new commandResult("invalidData");
         $commandResult->addValuePair("Description", "Invalid input parameters for GetSchedule.");
     }
     return $commandResult;
 }
Ejemplo n.º 5
0
 public function executeCommand()
 {
     // --- Variable Declarations  -------------------------------//
     /* @var $commands (Array) Used to cross check the request.   */
     $commandParams = array("DepartmentID", "CourseID", "Title", "Description");
     /* @var $commandResult (commandResult) The result model.     */
     $commandResult;
     /* @var $result (object) The output of PDO sql executes.     */
     $result = NULL;
     /* @var $sqlQuery (object) The query to execute on service.  */
     $sqlQuery = NULL;
     // --- Main Routine ------------------------------------------//
     // Check if the request contains all necessary parameters.
     if ($this->isValidContent($this->requestContent, $commandParams)) {
         // TODO: 3. Brief Description of what is going to happen.
         try {
             // TODO 4: Implement code.
         } catch (Exception $e) {
             $commandResult = new commandResult("systemError");
             $commandResult->addValuePair("Description", "Database failure.");
         }
     } else {
         $commandResult = new commandResult("invalidData");
         $commandResult->addValuePair("Description", "Invalid input parameters for AddCourse.");
     }
 }
 public function executeCommand()
 {
     // --- Variable Declarations  -------------------------------//
     /* @var $commands (Array) Used to cross check the request.   */
     $commandParams = array("DepartmentID", "CourseID", "NewDepartmentID", "NewCourseID", "NewTitle", "NewDescription");
     /* @var $commandResult (commandResult) The result model.     */
     $commandResult = NULL;
     /* @var $sqlQuery (object) The query to execute on service.  */
     $sqlQuery = NULL;
     // --- Main Routine ------------------------------------------//
     // Check if the request contains all necessary parameters.
     if ($this->isValidContent($this->requestContent, $commandParams)) {
         // TODO: 3. Brief Description of what is going to happen.
         try {
             // A. validate that the course doesn't exist already.
             $sqlQuery = "SELECT * FROM course WHERE cID = ? AND dNum = ?";
             $sqlParams = array($this->requestContent["CourseID"], $this->requestContent["DepartmentID"]);
             $this->dbAccess->executeQuery($sqlQuery, $sqlParams);
             // B. If the course doesnt exist
             if ($this->dbAccess->getResults() != NULL) {
                 $sqlQuery = "UPDATE course SET cID = ?, dNum = ?, title = ?, description = ? WHERE dNum = ? AND cID = ?";
                 $sqlParams = array($this->requestContent["NewCourseID"], $this->requestContent["NewDepartmentID"], $this->requestContent["NewTitle"], $this->requestContent["NewDescription"], $this->requestContent["DepartmentID"], $this->requestContent["CourseID"]);
                 if ($this->dbAccess->executeQuery($sqlQuery, $sqlParams)) {
                     $commandResult = new commandResult("success");
                 } else {
                     $commandResult = new commandResult("failed");
                     $commandResult->addValuePair("Description", "Database error.");
                 }
             } else {
                 $commandResult = new commandResult("failed");
                 $commandResult->addValuePair("Description", "Could not find class.");
             }
         } catch (Exception $e) {
             $commandResult = new commandResult("systemError");
             $commandResult->addValuePair("Description", "Database failure.");
         }
         // Return the result of the command.
         return $commandResult;
     }
 }
 public function executeCommand()
 {
     // --- Variable Declarations  -------------------------------//
     /* @var $commands (Array) Used to cross check the request.   */
     $commandParams = array();
     /* @var $commandResult (commandResult) The result model.     */
     $commandResult;
     /* @var $result (object) The output of PDO sql executes.     */
     $result = NULL;
     /* @var $sqlQuery (object) The query to execute on service.  */
     $sqlQuery = NULL;
     /* @var $semester (array) The semester list from the query.  */
     $semester;
     /* @var $semesterItem (array) A row from the query result.   */
     $semesterItem;
     /* @var $semesterList (array) the result to return to client.*/
     $semesterList = array();
     // --- Main Routine ------------------------------------------//
     // Check if the request contains all necessary parameters.
     if ($this->isValidContent($this->requestContent, $commandParams)) {
         // TODO: 3. Brief Description of what is going to happen.
         try {
             $sqlQuery = 'SELECT * FROM semester WHERE ?=?';
             $sqlParams = array(1, 1);
             if ($this->dbAccess->executeQuery($sqlQuery, $sqlParams)) {
                 $result = $this->dbAccess->getResults();
                 if ($result != null) {
                     foreach ($result as &$semester) {
                         $semesterItem["semesterID"] = $semester["semesterID"];
                         $semesterItem["year"] = $semester["year"];
                         $semesterItem["season"] = $semester["season"];
                         array_push($semesterList, $semesterItem);
                     }
                     // Return the result.
                     $commandResult = new commandResult("success");
                     $commandResult->addValuePair("semesters", $semesterList);
                 } else {
                     $commandResult = new commandResult("failed");
                     $commandResult->addValuePair("Description", "No semesters found.");
                 }
             } else {
                 $commandResult = new commandResult("systemError");
                 $commandResult->addValuePair("Description", "Database failure.");
             }
         } catch (Exception $e) {
             $commandResult = new commandResult("systemError");
             $commandResult->addValuePair("Description", "Database failure.");
         }
     } else {
         $commandResult = new commandResult("invalidData");
         $commandResult->addValuePair("Description", "Invalid input parameters for GetSemesters.");
     }
     // Return the command result.
     return $commandResult;
 }
Ejemplo n.º 8
0
    public function executeCommand()
    {
        // --- Variable Declarations  -------------------------------//
        /* @var $commands (Array) Used to cross check the request.   */
        $commandParams = array("email", "password");
        /* @var $commandResult (commandResult) The result model.     */
        $commandResult;
        /* @var $result (object) The output of PDO sql executes.     */
        $result = NULL;
        /* @var $sqlQuery (object) The query to execute on service.  */
        $sqlQuery = NULL;
        /* @var $uniqueID (string) The session key to use for login. */
        $uniqueID = uniqid("classyStudent_");
        /* @var $accountDataRes (array) The user data to return.     */
        $accountDataRes;
        // --- Main Routine ------------------------------------------//
        // Check if the request contains all necessary parameters.
        if ($this->isValidContent($this->requestContent, $commandParams)) {
            // Attempt to check the password and user name.
            try {
                $sqlQuery = 'SELECT s.studentID, s.password, s.salt, i.firstname, i.lastname,
						    i.classStanding, i.creditHours FROM student AS s
			            	JOIN studentinfo AS i
			            		ON s.studentID = i.studentID
			            	WHERE email = ?';
                $sqlParams = array($this->requestContent["email"]);
                // Execute the search for the account.
                if ($this->dbAccess->executeQuery($sqlQuery, $sqlParams)) {
                    $accountDataRes = $this->dbAccess->getResults();
                    // check the password to see if it matches.
                    if ($accountDataRes != null) {
                        $checkPassword = crypt($this->requestContent["password"], '$2a$07' . $accountDataRes[0]["salt"]);
                        // If it matches build insert query to create session.
                        if (strcmp($checkPassword, $accountDataRes[0]["password"]) == 0) {
                            $sqlQuery = 'INSERT INTO session (studentID, sessionKey, createTime, expireTime)
                                VALUES (?, ?, NOW(),ADDTIME(NOW(), "00:30:00"))';
                            $sqlParams = array($accountDataRes[0]["studentID"], $uniqueID);
                            // Execute and build the login data result.
                            if ($this->dbAccess->executeQuery($sqlQuery, $sqlParams)) {
                                $result = $this->dbAccess->getResults();
                                // Check and see if were already logged in.
                                if ($result) {
                                    $commandResult = new commandResult("success");
                                    $commandResult->addValuePair("studentID", $accountDataRes[0]["studentID"]);
                                    $commandResult->addValuePair("sessionID", $uniqueID);
                                    $commandResult->addValuePair("firstName", $accountDataRes[0]["firstname"]);
                                    $commandResult->addValuePair("lastName", $accountDataRes[0]["lastname"]);
                                    $commandResult->addValuePair("classStanding", $accountDataRes[0]["classStanding"]);
                                    $commandResult->addValuePair("creditHours", $accountDataRes[0]["creditHours"]);
                                } else {
                                    // Account already logged in.
                                    $commandResult = new commandResult("failed");
                                    $commandResult->addValuePair("Description", "The account is already signed in somewhere.");
                                }
                            } else {
                                // Issue with insert query.
                                $commandResult = new commandResult("systemError");
                                $commandResult->addValuePair("Description", "Database failure.");
                            }
                        } else {
                            // Invalid password.
                            $commandResult = new commandResult("failed");
                            $commandResult->addValuePair("Description", "Invalid email or password.");
                        }
                    } else {
                        // Account not found.
                        $commandResult = new commandResult("failed");
                        $commandResult->addValuePair("Description", "Invalid email or password.");
                    }
                } else {
                    // issue with search query.
                    $commandResult = new commandResult("systemError");
                    $commandResult->addValuePair("Description", "Database failure.");
                }
            } catch (Exception $e) {
                $commandResult = new commandResult("systemError");
                $commandResult->addValuePair("Description", "Database failure.");
            }
        } else {
            $commandResult = new commandResult("invalidData");
            $commandResult->addValuePair("Description", "Invalid input parameters for Login.");
        }
        // Return the command result.
        return $commandResult;
    }
 public function executeCommand()
 {
     // --- Variable Declarations  -------------------------------//
     /* @var $commands (Array) Used to cross check the request.   */
     $commandParams = array("facultyID", "courseID");
     /* @var $commandResult (commandResult) The result model.     */
     $commandResult;
     /* @var $result (object) The output of PDO sql executes.     */
     $result = NULL;
     /* @var $sqlQuery (object) The query to execute on service.  */
     $sqlQuery = NULL;
     /* @var $rating (array) The rating list from the query.      */
     $rating;
     /* @var $ratingItem (array) A row from the query result.     */
     $ratingItem;
     /* @var $ratingList (array) the result to return to client.  */
     $ratingList = array();
     // --- Main Routine ------------------------------------------//
     // Check if the request contains all necessary parameters.
     if ($this->isValidContent($this->requestContent, $commandParams)) {
         // Request for all the ratings for a particular faculty memeber.
         try {
             $sqlQuery = 'SELECT f.description, f.rating, f.time,s.firstName,s.lastName,s.classStanding
                         FROM facultyratings AS f
                         	JOIN studentinfo AS s
                             	ON s.studentID = f.studentID
                         WHERE f.facultyID = ? AND f.courseCode = ?';
             $sqlParams = array($this->requestContent["facultyID"], $this->requestContent["courseID"]);
             if ($this->dbAccess->executeQuery($sqlQuery, $sqlParams)) {
                 $result = $this->dbAccess->getResults();
                 if ($result != null) {
                     foreach ($result as &$rating) {
                         $ratingItem["rating"] = $rating["rating"];
                         $ratingItem["description"] = $rating["description"];
                         $ratingItem["revClassStanding"] = $rating["classStanding"];
                         $ratingItem["revFirstName"] = $rating["firstName"];
                         $ratingItem["revLastName"] = $rating["lastName"];
                         array_push($ratingList, $ratingItem);
                     }
                     // Return the ratings.
                     $commandResult = new commandResult("success");
                     $commandResult->addValuePair("ratings", $ratingList);
                 } else {
                     $commandResult = new commandResult("failed");
                     $commandResult->addValuePair("Description", "No ratings found.");
                 }
             } else {
                 $commandResult = new commandResult("systemError");
                 $commandResult->addValuePair("Description", "Database failure.");
             }
         } catch (Exception $e) {
             $commandResult = new commandResult("systemError");
             $commandResult->addValuePair("Description", "Database failure.");
         }
     } else {
         $commandResult = new commandResult("invalidData");
         $commandResult->addValuePair("Description", "Invalid input parameters for GetFacRatings.");
     }
     // Return the command result.
     return $commandResult;
 }
 public function executeCommand()
 {
     // --- Variable Declarations  -------------------------------//
     /* @var $commands (Array) Used to cross check the request.   */
     $commandParams = array("studentID", "sessionID");
     /* @var $commandResult (commandResult) The result model.     */
     $commandResult;
     /* @var $result (object) The output of PDO sql executes.     */
     $result = NULL;
     /* @var $sqlQuery (object) The query to execute on service.  */
     $sqlQuery = NULL;
     // --- Main Routine ------------------------------------------//
     // Check if the request contains all necessary parameters.
     if ($this->isValidContent($this->requestContent, $commandParams)) {
         // TODO: 3. Brief Description of what is going to happen.
         try {
             $sqlQuery = 'SELECT * FROM session WHERE studentID = ? AND sessionKey = ?
                         AND NOW() BETWEEN createTime AND expireTime';
             $sqlParams = array($this->requestContent["studentID"], $this->requestContent["sessionID"]);
             // Execute and build the login data result.
             if ($this->dbAccess->executeQuery($sqlQuery, $sqlParams)) {
                 $result = $this->dbAccess->getResults();
                 if (gettype($result) == "array" && count($result) == 1) {
                     $commandResult = new commandResult("success");
                 } else {
                     $commandResult = new commandResult("sessionInvalid");
                     $commandResult->addValuePair("Description", "Session data invalid, session may have ended.");
                 }
             } else {
                 $commandResult = new commandResult("systemError");
                 $commandResult->addValuePair("Description", "Database failure.");
             }
         } catch (Exception $e) {
             $commandResult = new commandResult("systemError");
             $commandResult->addValuePair("Description", "Database failure.");
         }
     } else {
         $commandResult = new commandResult("invalidData");
         $commandResult->addValuePair("Description", "Session information required for requested service.");
     }
     // Return the command result.
     return $commandResult;
 }
Ejemplo n.º 11
0
 public function executeCommand()
 {
     // --- Variable Declarations  -------------------------------//
     /* @var $commands (Array) Used to cross check the request.   */
     $commandParams = array("DepartmentID", "CourseID", "Title", "Description");
     /* @var $commandResult (commandResult) The result model.     */
     $commandResult;
     /* @var $result (object) The output of PDO sql executes.     */
     $result = NULL;
     /* @var $sqlQuery (object) The query to execute on service.  */
     $sqlQuery = NULL;
     // --- Main Routine ------------------------------------------//
     // Check if the request contains all necessary parameters.
     if ($this->isValidContent($this->requestContent, $commandParams)) {
         // 3. Brief Description of what is going to happen.
         try {
             // A. validate that the course doesn't exist already.
             $sqlQuery = "SELECT * FROM course WHERE cID = ? AND dNum = ?";
             $sqlParams = array($this->requestContent["CourseID"], $this->requestContent["DepartmentID"]);
             $this->dbAccess->executeQuery($sqlQuery, $sqlParams);
             // B. If the course doesnt exist
             if ($this->dbAccess->getResults() == NULL) {
                 $sqlQuery = "INSERT INTO course (`dNum`, `cID`, `title`, `description`) VALUES (?,?,?,?)";
                 $sqlParams = array($this->requestContent["DepartmentID"], $this->requestContent["CourseID"], $this->requestContent["Title"], $this->requestContent["Description"]);
                 if ($this->dbAccess->executeQuery($sqlQuery, $sqlParams)) {
                     $commandResult = new commandResult("success");
                 } else {
                     $commandResult = new commandResult("failed");
                     $commandResult->addValuePair("Description", "Database error creating class.");
                 }
             } else {
                 $commandResult = new commandResult("failed");
                 $commandResult->addValuePair("Description", "class already exists.");
             }
         } catch (Exception $e) {
             $commandResult = new commandResult("systemError");
             $commandResult->addValuePair("Description", "Database failure.");
         }
     } else {
         $commandResult = new commandResult("invalidData");
         $commandResult->addValuePair("Description", "Invalid input parameters for AddCourse.");
     }
     // Return the result of the command.
     return $commandResult;
 }
 public function executeCommand()
 {
     // --- Variable Declarations  -------------------------------//
     /* @var $commands (Array) Used to cross check the request.   */
     $commandParams = array("scheduleID", "sectionCodeID", "operation");
     /* @var $commandResult (commandResult) The result model.     */
     $commandResult;
     /* @var $result (object) The output of PDO sql executes.     */
     $result = NULL;
     /* @var $sqlQuery (object) The query to execute on service.  */
     $sqlQuery = NULL;
     /* @var $updateSQL (array) The update query specifics.       */
     $updateSQL;
     // --- Main Routine ------------------------------------------//
     // Check if the request contains all necessary parameters.
     if ($this->isValidContent($this->requestContent, $commandParams)) {
         // Depending on the operation, either add or drop course from schedule.
         try {
             $sqlQuery = 'SELECT * FROM scheduleitem WHERE scheduleID = ? AND sectionCode = ?';
             $sqlParams = array($this->requestContent["scheduleID"], $this->requestContent["sectionCodeID"]);
             if ($this->dbAccess->executeQuery($sqlQuery, $sqlParams)) {
                 $result = $this->dbAccess->getResults();
             } else {
                 $commandResult = new commandResult("systemError");
                 $commandResult->addValuePair("Description", "Database failure.");
                 return $commandResult;
             }
             // Determine which activity were preforming.
             if ($this->requestContent["operation"] == "add") {
                 if ($result == 0) {
                     $sqlQuery = 'INSERT INTO scheduleitem (scheduleID,sectionCode) VALUES(?,?)';
                     $updateSQL = 's.seatsOpen = s.seatsOpen - 1, ss.creditHours = ss.creditHours + t.creditHours';
                 } else {
                     $commandResult = new commandResult("failed");
                     $commandResult->addValuePair("Description", "Scheduled course already exists.");
                     return $commandResult;
                 }
             } else {
                 if ($this->requestContent["operation"] == "drop") {
                     if ($result > 0) {
                         $sqlQuery = 'DELETE FROM scheduleitem WHERE scheduleID = ? AND sectionCode = ?';
                         $sqlParams = array($this->requestContent["scheduleID"], $this->requestContent["sectionCodeID"]);
                         $updateSQL = 's.seatsOpen = s.seatsOpen + 1, ss.creditHours = ss.creditHours - t.creditHours';
                     } else {
                         $commandResult = new commandResult("failed");
                         $commandResult->addValuePair("Description", "Scheduled course doesn't exist.");
                         return $commandResult;
                     }
                 } else {
                     $commandResult = new commandResult("invalidData");
                     $commandResult->addValuePair("Description", "Invalid operation defined for command.");
                     return $commandResult;
                 }
             }
             // Update the seat and hours recorded for the schedule.
             if ($this->dbAccess->executeQuery($sqlQuery, $sqlParams)) {
                 $result = $this->dbAccess->getResults();
                 if ($result > 0) {
                     $sqlQuery = 'UPDATE studentschedule AS ss
                 JOIN section AS s ON
                   s.sectionCode = ?
                 JOIN timeblock AS t
                   ON t.timeblockID = s.timeblockID
               SET ' . $updateSQL . ' WHERE ss.scheduleID = ?';
                     $sqlParams = array($this->requestContent["sectionCodeID"], $this->requestContent["scheduleID"]);
                     // Respond with a pass.
                     if ($this->dbAccess->executeQuery($sqlQuery, $sqlParams)) {
                         $commandResult = new commandResult("success");
                     } else {
                         $commandResult = new commandResult("systemError");
                         $commandResult->addValuePair("Description", "Database failure.");
                     }
                 } else {
                     $commandResult = new commandResult("failed");
                     $commandResult->addValuePair("Description", "Desired Schedule or Section ID doesn't exist.");
                 }
             } else {
                 $commandResult = new commandResult("systemError");
                 $commandResult->addValuePair("Description", "Database failure.");
             }
         } catch (Exception $e) {
             $commandResult = new commandResult("systemError");
             $commandResult->addValuePair("Description", "Database failure.");
         }
     } else {
         $commandResult = new commandResult("invalidData");
         $commandResult->addValuePair("Description", "Invalid input parameters for UpdateSchedule Service.");
     }
     return $commandResult;
 }