From 5f7dac265c1906f9619daea399ef2d74b6174630 Mon Sep 17 00:00:00 2001 From: Fred Carlsen Date: Wed, 1 Nov 2017 19:52:57 +0100 Subject: [PATCH] Initial --- .craftplugin | 1 + .gitignore | 32 +++++++++++ CHANGELOG.md | 9 +++ LICENSE.md | 9 +++ README.md | 59 +++++++++++++++++++ composer.json | 52 +++++++++++++++++ resources/img/plugin-logo.png | Bin 0 -> 8622 bytes src/Beam.php | 88 +++++++++++++++++++++++++++++ src/icon.svg | 6 ++ src/services/BeamService.php | 100 +++++++++++++++++++++++++++++++++ src/variables/BeamVariable.php | 46 +++++++++++++++ 11 files changed, 402 insertions(+) create mode 100644 .craftplugin create mode 100644 .gitignore create mode 100644 CHANGELOG.md create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 composer.json create mode 100644 resources/img/plugin-logo.png create mode 100644 src/Beam.php create mode 100644 src/icon.svg create mode 100644 src/services/BeamService.php create mode 100644 src/variables/BeamVariable.php diff --git a/.craftplugin b/.craftplugin new file mode 100644 index 0000000..fba6059 --- /dev/null +++ b/.craftplugin @@ -0,0 +1 @@ +{"pluginName":"Beam","pluginDescription":"Generate CSVs and XLS files in your templates","pluginVersion":"2.0.0","pluginAuthorName":"Superbig","pluginVendorName":"superbig","pluginAuthorUrl":"https://superbig.co","pluginAuthorGithub":"sjelfull","codeComments":"","pluginComponents":["controllers","models","services","variables"],"consolecommandName":"","controllerName":"","cpsectionName":"","elementName":"","fieldName":"","modelName":"","purchasableName":"","recordName":"","serviceName":"","taskName":"","utilityName":"","widgetName":"","apiVersion":"api_version_3_0"} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a17970c --- /dev/null +++ b/.gitignore @@ -0,0 +1,32 @@ +# CRAFT ENVIRONMENT +.env.php +.env.sh +.env + +# COMPOSER +/vendor + +# BUILD FILES +/bower_components/* +/node_modules/* +/build/* +/yarn-error.log + +# MISC FILES +.cache +.DS_Store +.idea +.project +.settings +*.esproj +*.sublime-workspace +*.sublime-project +*.tmproj +*.tmproject +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +config.codekit3 +prepros-6.config diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..89b79aa --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,9 @@ +# Beam Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). + +## 2.0.0 - 2017-11-01 +### Added +- Initial release diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..197329e --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,9 @@ +The MIT License (MIT) + +Copyright (c) 2017 Superbig + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..b070d68 --- /dev/null +++ b/README.md @@ -0,0 +1,59 @@ +# Beam plugin for Craft CMS 3.x + +Generate CSVs and XLS files in your templates + +![Screenshot](resources/img/plugin-logo.png) + +## Requirements + +This plugin requires Craft CMS 3.0.0-beta.23 or later. + +## Installation + +To install the plugin, follow these instructions. + +1. Open your terminal and go to your Craft project: + + cd /path/to/project + +2. Then tell Composer to load the plugin: + + composer require superbig/craft3-beam + +3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Beam. + +## Using Beam + +To generate an CSV: + +```twig +{% spaceless %} +{% set options = { + header: ['Email', 'Name'], + rows: [ + [ 'test@example.com', 'John Doe' ], + [ 'another+test@example.com', 'Jane Doe' ], + [ 'third+test@example.com', 'Trond Johansen' ], + ] +} %} +{{ craft.beam.csv(options) }} +{% endspaceless %} +``` + +To generate an XLSX: + +```twig +{% spaceless %} +{% set options = { + header: ['Email', 'Name'], + rows: [ + [ 'test@example.com', 'John Doe' ], + [ 'another+test@example.com', 'Jane Doe' ], + [ 'third+test@example.com', 'Trond Johansen' ], + ] +} %} +{{ craft.beam.xlsx(options) }} +{% endspaceless %} +``` + +Brought to you by [Superbig](https://superbig.co) diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..494b53a --- /dev/null +++ b/composer.json @@ -0,0 +1,52 @@ +{ + "name": "superbig/craft3-beam", + "description": "Generate CSVs and XLS files in your templates", + "type": "craft-plugin", + "version": "2.0.0", + "keywords": [ + "craft", + "cms", + "craftcms", + "craft-plugin", + "beam" + ], + "support": { + "docs": "https://github.com/sjelfull/craft3-beam/blob/master/README.md", + "issues": "https://github.com/sjelfull/craft3-beam/issues" + }, + "license": "MIT", + "authors": [ + { + "name": "Superbig", + "homepage": "https://superbig.co" + } + ], + "require": { + "craftcms/cms": "~3.0.0-beta.23", + "league/csv": "^8.2", + "mk-j/php_xlsxwriter": "^0.32.0" + }, + "repositories": [ + { + "type": "composer", + "url": "https://asset-packagist.org" + } + ], + "autoload": { + "psr-4": { + "superbig\\beam\\": "src/" + } + }, + "extra": { + "name": "Beam", + "handle": "beam", + "schemaVersion": "2.0.0", + "hasCpSettings": false, + "hasCpSection": false, + "changelogUrl": "https://raw.githubusercontent.com/sjelfull/craft3-beam/master/CHANGELOG.md", + "components": { + "beamService": "superbig\\beam\\services\\BeamService" + }, + "class": "superbig\\beam\\Beam" + } +} diff --git a/resources/img/plugin-logo.png b/resources/img/plugin-logo.png new file mode 100644 index 0000000000000000000000000000000000000000..d5736f00b192ad8443bcde61959a640769611a44 GIT binary patch literal 8622 zcmZ8n1yoc~x4sj^5W_H}(g+BW(#=Rnhajmmf+8s?IdrFVqkweEpyUV$C@Ce<2qGXL zB_T0y_}_Z#z4g|bweHM0=kB}D+53F=JKvrdJsnkYlA9y|0FbMzDeD6O2>%rX5EJ4r zk6)DA<1bK$d)oH^pdpF$!kPd8*q*2>-+Sl_+Q}zPHvE*`-z9%CqDe^ry(fz1oxDk- zvH*yL#l$3K@!L)+S9?8wBa9L+RS)RfHu|Do+Nd7TYvwKiR5aYD4p#+5vDSUO>y#GWe9vBYw&bCI*JxwIDLZrnhy@O$&0Jkv z(`x2M5cvhDwhd~SM&SGQP|P4HF{d2(BIs8B|YLX z(CK5Ue-z*1GZ!!UQ+1kA)Q3LOWMzvE4UPuwsgQxwmls|!=^Lqikpf<`srk)3@gG{* zP(;g-`ZN<8UU6GOtu8d`g-LDy&V;-tN|Rjm8YwB*m?;~WKN`g9c=a`Qo_6n9ct`^j zS-(fBl4v(S0OSkw7YtpPFi9 zZ;T6j4g3bDBDB`DP!*zi8zO4&^!d&r94#8=&cJ=GoOs_e(v+k-Dt8RtcL|1nw2Ze) zfUDmylnSwE_YOeFh5dB2=$}Y;p!>tP0eqk&Fv`gi_3tyPppbU&1xf(ccSgPr%+G;+-rw<4GTdZ{!9@%^sMG>&CQ&h+*#D;7qC)!9B4|S_?yY9< z7MxzbY)iN|60J|6DeT^n({z+RvyrFzbw(QKSkL)7-t}kB>Of4EFLwQ#&&xY`Z(k7G zb?UThrbY!A51Ss`)6sH*+in7$#&hXH|5%o5lRnFmHQX+ml%XeEsy34jx+y{1@B+xH z3YN9sl7g7en}!iO1JVT%-FmnQ90E_67W~A*=?!q@$=q!|J#;aju6R> zLRBzV2hIo#_g`_tHFH$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aghaxi#?=RB~&Hu(S;T#-w`sdQ0(2Q1X z0+o7y{0!&b3caymE1-HD%BHA9(`ZLa04u+=y5z05s9pDxH5a;Z>oH{!#4X~pIeWl! zA*1o>Qub#T6}mRjh{5cP-KXiv8a%Qc-$tWND5BGY0FS>unQmgQq!IXA&<5&h*J9Tb zT!^MyOHNYXT&xVOX(o7byOOt(3RjyJ`OmUK_u_Y=zJP<74|Ilm!M&0@{aU?BVb&5e z`t{~sFd;mIA%C4SmRu}d7ABt*Eh<-S_Gd9e;)bqK0=~{UrPn&B)-`D%=#Oc(%5syx z+3HTbUtnpq_$@B<;qQ6KsC#4@!IVY)S2{jGWX)HbulWITnlM}LnE_+Qsender; + $variable->set('beam', BeamVariable::class); + } + ); + + Event::on( + Plugins::class, + Plugins::EVENT_AFTER_INSTALL_PLUGIN, + function (PluginEvent $event) { + if ($event->plugin === $this) { + } + } + ); + + Craft::info( + Craft::t( + 'beam', + '{name} plugin loaded', + ['name' => $this->name] + ), + __METHOD__ + ); + } + + // Protected Methods + // ========================================================================= + +} diff --git a/src/icon.svg b/src/icon.svg new file mode 100644 index 0000000..e89836e --- /dev/null +++ b/src/icon.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/services/BeamService.php b/src/services/BeamService.php new file mode 100644 index 0000000..d41285c --- /dev/null +++ b/src/services/BeamService.php @@ -0,0 +1,100 @@ +insertOne($options['header']); + } + // Insert all the rows + $csv->insertAll($options['rows']); + + $csv->output($filename); + } + + /** + * @param array $options + * + * @return null + */ + public function xlsx ($options = []) + { + $tempPath = Craft::$app->path->getTempPath() . DIRECTORY_SEPARATOR . 'beam' . DIRECTORY_SEPARATOR; + + if ( empty($options['headers']) && empty($options['rows']) ) { + return null; + } + + if ( !file_exists($tempPath) && !is_dir($tempPath) ) { + FileHelper::createDirectory($tempPath); + } + + // Load the CSV document from a string + $writer = new XLSXWriter(); + $filename = !empty($options['filename']) ? $options['filename'] : 'output.xlsx'; + $sheetName = isset($options['sheetName']) ? $options['sheetName'] : 'Sheet'; + + if ( !empty($options['header']) ) { + $headers = []; + foreach ($options['header'] as $header) { + $headers[ $header ] = 'string'; + } + // Insert the headers + $writer->writeSheetHeader($sheetName, $headers); + } + + $filename = filter_var($filename, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); + + foreach ($options['rows'] as $row) { + $writer->writeSheetRow($sheetName, $row); + } + + $writer->writeToFile($tempPath . $filename); + + //$mimeType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; + + Craft::$app->response->sendFile($tempPath . $filename, $filename); + } +} diff --git a/src/variables/BeamVariable.php b/src/variables/BeamVariable.php new file mode 100644 index 0000000..f41f03a --- /dev/null +++ b/src/variables/BeamVariable.php @@ -0,0 +1,46 @@ +beamService->csv($options); + } + + /** + * @param array $options + * + * @return null + */ + public function xlsx ($options = []) + { + return Beam::$plugin->beamService->xlsx($options); + } +}