/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Relatives::find()->orderBy('sname', 'fname', 'mname'); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->setSort(['attributes' => ['fullName' => ['asc' => ['sname' => SORT_ASC, 'fname' => SORT_ASC], 'desc' => ['sname' => SORT_DESC, 'fname' => SORT_DESC], 'default' => SORT_ASC]]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); $query->joinWith(['father', 'mother']); return $dataProvider; } $query->andWhere('fname LIKE "%' . $this->fullName . '%" OR sname LIKE "%' . $this->fullName . '%" OR mname LIKE "%' . $this->fullName . '%"'); $query->andFilterWhere(['id' => $this->id, 'bdate' => $this->bdate, 'bday' => $this->bday, 'mother_id' => $this->mother_id, 'father_id' => $this->father_id, 'gender' => $this->gender, 'ddate' => $this->ddate, 'cemetery_id' => $this->cemetery_id]); $query->andFilterWhere(['like', 'bmonth', $this->bmonth])->andFilterWhere(['like', 'byear', $this->byear])->andFilterWhere(['like', 'img', $this->img])->andFilterWhere(['like', 'bplace', $this->bplace])->andFilterWhere(['like', 'descr', $this->descr])->andFilterWhere(['like', 'second_sname', $this->second_sname])->andFilterWhere(['like', 'dday', $this->dday])->andFilterWhere(['like', 'dmonth', $this->dmonth])->andFilterWhere(['like', 'dyear', $this->dyear])->andFilterWhere(['like', 'rod', $this->rod])->andFilterWhere(['like', 'hidden', $this->hidden])->andFilterWhere(['like', 'grave_picture', $this->grave_picture]); return $dataProvider; }
/** * функция получения результатов поиска с полным совпадением по всем поисковым словам * @param string $searchString * @return array массив, содержащий id найденных записей */ static function getComplitMatch($keywords) { $keywords = explode(' ', $keywords); $results = []; $flag = FALSE; foreach ($keywords as $keyword) { $results2 = []; $records = Relatives::find()->orderBy('sname', 'fname', 'mname')->andWhere(['like', 'sname', $keyword])->orWhere(['like', 'descr', $keyword])->orWhere(['like', 'mname', $keyword])->orWhere(['like', 'rod', $keyword])->orWhere(['like', 'second_sname', $keyword])->orWhere(['like', 'fname', $keyword])->all(); if (!$flag) { foreach ($records as $record) { $results[] = $record->id; } $flag = true; } else { foreach ($records as $record) { $results2[] = $record->id; } $results = array_intersect($results2, $results); } } $result = Relatives::findAll($results); return $result; }
/** * 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.'); } }
public function getChildren() { $children = Relatives::find()->where(['father_id' => $this->husband_id])->andWhere(['mother_id' => $this->wife_id])->all(); return $children; }
<?php use yii\helpers\Html; use frontend\models\Relatives; /* @var $this yii\web\View */ $this->title = 'gapchich.ru'; ?> <div class="site-index"> <div class="jumbotron"> <h1>Гапчичи</h1> <p class="lead">Сайт посвящён фамилии Гапчич, людям с этой фамилией и их родственникам.</p> </div> <div class="body-content"> Если вы носите фамилию Гапчич - возникало ли у вас желание узнать откуда ведёт своё происхождение ваша фамилия? Как много людей в мире с такой же фамилией? Где они живут? Как с ними пообщаться? Или может быть вы когда-то потеряли связь со своим родственником и теперь хотели бы его найти? Ответы на эти вопросы и пытается дать наш сайт. <?php $count = Relatives::find()->where(['rod' => 'Гапчичи'])->count(); echo Html::tag('p', 'Кол-во людей из рода "Гапчич" внесённые в базу - ' . $count); ?> <div class="row"> </div> </div> </div>
/** * 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; } }
/** * @return \yii\db\ActiveQuery */ public function getRelative() { return $this->hasOne(Relatives::className(), ['id' => 'relative_id']); }
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; }
function renderRelativesTable($children, $level, &$common) { $nextLevelChildren = []; $count = 0; 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 ($children as $child) { echo Relatives::renderRow($child->id); $count++; if ($child->gender) { $field = 'mother_id'; } else { $field = 'father_id'; } $nextChildren = Relatives::findAll([$field => $child->id]); if (count($nextChildren) > 0) { foreach ($nextChildren as $nextChild) { $nextLevelChildren[] = $nextChild; } } } echo Html::beginTag('tr', ['class' => 'info']); echo Html::tag('th', 'Итого: ' . $count, ['colspan' => COL_SPAN]); echo Html::endTag('tr'); echo Html::endTag('table'); $common += $count; if (count($nextLevelChildren) > 0) { renderRelativesTable($nextLevelChildren, ++$level, $common); } }
?> </div> </div> <?php $relatives = Relatives::findAll(['cemetery_id' => $model->id]); if (count($relatives)) { ?> <div class="panel panel-default panel-info"> <div class="panel-heading"> <h3 class="panel-title">Список захороненых</h3> </div> <div class="panel-body"> <table class="table table-striped table-bordered detail-view"> <?php foreach ($relatives as $relative) { echo Relatives::renderRow($relative->id); } ?> </table> </div> <div class="panel-footer"> <?php echo 'Итого в списке: ' . count($relatives); ?> </div> </div> <?php } ?> </div>
} 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>'; }
$this->params['breadcrumbs'][] = $this->title; ?> <div class="relatives-index"> <?php if (isset($_POST['search'])) { $searchString = $_POST['search']; } else { $searchString = $_REQUEST['search']; } $searchString = trim($searchString); // $searchString = Html::encode($searchString); // $searchString = Html::decode($searchString); echo Html::tag('p', 'Поисковая строка: ' . $searchString); echo Html::beginTag('div', ['class' => 'panel panel-info']); $content = Html::tag('h3', '<i class="glyphicon glyphicon-calendar"></i> Результаты поиска', ['class' => "panel-title"]); echo Html::tag('div', $content, ['class' => "panel-heading"]); echo Html::endTag('div'); $result = Search::getComplitMatch($searchString, "full"); if (count($result)) { echo Html::beginTag('table', ['class' => 'table table-striped table-bordered detail-view']); foreach ($result as $record) { echo Relatives::renderRow($record->id); } echo Html::endTag('table'); } else { echo 'нет данных'; } ?> </div>