namespace App\Http\Controllers\Admin\Operations\Tools;
+use App\Jobs\ElearningPackageDownload;
+use App\Models\ELearningPackage;
+use App\Models\ToolSVGSprite;
+use Illuminate\Support\Facades\Route;
+use Prologue\Alerts\Facades\Alert;
+
trait SVGSpriteDownload
{
+ protected function setupDownloadRoutes($segment, $routeName, $controller)
+ {
+ Route::match(['get'], $segment . '/{id}/download', $controller . '@download');
+ }
+
+ protected function setupDownloadDefaults()
+ {
+ $this->crud->addButtonFromView('line', 'download', 'tools.svgsprite.download', 'end');
+ }
+ protected function download($id)
+ {
+ $sprite = ToolSVGSprite::find($id);
+ return response($sprite->generate(), 200, ['Content-type' => 'text/plain']);
+ }
}
}
+ public function generate()
+ {
+ $res = '<div class="svg-sprite" aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" style="display: none;"></svg></div>';
+ foreach ($this->icons as $icon) {
+ if (preg_match('/<svg(.*)viewBox="([^\"]+)"([^>]*)>(.*)<\/svg>/m', $icon['svgcode'], $matches)) {
+ $res .= '<symbol id="' . $this->prefix . $icon['iconname'] . '" viewBox="' . $matches[2] . '">' . $matches[4] . '</symbol>';
+ }
+ }
+
+ $res .= '</svg/></div>';
+ return $res;
+ }
+
}