Skip to content

Instantly share code, notes, and snippets.

View ChVuagniaux's full-sized avatar

Christophe Vuagniaux ChVuagniaux

View GitHub Profile
@ChVuagniaux
ChVuagniaux / Plugin.php
Last active April 2, 2019 10:09
Make October Import/Export feature compatible with Excel CSV (;) easily for your ends users
<?php namespace Your\Plugin;
use Event;
use System\Classes\PluginBase;
class Plugin extends PluginBase
{
// [...]
/**
@ChVuagniaux
ChVuagniaux / routes.php
Last active November 7, 2022 11:05
Translate OctoberCMS RainLab.Location (https://octobercms.com/plugin/rainlab-location) Countries via https://RESTcountries.eu API
<?php
use RainLab\Location\Models\Country;
Route::get('generate-country-translations', function () {
$countries = Country::all();
$countries->each(function (Country $country) {
$response = file_get_contents("https://restcountries.com/v2/alpha/{$country->code}");
@ChVuagniaux
ChVuagniaux / routes.php
Created May 1, 2018 13:39
RainLab - Generate indexed attribute for existring translations
<?php
/*
*
* Generate RainLab translation index
* @see https://github.com/rainlab/translate-plugin#indexed-attributes
*
*/
@ChVuagniaux
ChVuagniaux / .env.example
Created April 16, 2018 19:33 — forked from LukeTowers/.0 - cheatsheet.sh
Introduction to OctoberCMS
APP_DEBUG=true
APP_URL=http://example.local
APP_KEY=
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=website-oc-example-LOCAL
DB_USERNAME=homestead
DB_PASSWORD=secret
@ChVuagniaux
ChVuagniaux / horizon-supervisor.sh
Created February 7, 2018 08:58
Run Horizon with cron
#!/bin/bash
# Start horizon supervisord if not already started
if pgrep -f 'php /var/www/artisan horizon'; then
echo "Horizon already run"
else
<?php
/**
* This script convert a model using
* \October\Rain\Database\Traits\SimpleTree to
* \October\Rain\Database\Traits\NestedTree
*
* Before run create required fields in your DB for NestedTree
* ( https://octobercms.com/docs/database/traits#nested-tree )
*/
@ChVuagniaux
ChVuagniaux / csv-download.php
Last active March 9, 2018 07:53
CSV export for Excel
<?php
use League\Csv\Writer;
use League\Csv\AbstractCsv;
$csv = Writer::createFromFileObject(new \SplTempFileObject());
$csv->setDelimiter(';');
$csv->setOutputBOM(AbstractCsv::BOM_UTF8); // compatibility with Excel
$csv->insertOne(['1', 'é', 'à']);
@ChVuagniaux
ChVuagniaux / AjaxButton.vue
Last active January 17, 2018 12:38
VueJS code for make buttons that do Ajax Calls
<template>
<button v-on:click="click">
<slot></slot>
</button>
</template>
<script>
export default {
props: {
'url': {type: String},
@ChVuagniaux
ChVuagniaux / _relation_render.htm
Created November 28, 2017 14:36
Generic relation render for OctoberCMS forms
<?= $this->relationRender($field->fieldName, ['readOnly' => $formContext == 'preview']) ?>
@ChVuagniaux
ChVuagniaux / oc-blog-pagination.htm
Created November 23, 2017 08:28
OctoberCMS blog pagination that use "/post" instead of "/posts/1"
{% if posts.lastPage > 1 %}
<ul class="pagination">
{% if posts.currentPage > 1 %}
{% if (posts.currentPage == 2) %}
<li><a href="{{ listPage|page({ (pageParam): null }) }}">&larr; </a></li>
{% else %}
<li><a href="{{ listPage|page({ (pageParam): (posts.currentPage - 1) }) }}">&larr; </a></li>
{% endif %}
{% endif %}