/** * Initialize all of the class variables and things required from the * REQUEST. * * @return none, but as a side-effect modifies class */ function initialize() { ob_start('ob_gzhandler'); $client = new NDB_Client(); $client->makeCommandLine(); $client->initialize(); $this->caller =& NDB_Caller::singleton(); $this->caller->setDataEntryType('Direct'); if (empty($_REQUEST['key'])) { throw new Exception("Missing parameter", 403); } $this->key = $_REQUEST['key']; $DB = Database::singleton(); $this->TestName = $DB->pselectOne("SELECT Test_name FROM participant_accounts\n WHERE OneTimePassword=:key AND Status <> 'Complete'", array('key' => $this->key)); $this->CommentID = $DB->pselectOne("SELECT CommentID FROM participant_accounts \n WHERE OneTimePassword=:key AND Status <> 'Complete'", array('key' => $this->key)); $this->NumPages = $DB->pselectOne("SELECT COUNT(*) FROM instrument_subtests WHERE Test_name=:TN", array('TN' => $this->TestName)); if (empty($this->TestName) && empty($this->CommentID)) { throw new Exception("Data has already been submitted.", 403); } $pageNum = null; if (!empty($_REQUEST['pageNum'])) { $pageNum = $_REQUEST['pageNum']; } if ($pageNum === 'finalpage') { $this->Subtest = 'finalpage'; } else { $this->Subtest = $DB->pselectOne("SELECT Subtest_name\n FROM instrument_subtests\n WHERE Test_name=:TN AND Order_number=:PN", array('TN' => $this->TestName, 'PN' => $pageNum)); } $totalPages = $DB->pselectOne("SELECT COUNT(*)+1 from instrument_subtests WHERE Test_name=:TN", array('TN' => $this->TestName)); $this->NextPageNum = $this->getNextPageNum($pageNum); $this->PrevPageNum = $this->getPrevPageNum($pageNum); $this->CommentID = $this->getCommentID(); $this->tpl_data = array('nextpage' => $this->NextPageNum, 'prevpage' => $this->PrevPageNum, 'pageNum' => $pageNum ? $pageNum + 1 : 1, 'totalPages' => $totalPages, 'key' => $this->key); }
function setUp() { $client = new NDB_Client(); $client->makeCommandLine(); $client->initialize(); $this->DB = Database::singleton(); $this->DB->setFakeTableData("test_names", array(array('ID' => 1, 'Test_name' => 'ActiveTestByAge', 'Full_name' => 'Active Test 1', 'Sub_group' => 1, 'IsDirectEntry' => 0), array('ID' => 2, 'Test_name' => 'ActiveTestByAge2', 'Full_name' => 'Active Test 2', 'Sub_group' => 1, 'IsDirectEntry' => 0), array('ID' => 3, 'Test_name' => 'InactiveTest', 'Full_name' => 'Inactive Test 1', 'Sub_group' => 1, 'IsDirectEntry' => 0), array('ID' => 4, 'Test_name' => 'ActiveTestByVisit', 'Full_name' => 'Active Test by Visit 1', 'Sub_group' => 1, 'IsDirectEntry' => 0), array('ID' => 5, 'Test_name' => 'ActiveTestByVisit2', 'Full_name' => 'Active Test by Visit 2', 'Sub_group' => 1, 'IsDirectEntry' => 0), array('ID' => 6, 'Test_name' => 'ActiveTestByFirstVisit', 'Full_name' => 'Active Test by First Visit 2', 'Sub_group' => 1, 'IsDirectEntry' => 0), array('ID' => 7, 'Test_name' => 'ActiveTestByNotFirstVisit', 'Full_name' => 'Active Test by Not First Visit 2', 'Sub_group' => 1, 'IsDirectEntry' => 0))); $this->DB->setFakeTableData("test_battery", array(array('ID' => 1, 'Test_name' => 'ActiveTestByAge', 'AgeMinDays' => 0, 'AgeMaxDays' => 100, 'Active' => 'Y', 'Stage' => 'Visit', 'SubprojectID' => 1, 'Visit_label' => null, 'CenterID' => null, 'firstVisit' => null), array('ID' => 2, 'Test_name' => 'ActiveTestByAge2', 'AgeMinDays' => 0, 'AgeMaxDays' => 100, 'Active' => 'Y', 'Stage' => 'Visit', 'SubprojectID' => 1, 'Visit_label' => null, 'CenterID' => '1', 'firstVisit' => null), array('ID' => 3, 'Test_name' => 'InactiveTest', 'AgeMinDays' => 0, 'AgeMaxDays' => 0, 'Active' => 'N', 'Stage' => 'Visit', 'SubprojectID' => 2, 'Visit_label' => 'V01', 'CenterID' => '1', 'firstVisit' => null), array('ID' => 4, 'Test_name' => 'ActiveTestByVisit', 'AgeMinDays' => 0, 'AgeMaxDays' => 0, 'Active' => 'Y', 'Stage' => 'Visit', 'SubprojectID' => 2, 'Visit_label' => 'V01', 'CenterID' => null, 'firstVisit' => null), array('ID' => 5, 'Test_name' => 'ActiveTestByVisit2', 'AgeMinDays' => 0, 'AgeMaxDays' => 0, 'Active' => 'Y', 'Stage' => 'Visit', 'SubprojectID' => 2, 'Visit_label' => 'V01', 'CenterID' => '1', 'firstVisit' => null), array('ID' => 6, 'Test_name' => 'ActiveTestByFirstVisit', 'AgeMinDays' => 0, 'AgeMaxDays' => 100, 'Active' => 'Y', 'Stage' => 'Visit', 'SubprojectID' => 1, 'Visit_label' => null, 'CenterID' => '1', 'firstVisit' => 'Y'), array('ID' => 7, 'Test_name' => 'ActiveTestByNotFirstVisit', 'AgeMinDays' => 0, 'AgeMaxDays' => 100, 'Active' => 'Y', 'Stage' => 'Visit', 'SubprojectID' => 1, 'Visit_label' => null, 'CenterID' => '1', 'firstVisit' => 'N'))); }
function testSetFakeData() { $client = new NDB_Client(); $client->makeCommandLine(); $client->initialize(); $DB = Database::singleton(); $DB->setFakeTableData("Config", array(0 => array('ID' => 99999, 'ConfigID' => '123456', 'Value' => 'FKE1234'))); $allCandidates = $DB->pselect("SELECT * FROM Config", array()); $this->assertEquals($allCandidates, array(0 => array('ID' => 99999, 'ConfigID' => 123456, 'Value' => 'FKE1234'))); }
/** * Validates the data which was passed in the request. * * @param string $method The HTTP method of the request * @param array $data The array-encode JSON posted to * the URL. */ function __construct($method, $data = array()) { $this->AllowedMethods = array('POST'); $this->RequestData = $data; if (!in_array($method, $this->AllowedMethods)) { $this->header("HTTP/1.1 405 Method Not Allowed"); $this->header("Allow: " . join(", ", $this->AllowedMethods)); $this->safeExit(0); } $client = new \NDB_Client(); // Bypass session handling because we're trying to authenticate a session $client->makeCommandLine(); $client->initialize(__DIR__ . "/../../../project/config.xml"); $this->HTTPMethod = $method; $this->handleRequest(); }
<?php /** * User: Stella * Date: 15-08-15 * * Project Statistics - Updating Counts From Each LORIS */ set_include_path(get_include_path() . ":../php/libraries:"); require_once __DIR__ . "/../vendor/autoload.php"; $client = new NDB_Client(); $client->makeCommandLine(); $client->initialize('../project/config.xml'); $db =& Database::singleton(); $config = NDB_Config::singleton(); $date = date("m_d_Y"); $output_file = "project_statistics_{$date}.csv"; $fp = fopen($output_file, 'w'); echo "PROJECT STATISTICS SCRIPT - {$date}\n\n"; echo "Data can be found in {$output_file}.\n\n"; $headers = array('Project', 'Number of Scanning - Visits', 'Number of Sites', 'Variable Count', 'Number of instruments', 'total number of visits (for all candidates)', 'number of candidates', 'GB of imaging data (raw and processed)', '# of scans'); $counter = 0; // Where project's statistics will be stored $project_statistics = array(); // Project name $projectname = $config->getSetting('title'); // Number of Scanning - Visits $number_scanning_visits = $db->pselect("select count(*) from session where Scan_done='Y'", array()); // Number of Sites $number_sites = $db->pselect("select count(*) from psc WHERE CenterID <>1", array()); // Variable Count