Remove c_id, fix queries, use entities

pull/3844/head
Julio Montoya 5 years ago
parent 279dde0376
commit 2b0e924e17
  1. 6
      public/main/exercise/exercise.class.php
  2. 9
      public/main/forum/forumfunction.inc.php
  3. 13
      public/main/gradebook/lib/be/category.class.php
  4. 26
      public/main/inc/lib/extra_field.lib.php
  5. 13
      public/main/inc/lib/extra_field_value.lib.php
  6. 3
      public/main/lp/learnpathList.class.php
  7. 5
      public/main/survey/preview.php
  8. 25
      public/main/survey/survey.lib.php
  9. 6
      public/main/survey/survey.php
  10. 106
      public/main/survey/surveyUtil.class.php
  11. 36
      public/main/survey/survey_invite.php
  12. 82
      public/main/work/work.lib.php
  13. 16
      src/CourseBundle/Repository/CSurveyRepository.php

@ -10008,13 +10008,11 @@ var_dump($this->pageResultConfiguration);
$sql = "SELECT $sql = "SELECT
lp.name, lp.name,
lpi.lp_id, lpi.lp_id,
lpi.max_score, lpi.max_score
lp.session_id
FROM $tableLpItem lpi FROM $tableLpItem lpi
INNER JOIN $tblLp lp INNER JOIN $tblLp lp
ON (lpi.lp_id = lp.iid AND lpi.c_id = lp.c_id) ON (lpi.lp_id = lp.iid)
WHERE WHERE
lpi.c_id = $courseId AND
lpi.item_type = '".TOOL_QUIZ."' AND lpi.item_type = '".TOOL_QUIZ."' AND
lpi.path = '$exerciseId'"; lpi.path = '$exerciseId'";
$result = Database::query($sql); $result = Database::query($sql);

