added helper functions

This commit is contained in:
Denis Duliçi
2020-06-08 23:09:43 +03:00
parent 1441a56908
commit 5e51b494d2
3 changed files with 22 additions and 9 deletions

View File

@ -4,31 +4,44 @@ namespace App\Traits;
trait Contacts
{
public function isCustomer()
{
return in_array($this->type, $this->getCustomerTypes());
}
public function isVendor()
{
return in_array($this->type, $this->getVendorTypes());
}
public function getCustomerTypes($return = 'array')
{
$types = (string) setting('contact.type.customer', 'customer');
return ($return == 'array') ? explode(',', $types) : $types;
return $this->getContactTypes('customer', $return);
}
public function getVendorTypes($return = 'array')
{
$types = (string) setting('contact.type.vendor', 'vendor');
return $this->getContactTypes('vendor', $return);
}
public function getContactTypes($index, $return = 'array')
{
$types = (string) setting('contact.type.' . $index, $index);
return ($return == 'array') ? explode(',', $types) : $types;
}
public function addCustomerType($new_type)
{
$this->addType($new_type, 'customer');
$this->addContactType($new_type, 'customer');
}
public function addVendorType($new_type)
{
$this->addType($new_type, 'vendor');
$this->addContactType($new_type, 'vendor');
}
public function addType($new_type, $index)
public function addContactType($new_type, $index)
{
$types = explode(',', setting('contact.type.' . $index, $index));