Esempio n. 1
0
 /**
  * Export products
  */
 public function actionExport()
 {
     $exporter = new CsvExporter();
     if (Yii::app()->request->isPostRequest && isset($_POST['attributes']) && !empty($_POST['attributes'])) {
         $exporter->export($_POST['attributes']);
     }
     $this->render('export', array('exporter' => $exporter, 'importer' => new CsvImporter()));
 }
Esempio n. 2
0
 /**
  * Export products
  */
 public function actionExport()
 {
     $this->pageName = Yii::t('CsvModule.admin', 'EXPORT_PRODUCTS');
     $exporter = new CsvExporter();
     if (Yii::app()->request->isPostRequest && isset($_POST['attributes']) && !empty($_POST['attributes'])) {
         $exporter->export($_POST['attributes']);
     }
     $this->render('export', array('exporter' => $exporter, 'importer' => new CsvImporter()));
 }
Esempio n. 3
0
 /**
  * Export to .csv without data
  */
 public function testBadExport()
 {
     $data = [];
     $expectedHeadings = ['Month', 'Bonus date', 'Salary date'];
     // Mock getExportArray method to return $data
     $this->paymentMock->expects($this->any())->method('getExportArray')->will($this->returnValue($data));
     // Check for errors when exporting
     $this->assertTrue($this->csvExporter->export($this->paymentMock));
     // Check if file is created
     $this->assertFileExists($this->path);
     // Check if file contents are correct
     $csvFile = fopen($this->path, 'r');
     $headings = fgetcsv($csvFile, null, ';');
     $this->assertEquals($headings, $expectedHeadings);
     $firstLine = fgetcsv($csvFile, null, ';');
     $this->assertFalse($firstLine);
 }
Esempio n. 4
0
/**
 * Exports a CSV file from a list of user id's
 * @param array $userIdList id of the class
 * @param array $fields optionnal names for the headers of the generated csv
 * @return string
 * @author schampagne <http://forum.claroline.net/memberlist.php?mode=viewprofile&u=45044>
 */
