class SurveyAuditCsvRule implements Rule
{
public function passes($attribute, $value)
{
// Open the csv file.
$file = fopen($value->getRealPath(), 'r');
// Get the headers from the first line
$csvHeaders = fgetcsv($file);
// Set the header to check for
$headers = ['survey_id', 'batch_id'];
// Check if the number of columns is correct
if (count($csvHeaders) != count($headers)) {
return false;
}
// Check if the headers are correct
foreach ($csvHeaders as $header) {
if (!in_array($header, $headers)) {
return false;
}
}
// Loop through every line of the file and check if a survey with the given id exists.
while (($line = fgetcsv($file)) !== false) {
$survey = GasPipeSurvey::find($line[0]);
if (!$survey) {
return false;
}
}
// Close the file
fclose($file);
return true;
}
}
class SurveyAuditCsvRule implements Rule
{
public function passes($attribute, $value)
{
// Open the csv file.
$file = fopen($value->getRealPath(), 'r');
// Get the headers from the first line
$csvHeaders = fgetcsv($file);
// Set the header to check for
$headers = ['survey_id', 'batch_id'];
// Check if the number of columns is correct
if (count($csvHeaders) != count($headers)) {
return false;
}
// Check if the headers are correct
foreach ($csvHeaders as $header) {
if (!in_array($header, $headers)) {
return false;
}
}
// Loop through every line of the file and check if a survey with the given id exists.
while (($line = fgetcsv($file)) !== false) {
$survey = GasPipeSurvey::find($line[0]);
if (!$survey) {
return false;
}
}
// Close the file
fclose($file);
return true;
}
}