예제 #1
0
 /**
  * function ::create ($data)
  */
 public static function create($data)
 {
     $now = strtotime('now');
     $username = Yii::$app->user->identity->username;
     $model = new DiscoveryTranslation();
     if ($model->load($data)) {
         if ($log = new UserLog()) {
             $log->username = $username;
             $log->action = 'Create';
             $log->object_class = 'DiscoveryTranslation';
             $log->created_at = $now;
             $log->is_success = 0;
             $log->save();
         }
         do {
             $path = FileUtils::generatePath($now);
         } while (file_exists(Yii::$app->params['images_folder'] . $path));
         $model->image_path = $path;
         $targetFolder = Yii::$app->params['images_folder'] . $model->image_path;
         $targetUrl = Yii::$app->params['images_url'] . $model->image_path;
         $model->content = FileUtils::copyContentImages(['content' => $model->content, 'defaultFromFolder' => Yii::$app->params['uploads_folder'], 'toFolder' => $targetFolder, 'toUrl' => $targetUrl, 'removeInputImage' => true]);
         if ($model->save()) {
             if ($log) {
                 $log->object_pk = $model->id;
                 $log->is_success = 1;
                 $log->save();
             }
             return $model;
         }
         $model->getErrors();
         return $model;
     }
     return false;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = DiscoveryTranslation::find();
     if (!empty($params['discovery_id'])) {
         $query->where(['discovery_id' => $params['discovery_id']]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $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');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'language_id' => $this->language_id, 'discovery_id' => $this->discovery_id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'search_text', $this->search_text])->andFilterWhere(['like', 'page_title', $this->page_title])->andFilterWhere(['like', 'h1', $this->h1])->andFilterWhere(['like', 'meta_title', $this->meta_title])->andFilterWhere(['like', 'meta_description', $this->meta_description])->andFilterWhere(['like', 'meta_keywords', $this->meta_keywords])->andFilterWhere(['like', 'image_path', $this->image_path])->andFilterWhere(['like', 'caption', $this->caption]);
     return $dataProvider;
 }
예제 #3
0
파일: _form.php 프로젝트: quyettvq/luspel
use yii\web\View;
use yii\widgets\ActiveForm;
/* @var $this View */
/* @var $model DiscoveryTranslation */
/* @var $form ActiveForm */
?>

<div class="discovery-translation-form">

    <?php 
$form = ActiveForm::begin();
?>
    
    <div class="col-md-6">
        <?php 
echo $form->field($model, 'language_id')->dropDownList(array_diff_key($this->context->languages_idToName, ArrayHelper::map(DiscoveryTranslation::find()->where(['discovery_id' => $model->discovery_id])->andWhere(['<>', 'id', (int) $model->id])->all(), 'language_id', 'language_id')));
?>
        <?php 
echo $form->field($model, 'discovery_id')->textInput(['readonly' => true, 'type' => 'hidden'])->label(false);
?>
        <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => true]);
?>
        <?php 
echo $form->field($model, 'caption')->textInput(['maxlength' => true]);
?>
        <?php 
echo $form->field($model, 'description')->textarea(['maxlength' => true, 'rows' => 3, 'style' => 'resize:vertical']);
?>
        <?php 
// echo $form->field($model, 'search_text')->textInput(['maxlength' => true])
예제 #4
0
 /**
  * Deletes an existing Discovery model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     if ($model = $this->findModel($id)) {
         foreach (DiscoveryTranslation::findAll(['discovery_id' => $model->id]) as $item) {
             $item->delete();
         }
         $model->delete();
         return $this->goBack(Url::previous());
     } else {
         throw new NotFoundHttpException();
     }
 }
예제 #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDiscoveryTranslations()
 {
     return $this->hasMany(DiscoveryTranslation::className(), ['discovery_id' => 'id']);
 }
 /**
  * Finds the DiscoveryTranslation model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return DiscoveryTranslation the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = DiscoveryTranslation::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }