/** * @param int $workId * @param array $params * @param array $courseInfo * @param int $groupId */ function updatePublicationAssignment($workId, $params, $courseInfo, $groupId) { $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT); $workTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION); $workId = intval($workId); $time = time(); $course_id = $courseInfo['real_id']; // Insert into agenda $agendaId = 0; if (isset($params['add_to_calendar']) && $params['add_to_calendar'] == 1) { require_once api_get_path(SYS_CODE_PATH).'calendar/agenda.inc.php'; require_once api_get_path(SYS_CODE_PATH).'resourcelinker/resourcelinker.inc.php'; // Setting today date $date = $end_date = $time; if (!empty($params['enableExpiryDate'])) { $end_date = $params['expires_on']; $date = $end_date; } $title = sprintf(get_lang('HandingOverOfTaskX'), $params['new_dir']); $description = isset($params['description']) ? $params['description'] : ''; $content = '<a href="'.api_get_path(WEB_CODE_PATH).'work/work_list.php?'.api_get_cidreq().'&id='.$workId.'">' .$params['new_dir'].'</a>'.$description; $agendaId = agendaExistsForWork($workId, $courseInfo); // Add/edit agenda $agenda = new Agenda(); $agenda->set_course($courseInfo); $agenda->type = 'course'; if (empty($agendaId)) { $agendaId = $agenda->add_event( $date, $end_date, 'false', $title, $content, array('GROUP:'.$groupId) ); } else { $agenda->edit_event( $agendaId, $end_date, $end_date, 'false', $title, $content ); } } $qualification = isset($params['qualification']) && !empty($params['qualification']) ? 1 : 0; $expiryDate = (isset($params['enableExpiryDate']) && $params['enableExpiryDate'] == 1) ? api_get_utc_datetime($params['expires_on']) : '0000-00-00 00:00:00'; $endDate = ((isset($params['enableEndDate']) && $params['enableEndDate']==1) ? api_get_utc_datetime($params['ends_on']) : '0000-00-00 00:00:00'); $data = get_work_assignment_by_id($workId, $course_id); if (empty($data)) { $sql = "INSERT INTO $table SET c_id = $course_id , expires_on = '".Database::escape_string($expiryDate)."', ends_on = '".Database::escape_string($endDate)."', add_to_calendar = $agendaId, enable_qualification = '$qualification', publication_id = '$workId'"; Database::query($sql); $my_last_id = Database::insert_id(); $sql = "UPDATE $workTable SET has_properties = $my_last_id , view_properties = 1 WHERE c_id = $course_id AND id = $workId"; Database::query($sql); } else { $sql = "UPDATE $table SET expires_on = '".$expiryDate."', ends_on = '".$endDate."', add_to_calendar = $agendaId, enable_qualification = '".$qualification."' WHERE publication_id = $workId AND c_id = $course_id AND id = ".$data['id']; Database::query($sql); } if (!empty($params['category_id'])) { require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/gradebookitem.class.php'; require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/evaluation.class.php'; require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/abstractlink.class.php'; require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php'; $link_info = is_resource_in_course_gradebook( $courseInfo['code'], LINK_STUDENTPUBLICATION, $workId, api_get_session_id() ); $linkId = null; if (!empty($link_info)) { $linkId = $link_info['id']; } if (isset($params['make_calification']) && $params['make_calification'] == 1) { if (empty($linkId)) { add_resource_to_course_gradebook( $params['category_id'], $courseInfo['code'], LINK_STUDENTPUBLICATION, $workId, $params['dir_name'], (float)$params['weight'], (float)$params['qualification'], $params['description'], 1, api_get_session_id() ); } else { update_resource_from_course_gradebook( $linkId, $courseInfo['code'], $params['weight'] ); } } else { // Delete everything of the gradebook for this $linkId remove_resource_from_course_gradebook($linkId); } } }
/** * @param int $workId * @param array $params * @param array $courseInfo * @param int $groupId */ function updatePublicationAssignment($workId, $params, $courseInfo, $groupId) { $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT); $workTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION); $workId = intval($workId); $time = api_get_utc_datetime(); $course_id = $courseInfo['real_id']; // Insert into agenda $agendaId = 0; if (isset($params['add_to_calendar']) && $params['add_to_calendar'] == 1) { require_once api_get_path(SYS_CODE_PATH) . 'resourcelinker/resourcelinker.inc.php'; // Setting today date $date = $end_date = $time; if (isset($params['enableExpiryDate'])) { $end_date = $params['expires_on']; $date = $end_date; } $title = sprintf(get_lang('HandingOverOfTaskX'), $params['new_dir']); $description = isset($params['description']) ? $params['description'] : ''; $content = '<a href="' . api_get_path(WEB_CODE_PATH) . 'work/work_list.php?' . api_get_cidreq() . '&id=' . $workId . '">' . $params['new_dir'] . '</a>' . $description; $agendaId = agendaExistsForWork($workId, $courseInfo); // Add/edit agenda $agenda = new Agenda(); $agenda->set_course($courseInfo); $agenda->type = 'course'; if (empty($agendaId)) { $agendaId = $agenda->addEvent($date, $end_date, 'false', $title, $content, array('GROUP:' . $groupId)); } else { $agenda->editEvent($agendaId, $end_date, $end_date, 'false', $title, $content); } } $qualification = isset($params['qualification']) && !empty($params['qualification']) ? 1 : 0; $expiryDate = isset($params['enableExpiryDate']) && $params['enableExpiryDate'] == 1 ? api_get_utc_datetime($params['expires_on']) : ''; $endDate = isset($params['enableEndDate']) && $params['enableEndDate'] == 1 ? api_get_utc_datetime($params['ends_on']) : ''; $data = get_work_assignment_by_id($workId, $course_id); if (!empty($expiryDate)) { $expiryDateCondition = "expires_on = '" . Database::escape_string($expiryDate) . "', "; } else { $expiryDateCondition = "expires_on = null, "; } if (!empty($endDate)) { $endOnCondition = "ends_on = '" . Database::escape_string($endDate) . "', "; } else { $endOnCondition = "ends_on = null, "; } if (empty($data)) { $sql = "INSERT INTO {$table} SET\n c_id = {$course_id} ,\n {$expiryDateCondition}\n {$endOnCondition}\n add_to_calendar = {$agendaId},\n enable_qualification = '{$qualification}',\n publication_id = '{$workId}'"; Database::query($sql); $my_last_id = Database::insert_id(); if ($my_last_id) { $sql = "UPDATE {$table} SET\n id = iid\n WHERE iid = {$my_last_id}"; Database::query($sql); $sql = "UPDATE {$workTable} SET\n has_properties = {$my_last_id},\n view_properties = 1\n WHERE c_id = {$course_id} AND id = {$workId}"; Database::query($sql); } } else { $sql = "UPDATE {$table} SET\n {$expiryDateCondition}\n {$endOnCondition}\n add_to_calendar = {$agendaId},\n enable_qualification = '" . $qualification . "'\n WHERE\n publication_id = {$workId} AND\n c_id = {$course_id} AND\n id = " . $data['id']; Database::query($sql); } if (!empty($params['category_id'])) { $link_info = GradebookUtils::is_resource_in_course_gradebook($courseInfo['code'], LINK_STUDENTPUBLICATION, $workId, api_get_session_id()); $linkId = null; if (!empty($link_info)) { $linkId = $link_info['id']; } if (isset($params['make_calification']) && $params['make_calification'] == 1) { if (empty($linkId)) { GradebookUtils::add_resource_to_course_gradebook($params['category_id'], $courseInfo['code'], LINK_STUDENTPUBLICATION, $workId, $params['new_dir'], (double) $params['weight'], (double) $params['qualification'], $params['description'], 1, api_get_session_id()); } else { GradebookUtils::update_resource_from_course_gradebook($linkId, $courseInfo['code'], $params['weight']); } } else { // Delete everything of the gradebook for this $linkId GradebookUtils::remove_resource_from_course_gradebook($linkId); } } }