/**
  * Attempt to submit a CSV Tank for discrimination
  *
  * @param array $data
  * @return null
  */
 protected function rec_create($data)
 {
     $rec = $this->parent_rec;
     // check column headers
     $imp = new CSVImporter($rec);
     $valid = $imp->validate_headers();
     if ($valid !== true) {
         throw new Rframe_Exception(Rframe::BAD_DATA, $valid);
     }
     // check for extra data (project/activity/org/etc)
     if (!$rec->TankOrg->count() > 0) {
         throw new Rframe_Exception(Rframe::BAD_DATA, 'Must define organization');
     }
     if (!$rec->TankActivity->count() > 0) {
         throw new Rframe_Exception(Rframe::BAD_DATA, 'Must define activity');
     }
     if (!$rec->TankActivity[0]->tact_prj_id) {
         throw new Rframe_Exception(Rframe::BAD_DATA, 'Must define project');
     }
     // import in foreground... TODO: param for bg processing
     $n = $imp->import_file();
     if (is_string($n)) {
         $rec->set_meta_field('submit_message', $n);
         $rec->set_meta_field('submit_success', false);
         $rec->save();
         throw new Rframe_Exception(Rframe::BAD_DATA, $n);
     }
     // success!
     $rec->set_meta_field('submit_message', "Successfully imported {$n} rows");
     $rec->set_meta_field('submit_success', true);
     $rec->save();
     // add to job_queue
     if (!isset($data['nojob'])) {
         $this->queue_discriminator($rec->tank_id);
     }
     return '1';
 }
Ejemplo n.º 2
0
        // Dateiname ist gesetzt und format-Enrichment mit 'to download' oder 'upon request'
        if (is_null($this->_fulltextDir)) {
            echo "Dokument {$oldId}: [ERR004] zugeordnete Datei wurden nicht importiert, da Importverzeichnis nicht" . " lesbar oder nicht existent\n";
            return null;
        }
        $filename = $filename . '.' . $extension;
        $tempfile = $this->_fulltextDir . DIRECTORY_SEPARATOR . $filename;
        if (!file_exists($tempfile)) {
            echo "Dokument {$oldId}: [ERR006] zugeordnete Datei wurden nicht importiert, da sie nicht im angegebenen" . " Ordner existiert\n";
            return null;
        }
        if (!is_readable($tempfile)) {
            echo "Dokument {$oldId}: [ERR005] zugeordnete Datei wurden nicht importiert, da nicht lesbar\n";
            return null;
        }
        $file = $doc->addFile();
        $file->setTempFile($tempfile);
        $file->setPathName($filename);
        $file->setLanguage(trim($row[self::LANGUAGE]));
        $file->setVisibleInFrontdoor('1');
        $file->setVisibleInOai('1');
        // guest-Role darf Datei nur lesen, wenn format-Enrichment den Wert 'to download' hat (ansonsten nur die
        // administrator-Role, die das Leserecht automatisch erhält)
        if (!(strpos($format, 'to download') === false)) {
            return $file;
        }
        return null;
    }
}
$importer = new CSVImporter();
$importer->run($argv);
Ejemplo n.º 3
0
 public function testDrawFilledLineGraph()
 {
     // Dataset definition
     $DataSet = new pData();
     CSVImporter::importFromCSV($DataSet, dirname(__FILE__) . "/../sample/datawithtitle.csv", ",", array(1, 2, 3), TRUE, 0);
     $DataSet->AddAllSeries();
     $DataSet->SetAbscissaLabelSeries();
     // Initialise the graph
     $canvas = new TestCanvas();
     $Test = new pChart(700, 230, $canvas);
     $Test->setFontProperties("Fonts/tahoma.ttf", 8);
     $Test->setGraphArea(60, 30, 680, 200);
     $backgroundStyle = new BackgroundStyle(new Color(255), TRUE);
     $Test->drawGraphBackground($backgroundStyle);
     $Test->drawScale($DataSet, ScaleStyle::DefaultStyle(), 0, 2);
     $Test->drawGrid(new GridStyle(4, TRUE, new Color(230), 50));
     // Draw the 0 line
     $Test->setFontProperties("Fonts/tahoma.ttf", 6);
     $Test->drawTreshold(0, new Color(143, 55, 72), TRUE, TRUE);
     // Draw the filled line graph
     $Test->drawFilledLineGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 50, TRUE);
     // Finish the graph
     $Test->setFontProperties("Fonts/tahoma.ttf", 8);
     $Test->drawLegend(65, 35, $DataSet->GetDataDescription(), new Color(255));
     $Test->setFontProperties("Fonts/tahoma.ttf", 10);
     $Test->drawTitle(60, 22, "Example 6", new Color(50), 585);
     $this->assertEquals('9816ffbe4277df46fdce89cdc0b28a47', md5($canvas->getActionLog()));
 }
