Exemple #1
0
 public static function ExportQuarterlyForms()
 {
     include_once Core::LibDir() . DS . 'easycsv' . DS . 'EasyCsv.php';
     include_once dirname(__DIR__) . DS . 'database' . DS . 'ScheduleDatabase.php';
     $db = ScheduleDatabase::GetInstance();
     include_once __DIR__ . '/RWAForm.php';
     $fieldsNames = array_unique(array_merge(array('id', 'code', 'submitDate', 'formDate'), RWAForm::GetFieldNames('quarterly')));
     $csv = EasyCsv::CreateCsv($fieldsNames);
     $db->iterateAllQuarterlys(function ($record) use(&$csv, $fieldsNames) {
         $form = get_object_vars(json_decode($record->formData));
         $values = array();
         foreach ($fieldsNames as $field) {
             if (key_exists($field, $form)) {
                 $theValue = $form[$field];
                 if (is_object($theValue) || is_array($theValue)) {
                     $theValue = json_encode($theValue);
                 }
                 $values[] = $theValue;
             } else {
                 $values[] = "";
             }
         }
         $values[0] = $record->id;
         $values[1] = $record->code;
         $values[2] = $record->submitDate;
         $values[3] = $record->formDate;
         EasyCsv::AddRow($csv, $values);
     });
     header('Content-Type: application/csv;');
     header('Content-disposition: filename="rwa-export-quarterly-' . date('Y-m-d') . '.csv"');
     echo EasyCsv::Write($csv);
     return;
 }
 /**
  * @runInSeparateProcess
  */
 public function testDatabase()
 {
     $this->_includeCore();
     include_once dirname(__DIR__) . DS . 'forms/database' . DS . 'ScheduleDatabase.php';
     $db = ScheduleDatabase::GetInstance();
     $db->iterateAllSchedules(function ($row) use(&$db) {
         $formData = json_decode($row->formData);
         $this->assertTrue(is_object($formData));
         $needsUpdate = false;
         $keys = array('job-1-type', 'job-2-type', 'job-3-type');
         foreach ($keys as $key) {
             if (strpos($formData->{$key}, 'seasonal') !== false) {
                 //$this->fail($key . '=' . $formData->$key);
                 $formData->{$key} = 'seasonal';
                 $needsUpdate = true;
             }
             if (strpos($formData->{$key}, 'permanent') !== false) {
                 //$this->fail($key . '=' . $formData->$key);
                 $formData->{$key} = 'permanent';
                 $needsUpdate = true;
             }
         }
         $formJson = json_encode($formData, JSON_PRETTY_PRINT);
         $update = array('id' => $row->id, 'formData' => $formJson);
         if ($needsUpdate) {
             //$db->updateSchedule($update);
             //$this->fail(print_r($update, true));
         }
     });
     $db->iterateAllAddendums(function ($row) use(&$db) {
         $formData = json_decode($row->formData);
         $this->assertTrue(is_object($formData));
         $needsUpdate = false;
         $keys = array('job-1-type', 'job-2-type', 'job-3-type');
         foreach ($keys as $key) {
             if (strpos($formData->{$key}, 'seasonal') !== false) {
                 //$this->fail($key . '=' . $formData->$key);
                 $formData->{$key} = 'seasonal';
                 $needsUpdate = true;
             }
             if (strpos($formData->{$key}, 'permanent') !== false) {
                 //$this->fail($key . '=' . $formData->$key);
                 $formData->{$key} = 'permanent';
                 $needsUpdate = true;
             }
         }
         $formJson = json_encode($formData, JSON_PRETTY_PRINT);
         $update = array('id' => $row->id, 'formData' => $formJson);
         if ($needsUpdate) {
             //$db->updateAddendum($update);
             $this->fail(print_r($update, true));
         }
     });
     //$this->assertTrue(true);
 }
 /**
  * @runInSeparateProcess
  */
 public function testExportFormsMetadata()
 {
     $this->_includeCore();
     include_once Core::LibDir() . DS . 'easycsv' . DS . 'EasyCsv.php';
     include_once dirname(__DIR__) . DS . 'forms/database' . DS . 'ScheduleDatabase.php';
     include_once dirname(__DIR__) . DS . 'forms/lib' . DS . 'RWAForm.php';
     $db = ScheduleDatabase::GetInstance();
     $fieldsNames = RWAForm::GetFieldNames('scheduled');
     $fieldValuesArray = array();
     $db->iterateAllSchedules(function ($record) use($fieldsNames, &$fieldValuesArray) {
         $form = get_object_vars(json_decode($record->formData));
         $values = array();
         foreach ($fieldsNames as $field) {
             if (key_exists($field, $form)) {
                 $values[] = $form[$field];
             } else {
                 $values[] = "";
             }
         }
         $fieldValuesArray[] = $values;
     });
     echo print_r($fieldsNames, true) . print_r($fieldValuesArray, true) . "\n";
 }
Exemple #4
0
                $values[] = $form[$field];
            } else {
                $values[] = "";
            }
        }
        EasyCsv::AddRow($csv, $values);
    });
    //header('Content-Type: application/csv;');
    //header('Content-disposition: filename="rwa-export-scheduled-' . date('Y-m-d') . '.csv"');
    echo EasyCsv::Write($csv);
    return;
}
Scaffold('user.admin.panel', array('url' => UrlFrom(__FILE__)), __DIR__ . DS . 'views');
/* @var $db ScheduleDatabase */
include_once __DIR__ . DS . 'database' . DS . 'ScheduleDatabase.php';
$db = ScheduleDatabase::GetInstance();
$total = 0;
foreach ($db->tables() as $table) {
    $updates = $db->verifyTable($table);
    if (count($updates)) {
        array_walk($updates, function ($alter) use($db) {
            $db->execute($alter);
            $count++;
        });
    }
}
echo '<!-- ';
echo "<br/><br/>by the way, the database was just validated";
if ($total > 0) {
    echo " and " + $total + " update" + ($total == 1 ? "" : "s") + " where made";
} else {
Exemple #5
0
 public static function GetUserData()
 {
     $json = json_decode(UrlVar('json'));
     $uid = $json->id;
     include_once dirname(__DIR__) . DS . 'database' . DS . 'ScheduleDatabase.php';
     $db = ScheduleDatabase::GetInstance();
     //$uid=Core::Client()->getUserId();
     $results = $db->getUserData($uid);
     if ($results) {
         $prefixes = implode(', ', json_decode($results[0]->data)->{'rwa-prefixes'});
         echo json_encode(array('success' => true, 'data' => array('rwa-prefixes' => $prefixes)));
         return;
     }
     echo '{"success":true, data:{}}';
     return;
 }