예제 #1
0
파일: test-data.php 프로젝트: newga/newga
<div class="alert alert-warning">
	<p>You are on the server <em><?php 
print $_SERVER['HTTP_HOST'];
?>
</em>, which is the <?php 
print ENVIRONMENT;
?>
 environment.</p>
</div>

<p>Your current data is as follows:</p>

<?php 
$Store = Store::model()->count();
$Store2Contact = Store2Contact::model()->count();
$Accession = Accession::model()->count();
$CleanWarehouse = Yii::app()->db->createCommand("SELECT COUNT(*) as tot FROM clean_warehouse")->queryRow();
?>

<table class="table table-bordered">
	<tr>
		<th>Table</th>
		<th>Rows</th>
	</tr>
	<tr>
		<td>store</td>
		<td><?php 
print $Store;
?>
</td>
	</tr>
예제 #2
0
 public function actionDownload($id)
 {
     // no limit for this. See #472
     ini_set('memory_limit', '-1');
     // ensure no timeout occurs during the creation of csv
     ini_set('max_execution_time', '180');
     // do not include log info in generated file
     foreach (Yii::app()->log->routes as $route) {
         if ($route instanceof CProfileLogRoute) {
             $route->enabled = false;
         }
     }
     $Store = new Store();
     $Campaign = Campaign::model()->findByPk($id, array('select' => array('name'), 'with' => array('contacts' => array('select' => array('id', 'opened', 'bounced', 'warehouse_id'), 'index' => 'warehouse_id', 'with' => array('contact2outcomes' => array('with' => 'campaign_outcome', 'select' => array('outcome')), 'group')), 'outcomes' => array('select' => array('id', 'name')))));
     $implodedContactKeys = implode(', ', array_keys($Campaign->contacts));
     if (!sizeof($implodedContactKeys)) {
         throw new CHttpException('404', 'That campaign has no data to return');
     }
     $Accessions = Accession::model()->findAll(array('condition' => 'warehouse_id IN (' . $implodedContactKeys . ')', 'index' => 'warehouse_id'));
     $Store2Contacts = Store2Contact::model()->findAll(array('condition' => 'contact_warehouse_id IN (' . $implodedContactKeys . ')', 'index' => 'contact_warehouse_id', 'with' => array('store')));
     unset($implodedContactKeys);
     // build the csv
     $rows = array();
     $outcomeColumns = array();
     $headings = array('campaign_contact_id' => 'campaign_contact_id', 'salutation' => 'Prefix', 'first_name' => 'Forename', 'last_name' => 'Surname', 'email' => 'Email', 'culture_segment' => 'Culture Segment');
     $csvHeader = array_values($headings);
     // add each outcome as a column heading
     foreach ($Campaign->outcomes as $Outcome) {
         $csvHeader[] = 'outcome_' . $Outcome->id . ' - ' . $Outcome->name;
     }
     // add an empty one for
     $csvHeader[] = "Group";
     $csvHeader[] = "Opened";
     $csvHeader[] = "Bounced";
     header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
     header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate");
     header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
     header('Content-Encoding: UTF-8');
     header('Content-type: text/csv; charset=UTF-8');
     // disposition / encoding on response body
     header("Content-Disposition: attachment;filename=Contacts - " . $Campaign->name . ".csv");
     header("Content-Transfer-Encoding: binary");
     flush();
     $csv = fopen('php://output', 'w');
     fputcsv($csv, $csvHeader);
     // build each row
     $loop = 0;
     foreach ($Campaign->contacts as $warehouse_id => $CampaignContact) {
         $row = array();
         // use headings to get data for basic details
         foreach ($headings as $key => $value) {
             switch ($key) {
                 case 'campaign_contact_id':
                     $row['campaign_contact_id'] = $Campaign->contacts[$warehouse_id]->id;
                     break;
                 case 'email':
                     // already decrypted on find
                     $row[$value] = $Store2Contacts[$warehouse_id]->store->{$key};
                     break;
                 case 'last_name':
                     // already decrypted on find
                     $row[$value] = $Store2Contacts[$warehouse_id]->store->{$key};
                     break;
                 case 'culture_segment':
                     $row[$value] = $Accessions[$warehouse_id]->culture_segment;
                     break;
                 default:
                     $row[$value] = $Store2Contacts[$warehouse_id]->store->{$key};
             }
         }
         // do outcome row values
         foreach ($CampaignContact->contact2outcomes as $Outcome) {
             $row[$Outcome->campaign_outcome->name] = $Outcome->outcome;
         }
         $row['Group'] = $CampaignContact->group->name;
         // open and bounce. Once will likely be null / blank.
         $row['Opened'] = $CampaignContact->opened;
         $row['Bounced'] = $CampaignContact->bounced;
         //$rows[] = $row;
         fputcsv($csv, $row, ',', '"');
         if (!($loop++ % 100)) {
             ob_flush();
             flush();
             // Attempt to flush output to the browser every 100 lines.
             // You may want to tweak this number based upon the size of your CSV rows.
         }
         unset($row);
         unset($CampaignContact);
     }
     fclose($csv);
 }
예제 #3
0
 public function getAccessionRecord()
 {
     $Accession = Accession::model()->find(array('condition' => 'accession_hash = :accession_hash', 'params' => array(':accession_hash' => $_GET['accessionhash'])));
     if (is_null($Accession)) {
         throw new CHttpException(404, 'Accession record not found');
     }
     return $Accession;
 }