/// <summary> /// Shows the results of the assessment test. /// </summary> /// <param name="savedScores">The saved scores.</param> private void ShowResult(DiscService.AssessmentResults savedScores, Assessment assessment) { pnlInstructions.Visible = false; pnlQuestion.Visible = false; pnlResult.Visible = true; if (CurrentPersonId == _targetPerson.Id) { lPrintTip.Visible = true; } else { pnlAdditionalInformation.Visible = true; } lHeading.Text = string.Format("<div class='disc-heading'><h1>{0}</h1><h4>Personality Type: {1}</h4></div>", _targetPerson.FullName, savedScores.PersonalityType); double days = assessment.AssessmentType.MinimumDaysToRetake; if (!_isQuerystringPersonKey && assessment.CompletedDateTime.HasValue && assessment.CompletedDateTime.Value.AddDays(days) <= RockDateTime.Now) { btnRetakeTest.Visible = true; } PlotGraph(savedScores); ShowExplaination(savedScores.PersonalityType); }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnInit(EventArgs e) { base.OnInit(e); // otherwise use the currently logged in person if (CurrentPerson != null) { _targetPerson = CurrentPerson; } else { nbError.Visible = true; pnlInstructions.Visible = false; pnlQuestions.Visible = false; pnlResults.Visible = false; } if (_targetPerson != null) { DiscService.AssessmentResults savedScores = DiscService.LoadSavedAssessmentResults(_targetPerson); if (savedScores.LastSaveDate <= DateTime.MinValue || !string.IsNullOrWhiteSpace(PageParameter("RetakeDisc"))) { ShowInstructions(); } else { ShowResults(savedScores); } } }
/// <summary> /// Shows the results of the assessment test. /// </summary> /// <param name="savedScores">The saved scores.</param> private void ShowResult(DiscService.AssessmentResults savedScores, Assessment assessment, bool isPrevious = false) { pnlInstructions.Visible = false; pnlQuestion.Visible = false; pnlResult.Visible = true; if (isPrevious) { ShowNotification("A more recent assessment request has been made but has not been taken. Displaying the most recently completed test.", NotificationBoxType.Info); } if (CurrentPersonId == _targetPerson.Id) { lPrintTip.Visible = true; } else { pnlAdditionalInformation.Visible = true; } lHeading.Text = string.Format("<div class='disc-heading'><h1>{0}</h1><h4>Personality Type: {1}</h4></div>", _targetPerson.FullName, savedScores.PersonalityType); double days = assessment.AssessmentType.MinimumDaysToRetake; if (!_isQuerystringPersonKey && assessment.CompletedDateTime.HasValue && assessment.CompletedDateTime.Value.AddDays(days) <= RockDateTime.Now) { btnRetakeTest.Visible = true; } PlotGraph(savedScores); ShowExplaination(savedScores.PersonalityType); }
/// <summary> /// Shows the results of the assessment test. /// </summary> /// <param name="savedScores">The saved scores.</param> private void ShowResults(DiscService.AssessmentResults savedScores) { // NewPointe alteration: redirect to SHAPE profile page instead string shapeRedirectUrl = "https://newpointe.org/ShapeProfile?PersonId=" + _targetPerson.Id; Response.Redirect(shapeRedirectUrl, true); // end NewPointe alteration: pnlInstructions.Visible = false; pnlQuestions.Visible = false; pnlResults.Visible = true; if (CurrentPersonId == _targetPerson.Id) { lPrintTip.Visible = true; } lHeading.Text = string.Format("<div class='disc-heading'><h1>{0}</h1><h4>Personality Type: {1}</h4></div>", _targetPerson.FullName, savedScores.PersonalityType); // Show re-take test button if MinDaysToRetake has passed... double days = GetAttributeValue("MinDaysToRetake").AsDouble(); if ((savedScores.LastSaveDate.AddDays(days) <= RockDateTime.Now) || GetAttributeValue("AlwaysAllowRetakes").AsBoolean()) { btnRetakeTest.Visible = true; } PlotGraph(savedScores); ShowExplaination(savedScores.PersonalityType); }
/// <summary> /// Shows the results of the assessment test. /// </summary> /// <param name="savedScores">The saved scores.</param> private void ShowResults(DiscService.AssessmentResults savedScores) { // Plot the Natural graph DiscService.PlotOneGraph(discNaturalScore_D, discNaturalScore_I, discNaturalScore_S, discNaturalScore_C, savedScores.NaturalBehaviorD, savedScores.NaturalBehaviorI, savedScores.NaturalBehaviorS, savedScores.NaturalBehaviorC, 35); ShowExplaination(savedScores.PersonalityType); }
/// <summary> /// Handles the Click event of the btnNext control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnNext_Click(object sender, EventArgs e) { int pageNumber = hfPageNo.ValueAsInt() + 1; GetResponse(); LinkButton btn = ( LinkButton )sender; string commandArgument = btn.CommandArgument; var totalQuestion = pageNumber * QuestionCount; if ((AssessmentResponses.Count > totalQuestion && !AssessmentResponses.All(a => !string.IsNullOrEmpty(a.MostScore) && !string.IsNullOrEmpty(a.LeastScore))) || "Next".Equals(commandArgument)) { BindRepeater(pageNumber); } else { try { var moreD = AssessmentResponses.Where(a => a.MostScore == "D").Count(); var moreI = AssessmentResponses.Where(a => a.MostScore == "I").Count(); var moreS = AssessmentResponses.Where(a => a.MostScore == "S").Count(); var moreC = AssessmentResponses.Where(a => a.MostScore == "C").Count(); var lessD = AssessmentResponses.Where(a => a.LeastScore == "D").Count(); var lessI = AssessmentResponses.Where(a => a.LeastScore == "I").Count(); var lessS = AssessmentResponses.Where(a => a.LeastScore == "S").Count(); var lessC = AssessmentResponses.Where(a => a.LeastScore == "C").Count(); // Score the responses and return the results DiscService.AssessmentResults results = DiscService.Score(moreD, moreI, moreS, moreC, lessD, lessI, lessS, lessC); // Now save the results for this person DiscService.SaveAssessmentResults( _targetPerson, results.AdaptiveBehaviorD.ToString(), results.AdaptiveBehaviorI.ToString(), results.AdaptiveBehaviorS.ToString(), results.AdaptiveBehaviorC.ToString(), results.NaturalBehaviorD.ToString(), results.NaturalBehaviorI.ToString(), results.NaturalBehaviorS.ToString(), results.NaturalBehaviorC.ToString(), results.PersonalityType ); ShowResults(results); } catch (Exception ex) { nbError.Visible = true; nbError.Title = "We're Sorry..."; nbError.Text = "Something went wrong while trying to save your test results."; LogException(ex); } } }
/// <summary> /// Shows the results of the assessment test. /// </summary> /// <param name="savedScores">The saved scores.</param> private void ShowResults(DiscService.AssessmentResults savedScores) { // Plot the Natural graph DiscService.PlotOneGraph(discNaturalScore_D, discNaturalScore_I, discNaturalScore_S, discNaturalScore_C, savedScores.NaturalBehaviorD, savedScores.NaturalBehaviorI, savedScores.NaturalBehaviorS, savedScores.NaturalBehaviorC, 35); ShowExplaination(savedScores.PersonalityType); hlAssessmentDate.Text = String.Format("Assessment Date: {0}", savedScores.LastSaveDate.ToShortDateString()); lPersonName.Text = _targetPerson.FullName; lHeading.Text = string.Format("<div class='disc-heading'><h1>{0}</h1><h4>Personality Type: {1}</h4></div>", _targetPerson.FullName, savedScores.PersonalityType); }
/// <summary> /// Plots the graphs using the Disc score results. /// </summary> /// <param name="results">The results.</param> private void PlotGraph(DiscService.AssessmentResults results) { // Plot the Natural graph DiscService.PlotOneGraph( discNaturalScore_D, discNaturalScore_I, discNaturalScore_S, discNaturalScore_C, results.NaturalBehaviorD, results.NaturalBehaviorI, results.NaturalBehaviorS, results.NaturalBehaviorC, 100); }
// used for public / protected properties #endregion #region Base Control Methods /// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnInit(EventArgs e) { base.OnInit(e); string personKey = PageParameter("rckipid"); if (!string.IsNullOrEmpty(personKey)) { try { _targetPerson = new PersonService(new RockContext()).GetByUrlEncodedKey(personKey); } catch { nbError.Visible = true; } } else { // otherwise use the currently logged in person if (CurrentPerson != null) { _targetPerson = CurrentPerson; } else { nbError.Visible = true; } } if (_targetPerson != null) { DiscService.AssessmentResults savedScores = DiscService.LoadSavedAssessmentResults(_targetPerson); if (savedScores.LastSaveDate <= DateTime.MinValue || !string.IsNullOrWhiteSpace(PageParameter("RetakeDisc"))) { ShowInstructions(); } else { ShowResults(savedScores); } } }
protected void Page_Load(object sender, EventArgs e) { //Checks if RockPage IsPostBack (making the assumption that the PostBack is because the // 'Score Test' button was clicked. //Tell Javascript that the page is posted back or not. // See: http://stackoverflow.com/questions/59719/how-can-i-check-for-ispostback-in-javascript string script = IsPostBack ? "var isScored = true;" : "var isScored = false;"; Page.ClientScript.RegisterStartupScript(GetType(), "IsScored", script, true); //Add reference to my JS file RockPage.AddScriptLink("~/Blocks/Crm/DiscAssessment/scripts/disc.js"); //Yup, build question table buildQuestionTable(); DiscService.AssessmentResults savedScores = DiscService.LoadSavedAssessmentResults(CurrentPerson); if (savedScores.LastSaveDate > DateTime.MinValue) { //build last results table lblLastAssessmentDate.Text = savedScores.LastSaveDate.ToString("MM/dd/yyyy"); lblPrevABd.Text = savedScores.AdaptiveBehaviorD.ToString(); lblPrevABi.Text = savedScores.AdaptiveBehaviorI.ToString(); lblPrevABs.Text = savedScores.AdaptiveBehaviorS.ToString(); lblPrevABc.Text = savedScores.AdaptiveBehaviorC.ToString(); lblPrevNBd.Text = savedScores.NaturalBehaviorD.ToString(); lblPrevNBi.Text = savedScores.NaturalBehaviorI.ToString(); lblPrevNBs.Text = savedScores.NaturalBehaviorS.ToString(); lblPrevNBc.Text = savedScores.NaturalBehaviorC.ToString(); } if (IsPostBack) { btnSaveResults.Enabled = true; } else { btnSaveResults.Enabled = false; } }
/// <summary> /// Gets checked RadioButtons, scores test, and displays results. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnScoreTest_Click(object sender, EventArgs e) { List <DiscService.ResponseItem> responses = DiscService.GetResponses(); List <string> selectedResponseIDs = new List <string>(); // Collect selected responses into a string array. // All we need is the selected RadioButton's ID (which we set to the ResponseID + ("l" or "m") for each responses record). // Examples: "012m", "130l" // We now know the selected response and whether it was 'm'ost or 'l'east. foreach (DiscService.ResponseItem response in responses) { string rbID = response.ResponseID + "m"; RadioButton rb = findRadioButton(this, rbID); if (rb.Checked) { selectedResponseIDs.Add(rb.ID); } rbID = response.ResponseID + "l"; rb = findRadioButton(this, rbID); if (rb.Checked) { selectedResponseIDs.Add(rb.ID); } } // Score the responses and return the results DiscService.AssessmentResults results = DiscService.Score(selectedResponseIDs); //Display results out to user lblABd.Text = results.AdaptiveBehaviorD.ToString(); lblABi.Text = results.AdaptiveBehaviorI.ToString(); lblABs.Text = results.AdaptiveBehaviorS.ToString(); lblABc.Text = results.AdaptiveBehaviorC.ToString(); lblNBd.Text = results.NaturalBehaviorD.ToString(); lblNBi.Text = results.NaturalBehaviorI.ToString(); lblNBs.Text = results.NaturalBehaviorS.ToString(); lblNBc.Text = results.NaturalBehaviorC.ToString(); }
// used for public / protected properties #endregion #region Base Control Methods /// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnInit(EventArgs e) { base.OnInit(e); string personKey = PageParameter("Person"); if (!string.IsNullOrEmpty(personKey)) { try { _targetPerson = new PersonService(new RockContext()).GetByUrlEncodedKey(personKey); } catch (Exception) { nbError.Visible = true; } } else { // otherwise use the currently logged in person if (CurrentPerson != null) { _targetPerson = CurrentPerson; } else { nbError.Visible = true; } } if (_targetPerson != null) { pnlResults.Visible = true; DiscService.AssessmentResults savedScores = DiscService.LoadSavedAssessmentResults(_targetPerson); ShowResults(savedScores); } }
/// <summary> /// Shows the results of the assessment test. /// </summary> /// <param name="savedScores">The saved scores.</param> private void ShowResults(DiscService.AssessmentResults savedScores) { pnlInstructions.Visible = false; pnlQuestions.Visible = false; pnlResults.Visible = true; if (CurrentPersonId == _targetPerson.Id) { lPrintTip.Visible = true; } lHeading.Text = string.Format("<div class='disc-heading'><h1>{0}</h1><h4>Personality Type: {1}</h4></div>", _targetPerson.FullName, savedScores.PersonalityType); // Show re-take test button if MinDaysToRetake has passed... double days = GetAttributeValue("MinDaysToRetake").AsDouble(); if ((savedScores.LastSaveDate.AddDays(days) <= RockDateTime.Now) || GetAttributeValue("AlwaysAllowRetakes").AsBoolean()) { btnRetakeTest.Visible = true; } PlotGraph(savedScores); ShowExplaination(savedScores.PersonalityType); }
protected void Page_Load(object sender, EventArgs e) { var shapePageReference = new Rock.Web.PageReference(GetAttributeValue("SHAPEAssessmentPage")); var discPageReference = new Rock.Web.PageReference(GetAttributeValue("DISCAssessmentPage")); if (!string.IsNullOrWhiteSpace(PageParameter("FormId"))) { //Load the person based on the FormId var personInUrl = PageParameter("FormId"); SelectedPerson = GetPersonFromForm(personInUrl); PersonEncodedKey = SelectedPerson.UrlEncodedKey; } else if (!string.IsNullOrWhiteSpace(PageParameter("PersonId"))) { //Load the person based on the PersonId SelectedPerson = GetPersonFromId(PageParameter("PersonId")); PersonEncodedKey = SelectedPerson.UrlEncodedKey; } else if (CurrentPerson != null) { //Load the person based on the currently logged in person SelectedPerson = CurrentPerson; PersonEncodedKey = SelectedPerson.UrlEncodedKey; } else { //Show Error Message nbNoPerson.Visible = true; Response.Redirect(shapePageReference.BuildUrl(), true); return; } // Load the attributes AttributeValueService attributeValueService = new AttributeValueService(rockContext); DefinedValueService definedValueService = new DefinedValueService(rockContext); string spiritualGift1 = ""; string spiritualGift2 = ""; string spiritualGift3 = ""; string spiritualGift4 = ""; string heartCategories = ""; string heartCauses = ""; string heartPassion = ""; string ability1 = ""; string ability2 = ""; string people = ""; string places = ""; string events = ""; var spiritualGift1AttributeValue = attributeValueService .Queryable() .FirstOrDefault(a => a.Attribute.Key == "SpiritualGift1" && a.EntityId == SelectedPerson.Id); // Redirect if they haven't taken the Assessment if (spiritualGift1AttributeValue == null) { Response.Redirect(shapePageReference.BuildUrl(), true); } else { var spiritualGift2AttributeValue = attributeValueService .Queryable() .FirstOrDefault(a => a.Attribute.Key == "SpiritualGift2" && a.EntityId == SelectedPerson.Id); var spiritualGift3AttributeValue = attributeValueService .Queryable() .FirstOrDefault(a => a.Attribute.Key == "SpiritualGift3" && a.EntityId == SelectedPerson.Id); var spiritualGift4AttributeValue = attributeValueService .Queryable() .FirstOrDefault(a => a.Attribute.Key == "SpiritualGift4" && a.EntityId == SelectedPerson.Id); var ability1AttributeValue = attributeValueService .Queryable().FirstOrDefault(a => a.Attribute.Key == "Ability1" && a.EntityId == SelectedPerson.Id); var ability2AttributeValue = attributeValueService .Queryable().FirstOrDefault(a => a.Attribute.Key == "Ability2" && a.EntityId == SelectedPerson.Id); var peopleAttributeValue = attributeValueService .Queryable() .FirstOrDefault(a => a.Attribute.Key == "SHAPEPeople" && a.EntityId == SelectedPerson.Id); var placesAttributeValue = attributeValueService .Queryable() .FirstOrDefault(a => a.Attribute.Key == "SHAPEPlaces" && a.EntityId == SelectedPerson.Id); var eventsAttributeValue = attributeValueService .Queryable() .FirstOrDefault(a => a.Attribute.Key == "SHAPEEvents" && a.EntityId == SelectedPerson.Id); var heartCategoriesAttributeValue = attributeValueService .Queryable() .FirstOrDefault(a => a.Attribute.Key == "HeartCategories" && a.EntityId == SelectedPerson.Id); var heartCausesAttributeValue = attributeValueService .Queryable() .FirstOrDefault(a => a.Attribute.Key == "HeartCauses" && a.EntityId == SelectedPerson.Id); var heartPassionAttributeValue = attributeValueService .Queryable() .FirstOrDefault(a => a.Attribute.Key == "HeartPassion" && a.EntityId == SelectedPerson.Id); if (spiritualGift1AttributeValue.Value != null) { spiritualGift1 = spiritualGift1AttributeValue.Value; } if (spiritualGift2AttributeValue.Value != null) { spiritualGift2 = spiritualGift2AttributeValue.Value; } if (spiritualGift3AttributeValue.Value != null) { spiritualGift3 = spiritualGift3AttributeValue.Value; } if (spiritualGift4AttributeValue.Value != null) { spiritualGift4 = spiritualGift4AttributeValue.Value; } if (heartCategoriesAttributeValue.Value != null) { heartCategories = heartCategoriesAttributeValue.Value; } if (heartCausesAttributeValue.Value != null) { heartCauses = heartCausesAttributeValue.Value; } if (heartPassionAttributeValue.Value != null) { heartPassion = heartPassionAttributeValue.Value; } if (ability1AttributeValue.Value != null) { ability1 = ability1AttributeValue.Value; } if (ability2AttributeValue.Value != null) { ability2 = ability2AttributeValue.Value; } if (peopleAttributeValue.Value != null) { people = peopleAttributeValue.Value; } if (placesAttributeValue.Value != null) { places = placesAttributeValue.Value; } if (eventsAttributeValue.Value != null) { events = eventsAttributeValue.Value; } string spiritualGift1Guid; string spiritualGift2Guid; string spiritualGift3Guid; string spiritualGift4Guid; string ability1Guid; string ability2Guid; // Check to see if there are already values saved as an ID. If so, convert them to GUID if (spiritualGift1.ToString().Length < 5) { if (spiritualGift1 != null) { SpiritualGift1 = Int32.Parse(spiritualGift1); } if (spiritualGift2 != null) { SpiritualGift2 = Int32.Parse(spiritualGift2); } if (spiritualGift3 != null) { SpiritualGift3 = Int32.Parse(spiritualGift3); } if (spiritualGift4 != null) { SpiritualGift4 = Int32.Parse(spiritualGift4); } if (ability1 != null) { Ability1 = Int32.Parse(ability1); } if (ability2 != null) { Ability2 = Int32.Parse(ability2); } var intsOfGifts = definedValueService.GetByIds(new List <int> { SpiritualGift1, SpiritualGift2, SpiritualGift3, SpiritualGift4, Ability1, Ability2 }); spiritualGift1Guid = intsOfGifts.ToList()[SpiritualGift1].Guid.ToString(); spiritualGift2Guid = intsOfGifts.ToList()[SpiritualGift2].Guid.ToString(); spiritualGift3Guid = intsOfGifts.ToList()[SpiritualGift3].Guid.ToString(); spiritualGift4Guid = intsOfGifts.ToList()[SpiritualGift4].Guid.ToString(); ability1Guid = intsOfGifts.ToList()[Ability1].Guid.ToString(); ability2Guid = intsOfGifts.ToList()[Ability2].Guid.ToString(); } else { spiritualGift1Guid = spiritualGift1; spiritualGift2Guid = spiritualGift2; spiritualGift3Guid = spiritualGift3; spiritualGift4Guid = spiritualGift4; ability1Guid = ability1; ability2Guid = ability2; } // Get all of the data about the assiciated gifts and ability categories var shapeGift1Object = definedValueService.GetListByGuids(new List <Guid> { new Guid(spiritualGift1Guid) }).FirstOrDefault(); var shapeGift2Object = definedValueService.GetListByGuids(new List <Guid> { new Guid(spiritualGift2Guid) }).FirstOrDefault(); var shapeGift3Object = definedValueService.GetListByGuids(new List <Guid> { new Guid(spiritualGift3Guid) }).FirstOrDefault(); var shapeGift4Object = definedValueService.GetListByGuids(new List <Guid> { new Guid(spiritualGift4Guid) }).FirstOrDefault(); var ability1Object = definedValueService.GetListByGuids(new List <Guid> { new Guid(ability1Guid) }).FirstOrDefault(); var ability2Object = definedValueService.GetListByGuids(new List <Guid> { new Guid(ability2Guid) }).FirstOrDefault(); shapeGift1Object.LoadAttributes(); shapeGift2Object.LoadAttributes(); shapeGift3Object.LoadAttributes(); shapeGift4Object.LoadAttributes(); ability1Object.LoadAttributes(); ability2Object.LoadAttributes(); // Get heart choices Values from Guids string heartCategoriesString = ""; if (!heartCategories.IsNullOrWhiteSpace()) { string[] heartCategoryArray = heartCategories.Split(','); foreach (string category in heartCategoryArray) { var definedValueObject = definedValueService.Queryable().FirstOrDefault(a => a.Guid == new Guid(category)); if (category.Equals(heartCategoryArray.Last())) { heartCategoriesString += definedValueObject.Value; } else { heartCategoriesString += definedValueObject.Value + ", "; } } } // Get Volunteer Opportunities string gift1AssociatedVolunteerOpportunities = shapeGift1Object.GetAttributeValue("AssociatedVolunteerOpportunities"); string gift2AssociatedVolunteerOpportunities = shapeGift2Object.GetAttributeValue("AssociatedVolunteerOpportunities"); string gift3AssociatedVolunteerOpportunities = shapeGift3Object.GetAttributeValue("AssociatedVolunteerOpportunities"); string gift4AssociatedVolunteerOpportunities = shapeGift4Object.GetAttributeValue("AssociatedVolunteerOpportunities"); string allAssociatedVolunteerOpportunities = gift1AssociatedVolunteerOpportunities + "," + gift2AssociatedVolunteerOpportunities + "," + gift3AssociatedVolunteerOpportunities + "," + gift4AssociatedVolunteerOpportunities; if (allAssociatedVolunteerOpportunities != ",,,") { List <int> associatedVolunteerOpportunitiesList = allAssociatedVolunteerOpportunities.Split(',').Select(t => int.Parse(t)).ToList(); Dictionary <int, int> VolunteerOpportunities = new Dictionary <int, int>(); var i = 0; var q = from x in associatedVolunteerOpportunitiesList group x by x into g let count = g.Count() orderby count descending select new { Value = g.Key, Count = count }; foreach (var x in q) { VolunteerOpportunities.Add(i, x.Value); i++; } ConnectionOpportunityService connectionOpportunityService = new ConnectionOpportunityService(rockContext); List <ConnectionOpportunity> connectionOpportunityList = new List <ConnectionOpportunity>(); foreach (KeyValuePair <int, int> entry in VolunteerOpportunities.Take(4)) { var connection = connectionOpportunityService.GetByIds(new List <int> { entry.Value }).FirstOrDefault(); // Only display connection if it is marked Active if (connection.IsActive == true) { connectionOpportunityList.Add(connection); } } rpVolunteerOpportunities.DataSource = connectionOpportunityList; rpVolunteerOpportunities.DataBind(); } //Get DISC Info DiscService.AssessmentResults savedScores = DiscService.LoadSavedAssessmentResults(SelectedPerson); if (!string.IsNullOrWhiteSpace(savedScores.PersonalityType)) { ShowResults(savedScores); DISCResults.Visible = true; NoDISCResults.Visible = false; } else { discPageReference.Parameters = new System.Collections.Generic.Dictionary <string, string>(); discPageReference.Parameters.Add("rckipid", SelectedPerson.UrlEncodedKey); Response.Redirect(discPageReference.BuildUrl(), true); } // Build the UI lbPersonName.Text = SelectedPerson.FullName; lbGift1Title.Text = shapeGift1Object.Value; lbGift1BodyHTML.Text = shapeGift1Object.GetAttributeValue("HTMLDescription"); lbGift2Title.Text = shapeGift2Object.Value; lbGift2BodyHTML.Text = shapeGift2Object.GetAttributeValue("HTMLDescription"); lbGift3Title.Text = shapeGift3Object.Value; lbGift3BodyHTML.Text = shapeGift3Object.GetAttributeValue("HTMLDescription"); lbGift4Title.Text = shapeGift4Object.Value; lbGift4BodyHTML.Text = shapeGift4Object.GetAttributeValue("HTMLDescription"); lbAbility1Title.Text = ability1Object.Value; lbAbility1BodyHTML.Text = ability1Object.GetAttributeValue("HTMLDescription"); lbAbility2Title.Text = ability2Object.Value; lbAbility2BodyHTML.Text = ability2Object.GetAttributeValue("HTMLDescription"); lbPeople.Text = people; lbPlaces.Text = places; lbEvents.Text = events; lbHeartCategories.Text = heartCategoriesString; lbHeartCauses.Text = heartCauses; lbHeartPassion.Text = heartPassion; if (spiritualGift1AttributeValue.ModifiedDateTime != null) { lbAssessmentDate.Text = spiritualGift1AttributeValue.ModifiedDateTime.Value.ToShortDateString(); } else { lbAssessmentDate.Text = spiritualGift1AttributeValue.CreatedDateTime.Value.ToShortDateString(); } // Show create account panel if this person doesn't have an account if (SelectedPerson.Users.Count == 0) { pnlAccount.Visible = true; } } }
/// <summary> /// Shows the assessment. /// A null value for _targetPerson is already handled in OnInit() so this method assumes there is a value /// </summary> private void ShowAssessment() { /* * 2020-01-09 - ETD * This block will either show the assessment results of the most recent assessment test or give the assessment test. * The following use cases are considered: * 1. If the assessment ID "0" was provided then create a new test for the current user. This covers user directed retakes. * 2. If the assessment ID was provided and is not "0" * Note: The assessment results are stored on the person's attributes and are overwritten if the assessment is retaken. So past Assessments will not be loaded by this block. * The test data is saved in the assessment table but would need to be recomputed, which may be a future feature. * a. The assessment ID is ignored and the current person is used. * b. If the assessment exists for the current person and is completed then show the results * c. If the assessment exists for the current person and is pending then show the questions. * d. If the assessment does not exist for the current person then nothing loads. * 3. If the assessment ID was not provided and the PersonKey was provided * a. If there is only one test of the type * 1. If the assessment is completed show the results * 2. If the assessment is pending and the current person is the one assigned the test then show the questions. * 3. If the assessment is pending and the current person is not the one assigned then show a message that the test has not been completed. * b. If more than one of type * 1. If the latest requested assessment is completed show the results. * 2. If the latest requested assessment is pending and the current person is the one assigned then show the questions. * 3. If the latest requested assessment is pending and the current person is not the one assigned the show the results of the last completed test. * 4. If the latest requested assessment is pending and the current person is not the one assigned and there are no previous completed assessments then show a message that the test has not been completed. * 4. If an assessment ID or PersonKey were not provided or are not valid then show an error message */ var rockContext = new RockContext(); var assessmentType = new AssessmentTypeService(rockContext).Get(Rock.SystemGuid.AssessmentType.DISC.AsGuid()); Assessment assessment = null; Assessment previouslyCompletedAssessment = null; // A "0" value indicates that the block should create a new assessment instead of looking for an existing one, so keep assessment null. e.g. a user directed re-take if (_assessmentId != 0) { var assessments = new AssessmentService(rockContext) .Queryable() .AsNoTracking() .Where(a => a.PersonAlias != null && a.PersonAlias.PersonId == _targetPerson.Id && a.AssessmentTypeId == assessmentType.Id) .OrderByDescending(a => a.CompletedDateTime ?? a.RequestedDateTime) .ToList(); if (_assessmentId == null && assessments.Count == 0) { // For this to happen the user has to have never taken the assessment, the user isn't using a link with the assessment ID, AND they are arriving at the block directly rather than through the assessment list block. // So treat this as a user directed take/retake. _assessmentId = 0; } else { if (assessments.Count > 0) { // If there are any results then pick the first one. If the assesement ID was specified then the query will only return one result assessment = assessments[0]; } if (assessments.Count > 1) { // If there are more than one result then we need to pick the right one (see developer note) // If the most recent assessment is "Completed" then it is already set as the assessment and we can move on. Otherwise check if there are previoulsy completed assessments. if (assessment.Status == AssessmentRequestStatus.Pending) { // If the most recent assessment is pending then check for a prior completed one previouslyCompletedAssessment = assessments.Where(a => a.Status == AssessmentRequestStatus.Complete).FirstOrDefault(); } } } } if (assessment == null) { // If assessment is null and _assessmentId = 0 this is user directed. If the type does not require a request then show instructions if (_assessmentId == 0 && !assessmentType.RequiresRequest) { hfAssessmentId.SetValue(0); ShowInstructions(); } else { // If assessment is null and _assessmentId != 0 or is 0 but the type does require a request then show requires request error HidePanelsAndShowError("Sorry, this test requires a request from someone before it can be taken."); } return; } hfAssessmentId.SetValue(assessment.Id); // If assessment is completed show the results if (assessment.Status == AssessmentRequestStatus.Complete) { DiscService.AssessmentResults savedScores = DiscService.LoadSavedAssessmentResults(_targetPerson); ShowResult(savedScores, assessment); return; } if (assessment.Status == AssessmentRequestStatus.Pending) { if (_targetPerson.Id != CurrentPerson.Id) { // If assessment is pending and the current person is not the one assigned the show previouslyCompletedAssessment results if (previouslyCompletedAssessment != null) { DiscService.AssessmentResults savedScores = DiscService.LoadSavedAssessmentResults(_targetPerson); ShowResult(savedScores, previouslyCompletedAssessment, true); return; } // If assessment is pending and the current person is not the one assigned and previouslyCompletedAssessment is null show a message that the test has not been completed. HidePanelsAndShowError(string.Format("{0} has not yet taken the {1} Assessment.", _targetPerson.FullName, assessmentType.Title)); } else { // If assessment is pending and the current person is the one assigned then show the questions ShowInstructions(); } return; } // This should never happen, if the block gets to this point then something is not right HidePanelsAndShowError("Unable to load assessment"); }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnLoad(EventArgs e) { if (!Page.IsPostBack) { var rockContext = new RockContext(); var assessmentType = new AssessmentTypeService(rockContext).Get(Rock.SystemGuid.AssessmentType.DISC.AsGuid()); Assessment assessment = null; if (_targetPerson != null) { var primaryAliasId = _targetPerson.PrimaryAliasId; if (_assessmentId == 0) { // This indicates that the block should create a new assessment instead of looking for an existing one. e.g. a user directed re-take assessment = null; } else { // Look for an existing pending or completed assessment. assessment = new AssessmentService(rockContext) .Queryable() .Where(a => (_assessmentId.HasValue && a.Id == _assessmentId) || (a.PersonAliasId == primaryAliasId && a.AssessmentTypeId == assessmentType.Id)) .OrderByDescending(a => a.CreatedDateTime) .FirstOrDefault(); } if (assessment != null) { hfAssessmentId.SetValue(assessment.Id); } else { hfAssessmentId.SetValue(0); } if (assessment != null && assessment.Status == AssessmentRequestStatus.Complete) { DiscService.AssessmentResults savedScores = DiscService.LoadSavedAssessmentResults(_targetPerson); ShowResult(savedScores, assessment); } else if ((assessment == null && !assessmentType.RequiresRequest) || (assessment != null && assessment.Status == AssessmentRequestStatus.Pending)) { if (_targetPerson.Id != CurrentPerson.Id) { // If the current person is not the target person and there are no results to show then show a not taken message. HidePanelsAndShowError(string.Format("{0} does not have results for the EQ Inventory Assessment.", _targetPerson.FullName)); } else { ShowInstructions(); } } else { HidePanelsAndShowError("Sorry, this test requires a request from someone before it can be taken."); } } } else { // Hide notification panels on every postback nbError.Visible = false; } }
/// <summary> /// Handles the Click event of the btnNext control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnNext_Click(object sender, EventArgs e) { int pageNumber = hfPageNo.ValueAsInt() + 1; GetResponse(); LinkButton btn = ( LinkButton )sender; string commandArgument = btn.CommandArgument; var totalQuestion = pageNumber * QuestionCount; if ((_assessmentResponses.Count > totalQuestion && !_assessmentResponses.All(a => !string.IsNullOrEmpty(a.MostScore) && !string.IsNullOrEmpty(a.LeastScore))) || "Next".Equals(commandArgument)) { BindRepeater(pageNumber); } else { try { var moreD = _assessmentResponses.Where(a => a.MostScore == "D").Count(); var moreI = _assessmentResponses.Where(a => a.MostScore == "I").Count(); var moreS = _assessmentResponses.Where(a => a.MostScore == "S").Count(); var moreC = _assessmentResponses.Where(a => a.MostScore == "C").Count(); var lessD = _assessmentResponses.Where(a => a.LeastScore == "D").Count(); var lessI = _assessmentResponses.Where(a => a.LeastScore == "I").Count(); var lessS = _assessmentResponses.Where(a => a.LeastScore == "S").Count(); var lessC = _assessmentResponses.Where(a => a.LeastScore == "C").Count(); // Score the responses and return the results DiscService.AssessmentResults results = DiscService.Score(moreD, moreI, moreS, moreC, lessD, lessI, lessS, lessC); // Now save the results for this person DiscService.SaveAssessmentResults( _targetPerson, results.AdaptiveBehaviorD.ToString(), results.AdaptiveBehaviorI.ToString(), results.AdaptiveBehaviorS.ToString(), results.AdaptiveBehaviorC.ToString(), results.NaturalBehaviorD.ToString(), results.NaturalBehaviorI.ToString(), results.NaturalBehaviorS.ToString(), results.NaturalBehaviorC.ToString(), results.PersonalityType); var assessmentData = _assessmentResponses.ToDictionary(a => a.QuestionNumber, b => new { Most = new string[2] { b.MostScore, b.Questions[b.MostScore] }, Least = new string[2] { b.LeastScore, b.Questions[b.LeastScore] } }); var rockContext = new RockContext(); var assessmentService = new AssessmentService(rockContext); Assessment assessment = null; if (hfAssessmentId.ValueAsInt() != 0) { assessment = assessmentService.Get(int.Parse(hfAssessmentId.Value)); } if (assessment == null) { var assessmentType = new AssessmentTypeService(rockContext).Get(Rock.SystemGuid.AssessmentType.DISC.AsGuid()); assessment = new Assessment() { AssessmentTypeId = assessmentType.Id, PersonAliasId = _targetPerson.PrimaryAliasId.Value }; assessmentService.Add(assessment); } assessment.Status = AssessmentRequestStatus.Complete; assessment.CompletedDateTime = RockDateTime.Now; assessment.AssessmentResultData = new { Result = assessmentData, TimeToTake = RockDateTime.Now.Subtract(StartDateTime).TotalSeconds }.ToJson(); rockContext.SaveChanges(); ShowResult(results, assessment); } catch (Exception ex) { nbError.Visible = true; nbError.Title = "We're Sorry..."; nbError.Text = "Something went wrong while trying to save your test results."; LogException(ex); } } }
/// <summary> /// Scores test, and displays results. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnScoreTest_Click(object sender, EventArgs e) { try { int moreN = 0; int moreD = 0; int moreI = 0; int moreS = 0; int moreC = 0; int lessN = 0; int lessD = 0; int lessI = 0; int lessS = 0; int lessC = 0; foreach (RepeaterItem rItem in rQuestions.Items) { RockRadioButtonList rblMore1 = rItem.FindControl("rblMore1") as RockRadioButtonList; RockRadioButtonList rblMore2 = rItem.FindControl("rblMore2") as RockRadioButtonList; RockRadioButtonList rblMore3 = rItem.FindControl("rblMore3") as RockRadioButtonList; RockRadioButtonList rblMore4 = rItem.FindControl("rblMore4") as RockRadioButtonList; RockRadioButtonList rblLess1 = rItem.FindControl("rblLess1") as RockRadioButtonList; RockRadioButtonList rblLess2 = rItem.FindControl("rblLess2") as RockRadioButtonList; RockRadioButtonList rblLess3 = rItem.FindControl("rblLess3") as RockRadioButtonList; RockRadioButtonList rblLess4 = rItem.FindControl("rblLess4") as RockRadioButtonList; string selectedMoreValue = GetSelectedValue(rblMore1, rblMore2, rblMore3, rblMore4); string selectedLessValue = GetSelectedValue(rblLess1, rblLess2, rblLess3, rblLess4); switch (selectedMoreValue) { case "N": moreN++; break; case "D": moreD++; break; case "I": moreI++; break; case "S": moreS++; break; case "C": moreC++; break; default: break; } switch (selectedLessValue) { case "N": lessN++; break; case "D": lessD++; break; case "I": lessI++; break; case "S": lessS++; break; case "C": lessC++; break; default: break; } } // Score the responses and return the results DiscService.AssessmentResults results = DiscService.Score(moreN, moreD, moreI, moreS, moreC, lessN, lessD, lessI, lessS, lessC); // Now save the results for this person DiscService.SaveAssessmentResults( _targetPerson, results.AdaptiveBehaviorD.ToString(), results.AdaptiveBehaviorI.ToString(), results.AdaptiveBehaviorS.ToString(), results.AdaptiveBehaviorC.ToString(), results.NaturalBehaviorD.ToString(), results.NaturalBehaviorI.ToString(), results.NaturalBehaviorS.ToString(), results.NaturalBehaviorC.ToString(), results.PersonalityType ); // Show the results ShowResults(results); } catch (Exception ex) { nbError.Visible = true; nbError.Title = "We're Sorry..."; nbError.Text = "Something went wrong while trying to save your test results."; LogException(ex); } }