public function getFilteredEntries($lastNames) { $entries = Entry::with('restorationType')->with('folders')->whereIn('last_name', $lastNames)->get(); //Transform $resource = createCollection($entries, new EntryTransformer()); return transform($resource)['data']; }
public function actionGetentry() { $id = Yii::$app->request->get('id'); $tags = EntryTag::findAll(['entry_id' => $id]); $retTags = []; // TODO relations foreach ($tags as $k => $v) { $retTags[] = Tag::findOne($v['tag_id']); } Yii::$app->response->format = Response::FORMAT_JSON; return (object) ['data' => Entry::findOne($id), 'tags' => $retTags]; }
/** * Prepare data for frontend controller * @return array */ public static function getPreparedJsonEntries() { $entries = Entry::find()->orderBy('name')->asArray()->all(); $categories = Category::find()->orderBy('name')->asArray()->all(); // Sort entries $sortedEntries = []; foreach ($entries as $k => $e) { $e['type'] = self::TYPE_ENTRY; $sortedEntries[$e['category']][] = $e; } return static::recursiveTree($categories, $sortedEntries); }
public function run() { $this->faker = Faker::create(); Entry::truncate(); DB::table('entry_folder')->truncate(); foreach (range(0, 20) as $index) { $originalRestorationDate = $this->faker->dateTimeBetween('-10 years', '-2 years')->format('Y-m-d'); $lastPhotoDate = $this->faker->dateTimeBetween('-2 years', 'now')->format('Y-m-d'); $restorationAge = Carbon::createFromFormat('Y-m-d', $lastPhotoDate)->diffInMonths(Carbon::createFromFormat('Y-m-d', $originalRestorationDate)) / 12; $restorationAge = round($restorationAge * 2) / 2; $entry = new Entry(['first_name' => $this->faker->firstName, 'last_name' => $this->faker->lastName, 'tooth_number' => $this->faker->numberBetween(1, 6), 'original_restoration_date' => $originalRestorationDate, 'last_photo_date' => $lastPhotoDate, 'restoration_age' => $restorationAge, 'note' => $this->faker->sentence()]); $restorationTypeIds = RestorationType::lists('id')->all(); $restorationTypeId = $this->faker->randomElement($restorationTypeIds); $restorationType = RestorationType::find($restorationTypeId); $entry->restorationType()->associate($restorationType); $entry->save(); $folderCount = $this->faker->numberBetween(1, 2); $folder_ids = $this->faker->randomElements(Folder::lists('id')->all(), $folderCount); foreach ($folder_ids as $folder_id) { $entry->folders()->attach($folder_id); } } }
/** * Updates all Entries of a Contest with votecount and avg rating * * @param \app\models\Contest $Contest Contest Object */ private function UpdateContestEntries($Contest) { $Entries = Entry::findAll(['contest_id' => $Contest->id]); foreach ($Entries as $Entry) { $avgQuery = new Query(); $avgQuery->from(Tweet::tableName())->where(['entry_id' => $Entry->id, 'needs_validation' => 0, 'old_vote' => 0]); $avgRating = $avgQuery->average('rating'); $votestQuery = new Query(); $votestQuery->from(Tweet::tableName())->where(['entry_id' => $Entry->id, 'needs_validation' => 0, 'old_vote' => 0]); $votes = $votestQuery->count(); $Entry->votes = $votes; $Entry->avg_rating = round($avgRating, 2); $Entry->save(); } }
/** * @return \yii\db\ActiveQuery */ public function getEntries() { return $this->hasMany(Entry::className(), ['contest_id' => 'id']); }
<h2>@<?php echo Html::encode($model->user->screen_name); ?> </h2> <p class="well well-sm"><?php echo Html::encode($model->text); ?> </p> <?php echo $form->field($model, 'contest_id')->widget(Select2::classname(), ['data' => ArrayHelper::map(Contest::find()->all(), 'id', 'name'), 'options' => ['placeholder' => 'Select a Contest ...'], 'pluginOptions' => ['allowClear' => true]]); ?> <?php echo $form->field($model, 'entry_id')->widget(DepDrop::classname(), ['data' => ArrayHelper::map(Entry::find()->where(['contest_id' => $model->contest_id])->all(), 'id', 'name'), 'options' => ['placeholder' => Yii::t('app', 'Select a Entry ...')], 'type' => DepDrop::TYPE_SELECT2, 'select2Options' => ['pluginOptions' => ['allowClear' => true]], 'pluginOptions' => ['depends' => ['tweet-contest_id'], 'url' => Url::to(['/entry/contest-entries']), 'loadingText' => Yii::t('app', 'Loading Entries ...')]]); ?> <?php echo $form->field($model, 'rating')->textInput(['maxlength' => 4]); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?>
/** * . * * @return \Illuminate\Http\Response */ public function index(Entry $entry) { $entries = $entry->getPublishedEntries(); return view('entries.list', ['entries' => $entries]); }
/** * Updates all Entry of the Tweet with votecount and avg rating * * @param \app\models\Tweet $Tweet Tweet Object */ private function UpdateEntry($Tweet) { $Entry = Entry::findOne($Tweet->entry_id); $avgQuery = new Query(); $avgQuery->from(Tweet::tableName())->where(['entry_id' => $Entry->id, 'needs_validation' => 0, 'old_vote' => 0]); $avgRating = $avgQuery->average('rating'); $votestQuery = new Query(); $votestQuery->from(Tweet::tableName())->where(['entry_id' => $Entry->id, 'needs_validation' => 0, 'old_vote' => 0]); $votes = $votestQuery->count(); $Entry->votes = $votes; $Entry->avg_rating = round($avgRating, 2); $Entry->save(); }
/** * Finds the Entry model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Entry the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Entry::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
?> </p> <?php echo DetailView::widget(['model' => $model, 'attributes' => ['trigger', 'year', 'active:boolean', 'last_parse', 'parse_from', 'parse_to']]); ?> </div> </div> </div> <div class="row"> <div class="col-lg-12"> <h2><?php echo Yii::t('app', 'Entries'); ?> </h2> <?php if (!Yii::$app->user->isGuest) { echo Html::a(Yii::t('app', 'Create {modelClass}', ['modelClass' => 'Entry']), ['entry/create', 'id' => $model->id], ['class' => 'btn btn-success']); } ?> <?php echo GridView::widget(['dataProvider' => new ActiveDataProvider(['query' => Entry::find()->where(['contest_id' => $model->id])]), 'columns' => [['attribute' => 'contest_entry_id', 'format' => 'raw', 'value' => function ($data) { return Html::a(Html::encode($data->contest_entry_id), ['entry/view', 'id' => $data->id]); }], 'avg_rating', ['attribute' => 'min_rating', 'contentOptions' => ['class' => 'hidden-xs'], 'headerOptions' => ['class' => 'hidden-xs']], ['attribute' => 'max_rating', 'contentOptions' => ['class' => 'hidden-xs'], 'headerOptions' => ['class' => 'hidden-xs']], 'votes']]); ?> </div> </div>
/** * @return \yii\db\ActiveQuery */ public function getEntry() { return $this->hasOne(Entry::className(), ['id' => 'entry_id']); }
/** * * @param $id */ public function destroy($id) { Entry::find($id)->delete(); return $this->responseNoContent(); }