/**
  * Finds the CsServicesTranslation model based on its translated title.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return CsServices the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModelByTitle($title)
 {
     if (($model = \common\models\CsIndustriesTranslation::find()->where('name=:name and lang_code="SR"', [':name' => str_replace('-', ' ', $title)])->one()) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Creates a new CsIndustries model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new CsIndustries();
     $model_trans = new CsIndustriesTranslation();
     if ($model->load(Yii::$app->request->post()) and $model_trans->load(Yii::$app->request->post())) {
         if ($model->save()) {
             if ($model->imageFile) {
                 $model->upload();
             }
             $model_trans->industry_id = $model->id;
             $model_trans->orig_name = $model->name;
             $model_trans->save();
             return $this->redirect(['view', 'id' => $model->id]);
             //}
         }
     } else {
         return $this->render('create', ['model' => $model, 'model_trans' => $model_trans]);
     }
 }
Exemple #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTranslation()
 {
     $industry_translation = \common\models\CsIndustriesTranslation::find()->where('lang_code="SR" and industry_id=' . $this->id)->one();
     if ($industry_translation) {
         return $industry_translation;
     }
     return false;
 }
Exemple #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getT()
 {
     return $this->hasMany(CsIndustriesTranslation::className(), ['industry_id' => 'id']);
 }
 public function suggested_word($result, &$p = null, &$percent = null)
 {
     $actions = \common\models\CsIndustriesTranslation::find()->all();
     $data = [];
     foreach ($actions as $key => $word) {
         $string = explode(' ', $word->name);
         $res_string = explode(' ', $result);
         for ($i = 0; $i < 6; $i++) {
             for ($j = 0; $j < 6; $j++) {
                 if (!empty($res_string[$i]) && !empty($string[$j])) {
                     $f = similar_text($res_string[$i], $string[$j], $p);
                     $lev = levenshtein($res_string[$i], $string[$j]);
                     $percent = round((1 - $lev / max(strlen($res_string[$i]), strlen($string[$j]))) * 100, 0);
                     if (strlen($res_string[$i]) == $f && strpos($string[$j], $res_string[$i]) !== false) {
                         $data[] = array($f, $percent, $word->name, round($p, 0), $word->id);
                     }
                     if (strlen($res_string[$i]) != $f && $p > 70 && $percent > 50) {
                         $data[] = array($f, $percent, $word->name, round($p, 0), $word->id);
                     }
                 }
             }
         }
     }
     // kraj foreach
     if (!empty($data)) {
         $fs = [];
         foreach ($data as $row) {
             $fs[] = $row[0];
             $percents[] = $row[1];
             $words[] = $row[2];
             $ps[] = $row[3];
         }
         array_multisort($fs, SORT_DESC, $percents, SORT_DESC, $data);
         $output = [];
         foreach ($data as $date) {
             $delatnost = \frontend\models\CsIndustriesTranslation::find($date[4])->one();
             $ind = $delatnost->industry;
             //$output .= '<li class="list-group-item" style="height: auto; line-height: 22px; font-size: 16px; font-weight:700; padding:5px 20px;"><span style="font-size: 11px; font-weight:400; color: '.$ind->color.'"><i class="'.$ind->icon.'"></i></span> '.c($ind->tName), Yii::app()->createUrl('site/index', array('del'=>$delatnost->delatnost->id, 'controller'=>'ind', 'page_action'=>'details')), array('style'=>'background: none !important;')).' | <span class="fs_12" style="color:#aaa;">'.$delatnost->delatnost->kat->kategorijeTranslations[0]->ime.'</span><span style="float: right; font-size: 11px; color: #aaa;">('.$date[1].'%)</span></li>'; // treba uaciti action_translations
             $output[] = $ind;
         }
         // kraj foreach action
         return $output;
     } else {
         return false;
     }
 }
Exemple #6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIndustriesTranslations()
 {
     return $this->hasMany(CsIndustriesTranslation::className(), ['lang_code' => 'code']);
 }