From 310bd2bdbc14bf99b35b8e17b7523e2f69cbb9d9 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 11 Jan 2015 14:30:08 +0200 Subject: [PATCH] Updating code to PSR-2 guidelines --- app/controllers/ActivityController.php | 23 +- app/controllers/AppController.php | 6 +- app/controllers/BaseController.php | 37 +- app/controllers/ClientApiController.php | 96 +- app/controllers/ClientController.php | 482 +++++----- app/controllers/CreditController.php | 98 +- app/controllers/DashboardController.php | 35 +- app/controllers/HomeController.php | 246 +++-- app/controllers/IntegrationController.php | 47 +- app/controllers/InvoiceApiController.php | 41 +- app/controllers/InvoiceController.php | 907 +++++++++---------- app/controllers/PaymentApiController.php | 41 +- app/controllers/PaymentController.php | 499 +++++----- app/controllers/ProductController.php | 131 ++- app/controllers/QuoteApiController.php | 39 +- app/controllers/QuoteController.php | 188 ++-- app/controllers/ReportController.php | 227 +++-- app/controllers/UserController.php | 223 ++--- app/models/Account.php | 498 +++++----- app/models/AccountGateway.php | 22 +- app/models/Activity.php | 785 ++++++++-------- app/models/Affiliate.php | 6 +- app/models/Client.php | 387 ++++---- app/models/Contact.php | 131 ++- app/models/Country.php | 10 +- app/models/Credit.php | 83 +- app/models/Currency.php | 6 +- app/models/DateFormat.php | 6 +- app/models/DatetimeFormat.php | 6 +- app/models/EntityModel.php | 142 ++- app/models/Frequency.php | 4 +- app/models/Gateway.php | 88 +- app/models/Industry.php | 5 +- app/models/Invoice.php | 401 ++++---- app/models/InvoiceDesign.php | 4 +- app/models/InvoiceItem.php | 18 +- app/models/InvoiceStatus.php | 4 +- app/models/Language.php | 4 +- app/models/License.php | 6 +- app/models/Payment.php | 87 +- app/models/PaymentLibrary.php | 14 +- app/models/PaymentTerm.php | 6 +- app/models/PaymentType.php | 6 +- app/models/Product.php | 12 +- app/models/Project.php | 80 +- app/models/ProjectCode.php | 79 +- app/models/Size.php | 4 +- app/models/Subscription.php | 6 +- app/models/TaxRate.php | 3 +- app/models/Theme.php | 6 +- app/models/Timesheet.php | 30 +- app/models/TimesheetEvent.php | 139 ++- app/models/TimesheetEventSource.php | 72 +- app/models/Timezone.php | 8 +- app/models/User.php | 277 +++--- app/ninja/mailers/ContactMailer.php | 2 +- app/ninja/mailers/Mailer.php | 38 +- app/ninja/mailers/UserMailer.php | 97 +- app/ninja/repositories/AccountRepository.php | 372 ++++---- app/ninja/repositories/ClientRepository.php | 373 ++++---- app/ninja/repositories/CreditRepository.php | 90 +- app/ninja/repositories/InvoiceRepository.php | 6 +- app/ninja/repositories/PaymentRepository.php | 107 +-- app/ninja/repositories/TaxRateRepository.php | 68 +- 64 files changed, 3745 insertions(+), 4219 deletions(-) diff --git a/app/controllers/ActivityController.php b/app/controllers/ActivityController.php index d66607550d59..125e3bd72948 100755 --- a/app/controllers/ActivityController.php +++ b/app/controllers/ActivityController.php @@ -1,22 +1,21 @@ join('clients', 'clients.id', '=', 'activities.client_id') ->where('clients.public_id', '=', $clientPublicId) ->where('activities.account_id', '=', Auth::user()->account_id) ->select('activities.id', 'activities.message', 'activities.created_at', 'clients.currency_id', 'activities.balance', 'activities.adjustment'); - + return Datatable::query($query) //->addColumn('blank', function($model) { return ''; }) - ->addColumn('id', function($model) { return Utils::timestampToDateTimeString(strtotime($model->created_at)); }) - ->addColumn('message', function($model) { return Utils::decodeActivity($model->message); }) - ->addColumn('balance', function($model) { return Utils::formatMoney($model->balance, $model->currency_id); }) - ->addColumn('adjustment', function($model) { return $model->adjustment != 0 ? Utils::formatMoney($model->adjustment, $model->currency_id) : ''; }) - ->make(); - } - -} \ No newline at end of file + ->addColumn('id', function ($model) { return Utils::timestampToDateTimeString(strtotime($model->created_at)); }) + ->addColumn('message', function ($model) { return Utils::decodeActivity($model->message); }) + ->addColumn('balance', function ($model) { return Utils::formatMoney($model->balance, $model->currency_id); }) + ->addColumn('adjustment', function ($model) { return $model->adjustment != 0 ? Utils::formatMoney($model->adjustment, $model->currency_id) : ''; }) + ->make(); + } +} diff --git a/app/controllers/AppController.php b/app/controllers/AppController.php index ecaa5f6d8835..0d9405d846eb 100644 --- a/app/controllers/AppController.php +++ b/app/controllers/AppController.php @@ -43,7 +43,7 @@ class AppController extends BaseController { $database = Input::get('database'); $dbType = $database['default']; $database[$dbType] = $database['type']; - //unset($database['type']); + unset($database['type']); $mail = Input::get('mail'); $email = $mail['username']; @@ -58,7 +58,7 @@ class AppController extends BaseController { if ($test == 'db') { - return $valid ? 'Success' : 'Failed'; + return $valid === true ? 'Success' : $valid; } else if (!$valid) { @@ -115,7 +115,7 @@ class AppController extends BaseController { { Config::set("database.connections.{$dbType}.{$key}", $val); } - + try { $valid = DB::connection()->getDatabaseName() ? true : false; diff --git a/app/controllers/BaseController.php b/app/controllers/BaseController.php index 5c28d5fa1cca..11891536c641 100755 --- a/app/controllers/BaseController.php +++ b/app/controllers/BaseController.php @@ -1,22 +1,21 @@ layout)) { + $this->layout = View::make($this->layout); + } + } - /** - * Setup the layout used by the controller. - * - * @return void - */ - protected function setupLayout() - { - if ( ! is_null($this->layout)) - { - $this->layout = View::make($this->layout); - } - } - - public function __construct() - { - $this->beforeFilter('csrf', array('on' => array('post', 'delete', 'put'))); - } -} \ No newline at end of file + public function __construct() + { + $this->beforeFilter('csrf', array('on' => array('post', 'delete', 'put'))); + } +} diff --git a/app/controllers/ClientApiController.php b/app/controllers/ClientApiController.php index 3a1abc6fd135..2d76dfab108b 100644 --- a/app/controllers/ClientApiController.php +++ b/app/controllers/ClientApiController.php @@ -2,56 +2,56 @@ use ninja\repositories\ClientRepository; -class ClientApiController extends Controller { +class ClientApiController extends Controller +{ + protected $clientRepo; - protected $clientRepo; - - public function __construct(ClientRepository $clientRepo) - { - $this->clientRepo = $clientRepo; - } - - public function ping() - { - $headers = Utils::getApiHeaders(); - return Response::make('', 200, $headers); - } - - public function index() - { - if (!Utils::isPro()) { - return Redirect::to('/'); - } - - $clients = Client::scope()->with('contacts')->orderBy('created_at', 'desc')->get(); - $clients = Utils::remapPublicIds($clients->toArray()); - - $response = json_encode($clients, JSON_PRETTY_PRINT); - $headers = Utils::getApiHeaders(count($clients)); - return Response::make($response, 200, $headers); - } - - public function store() - { - if (!Utils::isPro()) { - return Redirect::to('/'); - } - - $data = Input::all(); - $error = $this->clientRepo->getErrors($data); - - if ($error) + public function __construct(ClientRepository $clientRepo) { - $headers = Utils::getApiHeaders(); - return Response::make($error, 500, $headers); - } - else - { - $client = $this->clientRepo->save(false, $data, false); - $response = json_encode($client, JSON_PRETTY_PRINT); - $headers = Utils::getApiHeaders(); - return Response::make($response, 200, $headers); + $this->clientRepo = $clientRepo; } - } + public function ping() + { + $headers = Utils::getApiHeaders(); + + return Response::make('', 200, $headers); + } + + public function index() + { + if (!Utils::isPro()) { + return Redirect::to('/'); + } + + $clients = Client::scope()->with('contacts')->orderBy('created_at', 'desc')->get(); + $clients = Utils::remapPublicIds($clients->toArray()); + + $response = json_encode($clients, JSON_PRETTY_PRINT); + $headers = Utils::getApiHeaders(count($clients)); + + return Response::make($response, 200, $headers); + } + + public function store() + { + if (!Utils::isPro()) { + return Redirect::to('/'); + } + + $data = Input::all(); + $error = $this->clientRepo->getErrors($data); + + if ($error) { + $headers = Utils::getApiHeaders(); + + return Response::make($error, 500, $headers); + } else { + $client = $this->clientRepo->save(false, $data, false); + $response = json_encode($client, JSON_PRETTY_PRINT); + $headers = Utils::getApiHeaders(); + + return Response::make($response, 200, $headers); + } + } } diff --git a/app/controllers/ClientController.php b/app/controllers/ClientController.php index c073ad87254b..ea697d185320 100755 --- a/app/controllers/ClientController.php +++ b/app/controllers/ClientController.php @@ -2,300 +2,276 @@ use ninja\repositories\ClientRepository; -class ClientController extends \BaseController { +class ClientController extends \BaseController +{ + protected $clientRepo; - protected $clientRepo; + public function __construct(ClientRepository $clientRepo) + { + parent::__construct(); - public function __construct(ClientRepository $clientRepo) - { - parent::__construct(); + $this->clientRepo = $clientRepo; + } - $this->clientRepo = $clientRepo; - } + /** + * Display a listing of the resource. + * + * @return Response + */ + public function index() + { + return View::make('list', array( + 'entityType' => ENTITY_CLIENT, + 'title' => trans('texts.clients'), + 'columns' => Utils::trans(['checkbox', 'client', 'contact', 'email', 'date_created', 'last_login', 'balance', 'action']), + )); + } - /** - * Display a listing of the resource. - * - * @return Response - */ - public function index() - { - return View::make('list', array( - 'entityType'=>ENTITY_CLIENT, - 'title' => trans('texts.clients'), - 'columns'=>Utils::trans(['checkbox', 'client', 'contact', 'email', 'date_created', 'last_login', 'balance', 'action']) - )); - } - - public function getDatatable() - { - $clients = $this->clientRepo->find(Input::get('sSearch')); + public function getDatatable() + { + $clients = $this->clientRepo->find(Input::get('sSearch')); return Datatable::query($clients) - ->addColumn('checkbox', function($model) { return ''; }) - ->addColumn('name', function($model) { return link_to('clients/' . $model->public_id, $model->name); }) - ->addColumn('first_name', function($model) { return link_to('clients/' . $model->public_id, $model->first_name . ' ' . $model->last_name); }) - ->addColumn('email', function($model) { return link_to('clients/' . $model->public_id, $model->email); }) - ->addColumn('created_at', function($model) { return Utils::timestampToDateString(strtotime($model->created_at)); }) - ->addColumn('last_login', function($model) { return Utils::timestampToDateString(strtotime($model->last_login)); }) - ->addColumn('balance', function($model) { return Utils::formatMoney($model->balance, $model->currency_id); }) - ->addColumn('dropdown', function($model) - { - if ($model->is_deleted) - { - return '
'; + ->addColumn('checkbox', function ($model) { return ''; }) + ->addColumn('name', function ($model) { return link_to('clients/'.$model->public_id, $model->name); }) + ->addColumn('first_name', function ($model) { return link_to('clients/'.$model->public_id, $model->first_name.' '.$model->last_name); }) + ->addColumn('email', function ($model) { return link_to('clients/'.$model->public_id, $model->email); }) + ->addColumn('created_at', function ($model) { return Utils::timestampToDateString(strtotime($model->created_at)); }) + ->addColumn('last_login', function ($model) { return Utils::timestampToDateString(strtotime($model->last_login)); }) + ->addColumn('balance', function ($model) { return Utils::formatMoney($model->balance, $model->currency_id); }) + ->addColumn('dropdown', function ($model) { + if ($model->is_deleted) { + return '
'; } - $str = '