first commit
This commit is contained in:
166
ToggleVerifier.inc
Normal file
166
ToggleVerifier.inc
Normal file
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
|
||||
require_once('TogglBase.inc');
|
||||
|
||||
class ToggleVerifier extends TogglBase
|
||||
{
|
||||
private $workspace;
|
||||
private $verifiedEntries;
|
||||
private $notFound;
|
||||
|
||||
static public function getFolderKeys()
|
||||
{
|
||||
$keys = array();
|
||||
|
||||
$dir = "converted/";
|
||||
$files = glob($dir . '*', GLOB_MARK);
|
||||
foreach ($files as $file) {
|
||||
if (is_dir($file)) {
|
||||
$file = basename($file);
|
||||
$keys[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
return $keys;
|
||||
}
|
||||
|
||||
static public function getVerifiedStatus($folderKey)
|
||||
{
|
||||
$status = array();
|
||||
$dir = "converted/$folderKey/";
|
||||
$files = glob($dir . '*', GLOB_MARK);
|
||||
foreach ($files as $file) {
|
||||
if (!is_dir($file)) {
|
||||
$file = basename($file);
|
||||
list($workspace, $verified) = explode('.', $file);
|
||||
$verified = ($verified == 'verified');
|
||||
|
||||
if (isset($status[$workspace])) {
|
||||
$verified = $verified || $status[$workspace];
|
||||
}
|
||||
$status[$workspace] = $verified;
|
||||
}
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
static public function isFolderVerified($folderKey)
|
||||
{
|
||||
$status = self::getVerifiedStatus($folderKey);
|
||||
foreach ($status as $ws => $s) {
|
||||
if ($s == false)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function __construct($workspace, $folderKey)
|
||||
{
|
||||
$this->workspace = $workspace;
|
||||
$this->folderKey = $folderKey;
|
||||
}
|
||||
|
||||
public function parseFile($filename)
|
||||
{
|
||||
if (!self::open($filename)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$this->verifiedEntries = array();
|
||||
while ($row = self::getVerifiedRow()) {
|
||||
$this->verifiedEntries[] = $row;
|
||||
|
||||
//self::incrementTime($row);
|
||||
}
|
||||
|
||||
self::close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function verify()
|
||||
{
|
||||
$dir = "converted/{$this->folderKey}/";
|
||||
$filename = $dir . $this->workspace . ".csv";
|
||||
|
||||
if (!self::open($filename)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->notFound = array();
|
||||
while ($row = self::getRebasedRow()) {
|
||||
$found = false;
|
||||
for ($i = 0; $i < count($this->verifiedEntries); $i++) {
|
||||
if ($this->rowEquals($row, $this->verifiedEntries[$i])) {
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$found) {
|
||||
$this->notFound[] = $row;
|
||||
echo(print_r($row));
|
||||
echo('<br>');
|
||||
}
|
||||
}
|
||||
|
||||
self::close();
|
||||
|
||||
if (count($this->notFound) == 0) {
|
||||
touch($dir . $this->workspace . '.verified');
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->lastErr = 'Not all entries were found in verification file.';
|
||||
return false;
|
||||
}
|
||||
|
||||
private function getVerifiedRow()
|
||||
{
|
||||
$data = fgetcsv($this->file);
|
||||
if (!$data)
|
||||
return false;
|
||||
$row = new stdClass();
|
||||
$row->user = $data[0];
|
||||
$row->email = $data[1];
|
||||
$row->client = $data[2];
|
||||
$row->project = $data[3];
|
||||
$row->description = $data[5];
|
||||
$row->duration = $data[11];
|
||||
return $row;
|
||||
}
|
||||
|
||||
private function getRebasedRow()
|
||||
{
|
||||
$data = fgetcsv($this->file);
|
||||
if (!$data)
|
||||
return false;
|
||||
$row = new stdClass();
|
||||
$row->user = $data[0];
|
||||
$row->email = $data[1];
|
||||
$row->client = $data[2];
|
||||
$row->project = $data[3];
|
||||
$row->description = $data[4];
|
||||
$row->duration = $data[7];
|
||||
return $row;
|
||||
}
|
||||
|
||||
private function rowEquals($a, $b)
|
||||
{
|
||||
if ($a->user != $b->user)
|
||||
return false;
|
||||
if ($a->email != $b->email)
|
||||
return false;
|
||||
if ($a->client != $b->client)
|
||||
return false;
|
||||
if ($a->project != $b->project)
|
||||
return false;
|
||||
if ($a->description != $b->description)
|
||||
return false;
|
||||
if ($a->duration != $b->duration)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user