1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00
invoiceninja/app/Ninja/Presenters/AccountPresenter.php
2016-12-12 20:42:51 +02:00

84 lines
2.4 KiB
PHP

<?php namespace App\Ninja\Presenters;
use stdClass;
use Utils;
use Laracasts\Presenter\Presenter;
/**
* Class AccountPresenter
*/
class AccountPresenter extends Presenter
{
/**
* @return mixed
*/
public function name()
{
return $this->entity->name ?: trans('texts.untitled_account');
}
/**
* @return string
*/
public function website()
{
return Utils::addHttp($this->entity->website);
}
/**
* @return mixed
*/
public function currencyCode()
{
$currencyId = $this->entity->getCurrencyId();
$currency = Utils::getFromCache($currencyId, 'currencies');
return $currency->code;
}
public function industry()
{
return $this->entity->industry ? $this->entity->industry->name : '';
}
public function size()
{
return $this->entity->size ? $this->entity->size->name : '';
}
private function createRBit($type, $source, $properties)
{
$data = new stdClass();
$data->receive_time = time();
$data->type = $type;
$data->source = $source;
$data->properties = new stdClass();
foreach ($properties as $key => $val) {
$data->properties->$key = $val;
}
return $data;
}
public function rBits()
{
$account = $this->entity;
$user = $account->users()->first();
$data = [];
$data[] = $this->createRBit('business_name', 'user', ['business_name' => $account->name]);
$data[] = $this->createRBit('industry_code', 'user', ['industry_detail' => $account->present()->industry]);
$data[] = $this->createRBit('comment', 'partner_database', ['comment_text' => 'Logo image not present']);
$data[] = $this->createRBit('business_description', 'user', ['business_description' => $account->present()->size]);
$data[] = $this->createRBit('person', 'user', ['name' => $user->getFullName()]);
$data[] = $this->createRBit('email', 'user', ['email' => $user->email]);
$data[] = $this->createRBit('phone', 'user', ['phone' => $user->phone]);
$data[] = $this->createRBit('website_uri', 'user', ['uri' => $account->website]);
$data[] = $this->createRBit('external_account', 'partner_database', ['is_partner_account' => 'yes', 'account_type' => 'Invoice Ninja', 'create_time' => time()]);
return $data;
}
}