예제 #1
0
/**
 * @param int $start
 * @param int $limit
 * @param string $column
 * @param string $direction
 * @param string $where_condition
 * @param bool $getCount
 * @return array
 */
function getWorkListTeacher(
    $start,
    $limit,
    $column,
    $direction,
    $where_condition,
    $getCount = false
) {
    $workTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
    $workTableAssignment  = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);

    $course_id = api_get_course_int_id();
    $session_id = api_get_session_id();
    $condition_session = api_get_session_condition($session_id);
    $group_id = api_get_group_id();
    $is_allowed_to_edit = api_is_allowed_to_edit() || api_is_coach();

    if (!in_array($direction, array('asc', 'desc'))) {
        $direction = 'desc';
    }

    $column = !empty($column) ? Database::escape_string($column) : 'sent_date';
    $start = intval($start);
    $limit = intval($limit);
    $works = array();

    // Get list from database
    if ($is_allowed_to_edit) {
        $active_condition = ' active IN (0, 1)';
        if ($getCount) {
            $select = " SELECT count(w.id) as count";
        } else {
            $select = " SELECT w.*, a.expires_on, expires_on, ends_on, enable_qualification ";
        }
        $sql = " $select
                FROM $workTable w
                LEFT JOIN $workTableAssignment a ON (a.publication_id = w.id AND a.c_id = w.c_id)
                WHERE
                    w.c_id = $course_id
                    $condition_session AND
                    $active_condition AND
                    (parent_id = 0) AND
                    post_group_id = '".$group_id."'
                    $where_condition
                ORDER BY $column $direction
                LIMIT $start, $limit";
        $result = Database::query($sql);

        if ($getCount) {
            $row = Database::fetch_array($result);
            return $row['count'];
        }
        $url = api_get_path(WEB_CODE_PATH).'work/work_list_all.php?'.api_get_cidreq();
        while ($work = Database::fetch_array($result, 'ASSOC')) {
            $workId = $work['id'];
            $work['type'] = Display::return_icon('work.png');
            $work['expires_on'] = $work['expires_on']  == '0000-00-00 00:00:00' ? null : api_get_local_time($work['expires_on']);

            $totalUsers = getStudentSubscribedToWork(
                $workId,
                $course_id,
                $group_id,
                $session_id,
                true
            );

            $countUniqueAttempts = getUniqueStudentAttemptsTotal(
                $workId,
                $group_id,
                $course_id,
                $session_id
            );

            $work['amount'] = Display::label(
                $countUniqueAttempts . '/' .
                $totalUsers,
                'success'
            );

            if (empty($work['title'])) {
                $work['title'] = basename($work['url']);
            }
            $work['title'] = Display::url($work['title'], $url.'&id='.$workId);
            $work['title'] .= ' '.Display::label(get_count_work($work['id']), 'success');
            $work['sent_date'] = api_get_local_time($work['sent_date']);

            $editLink = Display::url(
                Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL),
                api_get_path(WEB_CODE_PATH).'work/edit_work.php?id='.$workId.'&'.api_get_cidreq()
            );

            if ($countUniqueAttempts > 0) {
                $downloadLink = Display::url(
                    Display::return_icon(
                        'save_pack.png',
                        get_lang('Save'),
                        array(),
                        ICON_SIZE_SMALL
                    ),
                    api_get_path(WEB_CODE_PATH) . 'work/downloadfolder.inc.php?id=' . $workId . '&' . api_get_cidreq()
                );
            } else {
                $downloadLink = Display::url(
                    Display::return_icon(
                        'save_pack_na.png',
                        get_lang('Save'),
                        array(),
                        ICON_SIZE_SMALL
                    ),
                    '#'
                );
            }
            $deleteUrl = api_get_path(WEB_CODE_PATH).'work/work.php?id='.$workId.'&action=delete_dir&'.api_get_cidreq();
            $deleteLink = '<a href="#" onclick="showConfirmationPopup(this, \'' . $deleteUrl . '\' ) " >' .
                Display::return_icon(
                    'delete.png',
                    get_lang('Delete'),
                    array(),
                    ICON_SIZE_SMALL
                ) . '</a>';

            if (!api_is_allowed_to_edit()) {
                $deleteLink = null;
                $editLink = null;
            }
            $work['actions'] = $downloadLink.$editLink.$deleteLink;
            $works[] = $work;
        }
    }

    return $works;
}
예제 #2
0
/**
 * @param int $start
 * @param int $limit
 * @param string $column
 * @param string $direction
 * @param string $where_condition
 * @param bool $getCount
 * @return array
 */
