Skip to main content

Proud to be part of LJMU,
in partnership with the Dill Faulkes Educational Trust

 

fetchAllAssoc('uid'); // Teacher name $q = "SELECT u.uid,d.field_name_value FROM {users} AS u LEFT JOIN {users_roles} AS r ON u.uid=r.uid RIGHT JOIN {profile} AS p ON u.uid=p.uid RIGHT JOIN {field_data_field_name} AS d ON p.pid=d.entity_id WHERE ".$teacherlike." ORDER BY u.uid"; $tchnm = db_query($q)->fetchAllAssoc('uid'); // School name $q = "SELECT u.uid,d.field_school_name_value FROM {users} AS u LEFT JOIN {users_roles} AS r ON u.uid=r.uid RIGHT JOIN {profile} AS p ON u.uid=p.uid RIGHT JOIN {field_data_field_school_name} AS d ON p.pid=d.entity_id WHERE ".$teacherlike." ORDER BY u.uid"; $schnm = db_query($q)->fetchAllAssoc('uid'); // School postcode $q = "SELECT u.uid,d.field_school_postcode_value FROM {users} AS u LEFT JOIN {users_roles} AS r ON u.uid=r.uid RIGHT JOIN {profile} AS p ON u.uid=p.uid RIGHT JOIN {field_data_field_school_postcode} AS d ON p.pid=d.entity_id WHERE ".$teacherlike." ORDER BY u.uid"; $schpc = db_query($q)->fetchAllAssoc('uid'); // Country (if UK or Eire) $q = "SELECT u.uid,d.field_country_value FROM {users} AS u LEFT JOIN {users_roles} AS r ON u.uid=r.uid RIGHT JOIN {profile} AS p ON u.uid=p.uid RIGHT JOIN {field_data_field_country} AS d ON p.pid=d.entity_id WHERE (field_country_value != 'Other') && ".$teacherlike." ORDER BY u.uid"; $ukeire = db_query($q)->fetchAllAssoc('uid'); // Other Country $q = "SELECT u.uid,d.field_other_country_iso2 FROM {users} AS u LEFT JOIN {users_roles} AS r ON u.uid=r.uid RIGHT JOIN {profile} AS p ON u.uid=p.uid RIGHT JOIN {field_data_field_other_country} AS d ON p.pid=d.entity_id WHERE (field_other_country_iso2 != '') && ".$teacherlike." ORDER BY u.uid"; $othcry = db_query($q)->fetchAllAssoc('uid'); // Schools Classifications $q = "SELECT u.uid,d.field_school_kind_value FROM {users} AS u LEFT JOIN {users_roles} AS r ON u.uid=r.uid RIGHT JOIN {profile} AS p ON u.uid=p.uid RIGHT JOIN {field_data_field_school_kind} AS d ON p.pid=d.entity_id WHERE ".$teacherlike." ORDER BY u.uid"; $schtyp = db_query($q)->fetchAllAssoc('uid'); // Age/Subject (can be multiple so cannot use the fetchAllAssoc $q = "SELECT u.uid,d.field_teach_subject_value FROM {users} AS u LEFT JOIN {users_roles} AS r ON u.uid=r.uid RIGHT JOIN {profile} AS p ON u.uid=p.uid RIGHT JOIN {field_data_field_teach_subject} AS d ON p.pid=d.entity_id WHERE ".$teacherlike." ORDER BY u.uid"; $agesub = db_query($q)->fetchAll(); // === Prepare the PHP varaible for the CSV file $csv = '"User ID","Username","Email","Teacher name","School name","Postcode","Country","School type","Age/Subject","No. students","Registered","Last access"\n'; // === Loop over all the UIDs and create a row each. foreach ($users as $u) { print " "; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; // Add a new line to the CSV variable $_l = '"'.$u->uid.'","'.str_replace(['"',"'"],'', $u->name).'","'.str_replace(['"',"'"],'', $u->mail).'","'.str_replace(['"',"'"],'', $tchnm[$u->uid]->field_name_value).'","'.str_replace(['"',"'"],'', $schnm[$u->uid]->field_school_name_value).'","'.str_replace(['"',"'"],'', $schpc[$u->uid]->field_school_postcode_value).'","'; if(array_key_exists($u->uid, $ukeire)) { print " \n"; $_l = $_l . str_replace(['"',"'"],'', $ukeire[$u->uid]->field_country_value).'","'; } else if(array_key_exists($u->uid, $othcry)) { print " \n"; $_l = $_l . str_replace(['"',"'"],'',$othcry[$u->uid]->field_other_country_iso2 ).'","'; } else { print "\n"; $_l = $_l . '","'; } print " \n"; $_l = $_l . str_replace(['"',"'"],'', $schtyp[$u->uid]->field_school_type_value).'","'; // Loop over all the age/subject ones as there can be multiple ones print "\n"; // Count the number of students for this user. $q = "SELECT COUNT(entity_id) FROM {field_data_field_manager} WHERE field_manager_value='".$u->uid."'"; $nstud = db_query($q)->fetchField(); print "\n"; $_l = $_l . $nstud . '","'; // Created date $dt = new DateTime(); $dt = DateTime::createFromFormat('U', $u->created); $dtst = $dt->format('Y-m-d H:i:s'); print "\n"; $_l = $_l . $dtst . '","'; // Last access greatest of login or access $n = max($u->access, $u->login); $dt = DateTime::createFromFormat('U', $n); $dtst = $dt->format('Y-m-d H:i:s'); print "\n"; $_l = $_l . $dtst . '"'; print " "; $csv = $csv . $_l . '\n'; } ?>
User ID Username Email Teacher name Schools Name Postcode Country School type Age/Subject No. students Registered Last Access
".$u->uid."".$u->name."".$u->mail."".$tchnm[$u->uid]->field_name_value."".$schnm[$u->uid]->field_school_name_value."".$schpc[$u->uid]->field_school_postcode_value."".$ukeire[$u->uid]->field_country_value."".$othcry[$u->uid]->field_other_country_iso2."".$schtyp[$u->uid]->field_school_type_value.""; $n = 0; foreach ($agesub as $as) { if($as->uid == $u->uid) { if($n != 0) { print ", "; $_l = $_l . ','; } print $as->field_age_subject_value; $_l = $_l . str_replace(['"',"'"],'', $as->field_age_subject_value); $n += 1; } } $_l = $_l . '","'; print "".$nstud."".$dtst."".$dtst."