/** * Get a list of related organizations by an organization ID * * @param int $organizationId * @return array Example: [['org_name' => 'Big', 'relationship_type' => 'sister']] */ protected function getRelated(int $organizationId) : array { $parents = $this->organization->getParentIds($organizationId); $children = $this->organization->getChildIds($organizationId); $sisters = $this->organization->getSisterIds($organizationId); $organizations = DB::table('organizations')->whereIn('id', array_merge($parents, $children, $sisters))->orderBy('name')->paginate(self::MAX_RECORDS_PER_PAGE); $relatedOrganizations = []; foreach ($organizations as $organization) { if (in_array($organization->id, $parents)) { $relation = 'parent'; } elseif (in_array($organization->id, $children)) { $relation = 'daughter'; } else { $relation = 'sister'; } $relatedOrganizations[] = ['org_name' => $organization->name, 'relationship_type' => $relation]; } return $relatedOrganizations; }
/** * Check if the organization has a parent with the specified ID * * @param int $parentId * @param int $organizationId * @return bool */ private function hasParent(int $organizationId, int $parentId = null) : bool { return $parentId !== null && !$this->organization->hasChild($parentId, $organizationId); }
/** * Delete everything from the database * * @param Organization $organization * @return Response */ public function truncate(Organization $organization) { $organization->truncate(); return response('', 204); }