mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/portal.git
synced 2026-08-19 04:23:59 +00:00
add marking to company connection
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Services;
|
||||
|
||||
|
||||
class GeneratesInitials
|
||||
{
|
||||
protected $length = 3;
|
||||
protected $initials = 'CWW';
|
||||
protected $keepCase = false;
|
||||
protected $name = 'CIEF Worldwide';
|
||||
|
||||
/**
|
||||
* Set the name used for generating initials.
|
||||
*
|
||||
* @param string $nameOrInitials
|
||||
*
|
||||
* @return GeneratesInitials
|
||||
*/
|
||||
public function name($nameOrInitials)
|
||||
{
|
||||
$this->generate($nameOrInitials);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if should keep lettercase on name.
|
||||
* Setting this to false (default) will uppercase the name.
|
||||
*
|
||||
* @param boolean $keepCase
|
||||
*
|
||||
* @return GeneratesInitials
|
||||
*/
|
||||
public function keepCase($keepCase = true)
|
||||
{
|
||||
$this->keepCase = $keepCase;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the length of the generated initials.
|
||||
*
|
||||
* @param int $length
|
||||
*
|
||||
* @return GeneratesInitials
|
||||
*/
|
||||
public function length($length = 2)
|
||||
{
|
||||
$this->length = (int) $length;
|
||||
$this->initials = $this->generateInitials();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the initials.
|
||||
*
|
||||
* @param null|string $name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function generate($name = null)
|
||||
{
|
||||
if ($name !== null) {
|
||||
$this->name = $name;
|
||||
$this->initials = $this->generateInitials();
|
||||
}
|
||||
|
||||
return (string) $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Will return the generated initials.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getInitials()
|
||||
{
|
||||
return $this->initials;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the initials.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getInitials();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a two-letter initial from a name,
|
||||
* and if no name, assume its already initials.
|
||||
* For safety, we limit it to two characters,
|
||||
* in case its a single, but long, name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function generateInitials()
|
||||
{
|
||||
$nameOrInitials = trim($this->name);
|
||||
|
||||
if( !$this->keepCase ) {
|
||||
$nameOrInitials = mb_strtoupper($nameOrInitials);
|
||||
}
|
||||
|
||||
$nameOrInitials = trim( trim( $nameOrInitials, '-' ) );
|
||||
|
||||
$names = explode(' ', $nameOrInitials);
|
||||
|
||||
// Get names with dash (-) between into separate names
|
||||
$names = array_map( static function ($namePart) { return explode('-', $namePart); }, $names );
|
||||
$realNames = [];
|
||||
|
||||
foreach( new \RecursiveIteratorIterator( new \RecursiveArrayIterator($names) ) as $namePart ) {
|
||||
$realNames[] = $namePart;
|
||||
}
|
||||
|
||||
$names = $realNames;
|
||||
|
||||
$initials = $nameOrInitials;
|
||||
$assignedNames = 0;
|
||||
|
||||
if (count($names) > 1) {
|
||||
$initials = '';
|
||||
$start = 0;
|
||||
|
||||
for ($i = 0; $i < $this->length; $i++) {
|
||||
$index = $i;
|
||||
|
||||
if (($index === ($this->length - 1) && $index > 0) || ($index > (count($names) - 1))) {
|
||||
$index = count($names) - 1;
|
||||
}
|
||||
|
||||
if ($assignedNames >= count($names)) {
|
||||
$start++;
|
||||
}
|
||||
|
||||
$initials .= mb_substr($names[$index], $start, 1);
|
||||
$assignedNames++;
|
||||
}
|
||||
}
|
||||
|
||||
$initials = mb_substr($initials, 0, $this->length);
|
||||
|
||||
return $initials;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Classes\Modules\Companies\Services;
|
||||
|
||||
use App\Classes\General\Services\GeneratesInitials;
|
||||
use App\Classes\Modules\Companies\DataTransferObjects\ConnectionObject;
|
||||
use App\Classes\ValueObjects\Constants\ConnectionStatus;
|
||||
|
||||
@@ -11,6 +12,7 @@ class CreatesCompanyConnection
|
||||
public function execute(ConnectionObject $connection){
|
||||
$connection->getInviter()->connections()->attach($connection->getInvitee(),
|
||||
[
|
||||
'marking' => mt_rand(100, 999).(new GeneratesInitials())->name($connection->getInviter()->company()->name)->length(3)->generate(),
|
||||
'status' => ConnectionStatus::APPROVED,
|
||||
'instigator' => $connection->getInvitee()->id
|
||||
]
|
||||
|
||||
@@ -19,6 +19,7 @@ class CreateCompanyConnectionsTable extends Migration
|
||||
$table->id();
|
||||
$table->foreignId('module_one');
|
||||
$table->foreignId('module_two');
|
||||
$table->text('marking');
|
||||
$table->integer('status')->default(RelationStatus::PENDING);
|
||||
$table->foreignId('instigator')->comment('entity that is responsible for current status');
|
||||
$table->timestamps();
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
<td>
|
||||
<p style="font-size: 12px; margin-bottom: 0 !important; margin-top: 10px !important;">仓库地址:</p>
|
||||
<p style="margin-top: 5px !important; margin-bottom: 5px !important; word-wrap: break-word; font-size: 16px;">{{$warehouse_address->street_one.' '.$warehouse_address->street_two.' '.$warehouse_address->city.' '.$warehouse_address->state.' 邮编:'.$warehouse_address->post_code}}</p>
|
||||
<p style="margin-top: 5px !important; margin-bottom: 0px !important; font-size: 12px;">联系:{{$warehouse_contact[0]->contact.' '.$warehouse_contact[0]->name}} @if(array_key_exists(1, $warehouse_contact)) / {{$warehouse_contact[1]->contact.' '.$warehouse_contact[1]->name}} @endif</p>
|
||||
<p style="margin-top: 5px !important; margin-bottom: 0px !important; font-size: 12px;">联系:{{$warehouse_contact[0]->phone.' '.$warehouse_contact[0]->name}} @if(array_key_exists(1, $warehouse_contact)) / {{$warehouse_contact[1]->phone.' '.$warehouse_contact[1]->name}} @endif</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user