Compare commits

...

5 Commits

  1. 4
      main/inc/lib/extra_field.lib.php
  2. 1
      main/inc/lib/extra_field_value.lib.php
  3. 72
      main/inc/lib/webservices/Rest.php
  4. 18
      main/webservices/api/v2.php
  5. 1
      src/Chamilo/CoreBundle/Entity/ExtraField.php

@ -178,6 +178,9 @@ class ExtraField extends Model
case 'attendance_calendar':
$this->extraFieldType = EntityExtraField::ATTENDANCE_CALENDAR_TYPE;
break;
case 'attendance':
$this->extraFieldType = EntityExtraField::ATTENDANCE_TYPE;
break;
}
$this->pageUrl = 'extra_fields.php?type='.$this->type;
@ -213,6 +216,7 @@ class ExtraField extends Model
'message',
'document',
'attendance_calendar',
'attendance',
];
if (api_get_configuration_value('allow_scheduled_announcements')) {

@ -963,6 +963,7 @@ class ExtraFieldValue extends Model
}
/**
* Return extra fields details for an item if the extra field is marked as filter.
* @param int $itemId
*
* @return array

@ -109,8 +109,8 @@ class Rest extends WebService
public const GET_COURSES_FROM_EXTRA_FIELD = 'get_courses_from_extra_field';
public const SAVE_COURSE = 'save_course';
public const DELETE_COURSE = 'delete_course';
public const GET_SESSION_FROM_EXTRA_FIELD = 'get_session_from_extra_field';
public const GET_SESSION_INFO_FROM_EXTRA_FIELD = 'get_session_info_from_extra_field';
public const SAVE_SESSION = 'save_session';
public const CREATE_SESSION_FROM_MODEL = 'create_session_from_model';
public const UPDATE_SESSION = 'update_session';
@ -1682,7 +1682,7 @@ class Rest extends WebService
*
* @throws Exception
*/
public function getSessionsCampus(int $campusId = 0): array
public function getSessionsCampus(int $campusId = 0, bool $getExtraFields = false): array
{
self::protectAdminEndpoint();
@ -1695,12 +1695,18 @@ class Rest extends WebService
);
$shortList = [];
foreach ($list as $session) {
$shortList[] = [
$bundle = [
'id' => $session['id'],
'name' => $session['name'],
'access_start_date' => $session['access_start_date'],
'access_end_date' => $session['access_end_date'],
];
if ($getExtraFields) {
$extraFieldValues = new ExtraFieldValue('session');
$extraFields = $extraFieldValues->getAllValuesByItem($session['id']);
$bundle['extra_fields'] = $extraFields;
}
$shortList[] = $bundle;
}
return $shortList;
@ -2508,18 +2514,18 @@ class Rest extends WebService
}
/**
* finds the session which has a specific value in a specific extra field.
* Finds the session which has a specific value in a specific extra field and return its ID (only that)
*
* @param $fieldName
* @param $fieldValue
* @param string $fieldName
* @param string $fieldValue
*
* @return int The matching session id, or an array with details about the session
* @throws Exception when no session matched or more than one session matched
*
* @return int, the matching session id
*/
public function getSessionFromExtraField($fieldName, $fieldValue)
public function getSessionFromExtraField(string $fieldName, string $fieldValue)
{
// find sessions that that have value in field
// find sessions that have that value in the given field
$valueModel = new ExtraFieldValue('session');
$sessionIdList = $valueModel->get_item_id_from_field_variable_and_field_value(
$fieldName,
@ -2543,6 +2549,54 @@ class Rest extends WebService
return intval($sessionIdList[0]['item_id']);
}
/**
* Finds the session which has a specific value in a specific extra field and return its details
*
* @param string $fieldName
* @param string $fieldValue
*
* @return array The matching session id, or an array with details about the session
* @throws Exception when no session matched or more than one session matched
*
*/
public function getSessionInfoFromExtraField(string $fieldName, string $fieldValue): array
{
$session = [];
// find sessions that have that value in the given field
$valueModel = new ExtraFieldValue('session');
$sessionIdList = $valueModel->get_item_id_from_field_variable_and_field_value(
$fieldName,
$fieldValue,
false,
false,
true
);
// throw if none found
if (empty($sessionIdList)) {
throw new Exception(get_lang('NoSessionMatched'));
}
// throw if more than one found
if (count($sessionIdList) > 1) {
throw new Exception(get_lang('MoreThanOneSessionMatched'));
}
$session = api_get_session_info($sessionIdList[0]['item_id']);
$bundle = [
'id' => $session['id'],
'name' => $session['name'],
'access_start_date' => $session['access_start_date'],
'access_end_date' => $session['access_end_date'],
];
$extraFieldValues = new ExtraFieldValue('session');
$extraFields = $extraFieldValues->getAllValuesByItem($session['id']);
$bundle['extra_fields'] = $extraFields;
// return session details, including extra fields that have filter=1
return $bundle;
}
/**
* Get a list of users subscribed to the given session.
*

@ -751,6 +751,18 @@ try {
);
$restResponse->setData([$idSession]);
break;
case Rest::GET_SESSION_INFO_FROM_EXTRA_FIELD:
if (empty($_POST['field_name']) || empty($_POST['field_value'])) {
throw new Exception(get_lang('NoData'));
}
$idSession = $restApi->getSessionInfoFromExtraField($_POST['field_name'], $_POST['field_value']);
Event::addEvent(
LOG_WS.$action,
'extra_field_name-extra_field_value',
Database::escape_string($_POST['field_name']).':'.Database::escape_string($_POST['field_value'])
);
$restResponse->setData([$idSession]);
break;
case Rest::SAVE_SESSION:
$data = $restApi->addSession($_POST);
Event::addEvent(LOG_WS.$action, 'session_id', $data['id_session']);
@ -794,8 +806,12 @@ try {
if (!empty($_POST['id_campus'])) {
$campusId = (int) $_POST['id_campus'];
}
$getExtraFields = false;
if (!empty($_POST['get_extra_fields']) && ('false' != $_POST['get_extra_fields'])) {
$getExtraFields = true;
}
Event::addEvent(LOG_WS.$action, 'id_campus', $campusId);
$data = $restApi->getSessionsCampus($campusId);
$data = $restApi->getSessionsCampus($campusId, $getExtraFields);
$restResponse->setData($data);
break;
case Rest::ADD_COURSES_SESSION:

@ -43,6 +43,7 @@ class ExtraField extends BaseAttribute
public const MESSAGE_TYPE = 22;
public const DOCUMENT_TYPE = 23;
public const ATTENDANCE_CALENDAR_TYPE = 24;
public const ATTENDANCE_TYPE = 25;
/**
* @var int

Loading…
Cancel
Save