uuid = Uuid::v4()->toRfc4122(); $this->user = $user; $this->name = $name; $this->createdAt = time(); $this->updatedAt = time(); $this->specialties = new ArrayCollection(); $this->expertise = new ArrayCollection(); $this->states = new ArrayCollection(); $this->cities = new ArrayCollection(); $this->addresses = new ArrayCollection(); } public function getId(): ?int { return $this->id; } public function getUuid(): string { return $this->uuid; } public function getUser(): User { return $this->user; } public function getName(): string { return $this->name; } public function getGender(): ?string { return $this->gender; } public function getMedicalSystemCode(): ?string { return $this->medicalSystemCode; } public function getMobileNumber(): ?string { return $this->mobileNumber; } public function getActivityTime(): ?int { return $this->activityTime; } public function getDegree(): ?string { return $this->degree; } public function getInfo(): ?string { return $this->info; } public function getImages(): ?array { return $this->images; } public function getDoctorRate(): float { return $this->doctorRate; } public function getDoctorRatePercentage(): float { return $this->doctorRatePercentage; } public function isActiveDoctorAppointment(): bool { return $this->activeDoctorAppointment; } public function getRepresentationId(): ?int { return $this->representationId; } public function getCreatedAt(): int { return $this->createdAt; } public function getUpdatedAt(): int { return $this->updatedAt; } public function getSpecialties(): Collection { return $this->specialties; } public function getExpertise(): Collection { return $this->expertise; } public function getStates(): Collection { return $this->states; } public function getCities(): Collection { return $this->cities; } public function getAddresses(): Collection { return $this->addresses; } public function setName(string $v): self { $this->name = $v; return $this; } public function setGender(?string $v): self { $this->gender = $v; $this->touch(); return $this; } public function setMedicalSystemCode(?string $v): self { $this->medicalSystemCode = $v; $this->touch(); return $this; } public function setMobileNumber(?string $v): self { $this->mobileNumber = $v; $this->touch(); return $this; } public function setActivityTime(?int $v): self { $this->activityTime = $v; $this->touch(); return $this; } public function setDegree(?string $v): self { $this->degree = $v; $this->touch(); return $this; } public function setInfo(?string $v): self { $this->info = $v; $this->touch(); return $this; } public function setImages(?array $v): self { $this->images = $v; $this->touch(); return $this; } public function setDoctorRate(float $v): self { $this->doctorRate = $v; $this->touch(); return $this; } public function setDoctorRatePercentage(float $v): self { $this->doctorRatePercentage = $v; $this->touch(); return $this; } public function setActiveDoctorAppointment(bool $v): self { $this->activeDoctorAppointment = $v; $this->touch(); return $this; } public function setRepresentationId(?int $v): self { $this->representationId = $v; $this->touch(); return $this; } private function touch(): void { $this->updatedAt = time(); } public function getExperience(): int { if ($this->activityTime === null) { return 0; } return max(0, (int)((time() - $this->activityTime) / (365.25 * 24 * 3600))); } public function toListArray(): array { return [ 'id' => (string) $this->id, 'uuid' => $this->uuid, 'name' => $this->name, 'gender' => $this->gender, 'degree' => $this->degree, 'img' => $this->images ?? [], 'specialties' => $this->formatCategories($this->specialties), 'satisfaction' => (string) $this->doctorRatePercentage, 'point' => (string) $this->doctorRate, 'free_turn' => 'نوبت آزادی موجود نیست', 'hours_of_work' => 'برنامه کاری تنظیم نشده', 'active' => $this->activeDoctorAppointment, ]; } public function toDetailArray(): array { return [ 'id' => (string) $this->id, 'uuid' => $this->uuid, 'name' => $this->name, 'gender' => $this->gender, 'experience' => $this->getExperience(), 'activity_time' => $this->activityTime !== null ? (string) $this->activityTime : null, 'medical_system_code' => $this->medicalSystemCode, 'detail' => $this->info, 'degree' => $this->degree, 'specialties' => $this->formatCategories($this->specialties), 'img' => $this->images ?? [], 'expertise' => $this->formatCategories($this->expertise), 'satisfaction' => (string) $this->doctorRatePercentage, 'point' => (string) $this->doctorRate, 'free_turn' => 'نوبت آزادی موجود نیست', 'hours_of_work' => 'برنامه کاری تنظیم نشده', 'address' => array_map(fn(DoctorAddress $a) => $a->toArray(), $this->addresses->toArray()), 'average_rate' => ['total_rates' => null], 'state' => $this->formatCategories($this->states), 'city' => $this->formatCategoriesWithParent($this->cities), ]; } private function formatCategories(Collection $collection): array { return array_map(fn(Category $c) => [ 'uuid' => $c->getUuid(), 'id' => (string) $c->getId(), 'name' => $c->getLabel(), ], $collection->toArray()); } private function formatCategoriesWithParent(Collection $collection): array { return array_map(fn(Category $c) => [ 'uuid' => $c->getUuid(), 'id' => (string) $c->getId(), 'name' => $c->getLabel(), 'parent' => $c->getParentId() !== null ? (string) $c->getParentId() : null, ], $collection->toArray()); } }