Ejemplo n.º 4
0
/*
 Example4 : Showing how to draw area
*/
// Standard inclusions
require_once "../lib/pData.php";
require_once "../lib/pChart.php";
require_once "../lib/CSVImporter.php";
require_once '../lib/GDCanvas.php';
require_once '../lib/BackgroundStyle.php';
// Definitions
$DataSet = new pData();
$canvas = new GDCanvas(700, 230);
$Chart = new pChart(700, 230, $canvas);
// Dataset definition
CSVImporter::ImportFromCSV($DataSet, "../sample/datawithtitle.csv", ",", array(1, 2, 3), TRUE, 0);
$DataSet->AddAllSeries();
$DataSet->setAbscissaLabelSeries();
// Initialise the graph
$Chart->setFontProperties("../Fonts/tahoma.ttf", 8);
$Chart->setGraphArea(60, 30, 680, 200);
$canvas->drawFilledRoundedRectangle(new Point(7, 7), new Point(693, 223), 5, new Color(240), 1, 0, ShadowProperties::NoShadow());
$canvas->drawRoundedRectangle(new Point(5, 5), new Point(695, 225), 5, new Color(230), 1, 0, ShadowProperties::NoShadow());
$Chart->drawGraphBackground(new BackgroundStyle(new Color(255), TRUE));
$Chart->drawScale($DataSet, ScaleStyle::DefaultStyle(), 0, 2);
$Chart->drawGrid(new GridStyle(4, TRUE, new Color(230, 230, 230), TRUE));
// Draw the 0 line
$Chart->setFontProperties("../Fonts/tahoma.ttf", 6);
$Chart->drawTreshold(0, new Color(143, 55, 72), TRUE, TRUE);
// Draw the area
$Chart->drawArea($DataSet, "Serie 1", "Serie 3", new Color(239, 238, 227));
Ejemplo n.º 5
0
 /**
  * Update
  *
  * @param Tank  $rec
  * @param array $data
  */
 protected function air_update($rec, $data)
 {
     $allow_update = array(Tank::$STATUS_CSV_NEW);
     if (!in_array($rec->tank_status, $allow_update)) {
         throw new Rframe_Exception(Rframe::BAD_METHOD, 'Invalid tank status for update');
     }
     // meta delimiters
     if (isset($data['csv_delim'])) {
         $rec->set_meta_field('csv_delim', $data['csv_delim']);
     }
     if (isset($data['csv_encl'])) {
         $rec->set_meta_field('csv_encl', $data['csv_encl']);
     }
     // new file
     if (isset($data['csvfile'])) {
         $file = $data['csvfile'];
         if ($file['name'] != $rec->tank_name) {
             $n = $rec->tank_name;
             $msg = "Error: you must upload the original file '{$n}', or start a new csv import.";
             throw new Rframe_Exception(Rframe::BAD_DATA, $msg);
         }
         // change files
         $rec->copy_file($file['tmp_name']);
         $size_kb = number_format($file['size'] / 1024, 1);
         $rec->set_meta_field('file_size', "{$size_kb} KB");
         // setup submit errors and valids
         $rec->set_meta_field('submit_message', null);
         $rec->set_meta_field('submit_success', null);
         $rec->set_meta_field('valid_file', true);
         // use a CSVImporter to validate headers
         $imp = new CSVImporter($rec);
         $hdr_msg = $imp->validate_headers();
         $hdr_valid = $hdr_msg === true ? true : false;
         $rec->set_meta_field('valid_header', $hdr_valid);
     }
     // Org
     if (isset($data['org_uuid'])) {
         $org = AIR2_Record::find('Organization', $data['org_uuid']);
         if (!$org) {
             throw new Rframe_Exception(Rframe::BAD_DATA, 'Invalid org_uuid');
         }
         $rec->TankOrg[0]->to_org_id = $org->org_id;
     }
     // Activity
     $this->process_activity($rec, $data);
 }
Ejemplo n.º 6
0
        $action = CSV_UPDATEONLY;
    }
    if (isset($opts['d'])) {
        $debug = true;
    }
    if ($opts['r'] && !empty($opts['r'])) {
        $includedFile = $opts['r'];
    }
    if (!$opts['t'] || empty($opts['t'])) {
        showHelp('Table non définie');
        exit;
    }
    $table = $opts['t'];
}
// }}}
global $debug, $action, $keys;
$debug = false;
$action = CSV_INSERT;
$keys = 'id';
processArgs();
require_once dirname(__FILE__) . '/../core/classes/xdb.php';
$source = file_get_contents($sourceName);
$insert_relation = null;
$update_relation = null;
if (isset($includedFile)) {
    require_once $includedFile;
}
$translater = new CSVImporter($table, $keys, !$debug);
$translater->setCSV($source);
$translater->run($action, $insert_relation, $update_relation);
// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
Ejemplo n.º 7
0
 /**
  * Import clients details from CSV files
  *
  * @param sfWebRequest $request
  */
 public function executeImportclients($request)
 {
     $user = $this->getUser();
     $column_heading = array();
     $data_rows = array();
     $import_info = $request->getParameter('import');
     $email_notification = true;
     $is_header_row = (bool) $import_info['header_row'];
     $this->errors = array();
     $this->passed = '';
     $this->failed = '';
     $this->_branch = $request->getParameter('_bid', 0);
     if ($user->hasAttribute($this->upload_attribute)) {
         $filename = $user->getAttribute($this->upload_attribute);
         $csv_importer = new CSVImporter();
         $success_message = sfConfig::get('mod_client_upload_message');
         $column_heading = $csv_importer->readCSVColumns($filename, $success_message);
         $data_rows = $csv_importer->readCSVColumns($filename, '', false);
     }
     $this->column_heading = $column_heading;
     $this->data_rows = $data_rows;
     $form_data = $request->getParameter('field_name');
     if ($form_data && $user->hasAttribute($this->upload_attribute)) {
         $filename = $user->getAttribute($this->upload_attribute);
         $user->getAttributeHolder()->remove($this->upload_attribute);
         $this->column_heading = array();
         $csv_importer = new CSVImporter($user, CSVImporter::IMPORT_CLIENTS);
         $response = $csv_importer->saveCSVFileData($filename, $form_data, $is_header_row, $email_notification);
         if (empty($response[0])) {
             $this->redirect('client/index');
         } else {
             $this->errors = $response[0];
             $this->passed = $response[1];
             $this->failed = $response[2];
         }
     }
     $this->file_attribute = $this->upload_attribute;
 }
