<commit_before><?php
App::uses('AppController', 'Controller');

class StaffController extends AppController {
	public $helpers = ['ScoreEngine.EngineOutputter'];
	public $uses = [
		'Config', 'Inject', 'Log', 'Grade', 'Group', 'Schedule', 'Submission',
		'ScoreEngine.Check', 'ScoreEngine.Service', 'ScoreEngine.Team'
	];

	/**
	 * Pagination Settings
	 */
	public $paginate = [
		'Log' => [
			'fields' => [
				'Log.id', 'Log.time', 'Log.type', 'Log.data',
				'Log.ip', 'Log.message', 'User.username', 'User.group_id',
			],
			'contain' => [
				'User' => [
					'Group.name',
				]
			],
			'order' => [
				'Log.id' => 'DESC'
			],
		],

		'OnlyGraded' => [
			'fields' => [
				'Submission.id', 'Submission.created', 'Submission.deleted',
				'Inject.id', 'Inject.title', 'Inject.sequence', 'Inject.type',
				'User.username', 'Group.name', 'Group.team_number',
				'Grade.created', 'Grade.grade', 'Grade.comments',
				'Grader.username',
			],
			'joins' => [
				[
					'table'      => 'users',
					'alias'      => 'Grader',
					'type'       => 'LEFT',
					'conditions' => [
						'Grader.id = Grade.grader_id',
					],
				]
			],
			'conditions' => [
				'OR' => [
					'Grade.created IS NOT NULL',
					'Submission.deleted' => true,
				],
			],
			'order' => [
				'Grade.created' => 'DESC',
				'Submission.created' => 'DESC',
			],
		],
	];

	public function beforeFilter() {
		parent::beforeFilter();

		// Enforce staff only
		$this->Auth->protect(env('GROUP_STAFF'));

		// Load + setup the InjectStyler helper
		$this->helpers[] = 'InjectStyler';
		$this->helpers['InjectStyler'] = [
			'types'  => $this->Config->getInjectTypes(),
			'inject' => new stdClass(), // Nothing...for now
		];

		// We're at the staff page
		$this->set('at_staff', true);
	}

	public function beforeRender() {
		parent::beforeRender();

		// Setup the ScoreEngine EngineOutputter
		$this->helpers['ScoreEngine.EngineOutputter']['data'] = $this->Check->getChecksTable(
			$this->Team->find('all'),
			$this->Service->find('all')
		);
	}

	/**
	 * Competition Overview Page
	 *
	 * @url /staff
	 * @url /staff/index
	 */
	public function index() {
		$this->set('active_injects', $this->Schedule->getInjects(env('GROUP_BLUE')));
		$this->set('recent_expired', $this->Schedule->getRecentExpired(env('GROUP_BLUE')));

		$this->Paginator->settings += $this->paginate['Log'];
		$this->set('recent_logs', $this->Paginator->paginate('Log'));
	}

	/**
	 * Inject View Page
	 *
	 * @url /staff/inject/<id>
	 */
	public function inject($id=false) {
		$inject = $this->Inject->findById($id);
		if ( empty($inject) ) {
			throw new NotFoundException('Unknown Inject');
		}
	}

	/**
	 * Grader Island Page
	 *
	 * @url /staff/graders
	 */
	public function graders() {
		$this->set('ungraded', $this->Submission->getAllUngradedSubmissions());

		$this->Paginator->settings += $this->paginate['OnlyGraded'];
		$this->set('graded', $this->Paginator->paginate('Submission'));
	}

