Exemplo n.º 1
0
        /// <summary>
        /// Sets up display settings for dashboard posts and replies.
        /// </summary>
        /// <param name="post">The post or reply to be set up</param>
        private void SetupPostDisplay(AbstractDashboard post)
        {
            List <CourseUser> courseList = new List <CourseUser>();

            // Get list of users in course, either from the root post or its parent in the case of a reply.
            if (post is DashboardPost)
            {
                DashboardPost dp = (DashboardPost)post;
                courseList = db.CourseUsers.Where(c => c.AbstractCourseID == dp.CourseUser.AbstractCourseID).ToList();
            }
            else if (post is DashboardReply)
            {
                DashboardReply dr = (DashboardReply)post;
                courseList = db.CourseUsers.Where(c => c.AbstractCourseID == dr.Parent.CourseUser.AbstractCourseID).ToList();
            }

            // Get Course/User link for current user.
            CourseUser currentCu = courseList.FirstOrDefault(c => c.UserProfileID == CurrentUser.ID);

            // " " for poster of post/reply.
            CourseUser posterCu = courseList.FirstOrDefault(c => c.UserProfileID == post.CourseUser.UserProfileID);


            /*** Setup Display Name/Display Title/Profile Picture/Mail Button/Delete Button ***/

            // If user is not anonymous, this post was written by current user, or the poster is an Instructor/TA, display name and picture.
            if (currentCu != null &&
                ((posterCu == null) || !currentCu.AbstractRole.Anonymized ||
                 (currentCu.UserProfileID == posterCu.UserProfileID) || posterCu.AbstractRole.CanGrade))
            {
                // Display Name (may be anonymous depending on currentCu's AbstractRoleID)
                post.DisplayName = posterCu != null
                    ? posterCu.DisplayName(currentCu.AbstractRoleID, true)
                    : "Deleted User";

                // Allow deletion if current user is poster or is an instructor
                if (currentCu.AbstractRole.CanModify ||
                    ((posterCu != null) && (posterCu.UserProfileID == currentCu.UserProfileID)))
                {
                    post.CanDelete = true;
                }

                // If current user is not the poster, allow mailing
                if (posterCu != null && posterCu.UserProfileID != currentCu.UserProfileID)
                {
                    Course course = db.AbstractCourses.Where(ac => ac.ID == ActiveCourseUser.AbstractCourseID).FirstOrDefault() as Course;
                    if (null != course && course.HideMail)
                    {
                        post.CanMail = false;
                    }
                    else
                    {
                        post.CanMail = true;
                    }
                }

                if (posterCu != null)
                {
                    // Display Titles for Instructors/TAs for Courses, or Leader of Communities.
                    post.DisplayTitle       = GetRoleTitle(posterCu.AbstractRoleID);
                    post.ShowProfilePicture = true;
                }
            }
            else
            {
                // Display Anonymous name (or "Deleted User")
                post.DisplayName = posterCu != null
                    ? posterCu.DisplayName((int)CourseRole.CourseRoles.Observer, true)
                    : "Deleted User";

                // Profile picture will display default picture.
                post.ShowProfilePicture = false;
                post.CanMail            = false;
                post.CanDelete          = false;
            }

            // For root posts only
            if (post is DashboardPost)
            {
                DashboardPost thisDp = (DashboardPost)post;

                // For posts, set reply box display if the course allows replies or if Instructor/TA/Observer.
                if (currentCu != null && ((currentCu.AbstractCourse is Course &&
                                           ((currentCu.AbstractCourse as Course).AllowDashboardReplies) ||
                                           (currentCu.AbstractRole.CanGrade) ||
                                           (currentCu.AbstractRole.Anonymized))
                                          // For communities, always allow replies
                                          || (currentCu.AbstractCourse is Community))
                    )
                {
                    thisDp.CanReply = true;
                }

                // recursively set the display for post's replies.
                foreach (DashboardReply dr in thisDp.Replies)
                {
                    SetupPostDisplay(dr);
                }
            }
        }