예제 #1
0
 /**
  * @return bool
  * @throws \Exception
  */
 public function createFamily()
 {
     if (!$this->validate()) {
         return false;
     }
     $spouses = Human::find()->where(['id' => [$this->firstSpouseId, $this->secondSpouseId], 'id_descendant_family' => null])->all();
     if (!is_array($spouses) || count($spouses) !== 2) {
         return false;
     }
     $transaction = Yii::$app->db->beginTransaction();
     try {
         $family = new Family();
         $family->setAttribute('name', $spouses[0]->surname . '-' . $spouses[1]->surname);
         if (!$family->save()) {
             throw new Exception('Family creation error');
         }
         foreach ($spouses as $human) {
             $human->setAttribute('id_descendant_family', $family->id);
             if (!$human->update(true, ['id_descendant_family'])) {
                 throw new Exception('Spouses updating error');
             }
         }
     } catch (Exception $e) {
         $transaction->rollBack();
         Yii::$app->session->setFlash('danger', 'Произошла ошибка');
         return false;
     }
     $transaction->commit();
     $this->family = $family;
     return true;
 }
예제 #2
0
 /**
  * Finds the Family model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Family the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Family::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #3
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $family = Family::find($id);
     $family->alias = \Request::input('title');
     $family->description = \Request::input('description');
     $family->save();
     return redirect()->back();
 }
예제 #4
0
 public function index($cat = null, $id = null)
 {
     if (!$cat) {
         $resource = \App\Models\Kingdom::select('kingdom.kingdom_name as name', 'kingdom.kingdom_id as id', DB::raw('count(barcode.barcode_id) as count'), DB::raw("CONCAT('/dnabarcode/kingdom/', kingdom.kingdom_id) AS url"));
         $resourceData = $resource->join('phylum', 'kingdom.kingdom_id', '=', 'phylum.kingdom_id', 'left outer')->join('class', 'phylum.phylum_id', '=', 'class.phylum_id', 'left outer')->join('order', 'class.class_id', '=', 'order.class_id', 'left outer')->join('family', 'order.order_id', '=', 'family.order_id', 'left outer')->join('genus', 'family.family_id', '=', 'genus.family_id', 'left outer')->join('species', 'genus.genus_id', '=', 'species.genus_id', 'left outer')->join('barcode', 'barcode.species', '=', 'species.species_id', 'left outer')->groupBy('kingdom.kingdom_id', 'kingdom.kingdom_name')->paginate(20);
     } else {
         switch ($cat) {
             case 'kingdom':
                 $resource = \App\Models\Kingdom::find($id);
                 $resourceData = $resource->phylums()->select('phylum.phylum_name as name', 'phylum.phylum_id as id', DB::raw('count(barcode.barcode_id) as count'), DB::raw("CONCAT('/dnabarcode/phylum/', phylum.phylum_id) AS url"))->join('class', 'phylum.phylum_id', '=', 'class.phylum_id', 'left outer')->join('order', 'class.class_id', '=', 'order.class_id', 'left outer')->join('family', 'order.order_id', '=', 'family.order_id', 'left outer')->join('genus', 'family.family_id', '=', 'genus.family_id', 'left outer')->join('species', 'genus.genus_id', '=', 'species.genus_id', 'left outer')->join('barcode', 'barcode.species', '=', 'species.species_id', 'left outer')->groupBy('phylum.phylum_id', 'phylum.phylum_name')->paginate(20);
                 array_unshift($this->breadcrumbs, array('name' => $resource->kingdom_name));
                 break;
             case 'phylum':
                 $resource = \App\Models\Phylum::find($id);
                 $resourceData = $resource->classes()->select('class.class_name as name', 'class.class_id as id', DB::raw('count(barcode.barcode_id) as count'), DB::raw("CONCAT('/dnabarcode/class/', class.class_id) AS url"))->join('order', 'class.class_id', '=', 'order.class_id', 'left outer')->join('family', 'order.order_id', '=', 'family.order_id', 'left outer')->join('genus', 'family.family_id', '=', 'genus.family_id', 'left outer')->join('species', 'genus.genus_id', '=', 'species.genus_id', 'left outer')->join('barcode', 'barcode.species', '=', 'species.species_id', 'left outer')->groupBy('class.class_id', 'class.class_name')->paginate(20);
                 array_unshift($this->breadcrumbs, array('name' => $resource->phylum_name));
                 array_unshift($this->breadcrumbs, array('name' => $resource->kingdom->kingdom_name, 'url' => '/dnabarcode/kingdom/' . $resource->kingdom->kingdom_id));
                 break;
             case 'class':
                 $resource = \App\Models\Classes::find($id);
                 $resourceData = $resource->orders()->select('order.order_name as name', 'order.order_id as id', DB::raw('count(barcode.barcode_id) as count'), DB::raw("CONCAT('/dnabarcode/order/', order.order_id) AS url"))->join('family', 'order.order_id', '=', 'family.order_id', 'left outer')->join('genus', 'family.family_id', '=', 'genus.family_id', 'left outer')->join('species', 'genus.genus_id', '=', 'species.genus_id', 'left outer')->join('barcode', 'barcode.species', '=', 'species.species_id', 'left outer')->groupBy('order.order_id', 'order.order_name')->paginate(20);
                 array_unshift($this->breadcrumbs, array('name' => $resource->class_name));
                 array_unshift($this->breadcrumbs, array('name' => $resource->phylum->phylum_name, 'url' => '/dnabarcode/phylum/' . $resource->phylum->phylum_id));
                 array_unshift($this->breadcrumbs, array('name' => $resource->phylum->kingdom->kingdom_name, 'url' => '/dnabarcode/kingdom/' . $resource->phylum->kingdom->kingdom_id));
                 break;
             case 'order':
                 $resource = \App\Models\Order::find($id);
                 $resourceData = $resource->families()->select('family.family_name as name', 'family.family_id as id', DB::raw('count(barcode.barcode_id) as count'), DB::raw("CONCAT('/dnabarcode/family/', family.family_id) AS url"))->join('genus', 'family.family_id', '=', 'genus.family_id', 'left outer')->join('species', 'genus.genus_id', '=', 'species.genus_id', 'left outer')->join('barcode', 'barcode.species', '=', 'species.species_id', 'left outer')->groupBy('family.family_id', 'family.family_name')->paginate(20);
                 array_unshift($this->breadcrumbs, array('name' => $resource->order_name));
                 array_unshift($this->breadcrumbs, array('name' => $resource->classes->class_name, 'url' => '/dnabarcode/class/' . $resource->classes->class_id));
                 array_unshift($this->breadcrumbs, array('name' => $resource->classes->phylum->phylum_name, 'url' => '/dnabarcode/phylum/' . $resource->classes->phylum->phylum_id));
                 array_unshift($this->breadcrumbs, array('name' => $resource->classes->phylum->kingdom->kingdom_name, 'url' => '/dnabarcode/kingdom/' . $resource->classes->phylum->kingdom->kingdom_id));
                 break;
             case 'family':
                 $resource = \App\Models\Family::find($id);
                 $resourceData = $resource->genus()->select('genus.genus_name as name', 'genus.genus_id as id', DB::raw('count(barcode.barcode_id) as count'), DB::raw("CONCAT('/dnabarcode/genus/', genus.genus_id) AS url"))->join('species', 'genus.genus_id', '=', 'species.genus_id', 'left outer')->groupBy('genus.genus_id', 'genus.genus_name')->join('barcode', 'barcode.species', '=', 'species.species_id', 'left outer')->paginate(20);
                 array_unshift($this->breadcrumbs, array('name' => $resource->family_name));
                 array_unshift($this->breadcrumbs, array('name' => $resource->order->order_name, 'url' => '/dnabarcode/order/' . $resource->order->order_id));
                 array_unshift($this->breadcrumbs, array('name' => $resource->order->classes->class_name, 'url' => '/dnabarcode/class/' . $resource->order->classes->class_id));
                 array_unshift($this->breadcrumbs, array('name' => $resource->order->classes->phylum->phylum_name, 'url' => '/dnabarcode/phylum/' . $resource->order->classes->phylum->phylum_id));
                 array_unshift($this->breadcrumbs, array('name' => $resource->order->classes->phylum->kingdom->kingdom_name, 'url' => '/dnabarcode/kingdom/' . $resource->order->classes->phylum->kingdom->kingdom_id));
                 break;
             case 'genus':
                 $resource = \App\Models\Genus::find($id);
                 $resourceData = $resource->species()->select('species.species_name as name', DB::raw("CONCAT('/viewbarcode?id=' , barcode_id) AS url"))->join('barcode', 'barcode.species', '=', 'species.species_id')->where('barcode.status', 1)->paginate(20);
                 array_unshift($this->breadcrumbs, array('name' => $resource->genus_name));
                 array_unshift($this->breadcrumbs, array('name' => $resource->family->family_name, 'url' => '/dnabarcode/family/' . $resource->family->order_id));
                 array_unshift($this->breadcrumbs, array('name' => $resource->family->order->order_name, 'url' => '/dnabarcode/order/' . $resource->family->order->order_id));
                 array_unshift($this->breadcrumbs, array('name' => $resource->family->order->classes->class_name, 'url' => '/dnabarcode/class/' . $resource->family->order->classes->class_id));
                 array_unshift($this->breadcrumbs, array('name' => $resource->family->order->classes->phylum->phylum_name, 'url' => '/dnabarcode/phylum/' . $resource->family->order->classes->phylum->phylum_id));
                 array_unshift($this->breadcrumbs, array('name' => $resource->family->order->classes->phylum->kingdom->kingdom_name, 'url' => '/dnabarcode/kingdom/' . $resource->family->order->classes->phylum->kingdom->kingdom_id));
                 break;
         }
     }
     array_unshift($this->breadcrumbs, array('name' => 'DNA Barcode', 'url' => '/dnabarcode'));
     $viewData = array('resource' => $resourceData, 'breadcrumbs' => $this->breadcrumbs, 'cat' => $cat);
     return view('list')->with($viewData);
 }
예제 #5
0
 public function actionUpdate()
 {
     $id = Yii::$app->user->identity->family_id;
     $model = Family::findOne($id);
     if ($model->login_user_id) {
         $user = User::findOne($model->login_user_id);
     } else {
         $user = new User();
     }
     if ($model->load(Yii::$app->request->post())) {
         $transaction = Yii::$app->db->beginTransaction();
         if ($model->login_status == \app\enum\UserStatus::Ativo && $model->user_name) {
             //Cria novo utilizador
             $user = new \app\models\User();
             $user->username = $model->user_name;
             $user->email = $model->user_name;
             $user->status = \app\enum\UserStatus::Ativo;
             $user->family_id = 0;
             //sem familia atribuida
             $user->family_login_user = $model->id;
             //Utilizador familiar
             if ($user->validate() && $user->save()) {
                 $model->login_user_id = $user->id;
                 Yii::$app->getSession()->setFlash('success', 'Foi criado com sucesso o utilizador familiar.<br>' . 'A partir deste momento poderá usar este utilizador para ver eventos e tarefas da família,' . ' mesmo que não sejam membros do MemoBoard Familiar.');
             } else {
                 $err = '<br>';
                 foreach ($user->errors as $field => $error) {
                     $err .= '<br> <li> ' . $error[0] . '</li>';
                 }
                 //$err = implode('<br>',$user->errors);
                 Yii::$app->getSession()->setFlash('danger', 'O utilizador não pode ser criado porque não passou na validação: ' . $err);
                 $this->layout = 'main_user';
                 return $this->render('update', ['model' => $model, 'user' => $user]);
             }
         }
         if ($model->save()) {
             $transaction->commit();
             return $this->redirect('/user/index');
         } else {
             var_dump($model->errors);
             die;
             $transaction->rollBack();
         }
     }
     $this->layout = 'main_user';
     return $this->render('update', ['model' => $model, 'user' => $user]);
 }
예제 #6
0
 public function getFamily()
 {
     return $this->hasOne(Family::className(), ['id' => 'family_id']);
 }
예제 #7
0
 public static function joinMemberToFamilyAndSave($model, $user_id, $family_id)
 {
     if (!$user_id || !$family_id) {
         return 'Não foi fornecido um parametro necessário.';
     }
     $user = \app\models\User::findIdentity($user_id);
     if (!$user) {
         return 'O utilizador ainda não tem registo no memoboard.';
     }
     //O utilizador não pode pertencer a nenhuma familia ou ser membro
     if ($user->family_id) {
         return 'Este utilizador já pertence a uma família.';
     }
     $family = \app\models\Family::find()->where(['id' => $family_id])->one();
     if (!$family) {
         return 'A familia não exste.';
     }
     if (!$family->accepts_members) {
         return 'A familia ' . $family->name . ' não está a aceitar novos membros.';
     }
     //Se já existir um user não pode associar outros
     if ($model->user_id) {
         return 'Não pode alterar membros da família por outros.';
     }
     //Cria membro
     $model->user_type = \app\enum\UserType::Utilizador_registado;
     $model->family_id = $family->id;
     $model->user_id = $user->id;
     if (!$model->validate()) {
         return 'Dados não válidos:<br>' . implode('<br>', $model->errors);
     }
     $transaction = Yii::$app->db->beginTransaction();
     if (!$model->save()) {
         $transaction->rollBack();
         return 'Não foi possível salvar os dados.';
     }
     //Cria um calendário para oo membro se não existir
     $my_cal = \app\models\Calendar::findOne(['member_id' => $model->id]);
     if (!$my_cal) {
         $my_cal = new \app\models\Calendar();
         $my_cal->member_id = $model->id;
         $my_cal->name = $model->name;
         if (!$my_cal->save()) {
             $transaction->rollBack();
             return 'Não foi possível salvar o calendário.';
         }
     }
     //Coloca valores no utilizador
     $user->family_id = $family->id;
     $user->family_member_id = $model->id;
     $user->calendar_id = $my_cal->id;
     if (!$user->save(['family_id', 'family_member_id', 'calendar_id'])) {
         $transaction->rollBack();
         return 'Não foi possível atualizar o utilizador.';
     }
     $transaction->commit();
     //Coloca nas prefeencias do utilizador o calendário
     //para mostrar imediatamente
     $user->setPreference('tasks_selected', $model->id);
     $user->setPreference('calendars_selected', $model->id);
     return true;
 }
예제 #8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDescendantFamily()
 {
     return $this->hasOne(Family::className(), ['id' => 'id_descendant_family']);
 }
예제 #9
0
<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use app\models\Family;
/* @var $this yii\web\View */
/* @var $model app\models\Human */
/* @var $form yii\widgets\ActiveForm */
/* @var $create boolean */
$families = Family::getFamiliesDropDown();
?>

<div class="human-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'id_ancestry_family')->dropDownList($families, ['disabled' => !$create, 'prompt' => 'нет']);
?>

    <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'surname')->textInput(['maxlength' => true]);
?>

    <div class="form-group">