function csv_export_user_list($userIdList, $fields = array('user_id', 'username', 'lastname', 'firstname', 'email', 'officialCode'))
{
    $csv = new CsvExporter(',', '"');
    $csvData = array();
    $csvData[0] = $fields;
    foreach ($userIdList as $userId) {
        $userInfo = user_get_properties($userId);
        $row = array();
        foreach ($fields as $field) {
            if (isset($userInfo[$field])) {
                $row[$field] = $userInfo[$field];
            } else {
                $row[$field] = '';
            }
        }
        $csvData[] = $row;
    }
    return $csv->export($csvData);
}
Esempio n. 5
0
            $csvTab[] = $csvSubTab;
            foreach ($stats as $key => $elmt) {
                $csvSubTab = array();
                $csvSubTab['courseCode'] = $key;
                $csvSubTab['courseTitle'] = $elmt['courseTitle'];
                $csvSubTab['courseTitulars'] = $elmt['courseTitulars'];
                foreach ($elmt['courseStats'] as $key => $elmt2) {
                    $csvSubTab[$key . '_count'] = $elmt2['count'];
                    $csvSubTab[$key . '_size'] = round($elmt2['size'] / 1024);
                }
                foreach ($elmt['courseCategory'] as $key => $cat) {
                    $csvSubTab[$key . '_courseCategory'] = $cat;
                }
                $csvTab[] = $csvSubTab;
            }
            $csvExporter = new CsvExporter(';', '"');
            $fileName = get_lang('files_stats') . '_' . claro_date('d-m-Y') . '.csv';
            $stream = $csvExporter->export($csvTab);
            claro_send_stream($stream, $fileName, 'text/csv');
        }
    } else {
        $dialogBox->warning(get_lang('Statistics in progress, please don\'t refresh until further instructions ! ') . '<br />' . get_lang('Course actually treated : ') . $course['title'] . '<br />' . get_lang(' Number of course treated : ') . count($stats));
        $claroline->display->body->appendContent($dialogBox->render());
        echo $claroline->display->render();
    }
} else {
    $dialogBox = new DialogBox();
    $dialogBox->warning(get_lang('Caution: building files\' statistics is a pretty heavy work.  It might take a while and a lot of resources, depending of the size of your campus.'));
    if (!empty($extensions)) {
        $dialogBox->info(get_lang('You\'ve chosen to isolate the following extensions: %types.  If you wish to modify these extensions, check the advanced platform settings', array('%types' => implode(', ', $extensions))));
    } else {
Esempio n. 6
0
 protected function call_details()
 {
     $product_id = $this->getParam('p') ? urldecode($this->getParam('p')) : '';
     $where = '';
     if ($this->getParam('from')) {
         $from = $this->getParam('from');
         $where .= " AND es_date >='{$from}'";
         $this->smarty->assign('from', $from);
     }
     if ($this->getParam('to')) {
         $to = $this->getParam('to');
         $where .= " AND es_date <='{$to}'";
         $this->smarty->assign('to', $to);
     }
     //$join = ' LEFT JOIN '.$db_name.'.products as p on p.p_id = t.es_product_id';
     $join = '';
     $q = 'SELECT es_email, es_product_id as product_id, COUNT(es_email) as count_send, SUM(es_count_open) as count_open, SUM(es_count_click) as count_click, MIN(es_date) as start_date FROM ' . $this->table_name . ' as t ' . $join . ' WHERE ((es_product_id = ? AND ? <> "") OR ( ? = "" )) ' . $where . ' GROUP BY es_email ORDER BY es_product_id';
     if (DB::executeQuery($q, 'details', array($product_id, $product_id, $product_id))) {
         $q = 'SELECT MIN(es_date) as min_date, MAX(es_date) as max_date FROM ' . $this->table_name . ' WHERE ((es_product_id = ? AND ? <> "") OR ( ? = "" ))';
         if (DB::executeQuery($q, 'maccdetails', array($product_id, $product_id, $product_id))) {
             $dates = DB::fetchResults('maccdetails');
             $this->smarty->assign('min_date', $dates[0]['min_date']);
             $this->smarty->assign('max_date', $dates[0]['max_date']);
         }
         $rows = DB::fetchResults('details');
         if (count($rows) == 0) {
             $vars['alert'] = 'Empty result';
             $vars['page_title'] = "Empty SQL result";
             $this->smarty->assign('vars', $vars);
             $this->to_print();
         } else {
             /*                $result[0] = array('email' => 'Email address', 'product_name' => 'Product', 'product_sent' => 'Sum send', 'count_open'=>'Sum open', 'count_click'=>'Sum clicks', 'start_date'=>'Start date');*/
             $result[0] = array('email' => 'Email address', 'product_name' => 'Product', 'product_sent' => 'Sum send', 'start_date' => 'Start date');
             foreach ($rows as $row) {
                 /*				    $result[] = array('email' => $row['es_email'], 'product_name' => $row['product_id'], 'product_sent' => $row['count_send'], 'count_open' => $row['count_open'], 'count_click' => $row['count_click'], 'start_date' => $row['start_date']);*/
                 $result[] = array('email' => $row['es_email'], 'product_name' => $row['product_id'], 'product_sent' => $row['count_send'], 'start_date' => $row['start_date']);
             }
             if ($this->getParam('getcsv')) {
                 include_once CLASSES . 'CsvExporter.php';
                 $filename = 'notify-users-' . date('Y-m-d') . '.csv';
                 ob_end_clean();
                 CsvExporter::sendArrayAsCSV($result, false, $filename);
             } else {
                 $vars['file'] = 'reports/details.tpl';
                 $vars['data'] = $result;
                 $vars['page_title'] = "General report";
                 $this->smarty->assign('vars', $vars);
                 $this->to_print();
             }
         }
     } else {
         $vars['file'] = 'reports/details.tpl';
         $vars['alert'] = '<strong>SQL error!</strong> Something happened!';
         $vars['page_title'] = "SQL error";
         $this->smarty->assign('vars', $vars);
         $this->to_print();
     }
 }