本文整理汇总了PHP中app\models\Tag::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Tag::find方法的具体用法?PHP Tag::find怎么用?PHP Tag::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Tag
的用法示例。
在下文中一共展示了Tag::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getById
/**
* Get tag by id.
*
* @param $id
* @return mixed
*/
public function getById($id)
{
$tag = $this->model->find($id);
if (!is_null($tag)) {
$tag->hot++;
$tag->update();
}
return $tag;
}
示例2: actionInit
public function actionInit()
{
$imageList = Image::find()->asArray()->all();
foreach ($imageList as $image) {
$rawFilePath = $image['rawFilePath'];
$match = [];
if (preg_match('/\\/homeNASDownloads\\/photo_[0-9\\-]+\\/?(.*)/', dirname($rawFilePath), $match)) {
$tagName = $match[1];
if (empty($tagName)) {
continue;
}
$tag = Tag::find()->where(['tagName' => $tagName])->one();
if ($tag === null) {
$tag = new Tag();
$tag->tagName = $tagName;
$tag->isDelete = false;
$now = date('Y-m-d H:i:s');
$tag->createTime = $now;
$tag->updateTime = $now;
$tag->save();
}
$imageTag = ImageTag::find()->where(['imageId' => $image['id'], 'tagId' => $tag->id])->one();
if ($imageTag == null) {
$imageTag = new ImageTag();
$imageTag->imageId = $image['id'];
$imageTag->tagId = $tag->id;
$imageTag->isDelete = false;
$imageTag->createTime = $now;
$imageTag->updateTime = $now;
$imageTag->save();
}
}
}
}
示例3: addTags
public static function addTags($tags_str, $id)
{
$tags = self::string2array($tags_str);
foreach ($tags as $one) {
$tag_exists = Tag::find()->where("name = '" . $one . "'")->one();
//var_dump($tag_exists); exit;
if ($tag_exists == null) {
$tag = new Tag();
$tag->name = $one;
$tag->frequency = 1;
$tag->items .= $id;
$tag->save();
} else {
if (array_search($id, self::string2array($tag_exists->items)) === false || array_search($id, self::string2array($tag_exists->items)) < 0) {
//var_dump($id);
//var_dump(self::string2array($tag_exists->items));
//var_dump(array_search($id, self::string2array($tag_exists->items)) === false);
//var_dump(array_search($id, self::string2array($tag_exists->items)) < 0); exit;
$tag_exists->frequency++;
$tag_exists->items .= "," . $id;
$tag_exists->update();
}
}
}
}
示例4: delete
public function delete()
{
$user = $this->auth();
$tag = Tag::find(Input::get('tagId'));
$tag->delete();
return $this->output(new \stdClass());
}
示例5: actionIndex
/**
* Lists all Partner models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new PartnerSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
// $this->ajaxAssign('tags', Tag::find()->asArray()->publicTags()->all());
return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'tags' => [__('Public tags') => Tag::find()->publicTags()->all(), __('Personal tags') => Tag::find()->personalTags()->all()]]);
}
示例6: getTagWeights
public static function getTagWeights($limit = 20)
{
$models = Tag::find()->with('posts')->orderBy('name')->all();
$minFrequency = 0;
$maxFrequency = 0;
foreach ($models as $model) {
$weight = count($model->posts);
$minFrequency = $minFrequency > $weight ? $weight : $minFrequency;
$maxFrequency = $maxFrequency < $weight ? $weight : $maxFrequency;
}
$sizeRange = self::MAX_FONT_SIZE - self::MIN_FONT_SIZE;
$minCount = log($minFrequency + 1);
$maxCount = log($maxFrequency + 1);
if ($maxCount != $minCount) {
$countRange = $maxCount - $minCount;
} else {
$countRange = 1;
}
$tags = [];
foreach ($models as $model) {
$tags[$model->name] = round(self::MIN_FONT_SIZE + (log(count($model->posts) + 1) - $minCount) * ($sizeRange / $countRange));
}
arsort($tags);
return $tags;
}
示例7: actionCreate
/**
* Creates a new Artist model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Artist();
$photos = [];
if (Yii::$app->request->isPost) {
for ($i = 0; $i < count(Yii::$app->request->post('Photo', [])); $i++) {
$photos[] = new Photo();
}
$data = Yii::$app->request->post();
$data['Artist']['user_id'] = Yii::$app->user->id;
} else {
$data = null;
}
if ($model->load($data) && $model->save()) {
Photo::loadMultiple($photos, Yii::$app->request->post());
foreach ($photos as $photo) {
$photo->artist_id = $model->id;
}
if (Photo::validateMultiple($photos)) {
foreach ($photos as $photo) {
$model->link('photos', $photo);
}
}
$tags = Yii::$app->request->post('Artist', '');
$tags = Tag::find()->where(['in', 'id', explode(',', $tags['tags'])])->all();
foreach ($tags as $tag) {
$model->link('tags', $tag);
}
return $this->redirect(['release/index', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model, 'photos' => $photos]);
}
}
示例8: show
/**
* Get a tag JSON by a given tag_id
* method: get
* route: api/tags/<tag_id>
* @param int $tag_id
* @return json {"success": true or false, "data": {"tag": tag}};
*/
public function show($tag_id)
{
$tag = Tag::find($tag_id);
if ($tag == NULL) {
return \Response::json(array("success" => false));
}
return \Response::json(["success" => true, "data" => array("tag" => $tag)]);
}
示例9: show
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
$tag = Tag::find($id);
if (empty($tag)) {
Flash::error('Tag not found');
return redirect(route('admin.tags.index'));
}
return view('admin.tags.show')->with('tag', $tag);
}
示例10: show
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
//
$tag = Tag::find($id);
if (!$tag) {
return $this->respondNotFound();
}
return $this->respond(['data' => [$this->tagTransformer->transform($tag->toArray())]]);
}
示例11: deleteChildRe
public function deleteChildRe($id)
{
$tags = $this->where('parent_id', $id)->get();
if (count($tags) > 0) {
foreach ($tags as $tag) {
Tag::find($tag->id)->delete();
}
}
}
示例12: delete
public function delete($id)
{
$tag = Tag::find($id);
if (!$tag) {
return false;
}
$tag->posts()->detach();
return $tag->delete();
}
示例13: update
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param int $id
* @return Response
*/
public function update(Request $request, $id)
{
$tag = Tag::find($id);
$tag->tagname = $request->get('tagname');
$updateStatus = $tag->save();
if (!$updateStatus) {
abort(500, 'Some error occurred while saving user data');
}
}
示例14: run
public function run()
{
$tags = Tag::find()->joinWith(['postLinks'])->groupBy('tag.id')->limit($this->count)->orderBy('tag.frequency desc')->all();
$output = '';
foreach ($tags as $tag) {
/* @var $tag Tag */
$output .= Html::a('#' . $tag->tag, ['/frontend/post/search', 'tag' => $tag->tag], ['class' => 'tag']);
}
return $output;
}
示例15: publish
/**
* Update status of the specified resource in storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function publish($id, $status = 'n')
{
if (!is_admin()) {
return abort(404);
}
$tag = Tag::find($id);
$status = $status == 'y' ? Tag::openCode : Tag::hiddenCode;
TagService::updateTag($tag->id, $status);
return redirect()->back()->with('success', '[' . $tag->name . ']을 공개했습니다.');
}