/** * Finds the Tag model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Tag the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Tag::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Удаление метки. * * @param int $id * @return \yii\web\Response */ public function actionDelete($id) { /** @var Tag $modelTag */ $modelTag = Tag::findOne($id); if ($modelTag->delete()) { return $this->redirect(['back-tag/index']); } return $this->refresh(); }
/** * Creates a new TagUserAccess model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($tagID) { $model = new TagUserAccess(); /** @var Tag $tag */ $tag = Tag::findOne($tagID); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index', 'tagID' => $tagID]); } else { return $this->render('create', ['model' => $model, 'tag' => $tag, 'users' => $this->getAvailableUsers($tagID)]); } }
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]; }
/** * Сохраняет модель и связанные данные * * @param Book $modelBook * @return \yii\web\Response */ private function _saveBook(Book $modelBook) { $authorIds = Yii::$app->request->post('authors'); $tagIds = Yii::$app->request->post('tags'); if ($modelBook->load(Yii::$app->request->post()) && $modelBook->save()) { array_map(function ($model) use($modelBook) { $modelBook->unlink('authors', $model, true); }, $modelBook->authors); foreach ($authorIds ?: [] as $authorId) { /** @var Author $modelAuthor */ $modelAuthor = Author::findOne($authorId); $modelBook->link('authors', $modelAuthor); } array_map(function ($model) use($modelBook) { $modelBook->unlink('tags', $model, true); }, $modelBook->tags); foreach ($tagIds ?: [] as $tagId) { /** @var Tag $modelTag */ $modelTag = Tag::findOne($tagId); $modelBook->link('tags', $modelTag); } return $this->redirect(['back-book/view', 'id' => $modelBook->id]); } }
public function actionArtist() { $model = Artist::findOne(Yii::$app->request->post('pk', '')); $ownerId = $model->user_id; if (Yii::$app->request->post('name', '') == 'artist-tags') { $artistTags = (new \yii\db\Query())->select('tag_id')->from('artist_tag')->where(['artist_id' => $model->id])->column(); $requestTags = Yii::$app->request->post('value', []); foreach ($requestTags as $tagId) { if (!in_array($tagId, $artistTags)) { $tag = Tag::findOne($tagId); if ($tag) { $model->link('tags', $tag); } } } foreach ($artistTags as $tagId) { if (!in_array($tagId, $requestTags)) { Yii::$app->db->createCommand()->delete('artist_tag', ['artist_id' => $model->id, 'tag_id' => $tagId])->execute(); } } return null; } return self::update($model, $ownerId); }
/** * @param int $antrag_id * * @return string */ public function actionSaveantrag($antrag_id) { \yii::$app->response->format = \yii\web\Response::FORMAT_RAW; \yii::$app->response->headers->add('Content-Type', 'application/json'); /** @var Antrag $antrag */ $antrag = Antrag::findOne($antrag_id); if (!$antrag) { return json_encode(['error' => 'Antrag nicht gefunden.']); } $antrag->notiz = $_POST['antrag']['notiz']; if ($_POST['antrag']['abgeschlossen'] == 1) { $antrag->status_override = $antrag->status == 'erledigt' ? '' : 'erledigt'; } else { $antrag->status_override = $antrag->status == 'erledigt' ? 'In Bearbeitung' : ''; } if (!$antrag->save()) { return json_encode(['error' => 'Es ist ein (seltsamer) Fehler beim Speichern aufgetreten.']); } foreach ($antrag->tags as $tag) { $antrag->unlink('tags', $tag, true); } $tags = explode(',', $_POST['antrag']['tags']); foreach ($tags as $tagName) { $tag = Tag::findOne(['name' => $tagName]); if (!$tag) { $tag = new Tag(); $tag->name = $tagName; $tag->save(); } $antrag->link('tags', $tag); } $row = $this->renderPartial('index_antrag_row', ['antrag' => $antrag]); return json_encode(['success' => 1, 'content' => $row]); }
public static function findByName($name) { return Tag::findOne(['name' => $name, 'user_id' => Yii::$app->user->id]); }
protected function getTegName($id) { if (($tag = Tag::findOne($id)) !== null) { return $tag->tag_name; } else { throw new NotFoundHttpException('The requested page does not exist. (getTegName())'); } }
/** * Finds the Tag model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Tag the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Tag::findOne($id)) !== null) { if ($model->user_id != Yii::$app->user->id) { throw new ForbiddenHttpException(); } return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
use yii\helpers\Html; $this->title = \Yii::t('app', 'Wiki') . ' - ' . $project->title . ' - ' . $this->params['appSettings']['app_name']; echo $this->render('/project/_topMenu', ['model' => $project]); ?> <div class="row"> <div class="col-sm-10"> <?php echo Html::a('<i class="fa fa-plus"></i> ' . \Yii::t('app', 'Add'), ['/wiki/create', 'id' => $project->id], ['class' => 'btn btn-primary pull-right']); ?> <h1> <?php echo \Yii::t('app', 'Wiki'); if (isset($tagId)) { echo ' / <i>' . \app\models\Tag::findOne($tagId)->name . '</i>'; } ?> </h1> <?php echo \yii\grid\GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'layout' => '{items} {pager}', 'columns' => [['attribute' => 'title', 'format' => 'raw', 'value' => function ($data) { return Html::a($data->title, ['/wiki/view', 'id' => $data->id]); }], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete}']]]); ?> </div> <div class="col-sm-2"> <?php echo \app\components\widgets\TagsPanelWidget::widget(['modelName' => \app\models\TagModel::MODEL_WIKI, 'projectId' => $project->id]); ?> </div>
// анализ и вывод соответствующего объекта: картинка, галлерея, файл, музыка, видео, гиперссылка echo ContentGenerator::parse($data); } else { echo str_replace("\n", "<br>", $model->text); /*Html::encode()*/ // plain text, not json } ?> <?php if (!empty($model->tags)) { ?> <br>-- <br> <?php foreach ($model->tags as $tag) { $tagName = Tag::findOne($tag)->name; echo Html::a("#" . $tagName, Url::toRoute(['/', 'query' => "#" . $tagName])) . " "; } ?> <?php } ?> <hr> <?php $form = ActiveForm::begin(['action' => '', 'method' => 'post', 'id' => 'edit-form']); echo Html::tag("div", $form->field($model, 'id')->hiddenInput() . $form->field($model, 'hash')->hiddenInput() . $form->field($model, 'created')->hiddenInput() . $form->field($model, 'ip')->hiddenInput() . $form->field($model, 'user_agent')->hiddenInput(), ['style' => "display: none;"]); echo $form->field($model, 'text')->textarea(); echo $form->field($model, 'tags')->widget(Select2::className(), ['data' => ArrayHelper::map(Tag::find()->all(), 'id', 'name'), 'options' => ['multiple' => true, 'placeholder' => 'Теги'], 'pluginOptions' => ['tags' => true, 'maximumInputLength' => 255]]); echo Html::tag("div", Html::submitButton('Опубликовать', ['class' => 'btn btn-success']), ['style' => "text-align: center;"]); $form->end(); ?>
<div class="description-index"> <div class="tab"> <div class="tab-cell"> <h1>Стаття</h1> </div> <div class="tab-cell"> <?php echo Html::a('Створити статті', ['create'], ['class' => 'btn btn-success']); ?> </div> </div> <?php foreach ($model as $m) { $tag = Tag::findOne($m->tag); $tag = $tag->tag_name; $desc = null; $to_sub = 500; $size = strlen($m->art_body); if ($size <= $to_sub) { $desc = $m->art_body; } else { $desc = mb_substr($m->art_body, 0, $to_sub) . "... <a href='/mysite/basic/web/index.php?r=description/read&id={$m->desid}'> Читать далі>></a>"; } echo "<div style='display:table;width:100%'>\n\t\t\t\t\t<div style='display:table-cell;'>\n\t\t\t\t\t\t<h3><a href='/mysite/basic/web/index.php?r=description/read&id={$m->desid}'>{$m->header}</a></h3>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div style='display:table-cell;text-align:right;'>\n\t\t\t\t\t\t<a href='/mysite/basic/web/index.php?r=description/update&id={$m->desid}' ><i class='fa fa-pencil' title='Редагувати'></i></a>\n\t\t\t\t\t\t<a data-confirm='Are you sure you want to delete this item?' data-method='post' href='/mysite/basic/web/index.php?r=description/delete&id={$m->desid}' ><i class='fa fa-times' title='Видалити' ></i></a>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t\t<div>\n\t\t\t\t\t{$desc}\n\t\t\t\t</div>\n\t\t\t\t<div>\n\t\t\t\t\t<span style='color:rgb(246, 131, 2);'>Теги: #{$tag}</span>\n\t\t\t\t\t<span style='float: right;color: gray;'>Oпубліковано: {$m->date}</span>\n\t\t\t\t</div>\n\t\t\t\t<hr />\n\t\t\t"; } ?> </div>
<?php use yii\helpers\Html; use yii\grid\GridView; use app\models\Tag; /* @var $this yii\web\View */ /* @var $searchModel app\models\DescriptionSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = 'Заголовок: ' . $model->header; $this->params['breadcrumbs'][] = ['label' => 'Стаття', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; $html_photo = ''; if ($model->photo != '') { $html_photo = "<div><img src='{$model->photo}' width='300' /></div>"; } $tag = Tag::findOne($model->tag); ?> <div> <div class="tab2"> <div class="tab2-cell"> <h3><?php echo $model->header; ?> </h3> </div> <div class="tab2-cell" style='text-align:right;'> <span style='float: right;color: gray;'>Oпубліковано: <?php echo $model->date; ?> </span>