function getWorkListTeacher($start, $limit, $column, $direction, $where_condition, $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();
    $session_id = api_get_session_id();
    $condition_session = api_get_session_condition($session_id);
    $group_id = api_get_group_id();
    $is_allowed_to_edit = api_is_allowed_to_edit() || api_is_coach();
    if (!in_array($direction, array('asc', 'desc'))) {
        $direction = 'desc';
    }
    if (!empty($where_condition)) {
        $where_condition = ' AND ' . $where_condition;
    }
    $column = !empty($column) ? Database::escape_string($column) : 'sent_date';
    $start = intval($start);
    $limit = intval($limit);
    $works = array();
    // Get list from database
    if ($is_allowed_to_edit) {
        $active_condition = ' active IN (0, 1)';
        if ($getCount) {
            $select = " SELECT count(w.id) as count";
        } else {
            $select = " SELECT w.*, a.expires_on, expires_on, ends_on, enable_qualification ";
        }
        $sql = " {$select}\n                FROM {$workTable} w\n                LEFT JOIN {$workTableAssignment} a\n                ON (a.publication_id = w.id AND a.c_id = w.c_id)\n                WHERE\n                    w.c_id = {$course_id}\n                    {$condition_session} AND\n                    {$active_condition} AND\n                    (parent_id = 0) AND\n                    post_group_id = '" . $group_id . "'\n                    {$where_condition}\n                ORDER BY {$column} {$direction}\n                LIMIT {$start}, {$limit}";
        $result = Database::query($sql);
        if ($getCount) {
            $row = Database::fetch_array($result);
            return $row['count'];
        }
        $url = api_get_path(WEB_CODE_PATH) . 'work/work_list_all.php?' . api_get_cidreq();
        while ($work = Database::fetch_array($result, 'ASSOC')) {
            $workId = $work['id'];
            $work['type'] = Display::return_icon('work.png');
            $work['expires_on'] = empty($work['expires_on']) ? null : api_get_local_time($work['expires_on']);
            $totalUsers = getStudentSubscribedToWork($workId, $course_id, $group_id, $session_id, true);
            $countUniqueAttempts = getUniqueStudentAttemptsTotal($workId, $group_id, $course_id, $session_id);
            $work['amount'] = Display::label($countUniqueAttempts . '/' . $totalUsers, 'success');
            $visibility = api_get_item_visibility($courseInfo, 'work', $workId, $session_id);
            if ($visibility == 1) {
                $icon = 'visible.png';
                $text = get_lang('Visible');
                $action = 'invisible';
                $class = '';
            } else {
                $icon = 'invisible.png';
                $text = get_lang('Invisible');
                $action = 'visible';
                $class = 'muted';
            }
            $visibilityLink = Display::url(Display::return_icon($icon, $text, array(), ICON_SIZE_SMALL), api_get_path(WEB_CODE_PATH) . 'work/work.php?id=' . $workId . '&action=' . $action . '&' . api_get_cidreq());
            if (empty($work['title'])) {
                $work['title'] = basename($work['url']);
            }
            $work['title'] = Display::url($work['title'], $url . '&id=' . $workId, ['class' => $class]);
            $work['title'] .= ' ' . Display::label(get_count_work($work['id']), 'success');
            $work['sent_date'] = api_get_local_time($work['sent_date']);
            $editLink = Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL), api_get_path(WEB_CODE_PATH) . 'work/edit_work.php?id=' . $workId . '&' . api_get_cidreq());
            $correctionLink = Display::url(Display::return_icon('upload_file.png', get_lang('UploadCorrections'), '', ICON_SIZE_SMALL), api_get_path(WEB_CODE_PATH) . 'work/upload_corrections.php?' . api_get_cidreq() . '&id=' . $workId);
            if ($countUniqueAttempts > 0) {
                $downloadLink = Display::url(Display::return_icon('save_pack.png', get_lang('Save'), array(), ICON_SIZE_SMALL), api_get_path(WEB_CODE_PATH) . 'work/downloadfolder.inc.php?id=' . $workId . '&' . api_get_cidreq());
            } else {
                $downloadLink = Display::url(Display::return_icon('save_pack_na.png', get_lang('Save'), array(), ICON_SIZE_SMALL), '#');
            }
            // Remove Delete Work Button from action List
            // Because removeXSS "removes" the onClick JS Event to do the action (See model.ajax.php - Line 1639)
            // But still can use the another jqgrid button to remove works (trash icon)
            //
            // $deleteUrl = api_get_path(WEB_CODE_PATH).'work/work.php?id='.$workId.'&action=delete_dir&'.api_get_cidreq();
            // $deleteLink = '<a href="#" onclick="showConfirmationPopup(this, \'' . $deleteUrl . '\' ) " >' .
            //     Display::return_icon(
            //         'delete.png',
            //         get_lang('Delete'),
            //         array(),
            //         ICON_SIZE_SMALL
            //     ) . '</a>';
            if (!api_is_allowed_to_edit()) {
                // $deleteLink = null;
                $editLink = null;
            }
            $work['actions'] = $visibilityLink . $correctionLink . $downloadLink . $editLink;
            $works[] = $work;
        }
    }
    return $works;
}