	/**
	 * Submission Grade Page
	 *
	 * @url /staff/grade/<sid>
	 */
	public function grade($sid=false) {
		$submission = $this->Submission->getSubmission($sid);
		if ( empty($submission) ) {
			throw new NotFoundException('Unknown submission');
		}

		if ( $this->request->is('post') ) {
			if (
				!isset($this->request->data['grade']) ||
				!isset($this->request->data['comments']) ||
				empty($this->request->data['grade']) ||
				empty($this->request->data['comments']) ||
				$this->request->data['grade'] > $submission['Inject']['max_points']
			) {
				$this->Flash->danger('Incomplete data. Please try again.');
				return $this->redirect('/staff/grade/'.$sid);
			}<commit_msg>Allow a grade of 0<commit_after><?php
App::uses('AppController', 'Controller');

class StaffController extends AppController {
	public $helpers = ['ScoreEngine.EngineOutputter'];
	public $uses = [
		'Config', 'Inject', 'Log', 'Grade', 'Group', 'Schedule', 'Submission',
		'ScoreEngine.Check', 'ScoreEngine.Service', 'ScoreEngine.Team'
	];

	/**
	 * Pagination Settings
	 */
	public $paginate = [
		'Log' => [
			'fields' => [
				'Log.id', 'Log.time', 'Log.type', 'Log.data',
				'Log.ip', 'Log.message', 'User.username', 'User.group_id',
			],
			'contain' => [
				'User' => [
					'Group.name',
				]
			],
			'order' => [
				'Log.id' => 'DESC'
			],
		],

		'OnlyGraded' => [
			'fields' => [
				'Submission.id', 'Submission.created', 'Submission.deleted',
				'Inject.id', 'Inject.title', 'Inject.sequence', 'Inject.type',
				'User.username', 'Group.name', 'Group.team_number',
				'Grade.created', 'Grade.grade', 'Grade.comments',
				'Grader.username',
			],
			'joins' => [
				[
					'table'      => 'users',
					'alias'      => 'Grader',
					'type'       => 'LEFT',
					'conditions' => [
						'Grader.id = Grade.grader_id',
					],
				]
			],
			'conditions' => [
				'OR' => [
					'Grade.created IS NOT NULL',
					'Submission.deleted' => true,
				],
			],
			'order' => [
				'Grade.created' => 'DESC',
				'Submission.created' => 'DESC',
			],
		],
	];

	public function beforeFilter() {
		parent::beforeFilter();

		// Enforce staff only
		$this->Auth->protect(env('GROUP_STAFF'));

		// Load + setup the InjectStyler helper
		$this->helpers[] = 'InjectStyler';
		$this->helpers['InjectStyler'] = [
			'types'  => $this->Config->getInjectTypes(),
			'inject' => new stdClass(), // Nothing...for now
		];

		// We're at the staff page
		$this->set('at_staff', true);
	}

	public function beforeRender() {
		parent::beforeRender();

		// Setup the ScoreEngine EngineOutputter
		$this->helpers['ScoreEngine.EngineOutputter']['data'] = $this->Check->getChecksTable(
			$this->Team->find('all'),
			$this->Service->find('all')
		);
	}

	/**
	 * Competition Overview Page
	 *
	 * @url /staff
	 * @url /staff/index
	 */
	public function index() {
		$this->set('active_injects', $this->Schedule->getInjects(env('GROUP_BLUE')));
		$this->set('recent_expired', $this->Schedule->getRecentExpired(env('GROUP_BLUE')));

		$this->Paginator->settings += $this->paginate['Log'];
		$this->set('recent_logs', $this->Paginator->paginate('Log'));
	}

	/**
	 * Inject View Page
	 *
	 * @url /staff/inject/<id>
	 */
	public function inject($id=false) {
		$inject = $this->Inject->findById($id);
		if ( empty($inject) ) {
			throw new NotFoundException('Unknown Inject');
		}
	}

	/**
	 * Grader Island Page
	 *
	 * @url /staff/graders
	 */
	public function graders() {
		$this->set('ungraded', $this->Submission->getAllUngradedSubmissions());

		$this->Paginator->settings += $this->paginate['OnlyGraded'];
		$this->set('graded', $this->Paginator->paginate('Submission'));
	}

	/**
	 * Submission Grade Page
	 *
	 * @url /staff/grade/<sid>
	 */
	public function grade($sid=false) {
		$submission = $this->Submission->getSubmission($sid);
		if ( empty($submission) ) {
			throw new NotFoundException('Unknown submission');
		}

		if ( $this->request->is('post') ) {
			if (
				!isset($this->request->data['grade']) ||
				!isset($this->request->data['comments']) ||
				(empty($this->request->data['grade']) && $this->request->data['grade'] != 0) ||
				empty($this->request->data['comments']) ||
				$this->request->data['grade'] > $submission['Inject']['max_points']
			) {
				$this->Flash->danger('Incomplete data. Please try again.');
				return $this->redirect('/staff/grade/'.$sid);
			}
{'fraction_non_alphanumeric': 0.21872873281611543, 'fraction_numerical': 0.00027221995372260786, 'mean_word_length': 3.4345202172601086, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 161, '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': '4719262', 'n_tokens_mistral': 2959, 'n_tokens_neox': 2521, 'n_words': 412}