<commit_before><?php

namespace app\controllers\admin;

use app\controllers\AbstractController;
use app\libraries\DateUtils;
use app\libraries\routers\AccessControl;
use app\libraries\response\Response;
use app\libraries\response\JsonResponse;
use app\libraries\response\WebResponse;
use Symfony\Component\Routing\Annotation\Route;

/**
 * Class LateController
 * @package app\controllers\admin
 * @AccessControl(role="INSTRUCTOR")
 */
class LateController extends AbstractController {
    public function run() {
        return null;
    }

    /**
     * @Route("/{_semester}/{_course}/late_days")
     * @return Response
     */
    public function viewLateDays() {
        return Response::WebOnlyResponse(
            new WebResponse(
                ['admin', 'LateDay'],
                'displayLateDays',
                $this->core->getQueries()->getUsersWithLateDays()
            )
        );
    }

    /**
     * @Route("/{_semester}/{_course}/extensions")
     * @return Response
     */
    public function viewExtensions() {
        return Response::WebOnlyResponse(
            new WebResponse(
                ['admin', 'Extensions'],
                'displayExtensions',
                $this->core->getQueries()->getAllElectronicGradeablesIds()
            )
        );
    }

    /**
     * @param $csv_option string csv_option_overwrite_all or csv_option_preserve_higher
     *
     * @Route("/{_semester}/{_course}/late_days/update", methods={"POST"})
     * @return Response
     */
    public function updateLateDays($csv_option = null) {
        if (isset($_FILES['csv_upload']) && (file_exists($_FILES['csv_upload']['tmp_name']))) {
            $data = array();
            if (!($this->parseAndValidateCsv($_FILES['csv_upload']['tmp_name'], $data, "late"))) {
                $error = "Something is wrong with the CSV you have chosen. Try again.";
                return Response::JsonOnlyResponse(
                    JsonResponse::getFailResponse($error)
                );
            }
            else {
                for ($i = 0; $i < count($data); $i++){
                    $this->core->getQueries()->updateLateDays($data[$i][0], $data[$i][1], $data[$i][2], $csv_option);
                }
                return $this->getLateDays();
            }
        }
        else {
            $user = current($this->core->getQueries()->getUsersById([$_POST['user_id']]));
            if (!$user) {
                $error = "Invalid Student ID";
                return Response::JsonOnlyResponse(
                    JsonResponse::getFailResponse($error)
                );
            }
            if (!isset($_POST['datestamp']) || !DateUtils::validateTimestamp($_POST['datestamp'])) {
                $error = "Datestamp must be mm/dd/yy";
                return Response::JsonOnlyResponse(
                    JsonResponse::getFailResponse($error)
                );
            }
            if (((!isset($_POST['late_days'])) || $_POST['late_days'] == "" || (!ctype_digit($_POST['late_days'])))) {
                $error = "Late Days must be a nonnegative integer";<commit_msg>[Bugfix:InstructorUI] date format on latedays extension (#4248)<commit_after><?php

namespace app\controllers\admin;

use app\controllers\AbstractController;
use app\libraries\DateUtils;
use app\libraries\routers\AccessControl;
use app\libraries\response\Response;
use app\libraries\response\JsonResponse;
use app\libraries\response\WebResponse;
use Symfony\Component\Routing\Annotation\Route;

/**
 * Class LateController
 * @package app\controllers\admin
 * @AccessControl(role="INSTRUCTOR")
 */
class LateController extends AbstractController {
    public function run() {
        return null;
    }

    /**
     * @Route("/{_semester}/{_course}/late_days")
     * @return Response
     */
    public function viewLateDays() {
        return Response::WebOnlyResponse(
            new WebResponse(
                ['admin', 'LateDay'],
                'displayLateDays',
                $this->core->getQueries()->getUsersWithLateDays()
            )
        );
    }

    /**
     * @Route("/{_semester}/{_course}/extensions")
     * @return Response
     */
    public function viewExtensions() {
        return Response::WebOnlyResponse(
            new WebResponse(
                ['admin', 'Extensions'],
                'displayExtensions',
                $this->core->getQueries()->getAllElectronicGradeablesIds()
            )
        );
    }

    /**
     * @param $csv_option string csv_option_overwrite_all or csv_option_preserve_higher
     *
     * @Route("/{_semester}/{_course}/late_days/update", methods={"POST"})
     * @return Response
     */
    public function updateLateDays($csv_option = null) {
        if (isset($_FILES['csv_upload']) && (file_exists($_FILES['csv_upload']['tmp_name']))) {
            $data = array();
            if (!($this->parseAndValidateCsv($_FILES['csv_upload']['tmp_name'], $data, "late"))) {
                $error = "Something is wrong with the CSV you have chosen. Try again.";
                return Response::JsonOnlyResponse(
                    JsonResponse::getFailResponse($error)
                );
            }
            else {
                for ($i = 0; $i < count($data); $i++){
                    $this->core->getQueries()->updateLateDays($data[$i][0], $data[$i][1], $data[$i][2], $csv_option);
                }
                return $this->getLateDays();
            }
        }
        else {
            $user = current($this->core->getQueries()->getUsersById([$_POST['user_id']]));
            if (!$user) {
                $error = "Invalid Student ID";
                return Response::JsonOnlyResponse(
                    JsonResponse::getFailResponse($error)
                );
            }
            if (!isset($_POST['datestamp']) ||  (\DateTime::createFromFormat('Y-m-d', $_POST['datestamp']) === false)) {
                $error = "Datestamp must be Y-m-d";
                return Response::JsonOnlyResponse(
                    JsonResponse::getFailResponse($error)
                );
            }
            if (((!isset($_POST['late_days'])) || $_POST['late_days'] == "" || (!ctype_digit($_POST['late_days'])))) {
                $error = "Late Days must be a nonnegative integer";
{'fraction_non_alphanumeric': 0.14900714853057984, 'fraction_numerical': 0.0019062748212867356, 'mean_word_length': 2.1292246520874754, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3304701', 'n_tokens_mistral': 1782, 'n_tokens_neox': 1667, 'n_words': 297}