Sfoglia il codice sorgente

Ajout commentaires + indentation divers

dev
parent
commit
b93e9497c9
7 ha cambiato i file con 66 aggiunte e 52 eliminazioni
  1. +0
    -1
      backend/models/MailForm.php
  2. +12
    -6
      common/components/MyView.php
  3. +42
    -39
      common/helpers/CSV.php
  4. +4
    -2
      common/helpers/Mail.php
  5. +2
    -1
      common/helpers/Price.php
  6. +4
    -2
      common/helpers/Upload.php
  7. +2
    -1
      common/helpers/Url.php

+ 0
- 1
backend/models/MailForm.php Vedi File

@@ -80,7 +80,6 @@ class MailForm extends Model
*/
public function sendEmail($email)
{

return Yii::$app->mailer->compose()
->setTo($email)
->setFrom(['matthieu@lechatdesnoisettes.com' => 'Le Chat des Noisettes'])

+ 12
- 6
common/components/MyView.php Vedi File

@@ -38,12 +38,14 @@ termes.

namespace common\components ;

class MyView extends \yii\web\View {
class MyView extends \yii\web\View
{
var $title ;
var $page_title ;
public function setTitle($title, $page_title = '') {
public function setTitle($title, $page_title = '')
{
$this->title = $title ;
if(strlen($page_title))
$this->page_title = $page_title ;
@@ -51,19 +53,23 @@ class MyView extends \yii\web\View {
$this->page_title = $title ;
}
public function getTitle() {
public function getTitle()
{
return $this->title ;
}
public function setPageTitle($page_title) {
public function setPageTitle($page_title)
{
$this->page_title = $page_title ;
}
public function getPageTitle() {
public function getPageTitle()
{
return $this->page_title ;
}
public function getControllerAction() {
public function getControllerAction()
{
return Yii::$app->controller->id.'/'.Yii::$app->controller->action->id ;
}

+ 42
- 39
common/helpers/CSV.php Vedi File

@@ -39,45 +39,48 @@ termes.

namespace common\helpers;

class CSV {
class CSV
{
public static function array2csv(array &$array) {
if (count($array) == 0) {
return null;
}
ob_start();
$df = fopen("php://output", 'w');
// clés
//fputcsv($df, array_keys(reset($array)));
foreach ($array as $row) {
fputcsv($df, $row);
}
fclose($df);
return ob_get_clean();
}
public static function downloadSendHeaders($filename) {
// disable caching
$now = gmdate("D, d M Y H:i:s");
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: {$now} GMT");
// force download
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
// disposition / encoding on response body
header("Content-Disposition: attachment;filename={$filename}");
header("Content-Transfer-Encoding: binary");
}
/*
* usage
* download_send_headers("data_export_" . date("Y-m-d") . ".csv");
echo array2csv($array);
die();
*/
public static function array2csv(array &$array)
{
if (count($array) == 0) {
return null;
}
ob_start();
$df = fopen("php://output", 'w');
// clés
//fputcsv($df, array_keys(reset($array)));
foreach ($array as $row) {
fputcsv($df, $row);
}
fclose($df);
return ob_get_clean();
}

public static function downloadSendHeaders($filename)
{
// disable caching
$now = gmdate("D, d M Y H:i:s");
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: {$now} GMT");

// force download
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");

// disposition / encoding on response body
header("Content-Disposition: attachment;filename={$filename}");
header("Content-Transfer-Encoding: binary");
}

/*
* usage
* download_send_headers("data_export_" . date("Y-m-d") . ".csv");
echo array2csv($array);
die();
*/
}

+ 4
- 2
common/helpers/Mail.php Vedi File

@@ -40,8 +40,10 @@ namespace common\helpers;

use Yii;

class Mail {
public static function send($email, $subject, $view, $data) {
class Mail
{
public static function send($email, $subject, $view, $data)
{
$mail = Yii::$app->mailer->compose(
[ 'html' => $view.'-html',
'text' => $view.'-text'

+ 2
- 1
common/helpers/Price.php Vedi File

@@ -40,7 +40,8 @@ namespace common\helpers;

class Price {
public static function format($number) {
public static function format($number)
{
return number_format($number, 2).' €' ;
}

+ 4
- 2
common/helpers/Upload.php Vedi File

@@ -41,9 +41,11 @@ namespace common\helpers;
use yii\web\UploadedFile;
use Yii ;

class Upload {
class Upload
{

public static function uploadFile($model, $champs, $filename_old = '') {
public static function uploadFile($model, $champs, $filename_old = '')
{
$file = UploadedFile::getInstance($model, $champs);
if ($file) {
$file_name = $file->baseName . '-' . uniqid() ;

+ 2
- 1
common/helpers/Url.php Vedi File

@@ -141,7 +141,8 @@ class Url
}
}
public static function slugify($string) {
public static function slugify($string)
{
return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $string)));
}
}

Loading…
Annulla
Salva