diff --git a/app/Classes/General/Services/GeneratesInitials.php b/app/Classes/General/Services/GeneratesInitials.php new file mode 100644 index 00000000..05f06efd --- /dev/null +++ b/app/Classes/General/Services/GeneratesInitials.php @@ -0,0 +1,152 @@ +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; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/Services/CreatesCompanyConnection.php b/app/Classes/Modules/Companies/Services/CreatesCompanyConnection.php index cab27888..48653094 100644 --- a/app/Classes/Modules/Companies/Services/CreatesCompanyConnection.php +++ b/app/Classes/Modules/Companies/Services/CreatesCompanyConnection.php @@ -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 ] diff --git a/database/migrations/2020_08_04_042683_create_company_connections_table.php b/database/migrations/2020_08_04_042683_create_company_connections_table.php index 6c9e3382..b9511463 100644 --- a/database/migrations/2020_08_04_042683_create_company_connections_table.php +++ b/database/migrations/2020_08_04_042683_create_company_connections_table.php @@ -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(); diff --git a/resources/views/pages/pdf/qr.blade.php b/resources/views/pages/pdf/qr.blade.php index fa46b19e..1f23c66a 100644 --- a/resources/views/pages/pdf/qr.blade.php +++ b/resources/views/pages/pdf/qr.blade.php @@ -58,7 +58,7 @@
仓库地址:
{{$warehouse_address->street_one.' '.$warehouse_address->street_two.' '.$warehouse_address->city.' '.$warehouse_address->state.' 邮编:'.$warehouse_address->post_code}}
-联系:{{$warehouse_contact[0]->contact.' '.$warehouse_contact[0]->name}} @if(array_key_exists(1, $warehouse_contact)) / {{$warehouse_contact[1]->contact.' '.$warehouse_contact[1]->name}} @endif
+联系:{{$warehouse_contact[0]->phone.' '.$warehouse_contact[0]->name}} @if(array_key_exists(1, $warehouse_contact)) / {{$warehouse_contact[1]->phone.' '.$warehouse_contact[1]->name}} @endif