<commit_before><?php

class SwitchFlitController extends Controller
{
	private static $url_handlers = [
		'$DataObject/records' => 'getRecordsForDataObject'
	];

	private static $allowed_actions = [
		'getRecordsForDataObject'
	];

	/**
	 * Pulls all items from a SwitchFlitable DataObject and returns them as JSON.
	 *
	 * @param SS_HTTPRequest $request The current request.
	 * @return string The data in JSON format.
	 *
	 * @todo Allow custom columns? Pagination considerations?
	 */
	public function getRecordsForDataObject(SS_HTTPRequest $request)
	{
		$dataobject = $request->param('DataObject');

		if (! class_exists($dataobject)) {
			throw new Exception('The class ' . $dataobject . ' does not exist.');
		}

		if (! in_array('DataObject', class_parents($dataobject))) {
			throw new Exception('The class ' . $dataobject . ' is not a DataObject.');
		}

		if (! in_array('SwitchFlit\SwitchFlitable', class_implements($dataobject))) {
			throw new Exception('The class ' . $dataobject . ' is not SwitchFlitable.');
		}

		$records = $dataobject::get();
		$data = [];

		foreach ($records as $record) {
			$data[] = [
				'title' => $record->SwitchFlitTitle(),<commit_msg>Implements permission check (fixes #10).<commit_after><?php

class SwitchFlitController extends Controller
{
	private static $url_handlers = [
		'$DataObject/records' => 'getRecordsForDataObject'
	];

	private static $allowed_actions = [
		'getRecordsForDataObject'
	];

	/**
	 * Pulls all items from a SwitchFlitable DataObject and returns them as JSON.
	 *
	 * @param SS_HTTPRequest $request The current request.
	 * @return string The data in JSON format.
	 *
	 * @todo Allow custom columns? Pagination considerations?
	 */
	public function getRecordsForDataObject(SS_HTTPRequest $request)
	{
		$dataobject = $request->param('DataObject');

		if (! class_exists($dataobject)) {
			throw new Exception('The class ' . $dataobject . ' does not exist.');
		}

		if (! in_array('DataObject', class_parents($dataobject))) {
			throw new Exception('The class ' . $dataobject . ' is not a DataObject.');
		}

		if (! in_array('SwitchFlit\SwitchFlitable', class_implements($dataobject))) {
			throw new Exception('The class ' . $dataobject . ' is not SwitchFlitable.');
		}

		$records = $dataobject::get();
		$data = [];

		foreach ($records as $record) {
			if (! $record->canView()) continue;

			$data[] = [
				'title' => $record->SwitchFlitTitle(),
{'fraction_non_alphanumeric': 0.13791683820502265, 'fraction_numerical': 0.0008233841086867024, 'mean_word_length': 4.203426124197002, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, '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': '4599467', 'n_tokens_mistral': 796, 'n_tokens_neox': 721, 'n_words': 194}