Ejemplo n.º 8
0
 public function __construct()
 {
     parent::__construct('');
 }
Ejemplo n.º 9
0
<?php

/*
 Example6 : A simple filled line graph
*/
// Standard inclusions
require_once "../lib/pData.php";
require_once "../lib/pChart.php";
require_once '../lib/GDCanvas.php';
require_once '../lib/BackgroundStyle.php';
// Definitions
$DataSet = new pData();
$Canvas = new GDCanvas(700, 230);
$Chart = new pChart(700, 230, $Canvas);
// Dataset
CSVImporter::importFromCSV($DataSet, dirname(__FILE__) . "/../sample/datawithtitle.csv", ",", array(1, 2, 3), TRUE, 0);
$DataSet->AddAllSeries();
$DataSet->SetAbscissaLabelSeries();
// Initialise the graph
$Chart->setFontProperties("../Fonts/tahoma.ttf", 8);
$Chart->setGraphArea(60, 30, 680, 200);
$Canvas->drawFilledRoundedRectangle(new Point(7, 7), new Point(693, 223), 5, new Color(240), 1, 0, ShadowProperties::NoShadow());
$Canvas->drawFilledRoundedRectangle(new Point(5, 5), new Point(695, 225), 5, new Color(230), 1, 0, ShadowProperties::NoShadow());
$backgroundStyle = new BackgroundStyle(new Color(255), TRUE);
$Chart->drawGraphBackground($backgroundStyle);
$Chart->drawScale($DataSet, ScaleStyle::DefaultStyle(), 0, 2);
$Chart->drawGrid(new GridStyle(4, TRUE, new Color(230), 50));
// Draw the 0 line
$Chart->setFontProperties("../Fonts/tahoma.ttf", 6);
$Chart->drawTreshold(0, new Color(143, 55, 72), TRUE, TRUE);
// Draw the filled line graph
Ejemplo n.º 10
0
// Standard inclusions
require_once '../lib/pChart.php';
require_once '../lib/PieChart.php';
require_once '../lib/pData.php';
require_once '../lib/GDCanvas.php';
require_once '../lib/TestCanvas.php';
require_once '../lib/GridStyle.php';
require_once '../lib/BackgroundStyle.php';
require_once '../lib/ScaleStyle.php';
require_once '../lib/CSVImporter.php';
// Definitions
$DataSet = new pData();
$Canvas = new GDCanvas(700, 230);
$Chart = new pChart(700, 230, $Canvas);
// Dataset
CSVImporter::importFromCSV($DataSet, dirname(__FILE__) . "/../sample/bulkdata.csv", ",", array(1, 2, 3), FALSE, 0);
$DataSet->AddAllSeries();
$DataSet->SetAbscissaLabelSeries();
$DataSet->setSeriesName("January", "Serie1");
$DataSet->setSeriesName("February", "Serie2");
$DataSet->setSeriesName("March", "Serie3");
$DataSet->getDataDescription()->SetYAxisName("Average age");
$DataSet->getDataDescription()->SetYUnit("µs");
// Initialise the graph
$Chart->setFontProperties("../Fonts/tahoma.ttf", 8);
$Chart->setGraphArea(70, 30, 680, 200);
// Set Canvas
$Canvas->drawFilledRoundedRectangle(new Point(7, 7), new Point(693, 223), 5, new Color(240), 1, 0, ShadowProperties::NoShadow());
$Canvas->drawRoundedRectangle(new Point(5, 5), new Point(695, 225), 5, new Color(230), 1, 0, ShadowProperties::NoShadow());
$Chart->drawGraphBackground(new BackgroundStyle(new Color(255), true));
$Chart->drawScale($DataSet, ScaleStyle::DefaultStyle(), 0, 2);