Skip to content
This repository was archived by the owner on Apr 5, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions ExportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
*/
class ExportPlugin extends BasePlugin
{


protected function defineSettings()
{
return [
'emailRecipients' => AttributeType::String
];
}

/**
* Get plugin name.
*
Expand Down Expand Up @@ -77,6 +86,19 @@ public function registerUserPermissions()
);
}


/**
* Returns the rendered settings template for the plugin
*
* @return \Twig_Template
*/
public function getSettingsHtml()
{
return craft()->templates->render('export/settings/settings', array(
'settings' => $this->getSettings()
));
}

/**
* Run on plugin initialisation.
*/
Expand Down
48 changes: 48 additions & 0 deletions controllers/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,27 @@ public function actionMap()
$export = craft()->request->getRequiredPost('export');
$reset = craft()->request->getPost('reset');

<<<<<<< HEAD
// Send variables to template and display
$this->renderTemplate('export/_map', array(
'export' => $export,
'reset' => $reset,
));
=======
$deliveryOption = craft()->request->getPost('deliveryOption');
$emailRecipients = craft()->request->getPost('emailRecipients');

// Send variables to template and display
$this->renderTemplate(
'export/_map',
array(
'export' => $export,
'reset' => $reset,
'deliveryOption' => $deliveryOption,
'emailRecipients' => $emailRecipients,
)
);
>>>>>>> 7543ef1... Able to select options on whether or not you want to export and email the result later or download the responsr
}

/**
Expand All @@ -63,23 +79,55 @@ public function actionMap()
*/
public function actionDownload()
{
<<<<<<< HEAD

=======
>>>>>>> 7543ef1... Able to select options on whether or not you want to export and email the result later or download the responsr
// Get export post
$settings = craft()->request->getRequiredPost('export');

// Get mapping fields
$map = craft()->request->getParam('fields');

<<<<<<< HEAD
=======
$deliveryOption = craft()->request->getRequiredPost('deliveryOption');


$emailRecipients = craft()->request->getPost('emailRecipients');

>>>>>>> 7543ef1... Able to select options on whether or not you want to export and email the result later or download the responsr
// Save map
craft()->export->saveMap($settings, $map);

// Set more settings
$settings['map'] = $map;

// Get data
<<<<<<< HEAD
$data = craft()->export->download($settings);

// Download the csv
craft()->request->sendFile('export.csv', $data, array('forceDownload' => true, 'mimeType' => 'text/csv'));
=======


if ($deliveryOption === 'download') {
// Download the csv
$data = craft()->export->download($settings);
craft()->request->sendFile('export.csv', $data, array('forceDownload' => true, 'mimeType' => 'text/csv'));

return;
}
// start a task and notify upon completion
craft()->tasks->createTask(
'Export',
null,
array(
'dataSettings' => $settings,
'emails' => $emailRecipients,
)
);
>>>>>>> 7543ef1... Able to select options on whether or not you want to export and email the result later or download the responsr
}
}
55 changes: 55 additions & 0 deletions resources/js/export.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<<<<<<< HEAD
$(function() {

if($('#sections').length) {
Expand All @@ -10,10 +11,25 @@ $(function() {

});

=======
$(function () {

if ($('#sections').length) {

// Show the fields that match the export type
$('#types').change(function () {

$('.type').hide().find('input, select').prop('disabled', true);
$('.' + $(this).val().toLowerCase()).show().find('input, select').prop('disabled', false);

});

>>>>>>> 7543ef1... Able to select options on whether or not you want to export and email the result later or download the responsr
// Trigger change on load
$('#types').trigger('change');

// Find entry types by chosen section
<<<<<<< HEAD
$(document).on('change', '#sections', function() {

$('#entrytypes').html('<option value="">' + Craft.t('All') + '</option>');
Expand Down Expand Up @@ -45,4 +61,43 @@ $(function() {
$('.js-export-spinner').removeClass('hidden');
});

=======
$(document).on('change', '#sections', function () {

$('#entrytypes').html('<option value="">' + Craft.t('All') + '</option>');
Craft.postActionRequest('export/getEntryTypes', {'section': $(this).val()}, function (entrytypes) {

$.each(entrytypes, function (index, value) {
$('#entrytypes').append('<option value="' + value.id + '">' + value.name + '</option>');
});

});

});

}

if ($('table.sortable tbody').length) {

// Set an absolute width
$('table.sortable td').each(function () {
$(this).width($(this).width()).css('cursor', 'move');
});

// Enable sorting
$('table.sortable tbody').sortable().disableSelection();

}

$('.js-btn-export').click(function () {
$('.js-export-spinner').removeClass('hidden');
});

$('#deliveryOption').change(function () {
var emailInput = $('#emailInput').removeClass('hidden');

this.value === 'email' ? emailInput.removeClass('hidden') : emailInput.addClass('hidden');
});

>>>>>>> 7543ef1... Able to select options on whether or not you want to export and email the result later or download the responsr
});
4 changes: 4 additions & 0 deletions services/ExportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
*
* @link http://github.com/boboldehampsink
*/
<<<<<<< HEAD
=======

>>>>>>> 7543ef1... Able to select options on whether or not you want to export and email the result later or download the responsr
class ExportService extends BaseApplicationComponent
{
/**
Expand Down
88 changes: 88 additions & 0 deletions tasks/ExportTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

namespace Craft;

/**
* Power Nap task
*/
class ExportTask extends BaseTask
{
protected $tempName = '';

protected $data;

/**
* Gets the total number of steps for this task.
*
* @return int
*/
public function getTotalSteps()
{
return 3;
}

/**
* Defines the settings.
*
* @access protected
* @return array
*/
protected function defineSettings()
{
return array(
'dataSettings' => AttributeType::Mixed,
'emails' => AttributeType::String,
);
}

/**
* Runs a task step.
*
* @param int $step
* @return bool
*/
public function runStep($step)
{
if ($step == 2) {
//Finally send an email
$emails = explode(',', $this->getSettings()->emails);

$email = new EmailModel();
$email->subject = 'Your export';
$email->addAttachment($this->getStoragePath(), 'Report.csv', 'base64', 'text/csv');
$email->toEmail = array_shift($emails);

if (count($emails)) {
$email->cc = array_map(function($email) {
return [
'name' => 'Recipient',
'email' => $email
];
},$emails);
}

craft()->email->sendEmail($email);


return true;
} else if($step == 1) {
//Write it to a temp file
$this->tempName = (new \DateTime())->getTimestamp();

file_put_contents($this->getStoragePath(), $this->data);
return true;
} else {
//Build up a data variable
$this->data = craft()->export->download($this->getSettings()->dataSettings);
return true;
}
}

/**
* @return string
*/
private function getStoragePath()
{
return __DIR__.'/storage/'.$this->tempName.'.csv';
}
}
Empty file added tasks/hello.txt
Empty file.
Loading