1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 12:12:48 +01:00

Added activities to API dashboard data

This commit is contained in:
Hillel Coren 2016-08-15 16:43:26 +03:00
parent 18d4cbcfbc
commit 2ebd40f46e
5 changed files with 48 additions and 3 deletions

View File

@ -3,11 +3,14 @@
use Auth; use Auth;
use DB; use DB;
use App\Ninja\Repositories\DashboardRepository; use App\Ninja\Repositories\DashboardRepository;
use App\Ninja\Transformers\ActivityTransformer;
class DashboardApiController extends BaseAPIController class DashboardApiController extends BaseAPIController
{ {
public function __construct(DashboardRepository $dashboardRepo) public function __construct(DashboardRepository $dashboardRepo)
{ {
parent::__construct();
$this->dashboardRepo = $dashboardRepo; $this->dashboardRepo = $dashboardRepo;
} }
@ -47,7 +50,7 @@ class DashboardApiController extends BaseAPIController
'averageInvoiceCurrency' => $averageInvoice[0]->currency_id ? $averageInvoice[0]->currency_id : 0, 'averageInvoiceCurrency' => $averageInvoice[0]->currency_id ? $averageInvoice[0]->currency_id : 0,
'invoicesSent' => $metrics ? $metrics->invoices_sent : 0, 'invoicesSent' => $metrics ? $metrics->invoices_sent : 0,
'activeClients' => $metrics ? $metrics->active_clients : 0, 'activeClients' => $metrics ? $metrics->active_clients : 0,
//'activities' => $activities, 'activities' => $this->createCollection($activities, new ActivityTransformer(), ENTITY_ACTIVITY),
]; ];
return $this->response($data); return $this->response($data);

View File

@ -1,5 +1,6 @@
<?php namespace App\Http\Controllers; <?php namespace App\Http\Controllers;
use stdClass;
use Auth; use Auth;
use DB; use DB;
use View; use View;
@ -46,6 +47,14 @@ class DashboardController extends BaseController
} }
} }
$data = $activities->map(function($item, $key) {
$obj = new stdClass;
$obj->client_id = $item->client->public_id;
return $obj;
});
dd($data[0]);
$data = [ $data = [
'account' => $user->account, 'account' => $user->account,
'paidToDate' => $paidToDate, 'paidToDate' => $paidToDate,

View File

@ -0,0 +1,33 @@
<?php namespace App\Ninja\Transformers;
use App\Models\Activity;
/**
* @SWG\Definition(definition="Activity", @SWG\Xml(name="Activity"))
*/
class ActivityTransformer extends EntityTransformer
{
protected $defaultIncludes = [ ];
/**
* @var array
*/
protected $availableIncludes = [ ];
/**
* @param Client $client
* @return array
*/
public function transform(Activity $activity)
{
return [
'activity_type_id' => $activity->activity_type_id,
'client_id' => $activity->client->public_id,
'user_id' => $activity->user->public_id + 1,
'invoice_id' => $activity->invoice ? $activity->invoice->public_id : null,
'payment_id' => $activity->payment ? $activity->payment->public_id : null,
'credit_id' => $activity->credit ? $activity->credit->public_id : null,
];
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long