<?php
require __DIR__.'/db.php';$actor=json_decode(file_get_contents(__DIR__.'/private-actor.json'),true);$scope=json_decode(file_get_contents(__DIR__.'/private-scope.json'),true);$actorNow=static function()use($q,$p,$actor){return $q('SELECT ID,UUID,STAFF_UUID,ACCOUNT,TYPE,IS_DELETE FROM '.$p.'user WHERE ID=?',[$actor['id']])[0];};
$source=static function()use($q,$p,$scope,$check):array{$staff=$q('SELECT ID,UUID FROM '.$p.'staff WHERE UUID=?',[$scope['staff_uuid']]);$check(count($staff)===1,'Unique actual Staff');$rows=$q('SELECT * FROM '.$p.'syllabus_evaluate WHERE STAFF_UUID=? ORDER BY ID DESC',[$scope['staff_uuid']]);$ext=$q('SELECT ID,UUID,STAFF_UUID,CONTENT FROM '.$p.'syllabus_evaluate_ext WHERE STAFF_UUID=?',[$scope['staff_uuid']]);$check(count($ext)<=1,'No nondeterministic ext representative');foreach($rows as $r)foreach($r as $v)$check(!is_string($v)||strlen($v)<=262144,'Field cap256KiB');foreach($ext as $r)$check(strlen((string)$r['content'])<=262144,'Ext cap256KiB');$state=['staff'=>$staff,'rows'=>$rows,'ext'=>$ext];$check(strlen(json_encode($state))<=2097152,'Source cap2MiB');return $state;};
$listProjection=static function(array $row):array{return array_intersect_key($row,array_flip(['uuid','staff_uuid','test_content','test_time','achievement','demo']));};
$infoProjection=static function(array $row):array{$row['id']=(int)$row['id'];return $row;};
