/** * A method to get notification objects * @param int $projectId the project id these notes are associated with * @return array the notification objects */ public static function getNotificationsForProject($projectId) { # Get db connection $objPDO = PDOFactory::get(); # Get all notifications associated with the $projectId from a database $strQuery = "SELECT id, object_type FROM Notification WHERE project_id = :project_id AND is_deleted = 0 ORDER BY datetime_created DESC"; $objStatement = $objPDO->prepare($strQuery); $objStatement->bindValue(':project_id', $projectId, PDO::PARAM_INT); $objStatement->execute(); # Define empty array $myArr = array(); # Add all notifications associated with the $projectId to an array if ($result = $objStatement->fetchAll(PDO::FETCH_ASSOC)) { foreach ($result as $row) { # Decide what kind of object should be created switch ($row["object_type"]) { case "Action Point": $myArr[$row["id"]] = new NotificationAP(null, null, $row["id"]); break; case "Meeting": $myArr[$row['id']] = new NotificationMeeting(null, null, $row['id']); break; case "Note": $myArr[$row['id']] = new NotificationNote(null, null, $row['id']); break; default: $myArr[$row["id"]] = new Notification(null, null, $row["id"]); } } } # Return the array of notifications return $myArr; }
public function __construct($id = NULL, $temp = false) { # If we want to retrieve an object from temporary table # This is used for example when we have a notification that displays # action point that has been changed, we want to display what was the change # and therefore we need the old object as well as the new one if ($temp) { $temp = 'Temp'; } else { $temp = ''; } # Set instance variables $this->strTableName = $this->DefineTableName() . $temp; $this->arRelationMap = $this->DefineRelationMap(); # Get DB connection $this->objPDO = PDOFactory::get(); # By default properties are not loaded $this->blIsLoaded = false; # If we want to load a particular object if (isset($id)) { $this->ID = $id; } # By default, there are no modified properties $this->arModifiedRelations = array(); }
/** * A method to return action points' counts for RAG algorithm purposes * @param int $factor what kind of count should be returned * @return int the count */ public static function getActionPointsCount($factor) { # Get database connection $objPDO = PDOFactory::get(); # Get project ID from session $projectId = HTTPSession::getInstance()->PROJECT_ID; # Beginning of the select statement $select = "COUNT(id) AS ap_count"; # Decide what count to get from DB switch ($factor) { case RedAmberGreen::TO_BE_DONE: $factor = " AND is_done = 0"; break; case RedAmberGreen::RUNNING_OVER_DEADLINE: $factor = " AND is_done = 0 AND deadline < NOW()"; break; case RedAmberGreen::FINISHED: $factor = " AND is_done = 1"; break; case RedAmberGreen::FINISHED_AFTER_DEADLINE: $factor = " AND is_done = 1 AND deadline < datetime_done"; break; case RedAmberGreen::AVG_GRADE: $factor = " AND is_done = 1 AND grade <> 0"; $select = "TRUNCATE(AVG(grade),1) AS ap_count"; break; default: $factor = ""; } # Get a certain number of action points $strQuery = "SELECT " . $select . " FROM ActionPoint WHERE project_id = :project_id AND is_approved = 1" . $factor . " AND is_deleted = 0"; $objStatement = $objPDO->prepare($strQuery); $objStatement->bindValue(':project_id', $projectId, PDO::PARAM_INT); $objStatement->execute(); # Return the value $result = $objStatement->fetch()['ap_count']; # Return the count if ($result) { return $result; } else { return 0; } }
private function __construct() { # Set database connection $this->objPDO = PDOFactory::get(); # Set up the handler for default session methods session_set_save_handler(array(&$this, '_session_open_method'), array(&$this, '_session_close_method'), array(&$this, '_session_read_method'), array(&$this, '_session_write_method'), array(&$this, '_session_destroy_method'), array(&$this, '_session_gc_method')); # Get the user agent string $strUserAgent = $_SERVER["HTTP_USER_AGENT"]; # Check if session cookie has passed if (isset($_COOKIE["PHPSESSID"])) { # Save the cookie $this->php_session_id = $_COOKIE["PHPSESSID"]; # This statement gets the session from database under following conditions: # 1. If there's a session ID equal to $this->php_session_id # 2. If session_lifespan hasn't run out of time # 3. If a user is still in the same user_agent (browser) # 4. If session_timeout hasn't run out of time # Prepare statement for database $strQuery = "SELECT id FROM http_session WHERE ascii_session_id = '" . $this->php_session_id . "' AND (TIME_TO_SEC(TIMEDIFF(now(),created)) < " . $this->session_lifespan . ") AND user_agent='{$strUserAgent}" . "' AND (TIME_TO_SEC(TIMEDIFF(now(),last_impression)) <= " . $this->session_timeout . " OR last_impression IS NULL)"; # Execute statement $objStatement = $this->objPDO->query($strQuery); # Fetch it from the database $row = $objStatement->fetch(PDO::FETCH_ASSOC); # If such row doesn't exist if (!$row) { # Delete from database - we do garbage cleanup at the same time $maxlifetime = $this->session_lifespan; $strQuery = "DELETE FROM http_session WHERE (ascii_session_id = '" . $this->php_session_id . "') OR (now() - created > '{$maxlifetime} seconds')"; unset($objStatement); $objStatement = $this->objPDO->query($strQuery); # Clean up stray session variables $strQuery = "DELETE FROM session_variable WHERE session_id NOT IN (SELECT id FROM http_session)"; unset($objStatement); $objStatement = $this->objPDO->query($strQuery); # Get rid of old PHPSESSID, this will force PHP to give us another unset($_COOKIE["PHPSESSID"]); } } # Set the life time for the cookie session_set_cookie_params($this->session_lifespan); # Call the session_start method to get things started session_start(); }
/** * A method to return note objects from database * @param null $meeting filter by a specific meeting * @param bool $agenda if it should be agenda notes returned * @return array the note objects */ public static function getNotes($meeting = null, $agenda = false) { # Get database connection $objPDO = PDOFactory::get(); # Get project ID from session $projectId = HTTPSession::getInstance()->PROJECT_ID; # Get user ID from session $userID = HTTPSession::getInstance()->getUserId(); # If notes for specific meeting are requested if ($meeting) { $meeting = " AND meeting_id = " . $meeting; } else { $meeting = ""; } # If notes for agenda are requested if ($agenda) { $agenda = " AND is_agenda = 1"; } else { $agenda = " AND is_agenda = 0"; } # Get all notes associated with a given project with the following condition: # – Apart from notes that are private AND associated with a different user than logged in $strQuery = "SELECT id FROM Note WHERE project_id = :project_id AND NOT (user_id != :user_id AND is_private = 1) AND is_deleted = 0 " . $meeting . $agenda . " ORDER BY datetime_created DESC"; $objStatement = $objPDO->prepare($strQuery); $objStatement->bindValue(':project_id', $projectId, PDO::PARAM_INT); $objStatement->bindValue(':user_id', $userID, PDO::PARAM_INT); $objStatement->execute(); # Define empty array $myArr = array(); # Add all notes to an array if ($result = $objStatement->fetchAll(PDO::FETCH_ASSOC)) { foreach ($result as $row) { $myArr[$row["id"]] = new Note($row["id"]); } } # Return the note objects return $myArr; }
/** * A method to return all users associated with a project * @param int $projectI the project idd * @return array the user objects */ public static function getAllUsersForProject($projectId) { # Get PDO $objPDO = PDOFactory::get(); # Get alluserss associated with the $projectId from a database $strQuery = "SELECT user_id FROM UserProject WHERE project_id = :project_id"; $objStatement = $objPDO->prepare($strQuery); $objStatement->bindValue(':project_id', $projectId, PDO::PARAM_INT); $objStatement->execute(); # Define empty array $myArr = array(); # Add all users associated with the $projectId to an array if ($result = $objStatement->fetchAll(PDO::FETCH_ASSOC)) { foreach ($result as $row) { $myArr[$row["user_id"]] = new User($row["user_id"]); } } # Return the user objects return $myArr; }
/** * A method to return meetings' counts for RAG algorithm purposes * @param int $factor what kind of count should be returned * @return int the count */ public static function getMeetingsCount($factor) { # Get database connection $objPDO = PDOFactory::get(); # Get project ID from session $projectId = HTTPSession::getInstance()->PROJECT_ID; $select = "COUNT(id) AS m_count"; # Decide what count to get from DB switch ($factor) { case RedAmberGreen::TAKEN_PLACE: $factor = " AND taken_place = 1"; break; case RedAmberGreen::STUDENT_ARRIVED_ON_TIME: $factor = " AND taken_place = 1 AND arrived_on_time = 1"; break; case RedAmberGreen::CANCELLED: $factor = " AND is_cancelled = 1"; break; case RedAmberGreen::NO_SHOW: $factor = " AND datetime < NOW() AND taken_place = 0 AND is_cancelled = 0"; break; # Cancelled can be in the future and we want to include it in the total # Cancelled can be in the future and we want to include it in the total case RedAmberGreen::M_TOTAL: $factor = " AND (datetime < NOW() OR is_cancelled = 1)"; break; default: $factor = ""; } # Get a certain number of meetings $strQuery = "SELECT " . $select . " FROM Meeting WHERE project_id = :project_id AND is_approved = 1" . $factor . " AND is_deleted = 0"; $objStatement = $objPDO->prepare($strQuery); $objStatement->bindValue(':project_id', $projectId, PDO::PARAM_INT); $objStatement->execute(); # Return the value return $objStatement->fetch()['m_count']; }