Example #1
0
<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>
Example #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);
 }
Example #3
0
 public function actionStepOne()
 {
     $this->inAccession = true;
     // Have we arrived here with an accession hash, allowing us to track this contact through accession?
     if (isset($_GET['accessionhash'])) {
         $Accession = $this->getAccessionRecord();
         $this->checkStep($Accession, 1);
     } else {
         $Accession = new Accession();
         $Accession->step = 1;
     }
     $this->pageTitle = 'Welcome to ' . Yii::app()->name . ' | Step One | Accession';
     if (isset($_POST['Accession'])) {
         if ($_POST['Accession']['terms_agreed'] === '1') {
             // Accession hash will be null if they've signed up from the public link
             if (is_null($Accession->accession_hash)) {
                 $Accession->accession_hash = sha1(rand(1, 99999) . microtime(true));
             }
             // TERMS ARE AGREED! We're good to go. Set up all the models
             $Accession->terms_agreed = date('Y-m-d H:i:s');
             if (!$Accession->save()) {
                 print_r($Accession->errors);
                 exit;
             }
             // Now they've agreed terms, update the invite (if they had one)
             if ($Accession->invite_id) {
                 $Invite = Invite::model()->findByPk($Accession->invite_id);
                 if (!is_null($Invite)) {
                     $Invite->status = Invite::STATUS_ACCEPTED;
                     $Invite->save(true, array('status'));
                 }
             }
             $new = false;
             // If it's a new contact coming to the list, we just have a blank row
             // If they've come via an invite then we copy their Store row
             if (is_null($Accession->original_store2contact_id)) {
                 // This contact is new
                 $Store = new Store();
                 // Create a new warehouse row
                 $Warehouse = new Warehouse();
                 $Warehouse->save();
                 // Set the warehouse id to the accession model
                 $Accession->warehouse_id = $Warehouse->id;
                 $Accession->save(true, array('warehouse_id'));
                 $new = true;
             } else {
                 // This contact came from an invite
                 // Grab their previous data
                 $Store2Contact = Store2Contact::model()->findByPk($Accession->original_store2contact_id);
                 // Get the contact's warehouse_id - this identifies them uniquely, even if they have multiple instances in Store
                 $Warehouse = Warehouse::model()->findByPk($Store2Contact->contact_warehouse_id);
                 $ExistingStore = Store::model()->findByPk($Store2Contact->store_id);
                 // Now make a new store to duplicate their info to
                 $Store = new Store();
                 $Store->attributes = $ExistingStore->attributes;
                 $Store->id = null;
             }
             // Set the org ID to THE LIST
             $Store->origin_organisation_id = 10;
             // Try to save the Store
             if (!$Store->save()) {
                 print 'Store errors:<br>';
                 print_r($Store->errors);
                 exit;
             }
             // Also create a new Store2Contact row
             $Store2Contact = new Store2Contact();
             $Store2Contact->store_id = $Store->id;
             $Store2Contact->contact_warehouse_id = $Warehouse->id;
             $Store2Contact->origin_id = 10;
             if (!$Store2Contact->save()) {
                 print 'Store2Contact errors:<br>';
                 print_r($Store2Contact->errors);
                 exit;
             }
             // Now also save the new Store2Contact ID to Accession
             $Accession->store2contact_id = $Store2Contact->id;
             if ($new) {
                 $Accession->original_store2contact_id = $Store2Contact->id;
             }
         }
         if ($Accession->save(true, array('terms_agreed', 'store2contact_id', 'original_store2contact_id'))) {
             $this->updateStep($Accession, 1);
             $this->redirect(array('accession/stepTwo', 'accessionhash' => $Accession->accession_hash));
         }
     }
     $this->render('step1', array('Accession' => $Accession, 'progress' => 1));
 }