Browse Source

Ajout commentaires + indentation divers

refactoring
Guillaume Bourgeois 6 years ago
parent
commit
b93e9497c9
7 changed files with 66 additions and 52 deletions
  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 View File

*/ */
public function sendEmail($email) public function sendEmail($email)
{ {

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

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



namespace common\components ; namespace common\components ;


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

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



namespace common\helpers; 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 View File



use Yii; 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( $mail = Yii::$app->mailer->compose(
[ 'html' => $view.'-html', [ 'html' => $view.'-html',
'text' => $view.'-text' 'text' => $view.'-text'

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



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

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

use yii\web\UploadedFile; use yii\web\UploadedFile;
use Yii ; 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); $file = UploadedFile::getInstance($model, $champs);
if ($file) { if ($file) {
$file_name = $file->baseName . '-' . uniqid() ; $file_name = $file->baseName . '-' . uniqid() ;

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

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

Loading…
Cancel
Save