Author: Nick Sagona, III (nick@popphp.org)
Exemplo n.º 1
0
 /**
  * Export action method
  *
  * @param  int $tid
  * @return void
  */
 public function export($tid)
 {
     $entities = new Model\Entity(['tid' => $tid]);
     $type = new Model\EntityType();
     $type->getById($tid);
     if (!isset($type->id)) {
         $this->redirect(BASE_PATH . APP_URI . '/entities');
     }
     if ($this->services['acl']->isAllowed($this->sess->user->role, 'entity-type-' . $type->id, 'export')) {
         $rows = $entities->getAllForExport($tid);
         $data = new Data($rows);
         $data->serialize('csv', ['omit' => 'type_id']);
         $data->outputToHttp($type->name . '_' . date('Y-m-d') . '.csv');
     } else {
         $this->redirect(BASE_PATH . APP_URI . '/entities/' . $tid);
     }
 }
Exemplo n.º 2
0
require_once '../../bootstrap.php';
use Pop\Data\Data;
try {
    echo 'From a CSV file<br />-------------------<br />' . PHP_EOL;
    $data = new Data('../assets/files/test.csv');
    $obj = $data->parseFile();
    print_r($obj);
    echo PHP_EOL . '<br /><br />' . PHP_EOL;
    echo 'From a JSON file<br />-------------------<br />' . PHP_EOL;
    $data = new Data('../assets/files/test.json');
    $obj = $data->parseFile();
    print_r($obj);
    echo PHP_EOL . '<br /><br />' . PHP_EOL;
    echo 'From a SQL file<br />-------------------<br />' . PHP_EOL;
    $data = new Data('../assets/files/test.sql');
    $obj = $data->parseFile();
    print_r($obj);
    echo PHP_EOL . '<br /><br />' . PHP_EOL;
    echo 'From an XML file<br />-------------------<br />' . PHP_EOL;
    $data = new Data('../assets/files/test.xml');
    $obj = $data->parseFile();
    print_r($obj);
    echo PHP_EOL . '<br /><br />' . PHP_EOL;
    echo 'From a YML file<br />-------------------<br />' . PHP_EOL;
    $data = new Data('../assets/files/test.yml');
    $obj = $data->parseFile();
    print_r($obj);
} catch (\Exception $e) {
    echo $e->getMessage();
}
 /**
  * Export method
  *
  * @return void
  */
 public function export()
 {
     $user = new Model\User();
     $user->getExport($this->request->getPath(1), $this->request->getQuery('sort'), $this->request->getQuery('page'));
     if (isset($user->userRows[0])) {
         $userRows = $user->userRows;
         foreach ($userRows as $key => $value) {
             foreach ($value as $k => $v) {
                 if (is_array($v)) {
                     $userRows[$key]->{$k} = implode('|', $v);
                 }
             }
         }
         \Pop\Data\Data::factory($userRows)->writeData($_SERVER['HTTP_HOST'] . '_' . $user->userType . '_' . date('Y-m-d') . '.csv', true, true);
     } else {
         Response::redirect($this->request->getBasePath() . '/index/' . $this->request->getPath(1));
     }
 }
Exemplo n.º 4
0
 /**
  * Export action method
  *
  * @param  int $id
  * @return void
  */
 public function export($id)
 {
     $form = new Model\Form();
     $form->getById($id);
     if (!isset($form->id)) {
         $this->redirect(BASE_PATH . APP_URI . '/forms');
     }
     $submission = new Model\FormSubmission();
     $submissions = $submission->getAll($id, null, null, $this->request->getQuery('sort'), $this->application->modules());
     $data = [];
     foreach ($submissions['rows'] as $row) {
         $d = ['id' => $row->id];
         foreach ($submissions['fields'] as $name => $type) {
             $r = (array) $row;
             unset($r['ip_address']);
             unset($r['timestamp']);
             unset($r['form_id']);
             if (isset($r[$name])) {
                 $d[$name] = is_array($r[$name]) ? implode(', ', $r[$name]) : $r[$name];
             } else {
                 $d[$name] = '';
             }
         }
         $d['ip_address'] = $row->ip_address;
         $d['timestamp'] = $row->timestamp;
         $data[] = $d;
     }
     $data = new Data($data);
     $data->serialize('csv');
     $data->outputToHttp($_SERVER['HTTP_HOST'] . '_' . str_replace(' ', '_', strtolower($form->name)) . '_' . date('Y-m-d') . '.csv');
 }
Exemplo n.º 5
0
 public function testWriteDataException()
 {
     $this->setExpectedException('Pop\\Data\\Exception');
     $ary = array(array('name' => 'Test1', 'email' => '*****@*****.**'), array('name' => 'Test2', 'email' => '*****@*****.**'));
     $d = Data::factory($ary)->writeData(__DIR__ . '/../tmp/datatest.txt');
 }
Exemplo n.º 6
0
    $xml = $data->parseFile();
    $data = new Data('../assets/files/test.yml');
    $yml = $data->parseFile();
    echo 'CSV data to XML file<br />-------------------<br />' . PHP_EOL;
    $data = new Data($csv);
    $obj = $data->parseData('xml');
    echo $obj;
    echo PHP_EOL . '<br /><br />' . PHP_EOL;
    echo 'SQL data to CSV file<br />-------------------<br />' . PHP_EOL;
    $data = new Data($sql);
    $obj = $data->parseData('csv');
    echo $obj;
    echo PHP_EOL . '<br /><br />' . PHP_EOL;
    echo 'SQL data to YAML file<br />-------------------<br />' . PHP_EOL;
    $data = new Data($sql);
    $obj = $data->parseData('yaml');
    echo $obj;
    echo PHP_EOL . '<br /><br />' . PHP_EOL;
    echo 'XML data to SQL file<br />-------------------<br />' . PHP_EOL;
    $data = new Data($xml);
    $data->setTable('users')->setIdQuote('`');
    $obj = $data->parseData('sql');
    echo $obj;
    echo PHP_EOL . '<br /><br />' . PHP_EOL;
    echo 'YAML data to JSON file<br />-------------------<br />' . PHP_EOL;
    $data = new Data($yml);
    $obj = $data->parseData('json');
    echo $obj;
} catch (\Exception $e) {
    echo $e->getMessage();
}