/** * Finds the Relatives model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Relatives the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Relatives::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Returns full name of relative * @return null|string */ public function getRelativeName() { if ($this->relative_id != null) { return Relatives::findOne($this->relative_id)->getFullName(); } else { return null; } }
function renderAncestorsList($parents, $level) { $nextLevelAncestors = []; if ($level == 1) { $title = $level . ' Родители'; } elseif ($level == 2) { $title = $level . ' Бабушки, дедушки'; } elseif ($level == 3) { $title = $level . ' Прабабушки, прадедушки'; } else { $title = $level . ' уровень'; } echo Html::beginTag('table', ['class' => 'table table-striped table-bordered detail-view']); echo Html::beginTag('tr', ['class' => 'info']); echo Html::tag('th', $title, ['colspan' => COL_SPAN]); echo Html::endTag('tr'); foreach ($parents as $parent) { echo Relatives::renderRow($parent->id); if ($parent->father_id != null) { $nextLevelAncestors[] = Relatives::findOne($parent->father_id); } if ($parent->mother_id != null) { $nextLevelAncestors[] = Relatives::findOne($parent->mother_id); } } echo Html::beginTag('tr', ['class' => 'info']); echo Html::tag('th', 'Итого: ' . count($parents), ['colspan' => COL_SPAN]); echo Html::endTag('tr'); echo Html::endTag('table'); if (count($nextLevelAncestors) > 0) { renderAncestorsList($nextLevelAncestors, ++$level); } }
private static function getRelatives(&$relatives, $rel_id) { $relative = Relatives::findOne($rel_id); if ($relative->father_id != NULL) { $relatives[] = $relative->father_id; self::getRelatives($relatives, $relative->father_id); } if ($relative->mother_id != NULL) { $relatives[] = $relative->mother_id; self::getRelatives($relatives, $relative->mother_id); } return $relatives; }
} else { $rel = Relatives::findOne($model->mother_id); $result = $rel->sname . ' ' . $rel->fname . ' ' . $rel->mname; if ($rel->second_sname != '') { $result .= ' (' . $rel->second_sname . ')'; } $url = '/relatives/view?id=' . $model->mother_id; $options = ['title' => $rel->descr]; $result = Html::a($result, $url, $options); } return $result; }], ['attribute' => 'father_id', 'format' => 'html', 'value' => function ($model) { if ($model->father_id == 0) { $result = '<span class="glyphicon text-danger">Нет данных</span>'; } else { $rel = Relatives::findOne($model->father_id); $result = $rel->sname . ' ' . $rel->fname . ' ' . $rel->mname; if ($rel->second_sname != '') { $result .= ' (' . $rel->second_sname . ')'; } $url = '/relatives/view?id=' . $model->father_id; $options = ''; $result = Html::a($result, $url); } return $result; }], ['attribute' => 'gender', 'format' => 'html', 'filter' => array("1" => "Женский", "0" => "Мужской"), 'value' => function ($model) { if ($model->gender == 0) { $result = '<span class="label label-man">Мужской</span>'; } else { $result = '<span class="label label-woman">Женский</span>'; }