@ -701,16 +701,18 @@ function store_forum($values, $courseInfo = [], $returnId = false)
if (null === $values['forum_category']) { if (null === $values['forum_category']) {
$new_max = null; $new_max = null;
} else { } else {
$sql = "SELECT MAX(forum_order) as sort_max /*$sql = "SELECT MAX(forum_order) as sort_max
FROM $table_forums FROM $table_forums
WHERE WHERE
c_id = $courseId AND c_id = $courseId AND
forum_category='".Database::escape_string($values['forum_category'])."'"; forum_category='".Database::escape_string($values['forum_category'])."'";
$result = Database::query($sql); $result = Database::query($sql);
$row = Database::fetch_array($result); $row = Database::fetch_array($result);
$new_max = $row['sort_max'] + 1; $new_max = $row['sort_max'] + 1;*/
} }
$new_max = 0;
// Forum images // Forum images
$has_attachment = false; $has_attachment = false;
$image_moved = true; $image_moved = true;
@ -3799,11 +3801,12 @@ function updateThreadInfo($threadId, $lastPostId, $post_date)
* This function is used to find all the information about what's new in the forum tool. * This function is used to find all the information about what's new in the forum tool.
* *
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* * @deprecated
* @version february 2006, dokeos 1.8 * @version february 2006, dokeos 1.8
*/ */
function get_whats_new() function get_whats_new()
{ {
return ;
$userId = api_get_user_id(); $userId = api_get_user_id();
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();

@ -597,7 +597,11 @@ class Category implements GradebookItem
$category->setCertifMinScore($this->certificate_min_score); $category->setCertifMinScore($this->certificate_min_score);
$category->setSession(api_get_session_entity($this->session_id)); $category->setSession(api_get_session_entity($this->session_id));
$category->setGenerateCertificates($this->generateCertificates); $category->setGenerateCertificates($this->generateCertificates);
$category->setGradeModelId($this->grade_model_id); if (!empty($this->grade_model_id)) {
$model = $em->getRepository(\Chamilo\CoreBundle\Entity\GradeModel::class)->find($this->grade_model_id);
$category->setGradeModel($model);
}
$category->setIsRequirement($this->isRequirement); $category->setIsRequirement($this->isRequirement);
$category->setLocked(0); $category->setLocked(0);
@ -678,13 +682,16 @@ class Category implements GradebookItem
$category->setDescription($this->description); $category->setDescription($this->description);
$category->setUser(api_get_user_entity($this->user_id)); $category->setUser(api_get_user_entity($this->user_id));
$category->setCourse($course); $category->setCourse($course);
//$category->setCourseCode($this->course_code);
$category->setParent($parent); $category->setParent($parent);
$category->setWeight($this->weight); $category->setWeight($this->weight);
$category->setVisible($this->visible); $category->setVisible($this->visible);
$category->setCertifMinScore($this->certificate_min_score); $category->setCertifMinScore($this->certificate_min_score);
$category->setGenerateCertificates($this->generateCertificates); $category->setGenerateCertificates($this->generateCertificates);
$category->setGradeModelId($this->grade_model_id); if (!empty($this->grade_model_id)) {
$model = $em->getRepository(\Chamilo\CoreBundle\Entity\GradeModel::class)->find($this->grade_model_id);
$category->setGradeModel($model);
}
$category->setIsRequirement($this->isRequirement); $category->setIsRequirement($this->isRequirement);
$em->persist($category); $em->persist($category);

@ -710,13 +710,15 @@ class ExtraField extends Model
* Add elements to a form. * Add elements to a form.
* *
* @param FormValidator $form The form object to which to attach this element * @param FormValidator $form The form object to which to attach this element
* @param int $itemId The item (course, user, session, etc) this extra_field is linked to * @param int $itemId The item (course, user, session, etc) this extra_field is
* linked to
* @param array $exclude Variables of extra field to exclude * @param array $exclude Variables of extra field to exclude
* @param bool $filter Whether to get only the fields with the "filter" flag set to 1 (true) * @param bool $filter Whether to get only the fields with the "filter" flag set
* or not (false) * to 1 (true) or not (false)
* @param bool $useTagAsSelect Whether to show tag fields as select drop-down or not * @param bool $useTagAsSelect Whether to show tag fields as select drop-down or not
* @param array $showOnlyTheseFields Limit the extra fields shown to just the list given here * @param array $showOnlyTheseFields Limit the extra fields shown to just the list given here
* @param array $orderFields An array containing the names of the fields shown, in the right order * @param array $orderFields An array containing the names of the fields shown, in the
* right order
* @param array $extraData * @param array $extraData
* @param bool $orderDependingDefaults * @param bool $orderDependingDefaults
* @param bool $adminPermissions * @param bool $adminPermissions
@ -1279,9 +1281,9 @@ class ExtraField extends Model
'' ''
); );
} }
/** @var ExtraFieldRelTag $fieldTag */
foreach ($fieldTags as $fieldTag) { foreach ($fieldTags as $fieldTag) {
$tag = $em->find(Tag::class, $fieldTag->getTagId()); $tag = $fieldTag->getTag();
if (empty($tag)) { if (empty($tag)) {
continue; continue;
@ -1350,8 +1352,7 @@ class ExtraField extends Model
/** @var ExtraFieldRelTag $fieldTag */ /** @var ExtraFieldRelTag $fieldTag */
foreach ($fieldTags as $fieldTag) { foreach ($fieldTags as $fieldTag) {
/** @var Tag $tag */ $tag = $fieldTag->getTag();
$tag = $em->find(Tag::class, $fieldTag->getTagId());
if (empty($tag)) { if (empty($tag)) {
continue; continue;
} }
@ -1382,15 +1383,15 @@ class ExtraField extends Model
] ]
); );
$tagsAdded = []; $tagsAdded = [];
/** @var ExtraFieldRelTag $fieldTag */
foreach ($fieldTags as $fieldTag) { foreach ($fieldTags as $fieldTag) {
$tag = $em->find(Tag::class, $fieldTag->getTagId()); $tag = $fieldTag->getTag();
if (empty($tag)) { if (empty($tag)) {
continue; continue;
} }
$tagText = $tag->getTag(); $tagText = $tag->getTag();
if (in_array($tagText, $tagsAdded)) { if (in_array($tagText, $tagsAdded)) {
continue; continue;
} }
@ -2931,11 +2932,10 @@ JAVASCRIPT;
if (self::FIELD_TYPE_TAG === $fieldType) { if (self::FIELD_TYPE_TAG === $fieldType) {
$tags = $repoTag->findBy(['fieldId' => $field['id'], 'itemId' => $itemId]); $tags = $repoTag->findBy(['fieldId' => $field['id'], 'itemId' => $itemId]);
if ($tags) { if ($tags) {
/** @var ExtraFieldRelTag $tag */
$data = []; $data = [];
/** @var ExtraFieldRelTag $tag */
foreach ($tags as $extraFieldTag) { foreach ($tags as $extraFieldTag) {
/** @var \Chamilo\CoreBundle\Entity\Tag $tag */ $tag = $extraFieldTag->getTag();
$tag = $em->find(Tag::class, $extraFieldTag->getTagId());
$data[] = $tag->getTag(); $data[] = $tag->getTag();
} }
$valueData = implode(',', $data); $valueData = implode(',', $data);

@ -207,6 +207,8 @@ class ExtraFieldValue extends Model
$em->remove($extraFieldtag); $em->remove($extraFieldtag);
} }
$em->flush(); $em->flush();
$fieldEntity = $em->getRepository(\Chamilo\CoreBundle\Entity\ExtraField::class)->findBy($extraFieldInfo['id']);
$tagValues = is_array($value) ? $value : [$value]; $tagValues = is_array($value) ? $value : [$value];
$tags = []; $tags = [];
foreach ($tagValues as $tagValue) { foreach ($tagValues as $tagValue) {
@ -222,7 +224,7 @@ class ExtraFieldValue extends Model
if (empty($tagsResult)) { if (empty($tagsResult)) {
$tag = new Tag(); $tag = new Tag();
$tag->setFieldId($extraFieldInfo['id']); $tag->setField($fieldEntity);
$tag->setTag($tagValue); $tag->setTag($tagValue);
$tags[] = $tag; $tags[] = $tag;
@ -246,9 +248,9 @@ class ExtraFieldValue extends Model
foreach ($tags as $tag) { foreach ($tags as $tag) {
$fieldRelTag = new ExtraFieldRelTag(); $fieldRelTag = new ExtraFieldRelTag();
$fieldRelTag->setFieldId($extraFieldInfo['id']); $fieldRelTag->setField($fieldEntity);
$fieldRelTag->setItemId($params['item_id']); $fieldRelTag->setItemId($params['item_id']);
$fieldRelTag->setTagId($tag->getId()); $fieldRelTag->setTag($tag);
$em->persist($fieldRelTag); $em->persist($fieldRelTag);
} }
@ -965,10 +967,9 @@ class ExtraFieldValue extends Model
if ($tags) { if ($tags) {
/** @var ExtraFieldRelTag $extraFieldTag */ /** @var ExtraFieldRelTag $extraFieldTag */
foreach ($tags as $extraFieldTag) { foreach ($tags as $extraFieldTag) {
/** @var \Chamilo\CoreBundle\Entity\Tag $tag */ $tag = $extraFieldTag->getTag();
$tag = $em->find(Tag::class, $extraFieldTag->getTagId());
$tagResult[] = [ $tagResult[] = [
'id' => $extraFieldTag->getTagId(), 'id' => $extraFieldTag->getTag()->getId(),
'value' => $tag->getTag(), 'value' => $tag->getTag(),
]; ];
} }

@ -139,7 +139,7 @@ class LearnpathList
$this->list[$lp->getIid()] = [ $this->list[$lp->getIid()] = [
'lp_type' => $lp->getLpType(), 'lp_type' => $lp->getLpType(),
'lp_session' => $lp->getSessionId(), 'lp_session' => 0,
'lp_name' => stripslashes($lp->getName()), 'lp_name' => stripslashes($lp->getName()),
'lp_desc' => stripslashes($lp->getDescription()), 'lp_desc' => stripslashes($lp->getDescription()),
'lp_path' => $lp->getPath(), 'lp_path' => $lp->getPath(),
@ -155,7 +155,6 @@ class LearnpathList
'lp_scorm_debug' => $lp->getDebug(), 'lp_scorm_debug' => $lp->getDebug(),
'lp_display_order' => $lp->getDisplayOrder(), 'lp_display_order' => $lp->getDisplayOrder(),
'autolaunch' => $lp->getAutolaunch(), 'autolaunch' => $lp->getAutolaunch(),
'session_id' => $lp->getSessionId(),
'created_on' => $lp->getCreatedOn() ? $lp->getCreatedOn()->format('Y-m-d H:i:s') : null, 'created_on' => $lp->getCreatedOn() ? $lp->getCreatedOn()->format('Y-m-d H:i:s') : null,
'modified_on' => $lp->getModifiedOn() ? $lp->getModifiedOn()->format('Y-m-d H:i:s') : null, 'modified_on' => $lp->getModifiedOn() ? $lp->getModifiedOn()->format('Y-m-d H:i:s') : null,
'publicated_on' => $lp->getPublicatedOn() ? $lp->getPublicatedOn()->format('Y-m-d H:i:s') : null, 'publicated_on' => $lp->getPublicatedOn() ? $lp->getPublicatedOn()->format('Y-m-d H:i:s') : null,

@ -86,7 +86,6 @@ if (isset($_GET['show'])) {
$sql = "SELECT * FROM $table_survey_question $sql = "SELECT * FROM $table_survey_question
WHERE WHERE
survey_question NOT LIKE '%{{%' AND survey_question NOT LIKE '%{{%' AND
c_id = $course_id AND
survey_id = $surveyId survey_id = $surveyId
ORDER BY sort ASC"; ORDER BY sort ASC";
$result = Database::query($sql); $result = Database::query($sql);
@ -133,12 +132,10 @@ if (isset($_GET['show'])) {
FROM $table_survey_question survey_question FROM $table_survey_question survey_question
LEFT JOIN $table_survey_question_option survey_question_option LEFT JOIN $table_survey_question_option survey_question_option
ON ON
survey_question.iid = survey_question_option.question_id AND survey_question.iid = survey_question_option.question_id
survey_question_option.c_id = survey_question.c_id
WHERE WHERE
survey_question.survey_id = '".$surveyId."' AND survey_question.survey_id = '".$surveyId."' AND
survey_question.iid IN (".Database::escape_string(implode(',', $paged_questions[$_GET['show']]), null, false).") AND survey_question.iid IN (".Database::escape_string(implode(',', $paged_questions[$_GET['show']]), null, false).") AND
survey_question.c_id = $course_id AND
survey_question NOT LIKE '%{{%' survey_question NOT LIKE '%{{%'
ORDER BY survey_question.sort, survey_question_option.sort ASC"; ORDER BY survey_question.sort, survey_question_option.sort ASC";

@ -160,9 +160,7 @@ class SurveyManager
return []; return [];
} }
$sql = "SELECT * FROM $table_survey $sql = "SELECT * FROM $table_survey
WHERE WHERE iid = $survey_id";
iid = '".$survey_id."' AND
c_id = ".$courseInfo['real_id'];
} }
$result = Database::query($sql); $result = Database::query($sql);
@ -349,7 +347,6 @@ class SurveyManager
$session = api_get_session_entity(); $session = api_get_session_entity();
$survey $survey
->setCId($course_id)
->setCode(self::generateSurveyCode($values['survey_code'])) ->setCode(self::generateSurveyCode($values['survey_code']))
->setTitle($values['survey_title']) ->setTitle($values['survey_title'])
->setSubtitle($values['survey_title']) ->setSubtitle($values['survey_title'])
@ -362,7 +359,6 @@ class SurveyManager
->setIntro($values['survey_introduction']) ->setIntro($values['survey_introduction'])
->setSurveyThanks($values['survey_thanks']) ->setSurveyThanks($values['survey_thanks'])
->setAnonymous((string) $values['anonymous']) ->setAnonymous((string) $values['anonymous'])
->setSessionId(api_get_session_id())
->setVisibleResults((int) $values['visible_results']) ->setVisibleResults((int) $values['visible_results'])
->setParent($course) ->setParent($course)
->addCourseLink($course, $session) ->addCourseLink($course, $session)
@ -1092,7 +1088,7 @@ class SurveyManager
// Getting the information of the question // Getting the information of the question
$sql = "SELECT * FROM $tbl_survey_question $sql = "SELECT * FROM $tbl_survey_question
WHERE c_id = $courseId AND survey_id= $surveyId "; WHERE survey_id= $surveyId ";
$result = Database::query($sql); $result = Database::query($sql);
$questions = []; $questions = [];
while ($row = Database::fetch_array($result, 'ASSOC')) { while ($row = Database::fetch_array($result, 'ASSOC')) {
@ -1108,7 +1104,7 @@ class SurveyManager
// Getting the information of the question options // Getting the information of the question options
$sql = "SELECT * FROM $table_survey_question_option $sql = "SELECT * FROM $table_survey_question_option
WHERE c_id = $courseId AND survey_id= $surveyId AND question_id = $questionId"; WHERE survey_id= $surveyId AND question_id = $questionId";
$resultOptions = Database::query($sql); $resultOptions = Database::query($sql);
while ($rowOption = Database::fetch_array($resultOptions, 'ASSOC')) { while ($rowOption = Database::fetch_array($resultOptions, 'ASSOC')) {
$questions[$questionId]['answers'][] = $rowOption['option_text']; $questions[$questionId]['answers'][] = $rowOption['option_text'];
@ -1175,7 +1171,7 @@ class SurveyManager
// Finding the max sort order of the questions in the given survey // Finding the max sort order of the questions in the given survey
$sql = "SELECT max(sort) AS max_sort $sql = "SELECT max(sort) AS max_sort
FROM $tbl_survey_question FROM $tbl_survey_question
WHERE c_id = $course_id AND survey_id = $surveyId "; WHERE survey_id = $surveyId ";
$result = Database::query($sql); $result = Database::query($sql);
$row = Database::fetch_array($result, 'ASSOC'); $row = Database::fetch_array($result, 'ASSOC');
$max_sort = $row['max_sort']; $max_sort = $row['max_sort'];
@ -1196,7 +1192,7 @@ class SurveyManager
->setSurveyQuestionComment($form_content['question_comment'] ?? '') ->setSurveyQuestionComment($form_content['question_comment'] ?? '')
->setMaxValue($form_content['maximum_score'] ?? 0) ->setMaxValue($form_content['maximum_score'] ?? 0)
->setDisplay($form_content['horizontalvertical'] ?? '') ->setDisplay($form_content['horizontalvertical'] ?? '')
->setCId($course_id) //->setCId($course_id)
->setSurvey($survey) ->setSurvey($survey)
->setSurveyQuestion($form_content['question']) ->setSurveyQuestion($form_content['question'])
->setType($form_content['type']) ->setType($form_content['type'])
@ -1483,8 +1479,6 @@ class SurveyManager
if (empty($questionId)) { if (empty($questionId)) {
return false; return false;
} }
$course_id = api_get_course_int_id();
if ($shared) { if ($shared) {
self::delete_shared_survey_question($survey_id, $questionId); self::delete_shared_survey_question($survey_id, $questionId);
} }
@ -1592,7 +1586,6 @@ class SurveyManager
if (empty($answerId)) { if (empty($answerId)) {
$option = new CSurveyQuestionOption(); $option = new CSurveyQuestionOption();
$option $option
->setCId($course_id)
->setQuestion($question) ->setQuestion($question)
->setOptionText($form_content['answers'][$i]) ->setOptionText($form_content['answers'][$i])
->setSurvey($survey) ->setSurvey($survey)
@ -1813,9 +1806,9 @@ class SurveyManager
user.lastname, user.lastname,
user.id as user_id user.id as user_id
FROM $table_survey_answer answered_user FROM $table_survey_answer answered_user
LEFT JOIN $table_user as user ON answered_user.user = user.id LEFT JOIN $table_user as user
ON answered_user.user = user.id
WHERE WHERE
answered_user.c_id = $course_id AND
survey_id= '".$survey_id."' ". survey_id= '".$survey_id."' ".
$order_clause; $order_clause;
} else { } else {
@ -1829,8 +1822,6 @@ class SurveyManager
$sql = "SELECT i.user FROM $tblInvitation i $sql = "SELECT i.user FROM $tblInvitation i
INNER JOIN $tblSurvey s INNER JOIN $tblSurvey s
ON i.survey_code = s.code ON i.survey_code = s.code
AND i.c_id = s.c_id
AND i.session_id = s.session_id
WHERE i.answered IS TRUE AND s.iid = $survey_id"; WHERE i.answered IS TRUE AND s.iid = $survey_id";
} }
} }
@ -2486,7 +2477,6 @@ class SurveyManager
WHERE WHERE
survey_question NOT LIKE '%{{%' AND survey_question NOT LIKE '%{{%' AND
type = 'pagebreak' AND type = 'pagebreak' AND
c_id = $courseId AND
survey_id = $surveyId"; survey_id = $surveyId";
$result = Database::query($sql); $result = Database::query($sql);
$numberPageBreaks = Database::result($result, 0, 0); $numberPageBreaks = Database::result($result, 0, 0);
@ -2496,7 +2486,6 @@ class SurveyManager
WHERE WHERE
survey_question NOT LIKE '%{{%' AND survey_question NOT LIKE '%{{%' AND
type != 'pagebreak' AND type != 'pagebreak' AND
c_id = $courseId AND
survey_id = $surveyId"; survey_id = $surveyId";
$result = Database::query($sql); $result = Database::query($sql);
$countOfQuestions = Database::result($result, 0, 0); $countOfQuestions = Database::result($result, 0, 0);

@ -283,11 +283,9 @@ $sql = "SELECT survey_question.*, count(survey_question_option.iid) as number_of
FROM $table_survey_question survey_question FROM $table_survey_question survey_question
LEFT JOIN $table_survey_question_option survey_question_option LEFT JOIN $table_survey_question_option survey_question_option
ON ON
survey_question.iid = survey_question_option.question_id AND survey_question.iid = survey_question_option.question_id
survey_question_option.c_id = $course_id
WHERE WHERE
survey_question.survey_id = $survey_id AND survey_question.survey_id = $survey_id
survey_question.c_id = $course_id
GROUP BY survey_question.iid GROUP BY survey_question.iid
ORDER BY survey_question.sort ASC"; ORDER BY survey_question.sort ASC";

@ -30,18 +30,18 @@ class SurveyUtil
// Getting the information of the question // Getting the information of the question
$sql = "SELECT * FROM $tbl_survey_question $sql = "SELECT * FROM $tbl_survey_question
WHERE c_id = $course_id AND survey_id='".$survey_id."' WHERE survey_id='".$survey_id."'
ORDER BY sort ASC"; ORDER BY sort ASC";
$result = Database::query($sql); $result = Database::query($sql);
$total = Database::num_rows($result); $total = Database::num_rows($result);
$counter = 1; $counter = 1;
$error = false; $error = false;
while ($row = Database::fetch_array($result, 'ASSOC')) { while ($row = Database::fetch_array($result, 'ASSOC')) {
if (1 == $counter && 'pagebreak' == $row['type']) { if (1 == $counter && 'pagebreak' === $row['type']) {
echo Display::return_message(get_lang('The page break cannot be the first'), 'error', false); echo Display::return_message(get_lang('The page break cannot be the first'), 'error', false);
$error = true; $error = true;
} }
if ($counter == $total && 'pagebreak' == $row['type']) { if ($counter == $total && 'pagebreak' === $row['type']) {
echo Display::return_message(get_lang('The page break cannot be the last one'), 'error', false); echo Display::return_message(get_lang('The page break cannot be the last one'), 'error', false);
$error = true; $error = true;
} }
@ -3292,18 +3292,16 @@ class SurveyUtil
} }
} }
/**
* This function calculates the total number of surveys.
*
* @return int Total number of surveys
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
*
* @version January 2007
*/
public static function get_number_of_surveys() public static function get_number_of_surveys()
{ {
$table_survey = Database::get_course_table(TABLE_SURVEY); $repo = Container::getSurveyRepository();
$course = api_get_course_entity();
$session = api_get_session_entity();
$qb = $repo->findAllByCourse($course, $session);
return $repo->getCount($qb);
/*$table_survey = Database::get_course_table(TABLE_SURVEY);
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$search_restriction = self::survey_search_restriction(); $search_restriction = self::survey_search_restriction();
@ -3317,7 +3315,7 @@ class SurveyUtil
$res = Database::query($sql); $res = Database::query($sql);
$obj = Database::fetch_object($res); $obj = Database::fetch_object($res);
return $obj->total_number_of_items; return $obj->total_number_of_items;*/
} }
/** /**
@ -3353,6 +3351,15 @@ class SurveyUtil
$direction, $direction,
$isDrh = false $isDrh = false
) { ) {
$repo = Container::getSurveyRepository();
$course = api_get_course_entity();
$session = api_get_session_entity();
$qb = $repo->findAllByCourse($course, $session);
/** @var CSurvey[] $surveys */
$surveys = $qb->getQuery()->getResult();
$table_survey = Database::get_course_table(TABLE_SURVEY); $table_survey = Database::get_course_table(TABLE_SURVEY);
$table_user = Database::get_main_table(TABLE_MAIN_USER); $table_user = Database::get_main_table(TABLE_MAIN_USER);
$table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION); $table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
@ -3409,89 +3416,94 @@ class SurveyUtil
LIMIT $from,$number_of_items LIMIT $from,$number_of_items
"; ";
$res = Database::query($sql); //$res = Database::query($sql);
$surveys = [];
$array = []; $array = [];
$efv = new ExtraFieldValue('survey'); $efv = new ExtraFieldValue('survey');
while ($survey = Database::fetch_array($res)) { $list = [];
$array[0] = $survey[0]; foreach ($surveys as $survey) {
if (self::checkHideEditionToolsByCode($survey['col2'])) { $surveyId = $survey->getIid();
$array[1] = $survey[1]; $array[0] = $survey->getIid();
$type = $survey->getSurveyType();
$title = $survey->getTitle();
if (self::checkHideEditionToolsByCode($survey->getCode())) {
$array[1] = $title;
} else { } else {
// Doodle // Doodle
if (3 == $survey['survey_type']) { if (3 == $type) {
$array[1] = Display::url( $array[1] = Display::url(
$survey[1], $title,
api_get_path(WEB_CODE_PATH).'survey/meeting.php?survey_id='.$survey[0].'&'.api_get_cidreq() api_get_path(WEB_CODE_PATH).'survey/meeting.php?survey_id='.$surveyId.'&'.api_get_cidreq()
); );
} else { } else {
$array[1] = Display::url( $array[1] = Display::url(
$survey[1], $title,
api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey[0].'&'.api_get_cidreq() api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$surveyId.'&'.api_get_cidreq()
); );
} }
} }
// Validation when belonging to a session // Validation when belonging to a session
$session_img = api_get_session_image($survey['session_id'], $_user['status']); //$session_img = api_get_session_image($survey['session_id'], $_user['status']);
$array[2] = $survey[2].$session_img; $session_img = '';
$array[3] = $survey[3]; $array[2] = '$survey[2]'.$session_img;
$array[4] = $survey[4]; $array[3] = '$survey[3]';
$array[4] = '$survey[4]';
// Dates // Dates
$array[5] = ''; $array[5] = '';
if (!empty($survey[5]) && '0000-00-00' !== $survey[5] && '0000-00-00 00:00:00' !== $survey[5]) { $from = $survey->getAvailFrom() ?? $survey->getAvailFrom()->format('Y-m-d H:i:s');
if (null !== $from) {
$array[5] = api_convert_and_format_date( $array[5] = api_convert_and_format_date(
$survey[5], $from,
$allowSurveyAvailabilityDatetime ? DATE_TIME_FORMAT_LONG : DATE_FORMAT_LONG $allowSurveyAvailabilityDatetime ? DATE_TIME_FORMAT_LONG : DATE_FORMAT_LONG
); );
} }
$till = $survey->getAvailTill() ?? $survey->getAvailTill()->format('Y-m-d H:i:s');
$array[6] = ''; $array[6] = '';
if (!empty($survey[6]) && '0000-00-00' !== $survey[6] && '0000-00-00 00:00:00' !== $survey[6]) { if (null !== $till) {
$array[6] = api_convert_and_format_date( $array[6] = api_convert_and_format_date(
$survey[6], $till,
$allowSurveyAvailabilityDatetime ? DATE_TIME_FORMAT_LONG : DATE_FORMAT_LONG $allowSurveyAvailabilityDatetime ? DATE_TIME_FORMAT_LONG : DATE_FORMAT_LONG
); );
} }
$array[7] = $array[7] =
Display::url( Display::url(
$survey['answered'], $survey->getAnswered(),
api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=answered&survey_id='.$survey[0].'&' api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=answered&survey_id='.$surveyId.'&'
.api_get_cidreq() .api_get_cidreq()
).' / '. ).' / '.
Display::url( Display::url(
$survey['invited'], $survey->getInvited(),
api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=invited&survey_id='.$survey[0].'&' api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=invited&survey_id='.$surveyId.'&'
.api_get_cidreq() .api_get_cidreq()
); );
// Anon // Anon
$array[8] = $survey['col8']; $array[8] = $survey->getAnonymous();
if ($mandatoryAllowed) { if ($mandatoryAllowed) {
$efvMandatory = $efv->get_values_by_handler_and_field_variable( $efvMandatory = $efv->get_values_by_handler_and_field_variable(
$survey[9], $surveyId,
'is_mandatory' 'is_mandatory'
); );
$array[9] = $efvMandatory ? $efvMandatory['value'] : 0; $array[9] = $efvMandatory ? $efvMandatory['value'] : 0;
// Survey id // Survey id
$array[10] = $survey['col9']; $array[10] = $surveyId;
} else { } else {
// Survey id // Survey id
$array[9] = $survey['col9']; $array[9] = $surveyId;
} }
if ($isDrh) { if ($isDrh) {
$array[1] = $survey[1]; $array[1] = $title;
$array[7] = strip_tags($array[7]); $array[7] = strip_tags($survey->getInvited());
} }
$surveys[] = $array; $list[] = $array;
} }
return $surveys; return $list;
} }
/** /**

@ -2,6 +2,8 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
/** /**
* @author unknown, the initial survey that did not make it in 1.8 because of bad code * @author unknown, the initial survey that did not make it in 1.8 because of bad code
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
@ -12,8 +14,6 @@
* @todo add rules: title and text cannot be empty * @todo add rules: title and text cannot be empty
*/ */
use Chamilo\CoreBundle\Framework\Container;
require_once __DIR__.'/../inc/global.inc.php'; require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_COURSES; $this_section = SECTION_COURSES;
@ -77,10 +77,15 @@ $(function() {
// Checking if there is another survey with this code. // Checking if there is another survey with this code.
// If this is the case there will be a language choice // If this is the case there will be a language choice
$sql = "SELECT * FROM $table_survey $sql = "SELECT * FROM $table_survey
WHERE c_id = $course_id AND code='".Database::escape_string($survey_data['code'])."'"; WHERE code='".Database::escape_string($survey_data['code'])."'";
$result = Database::query($sql); $result = Database::query($sql);
if (Database::num_rows($result) > 1) { if (Database::num_rows($result) > 1) {
echo Display::return_message(get_lang('This survey code already exists. That probably means the survey exists in other languages. Invited people will choose between different languages.'), 'warning'); echo Display::return_message(
get_lang(
'This survey code already exists. That probably means the survey exists in other languages. Invited people will choose between different languages.'
),
'warning'
);
} }
// Invited / answered message // Invited / answered message
@ -109,15 +114,15 @@ $sessionId = api_get_session_id();
CourseManager::addUserGroupMultiSelect($form, [], true); CourseManager::addUserGroupMultiSelect($form, [], true);
// Additional users // Additional users
$form->addElement( $form->addTextarea(
'textarea', 'textarea',
'additional_users', 'additional_users',
[get_lang('Additional users'), get_lang('Additional usersComment')], [get_lang('Additional users'), get_lang('Additional usersComment')],
['rows' => 5] //['rows' => 5]
); );
$form->addElement('html', '<div id="check_mail">'); $form->addElement('html', '<div id="check_mail">');
$form->addElement('checkbox', 'send_mail', '', get_lang('Send mail')); $form->addCheckBox('send_mail', '', get_lang('Send mail'));
$form->addElement('html', '</div>'); $form->addElement('html', '</div>');
$form->addElement('html', '<div id="mail_text_wrapper">'); $form->addElement('html', '<div id="mail_text_wrapper">');
@ -126,7 +131,12 @@ $form->addText('mail_title', get_lang('Mail subject'), false);
// The text of the mail // The text of the mail
$form->addHtmlEditor( $form->addHtmlEditor(
'mail_text', 'mail_text',
[get_lang('E-mail message'), get_lang('The selected users will receive an email with the text above and a unique link that they have to click to fill the survey. If you want to put the link somewhere in your text you have to put the following text wherever you want in your text: **link** (star star link star star). This will then automatically be replaced by the unique link. If you do not add **link** to your text then the email link will be added to the end of the mail')], [
get_lang('E-mail message'),
get_lang(
'The selected users will receive an email with the text above and a unique link that they have to click to fill the survey. If you want to put the link somewhere in your text you have to put the following text wherever you want in your text: **link** (star star link star star). This will then automatically be replaced by the unique link. If you do not add **link** to your text then the email link will be added to the end of the mail'
),
],
false, false,
['ToolbarSet' => 'Survey', 'Height' => '150'] ['ToolbarSet' => 'Survey', 'Height' => '150']
); );
@ -136,7 +146,13 @@ if (1 != $survey_data['anonymous'] || api_get_configuration_value('survey_anonym
$form->addElement('checkbox', 'remindUnAnswered', '', get_lang('Remind only users who didn\'t answer')); $form->addElement('checkbox', 'remindUnAnswered', '', get_lang('Remind only users who didn\'t answer'));
} }
// Allow resending to all selected users // Allow resending to all selected users
$form->addElement('checkbox', 'resend_to_all', '', get_lang('Remind all users of the survey. If you do not check this checkbox only the newly-added users will receive an e-mail.')); $form->addCheckBox(
'resend_to_all',
'',
get_lang(
'Remind all users of the survey. If you do not check this checkbox only the newly-added users will receive an e-mail.'
)
);
$form->addElement('checkbox', 'hide_link', '', get_lang('Hide survey invitation link')); $form->addElement('checkbox', 'hide_link', '', get_lang('Hide survey invitation link'));
// Submit button // Submit button
@ -181,8 +197,6 @@ if ($form->validate()) {
$defaults['send_mail'] = 1; $defaults['send_mail'] = 1;
$form->setDefaults($defaults); $form->setDefaults($defaults);
$form->display(); $form->display();
return;
} }
} }

@ -94,7 +94,7 @@ function get_work_data_by_path($path, $courseId = 0)
$table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$sql = "SELECT * FROM $table $sql = "SELECT * FROM $table
WHERE url = '$path' AND c_id = $courseId "; WHERE url = '$path' ";
$result = Database::query($sql); $result = Database::query($sql);
$return = []; $return = [];
if (Database::num_rows($result)) { if (Database::num_rows($result)) {
@ -202,7 +202,6 @@ function get_work_count_by_student($user_id, $work_id)
$sql = "SELECT COUNT(*) as count $sql = "SELECT COUNT(*) as count
FROM $table FROM $table
WHERE WHERE
c_id = $course_id AND
parent_id = $work_id AND parent_id = $work_id AND
user_id = $user_id AND user_id = $user_id AND
active IN (0, 1) active IN (0, 1)
@ -232,7 +231,7 @@ function get_work_assignment_by_id($id, $courseId = 0)
$id = (int) $id; $id = (int) $id;
$table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT); $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
$sql = "SELECT * FROM $table $sql = "SELECT * FROM $table
WHERE c_id = $courseId AND publication_id = $id"; WHERE publication_id = $id";
$result = Database::query($sql); $result = Database::query($sql);
$return = []; $return = [];
if (Database::num_rows($result)) { if (Database::num_rows($result)) {
@ -412,8 +411,6 @@ function getUniqueStudentAttemptsTotal($workId, $groupId, $course_id, $sessionId
INNER JOIN $user_table u INNER JOIN $user_table u
ON w.user_id = u.id ON w.user_id = u.id
WHERE WHERE
w.c_id = $course_id
$sessionCondition AND
w.parent_id = $workId AND w.parent_id = $workId AND
w.post_group_id = $groupIid AND w.post_group_id = $groupIid AND
w.active IN (0, 1) w.active IN (0, 1)
@ -490,8 +487,6 @@ function getUniqueStudentAttempts(
ON w.user_id = u.id ON w.user_id = u.id
WHERE WHERE
w.filetype = 'file' AND w.filetype = 'file' AND
w.c_id = $course_id
$sessionCondition AND
$workCondition $workCondition
w.post_group_id = $groupIid AND w.post_group_id = $groupIid AND
w.active IN (0, 1) $studentCondition w.active IN (0, 1) $studentCondition
@ -716,7 +711,7 @@ function build_work_move_to_selector($folders, $curdirpath, $move_file, $group_d
$move_file = (int) $move_file; $move_file = (int) $move_file;
$tbl_work = Database::get_course_table(TABLE_STUDENT_PUBLICATION); $tbl_work = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$sql = "SELECT title, url FROM $tbl_work $sql = "SELECT title, url FROM $tbl_work
WHERE c_id = $course_id AND iid ='".$move_file."'"; WHERE iid ='".$move_file."'";
$result = Database::query($sql); $result = Database::query($sql);
$row = Database::fetch_array($result, 'ASSOC'); $row = Database::fetch_array($result, 'ASSOC');
$title = empty($row['title']) ? basename($row['url']) : $row['title']; $title = empty($row['title']) ? basename($row['url']) : $row['title'];
@ -910,18 +905,18 @@ function deleteDirWork($id)
// Gets calendar_id from student_publication_assigment // Gets calendar_id from student_publication_assigment
$sql = "SELECT add_to_calendar FROM $TSTDPUBASG $sql = "SELECT add_to_calendar FROM $TSTDPUBASG
WHERE c_id = $course_id AND publication_id = $id"; WHERE publication_id = $id";
$res = Database::query($sql); $res = Database::query($sql);
$calendar_id = Database::fetch_row($res); $calendar_id = Database::fetch_row($res);
// delete from agenda if it exists // delete from agenda if it exists
if (!empty($calendar_id[0])) { if (!empty($calendar_id[0])) {
$sql = "DELETE FROM $t_agenda $sql = "DELETE FROM $t_agenda
WHERE c_id = $course_id AND id = '".$calendar_id[0]."'"; WHERE id = '".$calendar_id[0]."'";
Database::query($sql); Database::query($sql);
} }
$sql = "DELETE FROM $TSTDPUBASG $sql = "DELETE FROM $TSTDPUBASG
WHERE c_id = $course_id AND publication_id = $id"; WHERE publication_id = $id";
Database::query($sql); Database::query($sql);
Skill::deleteSkillsFromItem($id, ITEM_TYPE_STUDENT_PUBLICATION); Skill::deleteSkillsFromItem($id, ITEM_TYPE_STUDENT_PUBLICATION);
@ -968,7 +963,7 @@ function get_work_path($id)
$table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$sql = 'SELECT url FROM '.$table.' $sql = 'SELECT url FROM '.$table.'
WHERE c_id = '.$course_id.' AND id='.(int) $id; WHERE id='.(int) $id;
$res = Database::query($sql); $res = Database::query($sql);
if (Database::num_rows($res)) { if (Database::num_rows($res)) {
$row = Database::fetch_array($res); $row = Database::fetch_array($res);
@ -999,7 +994,7 @@ function updateWorkUrl($id, $new_path, $parent_id)
$parent_id = (int) $parent_id; $parent_id = (int) $parent_id;
$sql = "SELECT * FROM $table $sql = "SELECT * FROM $table
WHERE c_id = $course_id AND id = $id"; WHERE iid = $id";
$res = Database::query($sql); $res = Database::query($sql);
if (1 != Database::num_rows($res)) { if (1 != Database::num_rows($res)) {
return -1; return -1;
@ -1116,56 +1111,6 @@ function to_javascript_work()
</script>'; </script>';
} }
/**
* Gets the id of a student publication with a given path.
*
* @param string $path
*
* @return true if is found / false if not found
*/
// TODO: The name of this function does not fit with the kind of information it returns.
// Maybe check_work_id() or is_work_id()?
function get_work_id($path)
{
$TBL_STUDENT_PUBLICATION = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$TBL_PROP_TABLE = Database::get_course_table(TABLE_ITEM_PROPERTY);
$course_id = api_get_course_int_id();
$path = Database::escape_string($path);
if (api_is_allowed_to_edit()) {
$sql = "SELECT work.iid
FROM $TBL_STUDENT_PUBLICATION AS work, $TBL_PROP_TABLE AS props
WHERE
props.c_id = $course_id AND
work.c_id = $course_id AND
props.tool='work' AND
work.id=props.ref AND
work.url LIKE 'work/".$path."%' AND
work.filetype='file' AND
props.visibility<>'2'";
} else {
$sql = "SELECT work.iid
FROM $TBL_STUDENT_PUBLICATION AS work, $TBL_PROP_TABLE AS props
WHERE
props.c_id = $course_id AND
work.c_id = $course_id AND
props.tool='work' AND
work.id=props.ref AND
work.url LIKE 'work/".$path."%' AND
work.filetype='file' AND
props.visibility<>'2' AND
props.lastedit_user_id = '".api_get_user_id()."'";
}
$result = Database::query($sql);
$num_rows = Database::num_rows($result);
if ($result && $num_rows > 0) {
return true;
} else {
return false;
}
}
/** /**
* @param int $work_id * @param int $work_id
* @param int $onlyMeUserId show only my works * @param int $onlyMeUserId show only my works
@ -1660,21 +1605,14 @@ function getWorkListTeacher(
$where_condition, $where_condition,
$getCount = false $getCount = false
) { ) {
$workTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$workTableAssignment = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
$courseInfo = api_get_course_info();
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$session_id = api_get_session_id(); $session_id = api_get_session_id();
$condition_session = api_get_session_condition($session_id);
$group_id = api_get_group_id(); $group_id = api_get_group_id();
$groupIid = 0; $groupIid = 0;
if ($group_id) { if ($group_id) {
$groupInfo = GroupManager::get_group_properties($group_id); $groupInfo = GroupManager::get_group_properties($group_id);
$groupIid = $groupInfo['iid']; $groupIid = $groupInfo['iid'];
} }
$groupIid = (int) $groupIid;
$is_allowed_to_edit = api_is_allowed_to_edit() || api_is_coach(); $is_allowed_to_edit = api_is_allowed_to_edit() || api_is_coach();
if (!in_array($direction, ['asc', 'desc'])) { if (!in_array($direction, ['asc', 'desc'])) {
$direction = 'desc'; $direction = 'desc';
@ -3622,7 +3560,7 @@ function getAllDocumentToWork($workId, $courseId)
{ {
$table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_REL_DOCUMENT); $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_REL_DOCUMENT);
$params = [ $params = [
'work_id = ? and c_id = ?' => [$workId, $courseId], 'work_id = ?' => [$workId],
]; ];
return Database::select('*', $table, ['where' => $params]); return Database::select('*', $table, ['where' => $params]);
@ -3686,7 +3624,7 @@ function getAllUserToWork($workId, $courseId, $getCount = false)
{ {
$table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_REL_USER); $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_REL_USER);
$params = [ $params = [
'work_id = ? and c_id = ?' => [$workId, $courseId], 'work_id = ?' => [$workId],
]; ];
if ($getCount) { if ($getCount) {
$count = 0; $count = 0;

@ -6,8 +6,11 @@ declare(strict_types=1);
namespace Chamilo\CourseBundle\Repository; namespace Chamilo\CourseBundle\Repository;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Repository\ResourceRepository; use Chamilo\CoreBundle\Repository\ResourceRepository;
use Chamilo\CourseBundle\Entity\CSurvey; use Chamilo\CourseBundle\Entity\CSurvey;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ManagerRegistry; use Doctrine\Persistence\ManagerRegistry;
final class CSurveyRepository extends ResourceRepository final class CSurveyRepository extends ResourceRepository
@ -16,4 +19,17 @@ final class CSurveyRepository extends ResourceRepository
{ {
parent::__construct($registry, CSurvey::class); parent::__construct($registry, CSurvey::class);
} }
public function findAllByCourse(
Course $course,
Session $session = null,
?string $title = null
): QueryBuilder {
$qb = $this->getResourcesByCourse($course, $session);
$this->addTitleQueryBuilder($title, $qb);
return $qb;
}
} }

Loading…
Cancel
Save