public function execute() { global $wgUser; if ( !$wgUser->isAllowed( 'surveyadmin' ) || $wgUser->isBlocked() ) { $this->dieUsageMsg( array( 'badaccess-groups' ) ); } $params = $this->extractRequestParams(); foreach ( $params['questions'] as &$question ) { $question = SurveyQuestion::newFromUrlData( $question ); } $survey = new Survey( Survey::getValidFields( $params, $params['id'] ) ); $this->getResult()->addValue( null, 'success', $survey->writeToDB() ); $this->getResult()->addValue( 'survey', 'id', $survey->getId() ); $this->getResult()->addValue( 'survey', 'name', $survey->getField( 'name' ) ); }
/** * @param $ans * @param SurveyQuestion $question */ function __construct($ans, SurveyQuestion $question) { switch ($question->getType()->getValue()) { case QuestionType::YesNo: $this->type = ChartFormats::Pie(); $this->yuiType = "pie"; break; case QuestionType::StarRating: $this->type = ChartFormats::Bar(); $this->yuiType = "bar"; break; case QuestionType::Text: $this->type = ChartFormats::TagCloud(); $this->yuiType = null; break; } $this->data = ReportChartFormatter::getChartData($ans, $this->type); $this->question = $question; }
public function execute() { global $wgUser; if ( !$wgUser->isAllowed( 'surveyadmin' ) || $wgUser->isBlocked() ) { $this->dieUsageMsg( array( 'badaccess-groups' ) ); } $params = $this->extractRequestParams(); foreach ( $params['questions'] as &$question ) { $question = SurveyQuestion::newFromUrlData( $question ); } try { $survey = new Survey( Survey::getValidFields( $params ) ); $success = $survey->writeToDB(); } catch ( DBQueryError $ex ) { if ( $ex->errno == 1062 ) { $this->dieUsage( wfMsgExt( 'survey-err-duplicate-name', 'parsemag', $params['name'] ), 'duplicate-survey-name' ); } else { throw $ex; } } $this->getResult()->addValue( null, 'success', $success ); $this->getResult()->addValue( 'survey', 'id', $survey->getId() ); $this->getResult()->addValue( 'survey', 'name', $survey->getField( 'name' ) ); }
/** * Import data from DB */ protected function importData() { global $ilAccess, $lng; include_once "Modules/Survey/classes/class.ilObjSurvey.php"; $table_data = array(); foreach ($this->question->getCopyIds(true) as $survey_obj_id => $questions) { $survey_id = new ilObjSurvey($survey_obj_id, false); $survey_id->loadFromDB(); $survey_id = $survey_id->getSurveyId(); $ref_ids = ilObject::_getAllReferences($survey_obj_id); $message = ""; // check permissions for "parent" survey $can_write = false; if (!ilObjSurvey::_hasDatasets($survey_id)) { foreach ($ref_ids as $ref_id) { if ($ilAccess->checkAccess("edit", "", $ref_id)) { $can_write = true; break; } } if (!$can_write) { $message = $lng->txt("survey_sync_insufficient_permissions"); } } else { $message = $lng->txt("survey_has_datasets_warning"); } $survey_title = ilObject::_lookupTitle($survey_obj_id); $survey_path = $this->buildPath($ref_ids); foreach ($questions as $question_id) { $title = SurveyQuestion::_getTitle($question_id); if (!$can_write) { $question_id = null; } $table_data[] = array("id" => $question_id, "title" => $title, "path" => $survey_path, "message" => $message); } } $this->setData($table_data); }
/** * Add new question to survey * * @param int $a_new_id */ public function insertNewQuestion($a_new_id) { global $rbacsystem, $ilDB, $lng; include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php"; if (!SurveyQuestion::_isComplete($a_new_id)) { ilUtil::sendFailure($lng->txt("survey_error_insert_incomplete_question")); } else { $a_new_id = $this->appendNewQuestionToSurvey($a_new_id); $this->object->loadQuestionsFromDb(); $pos = $_REQUEST["pgov_pos"]; // a[fter]/b[efore] on same page if (substr($pos, -1) != "c") { // block handling $current = $this->object->getSurveyPages(); $current = $current[$this->current_page - 1]; if (sizeof($current) == 1) { // as questions are moved to first block question // always use existing as first // the new question is moved later on (see below) $this->object->createQuestionblock($this->getAutoBlockTitle(), true, false, array((int) $pos, $a_new_id)); } else { $block_id = array_pop($current); $block_id = $block_id["questionblock_id"]; $this->object->addQuestionToBlock($a_new_id, $block_id); } } else { // after given question if ((int) $pos) { $pos = (int) $pos . "a"; $this->current_page++; } else { $first = $this->object->getSurveyPages(); $first = $first[0]; $first = array_shift($first); $pos = $first["question_id"] . "b"; $this->current_page = 1; } } // move to target position $this->object->moveQuestions(array($a_new_id), (int) $pos, substr($pos, -1) == "a" ? 1 : 0); } }
/** * Adds the entries for the title row of the user specific results * * @param array $a_array An array which is used to append the title row entries * @access public */ function addUserSpecificResultsExportTitles(&$a_array, $a_use_label = false, $a_substitute = true) { parent::addUserSpecificResultsExportTitles($a_array, $a_use_label, $a_substitute); for ($index = 0; $index < $this->categories->getCategoryCount(); $index++) { $category = $this->categories->getCategory($index); $title = $category->title; if (!$a_use_label || $a_substitute) { array_push($a_array, $title); } else { array_push($a_array, ""); } // optionally add headers for text answers if ($category->other) { if (!$a_use_label || $a_substitute) { array_push($a_array, $title . " - " . $this->lng->txt("other")); } else { array_push($a_array, ""); } } } }
/** * Export the user specific results for the survey * * Export the user specific results for the survey * * @access private */ function exportUserSpecificResults($export_format, $export_label, $finished_ids) { global $ilLog; // #13620 ilDatePresentation::setUseRelativeDates(false); $csvfile = array(); $csvrow = array(); $csvrow2 = array(); $questions = array(); $questions =& $this->object->getSurveyQuestions(true); array_push($csvrow, $this->lng->txt("lastname")); // #12756 array_push($csvrow, $this->lng->txt("firstname")); array_push($csvrow, $this->lng->txt("login")); array_push($csvrow, $this->lng->txt('workingtime')); // #13622 array_push($csvrow, $this->lng->txt('survey_results_finished')); array_push($csvrow2, ""); array_push($csvrow2, ""); array_push($csvrow2, ""); array_push($csvrow2, ""); array_push($csvrow2, ""); if ($this->object->canExportSurveyCode()) { array_push($csvrow, $this->lng->txt("codes")); array_push($csvrow2, ""); } /* #8211 if ($this->object->getAnonymize() == ilObjSurvey::ANONYMIZE_OFF) { array_push($csvrow, $this->lng->txt("gender")); } */ $cellcounter = 1; foreach ($questions as $question_id => $question_data) { include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php"; $question = SurveyQuestion::_instanciateQuestion($question_data["question_id"]); switch ($export_label) { case "label_only": $question->addUserSpecificResultsExportTitles($csvrow, true); break; case "title_only": $question->addUserSpecificResultsExportTitles($csvrow, false); break; default: $question->addUserSpecificResultsExportTitles($csvrow, false); $question->addUserSpecificResultsExportTitles($csvrow2, true, false); break; } $questions[$question_data["question_id"]] = $question; } array_push($csvfile, $csvrow); if (sizeof($csvrow2) && implode("", $csvrow2)) { array_push($csvfile, $csvrow2); } if (!$finished_ids) { $participants =& $this->object->getSurveyFinishedIds(); } else { $participants = $finished_ids; } $finished_data = array(); foreach ($this->object->getSurveyParticipants($participants) as $item) { $finished_data[$item["active_id"]] = $item; } foreach ($participants as $user_id) { if ($user_id < 1) { continue; } $resultset =& $this->object->getEvaluationByUser($questions, $user_id); $csvrow = array(); // #12756 array_push($csvrow, trim($resultset["lastname"]) ? $resultset["lastname"] : $resultset["name"]); // anonymous array_push($csvrow, $resultset["firstname"]); array_push($csvrow, $resultset["login"]); // #10579 if ($this->object->canExportSurveyCode()) { array_push($csvrow, $user_id); } /* #8211 if ($this->object->getAnonymize() == ilObjSurvey::ANONYMIZE_OFF) { array_push($csvrow, $resultset["gender"]); } */ $wt = $this->object->getWorkingtimeForParticipant($user_id); array_push($csvrow, $wt); $finished = $finished_data[$user_id]; if ((bool) $finished["finished"]) { array_push($csvrow, ilDatePresentation::formatDate(new ilDateTime($finished["finished_tstamp"], IL_CAL_UNIX))); } else { array_push($csvrow, "-"); } foreach ($questions as $question_id => $question) { $question->addUserSpecificResultsData($csvrow, $resultset); } array_push($csvfile, $csvrow); } // #11179 $surveyname = $this->object->getTitle() . " " . $this->lng->txt("svy_eval_user") . " " . date("Y-m-d"); $surveyname = preg_replace("/\\s/", "_", trim($surveyname)); $surveyname = ilUtil::getASCIIFilename($surveyname); switch ($export_format) { case self::TYPE_XLS: include_once "./Services/Excel/classes/class.ilExcelWriterAdapter.php"; $excelfile = ilUtil::ilTempnam(); $adapter = new ilExcelWriterAdapter($excelfile, FALSE); $workbook = $adapter->getWorkbook(); $workbook->setVersion(8); // Use Excel97/2000 Format // Creating a worksheet $format_bold =& $workbook->addFormat(); $format_bold->setBold(); $format_percent =& $workbook->addFormat(); $format_percent->setNumFormat("0.00%"); $format_datetime =& $workbook->addFormat(); $format_datetime->setNumFormat("DD/MM/YYYY hh:mm:ss"); $format_title =& $workbook->addFormat(); $format_title->setBold(); $format_title->setColor('black'); $format_title->setPattern(1); $format_title->setFgColor('silver'); $format_title_plain =& $workbook->addFormat(); $format_title_plain->setColor('black'); $format_title_plain->setPattern(1); $format_title_plain->setFgColor('silver'); // Creating a worksheet $pages = floor(count($csvfile[0]) / 250) + 1; $worksheets = array(); for ($i = 0; $i < $pages; $i++) { $worksheets[$i] =& $workbook->addWorksheet(); } $row = 0; include_once "./Services/Excel/classes/class.ilExcelUtils.php"; $contentstartrow = 0; foreach ($csvfile as $csvrow) { $col = 0; if ($row == 0) { $worksheet = 0; $mainworksheet =& $worksheets[$worksheet]; foreach ($csvrow as $text) { if (is_array($text)) { $textcount = 0; foreach ($text as $string) { $mainworksheet->writeString($row + $textcount, $col, ilExcelUtils::_convert_text($string, $_POST["export_format"]), $format_title); $textcount++; $contentstartrow = max($contentstartrow, $textcount); } $col++; } else { $mainworksheet->writeString($row, $col++, ilExcelUtils::_convert_text($text, $_POST["export_format"]), $format_title); } if ($col % 251 == 0) { $worksheet++; $col = 1; $mainworksheet =& $worksheets[$worksheet]; $mainworksheet->writeString($row, 0, ilExcelUtils::_convert_text($csvrow[0], $_POST["export_format"]), $format_title); } } $row = $contentstartrow; } else { $worksheet = 0; $mainworksheet =& $worksheets[$worksheet]; foreach ($csvrow as $text) { if (is_numeric($text)) { $mainworksheet->writeNumber($row, $col++, $text); } else { $mainworksheet->writeString($row, $col++, ilExcelUtils::_convert_text($text, $_POST["export_format"])); } if ($col % 251 == 0) { $worksheet++; $col = 1; $mainworksheet =& $worksheets[$worksheet]; $mainworksheet->writeString($row, 0, ilExcelUtils::_convert_text($csvrow[0], $_POST["export_format"])); } } } $row++; } $workbook->close(); ilUtil::deliverFile($excelfile, "{$surveyname}.xls", "application/vnd.ms-excel"); exit; break; case self::TYPE_SPSS: $csv = ""; $separator = ";"; foreach ($csvfile as $idx => $csvrow) { $csvrow =& str_replace("\n", " ", $this->object->processCSVRow($csvrow, TRUE, $separator)); $csv .= join($csvrow, $separator) . "\n"; } include_once "./Services/Utilities/classes/class.ilUtil.php"; ilUtil::deliverData($csv, "{$surveyname}.csv"); exit; break; } }
function addLocatorItems() { global $ilLocator; switch ($this->ctrl->getCmd()) { case "next": case "previous": case "start": case "resume": case "redirectQuestion": $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "infoScreen"), "", $_GET["ref_id"]); break; case "evaluation": case "checkEvaluationAccess": case "evaluationdetails": case "evaluationuser": $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluation"), "", $_GET["ref_id"]); break; case "create": case "save": case "cancel": case "importFile": case "cloneAll": break; case "infoScreen": $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "infoScreen"), "", $_GET["ref_id"]); break; default: $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ""), "", $_GET["ref_id"]); // this has to be done here because ilSurveyEditorGUI is called after finalizing the locator if ((int) $_GET["q_id"] && !(int) $_REQUEST["new_for_survey"]) { // not on create // see ilObjSurveyQuestionPool::addLocatorItems $q_id = (int) $_GET["q_id"]; include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php"; $q_type = SurveyQuestion::_getQuestionType($q_id) . "GUI"; $this->ctrl->setParameterByClass($q_type, "q_id", $q_id); $ilLocator->addItem(SurveyQuestion::_getTitle($q_id), $this->ctrl->getLinkTargetByClass(array("ilSurveyEditorGUI", $q_type), "editQuestion")); } break; } }
$ansObj->Save(); } } // Identify un-answered questions, both required and not. // We poll the DB because un-checked checkboxes aren't submitted // at all, so we have to manually check if they're missing. // If the question requires an answer, enforce that requirement. // If the question is not required, give un-filled answers an empty value. // (This whole block isn't very efficient way to do this, but for // the low traffic volume we get, it should be fine.... for now... // especially considering how quickly this had to be ready!) $q = "SELECT ID FROM SurveyQuestions WHERE WardID={$MEMBER->WardID} AND Visible='1'"; $r = DB::Run($q); while ($row = mysql_fetch_array($r)) { // Find out about the question and the user's answer to it, if any $reqQu = SurveyQuestion::Load($row['ID']); $userAns = isset($answers[$reqQu->ID()]) ? $answers[$reqQu->ID()] : null; if (is_string($userAns)) { $userAns = trim($userAns); } // If it IS required, and not answered, time to throw. if ($reqQu->Required && (!$userAns || !is_array($userAns) && strlen(trim($userAns)) == 0 || $userAns == ' ')) { Response::Send(400, "Please answer the required question:<br><br>\"" . $reqQu->Question . "\""); } // If NOT required, set to empty value if not filled out if (!$reqQu->Required && (!$userAns || !is_array($userAns) && strlen(trim($userAns)) == 0 || $userAns == ' ')) { // First we have to get it from the DB. $ansObj = $reqQu->Answers($memID); // TODO: FIX THIS: // I added this if statement because this block was causing errors // in the error log (a lot of them):
/** * Clone object * * @access public * @param int ref_id of target container * @param int copy id * @return object new svy object */ public function cloneObject($a_target_id, $a_copy_id = 0) { global $ilDB; $this->loadFromDb(); // Copy settings $newObj = parent::cloneObject($a_target_id, $a_copy_id); $this->cloneMetaData($newObj); $newObj->updateMetaData(); $newObj->setAuthor($this->getAuthor()); $newObj->setIntroduction($this->getIntroduction()); $newObj->setOutro($this->getOutro()); $newObj->setStatus($this->getStatus()); $newObj->setEvaluationAccess($this->getEvaluationAccess()); $newObj->setStartDate($this->getStartDate()); $newObj->setEndDate($this->getEndDate()); $newObj->setInvitation($this->getInvitation()); $newObj->setInvitationMode($this->getInvitationMode()); $newObj->setAnonymize($this->getAnonymize()); $newObj->setShowQuestionTitles($this->getShowQuestionTitles()); $newObj->setTemplate($this->getTemplate()); // :;TODO: 360° ?! // reminder/notification $newObj->setReminderStatus($this->getReminderStatus()); $newObj->setReminderStart($this->getReminderStart()); $newObj->setReminderEnd($this->getReminderEnd()); $newObj->setReminderFrequency($this->getReminderFrequency()); $newObj->setReminderTarget($this->getReminderTarget()); // reminder_last_sent must not be copied! $newObj->setTutorNotificationStatus($this->getTutorNotificationStatus()); $newObj->setTutorNotificationRecipients($this->getTutorNotificationRecipients()); $newObj->setTutorNotificationTarget($this->getTutorNotificationTarget()); $question_pointer = array(); // clone the questions $mapping = array(); include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php"; foreach ($this->questions as $key => $question_id) { $question = ilObjSurvey::_instanciateQuestion($question_id); if ($question) { $question->id = -1; $original_id = SurveyQuestion::_getOriginalId($question_id); $question->saveToDb($original_id); $newObj->questions[$key] = $question->getId(); $question_pointer[$question_id] = $question->getId(); $mapping[$question_id] = $question->getId(); } } $newObj->saveToDb(); $newObj->cloneTextblocks($mapping); // clone the questionblocks $questionblocks = array(); $questionblock_questions = array(); $result = $ilDB->queryF("SELECT * FROM svy_qblk_qst WHERE survey_fi = %s", array('integer'), array($this->getSurveyId())); if ($result->numRows() > 0) { while ($row = $ilDB->fetchAssoc($result)) { array_push($questionblock_questions, $row); $questionblocks[$row["questionblock_fi"]] = $row["questionblock_fi"]; } } // create new questionblocks foreach ($questionblocks as $key => $value) { $questionblock = ilObjSurvey::_getQuestionblock($key); $questionblock_id = ilObjSurvey::_addQuestionblock($questionblock["title"], $questionblock["owner_fi"]); $questionblocks[$key] = $questionblock_id; } // create new questionblock questions foreach ($questionblock_questions as $key => $value) { if ($questionblocks[$value["questionblock_fi"]] && $question_pointer[$value["question_fi"]]) { $next_id = $ilDB->nextId('svy_qblk_qst'); $affectedRows = $ilDB->manipulateF("INSERT INTO svy_qblk_qst (qblk_qst_id, survey_fi, questionblock_fi, question_fi) " . "VALUES (%s, %s, %s, %s)", array('integer', 'integer', 'integer', 'integer'), array($next_id, $newObj->getSurveyId(), $questionblocks[$value["questionblock_fi"]], $question_pointer[$value["question_fi"]])); } } // clone the constraints $constraints = ilObjSurvey::_getConstraints($this->getSurveyId()); $newConstraints = array(); foreach ($constraints as $key => $constraint) { if ($question_pointer[$constraint["for_question"]] && $question_pointer[$constraint["question"]]) { if (!array_key_exists($constraint['id'], $newConstraints)) { $constraint_id = $newObj->addConstraint($question_pointer[$constraint["question"]], $constraint["relation_id"], $constraint["value"], $constraint['conjunction']); $newConstraints[$constraint['id']] = $constraint_id; } $newObj->addConstraintToQuestion($question_pointer[$constraint["for_question"]], $newConstraints[$constraint['id']]); } } // clone the obligatory states $result = $ilDB->queryF("SELECT * FROM svy_qst_oblig WHERE survey_fi = %s", array('integer'), array($this->getSurveyId())); if ($result->numRows() > 0) { while ($row = $ilDB->fetchAssoc($result)) { if ($question_pointer[$row["question_fi"]]) { $next_id = $ilDB->nextId('svy_qst_oblig'); $affectedRows = $ilDB->manipulateF("INSERT INTO svy_qst_oblig (question_obligatory_id, survey_fi, question_fi, " . "obligatory, tstamp) VALUES (%s, %s, %s, %s, %s)", array('integer', 'integer', 'integer', 'text', 'integer'), array($next_id, $newObj->getSurveyId(), $question_pointer[$row["question_fi"]], $row["obligatory"], time())); } } } return $newObj; }
public function questions($reload = false) { if ($reload or !$this->questions_cache) { $id = mysql_real_escape_string($this->id); $this->questions_cache = SurveyQuestion::find_all("surveys.id = '{$id}'", "survey_questions.position ASC"); } return $this->questions_cache; }
/** * Get's the repository object ID of a parent object, if possible */ function getParentObjectIdForUsage($a_usage, $a_include_all_access_obj_ids = false) { if (is_int(strpos($a_usage["type"], ":"))) { $us_arr = explode(":", $a_usage["type"]); $type = $us_arr[1]; $cont_type = $us_arr[0]; } else { $type = $a_usage["type"]; } $id = $a_usage["id"]; $obj_id = false; switch ($type) { case "html": // "old" category pages if ($cont_type == "cat") { $obj_id = $id; } // Test InfoScreen Text if ($cont_type == "tst" || $cont_type == "svy") { $obj_id = $id; //var_dump($qinfo); } // Question Pool *Question* Text (Test) if ($cont_type == "qpl") { include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php"; $qinfo = assQuestion::_getQuestionInfo($id); if ($qinfo["original_id"] > 0) { include_once "./Modules/Test/classes/class.ilObjTest.php"; $obj_id = ilObjTest::_lookupTestObjIdForQuestionId($id); // usage in test } else { $obj_id = $qinfo["obj_fi"]; // usage in pool } } // Question Pool *Question* Text (Survey) if ($cont_type == "spl") { include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php"; $quest = SurveyQuestion::_instanciateQuestion($id); if ($quest) { if ($quest->getOriginalId() > 0) { $obj_id = $quest->getSurveyId(); } else { $obj_id = $quest->getObjId(); // usage in pool } unset($quest); } } // Forum if ($cont_type == "frm") { $post_pk = $a_usage['id']; include_once 'Modules/Forum/classes/class.ilForumPost.php'; include_once 'Modules/Forum/classes/class.ilForum.php'; $oPost = new ilForumPost($post_pk); $frm_pk = $oPost->getForumId(); $obj_id = ilForum::_lookupObjIdForForumId($frm_pk); } if ($cont_type == 'frm~') { $obj_id = $a_usage['id']; } if ($cont_type == "dcl") { $obj_id = $id; } break; case "pg": // Question Pool Question Pages if ($cont_type == "qpl") { include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php"; $qinfo = assQuestion::_getQuestionInfo($id); if ($qinfo["original_id"] > 0) { include_once "./Modules/Test/classes/class.ilObjTest.php"; $obj_id = ilObjTest::_lookupTestObjIdForQuestionId($id); // usage in test } else { $obj_id = $qinfo["obj_fi"]; // usage in pool } } // learning modules if ($cont_type == "lm" || $cont_type == "dbk") { include_once "./Modules/LearningModule/classes/class.ilLMObject.php"; $obj_id = ilLMObject::_lookupContObjID($id); } // glossary definition if ($cont_type == "gdf") { include_once "./Modules/Glossary/classes/class.ilGlossaryDefinition.php"; include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php"; $term_id = ilGlossaryDefinition::_lookupTermId($id); $obj_id = ilGlossaryTerm::_lookGlossaryID($term_id); } // wiki page if ($cont_type == 'wpg') { include_once 'Modules/Wiki/classes/class.ilWikiPage.php'; $obj_id = ilWikiPage::lookupObjIdByPage($id); } // sahs page if ($cont_type == 'sahs') { // can this implementation be used for other content types, too? include_once './Services/COPage/classes/class.ilPageObject.php'; $obj_id = ilPageObject::lookupParentId($id, 'sahs'); } // repository pages if (in_array($cont_type, array("crs", "grp", "cat", "fold", "root"))) { $obj_id = $id; } if ($cont_type == 'prtf') { include_once "Services/Portfolio/classes/class.ilPortfolioPage.php"; $obj_id = ilPortfolioPage::findPortfolioForPage($id); } if ($cont_type == 'blp') { include_once './Services/COPage/classes/class.ilPageObject.php'; $obj_id = ilPageObject::lookupParentId($id, 'blp'); } break; // Media Pool // Media Pool case "mep": $obj_id = $id; break; // News Context Object (e.g. MediaCast) // News Context Object (e.g. MediaCast) case "news": include_once "./Services/News/classes/class.ilNewsItem.php"; $obj_id = ilNewsItem::_lookupContextObjId($id); break; } return $obj_id; }
public function toArray() { $rArr = parent::toArray(); $rArr['choices'] = $this->choices; return $rArr; }
/** * Delete constraint confirmation */ public function confirmDeleteConstraintsObject() { $id = (int) $_REQUEST["precondition"]; if (!$this->validateConstraintForEdit($id)) { $this->ctrl->redirect($this, "constraints"); } $constraint = $this->object->getPrecondition($id); $questions = $this->object->getSurveyQuestions(); $question = $questions[$constraint["question_fi"]]; $relation = $questions[$constraint["ref_question_fi"]]; $relation = $relation["title"]; // see ilSurveyConstraintsTableGUI include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php"; $question_type = SurveyQuestion::_getQuestionType($constraint["question_fi"]); SurveyQuestion::_includeClass($question_type); $question_obj = new $question_type(); $question_obj->loadFromDb($constraint["question_fi"]); $valueoutput = $question_obj->getPreconditionValueOutput($constraint["value"]); $title = $question["title"] . " " . $constraint["shortname"] . " " . $valueoutput; $this->ctrl->saveParameter($this, "precondition"); include_once "./Services/Utilities/classes/class.ilConfirmationGUI.php"; $cgui = new ilConfirmationGUI(); $cgui->setHeaderText(sprintf($this->lng->txt("survey_sure_delete_constraint"), $title, $relation)); $cgui->setFormAction($this->ctrl->getFormAction($this, "deleteConstraints")); $cgui->setCancel($this->lng->txt("cancel"), "constraints"); $cgui->setConfirm($this->lng->txt("confirm"), "deleteConstraints"); $this->tpl->setContent($cgui->getHTML()); }
/** * Creates an instance of a question GUI with a given question id * * @param integer $question_id The question id * @return object The question GUI instance * @access public */ function &_instanciateQuestionGUI($question_id) { $question_type = SurveyQuestion::_getQuestionType($question_id); if ($question_type) { SurveyQuestion::_includeClass($question_type, 1); $guitype = $question_type . "GUI"; $question = new $guitype($question_id); return $question; } }
/** * Material tab of the survey questions */ public function material($checkonly = FALSE) { global $rbacsystem, $ilTabs; $ilTabs->activateTab("material"); $add_html = ''; if ($rbacsystem->checkAccess('write', $_GET['ref_id'])) { include_once "./Services/Form/classes/class.ilPropertyFormGUI.php"; $form = new ilPropertyFormGUI(); $form->setFormAction($this->ctrl->getFormAction($this)); $form->setTitle($this->lng->txt('add_material')); $form->setMultipart(FALSE); $form->setTableWidth("100%"); $form->setId("material"); // material $material = new ilRadioGroupInputGUI($this->lng->txt("material"), "internalLinkType"); $material->setRequired(true); $material->addOption(new ilRadioOption($this->lng->txt('obj_lm'), "lm")); $material->addOption(new ilRadioOption($this->lng->txt('obj_st'), "st")); $material->addOption(new ilRadioOption($this->lng->txt('obj_pg'), "pg")); $material->addOption(new ilRadioOption($this->lng->txt('glossary_term'), "glo")); $form->addItem($material); $form->addCommandButton("addMaterial", $this->lng->txt("add")); $errors = false; if ($checkonly) { $form->setValuesByPost(); $errors = !$form->checkInput(); if ($errors) { $checkonly = false; } } $add_html = $form->getHTML(); } $mat_html = ""; if (count($this->object->getMaterial())) { include_once "./Modules/SurveyQuestionPool/classes/tables/class.ilSurveyMaterialsTableGUI.php"; $table_gui = new ilSurveyMaterialsTableGUI($this, 'material', $rbacsystem->checkAccess('write', $_GET['ref_id']) ? true : false); $data = array(); foreach ($this->object->getMaterial() as $material) { switch ($material->type) { case 0: $href = SurveyQuestion::_getInternalLinkHref($material->internal_link, $_GET['ref_id']); $type = $this->lng->txt('internal_link'); break; } $title = strlen($material->title) ? ilUtil::prepareFormOutput($material->title) : $this->lng->txt('material'); array_push($data, array('href' => $href, 'title' => $title, 'type' => $type)); } $table_gui->setData($data); $mat_html = $table_gui->getHTML(); } if (!$checkonly) { $this->tpl->setVariable("ADM_CONTENT", $add_html . $mat_html); } return $errors; }
/** * Saves a SurveyMetricQuestion object to a database * * @access public */ function saveToDb($original_id = "") { global $ilDB; $affectedRows = parent::saveToDb($original_id); if ($affectedRows == 1) { $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s", array('integer'), array($this->getId())); $affectedRows = $ilDB->manipulateF("INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, subtype) VALUES (%s, %s)", array('integer', 'text'), array($this->getId(), $this->getSubType())); // saving material uris in the database $this->saveMaterial(); // save categories $affectedRows = $ilDB->manipulateF("DELETE FROM svy_variable WHERE question_fi = %s", array('integer'), array($this->getId())); if (preg_match("/[\\D]/", $this->maximum) or strcmp($this->maximum, "∞") == 0) { $max = -1; } else { $max = $this->getMaximum(); } $next_id = $ilDB->nextId('svy_variable'); $affectedRows = $ilDB->manipulateF("INSERT INTO svy_variable (variable_id, category_fi, question_fi, value1, value2, sequence, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s)", array('integer', 'integer', 'integer', 'float', 'float', 'integer', 'integer'), array($next_id, 0, $this->getId(), $this->getMinimum(), $max, 0, time())); } }
/** * Saves a SurveyTextQuestion object to a database * * @access public */ function saveToDb($original_id = "") { global $ilDB; $affectedRows = parent::saveToDb($original_id); if ($affectedRows == 1) { $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s", array('integer'), array($this->getId())); $affectedRows = $ilDB->manipulateF("INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, maxchars, width, height) VALUES (%s, %s, %s, %s)", array('integer', 'integer', 'integer', 'integer'), array($this->getId(), $this->getMaxChars(), $this->getTextWidth(), $this->getTextHeight())); $this->saveMaterial(); } }
/** * Get's the repository object ID of a parent object, if possible * * see ilWebAccessChecker */ function getParentObjectIdForUsage($a_usage, $a_include_all_access_obj_ids = false) { if (is_int(strpos($a_usage["type"], ":"))) { $us_arr = explode(":", $a_usage["type"]); $type = $us_arr[1]; $cont_type = $us_arr[0]; } else { $type = $a_usage["type"]; } $id = $a_usage["id"]; $obj_id = false; switch ($type) { // RTE / tiny mce case "html": switch ($cont_type) { case "qpl": // Question Pool *Question* Text (Test) include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php"; $qinfo = assQuestion::_getQuestionInfo($id); if ($qinfo["original_id"] > 0) { include_once "./Modules/Test/classes/class.ilObjTest.php"; $obj_id = ilObjTest::_lookupTestObjIdForQuestionId($id); // usage in test } else { $obj_id = $qinfo["obj_fi"]; // usage in pool } break; case "spl": // Question Pool *Question* Text (Survey) include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php"; $quest = SurveyQuestion::_instanciateQuestion($id); if ($quest) { if ($quest->getOriginalId() > 0) { $obj_id = $quest->getSurveyId(); } else { $obj_id = $quest->getObjId(); // usage in pool } unset($quest); } break; case "exca": // Exercise assignment $returned_pk = $a_usage['id']; // we are just checking against exercise object include_once 'Modules/Exercise/classes/class.ilObjExercise.php'; $obj_id = ilObjExercise::lookupExerciseIdForReturnedId($returned_pk); break; case "frm": // Forum $post_pk = $a_usage['id']; include_once 'Modules/Forum/classes/class.ilForumPost.php'; include_once 'Modules/Forum/classes/class.ilForum.php'; $oPost = new ilForumPost($post_pk); $frm_pk = $oPost->getForumId(); $obj_id = ilForum::_lookupObjIdForForumId($frm_pk); break; // temporary items (per user) // temporary items (per user) case "frm~": case "exca~": $obj_id = $a_usage['id']; break; // "old" category pages // "old" category pages case "cat": // InfoScreen Text // InfoScreen Text case "tst": case "svy": // data collection // data collection case "dcl": $obj_id = $id; break; } break; // page editor // page editor case "pg": switch ($cont_type) { case "qpl": // Question Pool Question Pages include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php"; $qinfo = assQuestion::_getQuestionInfo($id); if ($qinfo["original_id"] > 0) { include_once "./Modules/Test/classes/class.ilObjTest.php"; $obj_id = ilObjTest::_lookupTestObjIdForQuestionId($id); // usage in test } else { $obj_id = $qinfo["obj_fi"]; // usage in pool } break; case "lm": case "dbk": // learning modules include_once "./Modules/LearningModule/classes/class.ilLMObject.php"; $obj_id = ilLMObject::_lookupContObjID($id); break; case "gdf": // glossary definition include_once "./Modules/Glossary/classes/class.ilGlossaryDefinition.php"; include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php"; $term_id = ilGlossaryDefinition::_lookupTermId($id); $obj_id = ilGlossaryTerm::_lookGlossaryID($term_id); break; case "wpg": // wiki page include_once 'Modules/Wiki/classes/class.ilWikiPage.php'; $obj_id = ilWikiPage::lookupObjIdByPage($id); break; case "sahs": // sahs page // can this implementation be used for other content types, too? include_once './Services/COPage/classes/class.ilPageObject.php'; $obj_id = ilPageObject::lookupParentId($id, 'sahs'); break; case "prtf": // portfolio include_once "Modules/Portfolio/classes/class.ilPortfolioPage.php"; $obj_id = ilPortfolioPage::findPortfolioForPage($id); break; case "prtt": // portfolio template include_once "Modules/Portfolio/classes/class.ilPortfolioTemplatePage.php"; $obj_id = ilPortfolioTemplatePage::findPortfolioForPage($id); break; case "blp": // blog include_once './Services/COPage/classes/class.ilPageObject.php'; $obj_id = ilPageObject::lookupParentId($id, 'blp'); break; case "crs": case "grp": case "cat": case "fold": case "root": // repository pages $obj_id = $id; break; } break; // Media Pool // Media Pool case "mep": $obj_id = $id; break; // News Context Object (e.g. MediaCast) // News Context Object (e.g. MediaCast) case "news": include_once "./Services/News/classes/class.ilNewsItem.php"; $obj_id = ilNewsItem::_lookupContextObjId($id); break; } return $obj_id; }
public function Delete($sure = false, $hardDelete = false) { if ($sure !== true) { fail("Cannot delete ward; please pass boolean true as a second argument."); } if (!$this->ID) { return false; } $wid = $this->ID; // convenience // FHE groups DB::Run("DELETE FROM FheGroups WHERE WardID={$wid}"); // Residences $res = $ward->Residences(true); foreach ($res as $residence) { $res->Delete(true); } // SurveyQuestions, SurveyAnswers, SurveyAnswerOptions, Permissions $r = DB::Run("SELECT ID FROM SurveyQuestions WHERE WardID={$wid}"); while ($row = mysql_fetch_array($r)) { $sq = SurveyQuestion::Load($row['ID']); $sq->Delete(true); } // Callings, MembersCallings, and any remaining calling Permissions (shouldn't be any...) $r = DB::Run("SELECT ID FROM Callings WHERE WardID={$wid}"); while ($row = mysql_fetch_array($r)) { $c = Calling::Load($row['ID']); $c->Delete(true); } // Members, Credentials, GrantedPrivileges, remaining Callings, PwdResetTokens, // profile pic, and remaining member Permissions (shouldn't be any...) // (Everything else except the ward itself) $r = DB::Run("SELECT ID FROM Members WHERE WardID={$wid}"); while ($row = mysql_fetch_array($r)) { $m = Member::Load($row['ID']); $m->Delete(true); } // Ward itself if ($hardDelete) { DB::Run("DELETE FROM Wards WHERE ID={$wid} LIMIT 1"); // Unset this object so it can't inadvertently be saved again $this->ID = null; $this->Name = null; } else { $this->Deleted = true; $this->Save(); } return true; }
public static function load_from_row($row, $recurse_limit = 1, $current_level = 0) { // When PHP 5.3.0 is in, we can shift this over too and just redefine it // if needed (eg. loading child objects) $class = __CLASS__; $object = new $class(); $fields = self::fields_array(); $fields[] = array("created_at", "datetime"); $fields[] = array("updated_at", "datetime"); $fields[] = array("deleted", "bool"); foreach ($fields as $field) { $property = $field[0]; if (isset($field[2])) { $property = $field[2]; } if (isset($row[self::table . ".{$field[0]}"])) { if ($field[1] == "datetime") { $object->{$property} = strtotime($row[self::table . ".{$field[0]}"]); } else { $object->{$property} = $row[self::table . ".{$field[0]}"]; } } else { $object->{$property} = null; } } $object->is_new = false; // Load child objects here if ($current_level < $recurse_limit) { $current_level++; $object->survey = Survey::load_from_row($row, $recurse_limit, $current_level); $object->user = User::load_from_row($row, $recurse_limit, $current_level); $object->question = SurveyQuestion::load_from_row($row, $recurse_limit, $current_level); $object->response = SurveyResponse::load_from_row($row, $recurse_limit, $current_level); } return $object; }
public function executeCopyQuestionsToPoolObject() { $question_ids = explode(";", $_POST["question_ids"]); $pool_id = ilObject::_lookupObjId($_POST["sel_spl"]); foreach ($question_ids as $qid) { // create copy (== pool "original") $new_question = ilObjSurvey::_instanciateQuestion($qid); $new_question->setId(); $new_question->setObjId($pool_id); $new_question->saveToDb(); // link "source" (survey) to copy (pool) SurveyQuestion::_changeOriginalId($qid, $new_question->getId(), $pool_id); } ilUtil::sendSuccess($this->lng->txt("survey_copy_to_questionpool_success"), true); $this->ctrl->redirect($this, "questions"); }
/** * Build the Survey Questions * @param int $courseId Internal course ID */ public function build_survey_questions($courseId) { $table_que = Database::get_course_table(TABLE_SURVEY_QUESTION); $table_opt = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION); $sql = 'SELECT * FROM ' . $table_que . ' WHERE c_id = ' . $courseId . ' '; $db_result = Database::query($sql); while ($obj = Database::fetch_object($db_result)) { $question = new SurveyQuestion($obj->question_id, $obj->survey_id, $obj->survey_question, $obj->survey_question_comment, $obj->type, $obj->display, $obj->sort, $obj->shared_question_id, $obj->max_value); $sql = 'SELECT * FROM ' . $table_opt . ' WHERE c_id = ' . $courseId . ' AND question_id = ' . $obj->question_id; $db_result2 = Database::query($sql); while ($obj2 = Database::fetch_object($db_result2)) { $question->add_answer($obj2->option_text, $obj2->sort); } $this->course->add_resource($question); } }
/** * fill row * * @access public * @param * @return */ public function fillRow($data) { global $ilUser, $ilAccess; include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php"; include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php"; $class = strtolower(SurveyQuestionGUI::_getGUIClassNameForId($data["question_id"])); $guiclass = $class . "GUI"; $this->ctrl->setParameterByClass(strtolower($guiclass), "q_id", $data["question_id"]); if ($this->getEditable()) { $url_edit = $this->ctrl->getLinkTargetByClass(strtolower($guiclass), "editQuestion"); $this->tpl->setCurrentBlock("title_link_bl"); $this->tpl->setVariable("QUESTION_TITLE_LINK", $data["title"]); $this->tpl->setVariable("URL_TITLE", $url_edit); $this->tpl->parseCurrentBlock(); } else { $this->tpl->setCurrentBlock("title_nolink_bl"); $this->tpl->setVariable("QUESTION_TITLE", $data["title"]); $this->tpl->parseCurrentBlock(); } if ($data["complete"] == 0) { $this->tpl->setCurrentBlock("qpl_warning"); $this->tpl->setVariable("IMAGE_WARNING", ilUtil::getImagePath("icon_alert.svg")); $this->tpl->setVariable("ALT_WARNING", $this->lng->txt("warning_question_not_complete")); $this->tpl->setVariable("TITLE_WARNING", $this->lng->txt("warning_question_not_complete")); $this->tpl->parseCurrentBlock(); } foreach ($this->getSelectedColumns() as $c) { if (strcmp($c, 'description') == 0) { $this->tpl->setCurrentBlock('description'); $this->tpl->setVariable("QUESTION_COMMENT", strlen($data["description"]) ? $data["description"] : " "); $this->tpl->parseCurrentBlock(); } if (strcmp($c, 'type') == 0) { $this->tpl->setCurrentBlock('type'); $this->tpl->setVariable("QUESTION_TYPE", SurveyQuestion::_getQuestionTypeName($data["type_tag"])); $this->tpl->parseCurrentBlock(); } if (strcmp($c, 'author') == 0) { $this->tpl->setCurrentBlock('author'); $this->tpl->setVariable("QUESTION_AUTHOR", $data["author"]); $this->tpl->parseCurrentBlock(); } if (strcmp($c, 'created') == 0) { $this->tpl->setCurrentBlock('created'); $this->tpl->setVariable("QUESTION_CREATED", ilDatePresentation::formatDate(new ilDate($data['created'], IL_CAL_UNIX))); $this->tpl->parseCurrentBlock(); } if (strcmp($c, 'updated') == 0) { $this->tpl->setCurrentBlock('updated'); $this->tpl->setVariable("QUESTION_UPDATED", ilDatePresentation::formatDate(new ilDate($data["tstamp"], IL_CAL_UNIX))); $this->tpl->parseCurrentBlock(); } } // actions include_once "Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php"; $list = new ilAdvancedSelectionListGUI(); $list->setId($data["question_id"]); $list->setListTitle($this->lng->txt("actions")); if ($url_edit) { $list->addItem($this->lng->txt("edit"), "", $url_edit); } $list->addItem($this->lng->txt("preview"), "", $this->ctrl->getLinkTargetByClass(strtolower($guiclass), "preview")); $this->tpl->setVariable("ACTION", $list->getHTML()); $this->tpl->parseCurrentBlock(); // obligatory if ($this->getEditable()) { $checked = $data["obligatory"] ? " checked=\"checked\"" : ""; $obligatory = "<input type=\"checkbox\" name=\"obligatory_" . $data["question_id"] . "\" value=\"1\"" . $checked . " />"; } else { if ($data["obligatory"]) { $obligatory = "<img src=\"" . ilUtil::getImagePath("obligatory.png", "Modules/Survey") . "\" alt=\"" . $this->lng->txt("question_obligatory") . "\" title=\"" . $this->lng->txt("question_obligatory") . "\" />"; } } $this->tpl->setVariable("OBLIGATORY", $obligatory); if ($this->getWriteAccess()) { $this->tpl->setVariable('CBOX_ID', $data["question_id"]); } $this->tpl->setVariable('QUESTION_ID', $data["question_id"]); }
<div class="answer"> <?php echo $readonlyAnswer; ?> </div> <?php } } else { // Get this person's answers to the survey, and display those which // the current member is allowed to see. $permissions = $USER->Permissions(true); if (count($permissions) == 0) { echo "<i>None of {$mem->FirstName()}'s survey answers are available for you to view.</i>"; } foreach ($permissions as $per) { $qu = SurveyQuestion::Load($per->QuestionID()); if (!$qu) { continue; } $ans = $qu->Answers($mem->ID()); $readonlyAnswer = $ans && $ans->ReadonlyAnswer() ? $ans->ReadonlyAnswer() : '<i>no answer</i>'; ?> <div class="question"> <?php echo $qu->Question; ?> </div> <div class="answer"> <?php echo $readonlyAnswer; ?>
public function addLocatorItems() { global $ilLocator; switch ($this->ctrl->getCmd()) { case "create": case "importFile": case "cancel": break; default: $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ""), "", $_GET["ref_id"]); break; } if ($_GET["q_id"] > 0) { include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php"; $q_type = SurveyQuestion::_getQuestionType($_GET["q_id"]) . "GUI"; $this->ctrl->setParameterByClass($q_type, "q_id", $_GET["q_id"]); $ilLocator->addItem(SurveyQuestion::_getTitle($_GET["q_id"]), $this->ctrl->getLinkTargetByClass($q_type, "editQuestion")); } }
/** * export questions to xml */ function toXML($questions) { if (!is_array($questions)) { $questions =& $this->getQuestions(); } if (count($questions) == 0) { $questions =& $this->getQuestions(); } $xml = ""; include_once "./Services/Xml/classes/class.ilXmlWriter.php"; $a_xml_writer = new ilXmlWriter(); // set xml header $a_xml_writer->xmlHeader(); $attrs = array("xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", "xsi:noNamespaceSchemaLocation" => "http://www.ilias.de/download/xsd/ilias_survey_4_2.xsd"); $a_xml_writer->xmlStartTag("surveyobject", $attrs); $attrs = array("id" => "qpl_" . $this->getId(), "label" => $this->getTitle(), "online" => $this->getOnline()); $a_xml_writer->xmlStartTag("surveyquestions", $attrs); $a_xml_writer->xmlElement("dummy", NULL, "dummy"); // add ILIAS specific metadata $a_xml_writer->xmlStartTag("metadata"); $a_xml_writer->xmlStartTag("metadatafield"); $a_xml_writer->xmlElement("fieldlabel", NULL, "SCORM"); include_once "./Services/MetaData/classes/class.ilMD.php"; $md = new ilMD($this->getId(), 0, $this->getType()); $writer = new ilXmlWriter(); $md->toXml($writer); $metadata = $writer->xmlDumpMem(); $a_xml_writer->xmlElement("fieldentry", NULL, $metadata); $a_xml_writer->xmlEndTag("metadatafield"); $a_xml_writer->xmlEndTag("metadata"); $a_xml_writer->xmlEndTag("surveyquestions"); $a_xml_writer->xmlEndTag("surveyobject"); $xml = $a_xml_writer->xmlDumpMem(FALSE); $questionxml = ""; foreach ($questions as $key => $value) { $questiontype = $this->getQuestiontype($value); include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php"; SurveyQuestion::_includeClass($questiontype); $question = new $questiontype(); $question->loadFromDb($value); $questionxml .= $question->toXML(false); } $xml = str_replace("<dummy>dummy</dummy>", $questionxml, $xml); return $xml; }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param SurveyQuestion $value A SurveyQuestion object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(SurveyQuestion $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getQuestionId(); } // if key === null self::$instances[$key] = $obj; } }
protected static function load_question($survey, $id = null) { if (!$id) { $id = $_GET['question_id']; } $object = SurveyQuestion::find_by_id($id); if ($object and $object->survey_id == $survey->id) { return $object; } else { Error404(); } }
$opt = trim($opt); if ($opt != '') { $ansEmpty = false; break; } } } // Is this question designed to have answer choices/options? $multAns = $qtype == QuestionType::MultipleChoice || $qtype == QuestionType::MultipleAnswer; // Make sure that multiple-answer/choice questions have at least one // to choose from if ($multAns && $ansEmpty) { Response::Send(401, "Oops - for that type of question, it requires at least one possible answer (you have to add one). Go BACK and try again."); } // Create question. $qu = new SurveyQuestion(); $qu->Question = $question; $qu->QuestionType = $qtype; $qu->Required = $req; $qu->Visible = $visible; $qu->WardID = $MEMBER->WardID; // Save what we have (it needs an ID in order to add answer options) if (!$qu->Save()) { fail("Could not save this question. Please report this and try again..."); } // Add answer options, if applicable if ($multAns) { foreach ($ansArray as $ans) { if (strlen(trim($ans)) > 0 && $ans != ' ' && !$qu->AddAnswerOption($ans)) { echo "Could not add answer {$ans} to this question; go back, refresh, and add this answer manually."; }