model() public static method

Returns the static model of the specified AR class.
public static model ( string $className = __CLASS__ ) : Tag
$className string active record class name.
return Tag the static model class
示例#1
2
 public function run()
 {
     $tags = Tag::model()->findAll();
     if ($tags) {
         foreach ($tags as $tag) {
             $post = Post::model()->findAll("FIND_IN_SET(:tag, tags)", array(':tag' => $tag->tag_name));
             $image = Image::model()->findAll("FIND_IN_SET(:tag, tags)", array(':tag' => $tag->tag_name));
             $soft = Soft::model()->findAll("FIND_IN_SET(:tag, seo_keywords)", array(':tag' => $tag->tag_name));
             $video = Video::model()->findAll("FIND_IN_SET(:tag, seo_keywords)", array(':tag' => $tag->tag_name));
             if (!$post && !$image && !$soft && !$video) {
                 $tag->delete();
             } else {
                 $tag->data_count = count($post) + count($image) + count($soft);
                 $tag->save();
             }
         }
     }
     $tagdatas = TagData::model()->findAll();
     if ($tagdatas) {
         foreach ($tagdatas as $value) {
             $modelType = ModelType::model()->findByPk($value->type);
             $model = $modelType->model;
             $data = $model::model()->findByPk($value->content_id);
             if (!$data) {
                 $value->delete();
             }
         }
     }
     $this->controller->message('success', Yii::t('admin', 'Reset Tags Success'), $this->controller->createUrl('index'));
 }
示例#2
0
    public function run()
    {
        /* @var WebUser $webUser */
        /** @noinspection PhpUndefinedFieldInspection */
        $webUser = Yii::app()->user;

        $models = Tag::model()->userId($webUser->id)->findAll();
        $tagCount = EntryHasTag::model()->userId($webUser->id)->count();

        $tags = array();
        foreach ($models as $model) {
            /* @var Tag $model */

            $entryCount = 0;
            foreach ($model->entries as $entry) {
                if ($entry->userId == $webUser->id) {
                    $entryCount++;
                }
            }

            if ($entryCount > 0) {
                $tags[] = array(
                    'name' => $model->name,
                    'weight' => ceil($entryCount / $tagCount * 10)
                );
            }
        }

        $this->render('cloud', array('tags' => $tags));
    }
 /**
  * Suggest Tags for Object
  * @param type $keyword 
  */
 public function suggestTags($keyword)
 {
     $tags = Tag::model()->suggestTags($keyword);
     if ($tags !== array()) {
         echo implode("\n", $tags);
     }
 }
示例#4
0
文件: Entry.php 项目: hersoncruz/ppma
    /**
     * @return void
     */
    public function resaveTags()
    {
        // delete all tag relations
        $this->deleteTags();

        // save tags and tag relations
        foreach ($this->tags as $tag) {
            /* @var WebUser $webUser */
            /** @noinspection PhpUndefinedFieldInspection */
            $webUser = Yii::app()->user;

            // try to receive tag from db
            $model = Tag::model()->name($tag->name)->userId($webUser->id)->find();

            if (!is_object($model)) {
                $model = $tag;
            }

            // save tag
            $model->name = $tag->name;
            $model->save();

            // save relation
            $relation = new EntryHasTag();
            $relation->entryId = $this->id;
            $relation->tagId = $model->id;
            $relation->save();
        }
    }
示例#5
0
 /**
  * @return void
  */
 protected function upgradeTo02()
 {
     // Add Tag-column
     /* @var CDbCommand $cmd */
     $cmd = Yii::app()->db->createCommand();
     $cmd->addColumn('Tag', 'userId', 'integer NOT NULL');
     $cmd->addForeignKey('user', 'Tag', 'userId', 'User', 'id', 'CASCADE', 'CASCADE');
     // Refresh DB-Schema
     Yii::app()->db->schema->refresh();
     Tag::model()->refreshMetaData();
     // Set user-IDs
     foreach (Tag::model()->findAll() as $model) {
         // Collect User-IDs
         $userIds = array();
         foreach ($model->entries as $entry) {
             $userIds[$entry->userId] = $entry->userId;
         }
         // Save tag with user relation
         foreach ($userIds as $userId) {
             $tag = new Tag();
             $tag->name = $model->name;
             $tag->userId = $userId;
             $tag->save(false);
         }
         // Remove tag
         $model->delete();
     }
 }
示例#6
0
 public function setTagsArray(array $data)
 {
     // reset dei tag per semplificare lo script
     ProductTag::model()->deleteAll('product=:p', array(':p' => $this->id));
     // data attuale
     $now = new DateTime();
     $timestamp = $now->format('Y-m-d H-i-s');
     // ricerca dei tag e creazione dei link
     foreach ($data as $tagName) {
         $tag = Tag::model()->find('name=:nm', array(':nm' => $tagName));
         /** @var Tag $tag */
         if ($tag == null) {
             $tag = new Tag();
             $tag->name = $tagName;
             $tag->description = ucwords($tagName);
             $tag->timestamp = $timestamp;
             $tag->insert();
         }
         $productTag = ProductTag::model()->find('product=:p AND tag=:t', array(':p' => $this->id, ':t' => $tag->id));
         /** @var ProductTag $productTag */
         if ($productTag == null) {
             $productTag = new ProductTag();
             $productTag->product = $this->id;
             $productTag->tag = $tag->id;
             $productTag->insert();
         }
     }
 }
 public function actionWrite()
 {
     $post = new Post();
     $post->blog_id = Yii::app()->getRequest()->getParam('blog-id');
     if ($postId = (int) Yii::app()->getRequest()->getQuery('id')) {
         $post = Post::model()->findUserPost($postId, Yii::app()->getUser()->getId());
         if ($post === null) {
             throw new CHttpException(404);
         }
     }
     if (Yii::app()->getRequest()->getIsPostRequest() && !empty($_POST['Post'])) {
         $data = Yii::app()->getRequest()->getPost('Post');
         $data['user_id'] = Yii::app()->getUser()->getId();
         $data['status'] = Yii::app()->getRequest()->getPost('draft', Post::STATUS_PUBLISHED);
         $data['tags'] = Yii::app()->getRequest()->getPost('tags');
         if ($post->createPublicPost($data)) {
             $message = Yii::t('BlogModule.blog', 'Post sent for moderation!');
             $redirect = ['/blog/publisher/my'];
             if ($post->isDraft()) {
                 $message = Yii::t('BlogModule.blog', 'Post saved!');
             }
             if ($post->isPublished()) {
                 $message = Yii::t('BlogModule.blog', 'Post published!');
                 $redirect = ['/blog/post/view', 'slug' => $post->slug];
             }
             Yii::app()->getUser()->setFlash(\yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, $message);
             $this->redirect($redirect);
         }
     }
     $this->render('write', ['post' => $post, 'blogs' => (new Blog())->getListForUser(Yii::app()->getUser()->getId()), 'tags' => array_values(CHtml::listData(Tag::model()->findAll(), 'id', 'name'))]);
 }
示例#8
0
 public function afterSave($event)
 {
     $model_id = get_class($this->owner);
     if (!isset($_POST[$model_id]['tags'])) {
         return true;
     }
     $tags = explode(',', $_POST[$model_id]['tags']);
     $ids = [];
     foreach ($tags as $tag_name) {
         $tag = Tag::model()->findByAttributes(['name' => $tag_name]);
         if (!$tag) {
             continue;
         }
         $ids[] = $tag->id;
         $exists = TagRel::model()->existsByAttributes(['tag_id' => $tag->id, 'object_id' => $this->owner->id, 'model_id' => $model_id]);
         if ($exists) {
             continue;
         }
         $tag_rel = new TagRel();
         $tag_rel->tag_id = $tag->id;
         $tag_rel->object_id = $this->owner->id;
         $tag_rel->model_id = $model_id;
         $tag_rel->save();
     }
     $this->_deleteRels($ids);
 }
 public function run()
 {
     $criteria = new CdbCriteria();
     $criteria->limit = $this->data('limit');
     $criteria->offset = $this->data('offset');
     $criteria->condition = "post_status='publish' AND (post_modified <= '" . date('Y-m-d H:i:s') . "' AND post_modified >= '" . $this->data('time') . "')";
     $criteria->order = 'post_hits DESC';
     if ($this->data('autoByTerm')) {
         if (isset($_GET['id'])) {
             $category = Category::model()->findByPK((int) $_GET['id']);
             $label = Label::model()->findByPK((int) $_GET['id']);
             $topic = Topic::model()->findByPK((int) $_GET['id']);
             $tag = Tag::model()->findByPK((int) $_GET['id']);
             if ($category != null) {
                 $criteria = $this->getCriteriaTerm('categories', $criteria);
             } elseif ($label != null) {
                 $criteria = $this->getCriteriaTerm('labels', $criteria);
             } elseif ($topic != null) {
                 $criteria = $this->getCriteriaTerm('topics', $criteria);
             } elseif ($tag != null) {
                 $criteria = $this->getCriteriaTerm('tags', $criteria);
             }
         }
     }
     $model = Post::model()->findAll($criteria);
     if ($model != null) {
         $this->layout($model);
     }
 }
示例#10
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Request();
     $modelJoin = new RequestJoinForm();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Request'], $_POST['RequestJoinForm'])) {
         $model->attributes = $_POST['Request'];
         $modelJoin->attributes = $_POST['RequestJoinForm'];
         $transaction = Yii::app()->db->beginTransaction();
         try {
             $model->save();
             if (isset($_POST['tags'])) {
                 $tags = Tag::model()->string2array($_POST['tags']);
                 foreach ($tags as $tagName) {
                     $tag = Tag::model()->findOrCreate($tagName);
                     $requestToTag = new RequestToTag();
                     $requestToTag->Request_ID = $model->Request_ID;
                     $requestToTag->Tag_ID = $tag->Tag_ID;
                     $requestToTag->save();
                 }
             }
             $modelJoin->request_ID = $model->Request_ID;
             $modelJoin->user_ID = $model->Create_User_ID;
             $modelJoin->save();
             $transaction->commit();
             $this->redirect(array('view', 'id' => $model->Request_ID));
         } catch (Exception $e) {
             $transaction->rollback();
         }
     }
     $this->render('create', array('model' => $model, 'modelJoin' => $modelJoin));
 }
示例#11
0
 /**
  * 根据用户ID与文件ID获得标签
  */
 public function getByUserIdAndFileId($userId, $fileId)
 {
     $condition = 'id in (select tag_id from ' . FileTag::model()->tableName();
     $condition .= ' where file_id=:file_id) and user_id in(0,:user_id)';
     $items = Tag::model()->findAll($condition, array(':file_id' => $fileId, ':user_id' => $userId));
     return $this->db2list($items);
 }
示例#12
0
 public function run()
 {
     $config = new CConfiguration(Yii::app()->basePath . '/config/pager.php');
     $session = Yii::app()->session;
     $cookies = Yii::app()->request->cookies;
     // If referrer is not our action delete search parameters from session.
     if (strpos(Yii::app()->request->urlReferrer, '/tag/list') === false) {
         unset($session['search']);
     }
     if (!empty($_POST['search']) && is_array($_POST['search'])) {
         $search = $_POST['search'];
         $session['search'] = $search;
     } else {
         if (!empty($session['search'])) {
             $search = $session['search'];
         } else {
             $search = array('name' => '');
         }
     }
     $criteria = new CDbCriteria();
     $criteria->condition = 'name LIKE :name';
     $criteria->params = array(':name' => "%{$search['name']}%");
     $criteria->order = 'name';
     $pages = new CPagination(Tag::model()->count($criteria));
     $config->applyTo($pages);
     $pages->applyLimit($criteria);
     $tags = Tag::model()->with('quotesCount')->findAll($criteria);
     $showSearchForm = !empty($cookies['showSearchForm']) && $cookies['showSearchForm']->value ? true : false;
     $this->controller->render('list', array('tags' => $tags, 'pages' => $pages, 'search' => $search, 'showSearchForm' => $showSearchForm));
 }
示例#13
0
 public function testRemove()
 {
     $tag = 'iphone';
     $data = array('site_id' => TagSite::getSiteId('ent'), 'news_id' => ArticleTags::genId(1), 'type' => 1, 'time' => util_time(7));
     $tag_id = Tag::model()->fetch($tag)->id;
     $count = TagArticles::model()->count($tag_id);
     $this->assertEquals(2, $count);
     $count = TagArticles::model()->count($tag_id, $data['site_id']);
     $this->assertEquals(1, $count);
     $count = TagArticles::model()->count($tag_id, 0, $data['type']);
     $this->assertEquals(1, $count);
     $count = TagArticles::model()->count($tag_id, $data['site_id'], $data['type']);
     $this->assertEquals(1, $count);
     $result = TagArticles::model()->removeIndex($tag_id, $data);
     //$this->assertTrue($result);
     $count = TagArticles::model()->count($tag_id);
     $this->assertEquals(1, $count);
     $count = TagArticles::model()->count($tag_id, $data['site_id']);
     $this->assertEquals(0, $count);
     $count = TagArticles::model()->count($tag_id, 0, $data['type']);
     $this->assertEquals(0, $count);
     $count = TagArticles::model()->count($tag_id, $data['site_id'], $data['type']);
     $this->assertEquals(0, $count);
     $result = TagArticles::model()->index($tag_id, $data);
     //$this->assertTrue($result);
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $question = new Question();
     if (isset($_POST['Question'])) {
         $this->forcePostRequest();
         $_POST = Yii::app()->input->stripClean($_POST);
         $question->attributes = $_POST['Question'];
         $question->content->populateByForm();
         $question->post_type = "question";
         if ($question->validate()) {
             $question->save();
             if (isset($_POST['Tags'])) {
                 // Split tag string into array
                 $tags = explode(", ", $_POST['Tags']);
                 foreach ($tags as $tag) {
                     $tag = Tag::model()->firstOrCreate($tag);
                     $question_tag = new QuestionTag();
                     $question_tag->question_id = $question->id;
                     $question_tag->tag_id = $tag->id;
                     $question_tag->save();
                 }
             }
             $this->redirect($this->createUrl('//questionanswer/question/view', array('id' => $question->id)));
         }
     }
     $this->render('create', array('model' => $question));
 }
示例#15
0
 /**
  * 首页
  */
 public function actionIndex()
 {
     $catalog_id = trim($this->_request->getParam('catalog_id'));
     $keyword = trim($this->_request->getParam('keyword'));
     //获取子孙分类(包括本身)
     $data = Catalog::model()->getChildren($catalog_id);
     $catalog = $data['catalog'];
     $db_in_ids = $data['db_in_ids'];
     //SEO
     $navs = array();
     if ($catalog) {
         $this->_seoTitle = $catalog->seo_title ? $catalog->seo_title : $catalog->catalog_name . ' - ' . $this->_setting['site_name'];
         $this->_seoKeywords = $catalog->seo_keywords;
         $this->_seoDescription = $catalog->seo_description;
         $navs[] = array('url' => $this->createUrl('image/index', array('catalog_id' => $catalog->id)), 'name' => $catalog->catalog_name);
     } else {
         $seo = ModelType::getSEO('image');
         $this->_seoTitle = $seo['seo_title'] . ' - ' . $this->_setting['site_name'];
         $this->_seoKeywords = $seo['seo_keywords'];
         $this->_seoDescription = $seo['seo_description'];
         $navs[] = array('url' => $this->_request->getUrl(), 'name' => $this->_seoTitle);
     }
     //获取所有符合条件的图集
     $condition = '';
     $catalog && ($condition .= ' AND catalog_id IN (' . $db_in_ids . ')');
     $datalist = Image::model()->getList(array('condition' => $condition, 'limit' => 15, 'order' => $order_by, 'page' => true), $pages);
     //标签
     $tags = Tag::model()->findAll(array('order' => 'data_count DESC', 'limit' => 20));
     //最近的图集
     $last_images = Image::model()->getList(array('condition' => $condition, 'limit' => 10));
     //加载css,js
     Yii::app()->clientScript->registerCssFile($this->_stylePath . "/css/list.css");
     Yii::app()->clientScript->registerScriptFile($this->_static_public . "/js/jquery/jquery.js");
     $this->render('index', array('navs' => $navs, 'datalist' => $datalist, 'pagebar' => $pages, 'tags' => $tags, 'last_images' => $last_images));
 }
示例#16
0
 /**
  * 批量操作
  *
  */
 public function actionBatch()
 {
     if ($this->method() == 'GET') {
         $command = trim($_GET['command']);
         $ids = intval($_GET['id']);
     } else {
         if ($this->method() == 'POST') {
             $command = trim($_POST['command']);
             $ids = $_POST['id'];
         } else {
             $this->message('errorBack', Yii::t('admin', 'Only POST Or GET'));
         }
     }
     empty($ids) && $this->message('error', Yii::t('admin', 'No Select'));
     switch ($command) {
         case 'tagsDelete':
             //删除评论
             foreach ((array) $ids as $id) {
                 $tagModel = Tag::model()->findByPk($id);
                 if ($tagModel) {
                     $tagModel->delete();
                 }
             }
             break;
         default:
             throw new CHttpException(404, Yii::t('admin', 'Error Operation'));
             break;
     }
     $this->message('success', Yii::t('admin', 'Batch Operate Success'), $this->createUrl('index'));
 }
示例#17
0
    public function afterSave()
    {
        $this->_deleteRels();

        $model_id = get_class($this->owner);

        if (isset($_POST[$model_id]['tags']))
        {
            foreach (explode(',', $_POST[$model_id]['tags']) as $tag_name)
            {
                $tag = Tag::model()->find("name = '{$tag_name}'");
                if (!$tag)
                {
                    $tag = new Tag();
                    $tag->name = $tag_name;
                    $tag->save();
                }

                $tag_rel = new TagRel();
                $tag_rel->tag_id    = $tag->id;
                $tag_rel->object_id = $this->owner->id;
                $tag_rel->model_id  = $model_id;
            }
        }
    }
示例#18
0
 public function run()
 {
     /*Top nxb*/
     $criteria = new CDbCriteria();
     $criteria->order = 'frequency desc';
     $list = Tag::model()->findAll($criteria);
     $this->render('category', array('list' => $list));
 }
示例#19
0
 public function missingAction($name)
 {
     $model = Tag::model()->findByAttributes(array('name' => $name));
     if (!$model) {
         parent::missingAction($name);
     }
     $this->render('view', array('model' => $model));
 }
 private function loadModel($id, $slug)
 {
     $models = Tag::model()->findByAttributes(array('term_id' => (int) $id, 'slug' => $slug));
     if ($models === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $models;
 }
示例#21
0
 public function delete()
 {
     $post_id = $_GET['id'];
     Post::model()->delete($post_id);
     Tag::model()->delete($post_id);
     Comment::model()->delete($post_id);
     Application::redirect(array('post' => 'index'));
 }
示例#22
0
 protected function renderContent()
 {
     $tags = Tag::model()->findTagWeights($this->maxTags);
     foreach ($tags as $tag => $weight) {
         $link = CHtml::link(CHtml::encode($tag), array('post/index', 'tag' => $tag));
         echo CHtml::tag('span', array('class' => 'tag', 'style' => "font-size:{$weight}pt"), $link) . "\n";
     }
 }
示例#23
0
 public function actionSuggestTags()
 {
     if (isset($_GET['q']) && ($keyword = trim($_GET['q'])) !== '') {
         $tags = Tag::model()->suggestTags($keyword);
         if ($tags !== array()) {
             echo implode("\n", $tags);
         }
     }
 }
示例#24
0
 public function actionView($tid)
 {
     $criteria = new CDbCriteria();
     $criteria->with = 'questions';
     $criteria->addCondition('t.id=' . $tid);
     $tag = Tag::model()->find($criteria);
     $myLike = LikeQue::model()->findAll('userId=:uid', array(':uid' => Yii::app()->user->id));
     $this->render('view', array('tag' => $tag, 'myLike' => $myLike));
 }
 /**
  * @param int $tag_id
  * @param string $tag_name
  */
 public function actionTag($tag_id, $tag_name = "")
 {
     $tag_id = IntVal($tag_id);
     $this->top_menu = "themen";
     /** @var Tag $tag */
     $tag = Tag::model()->findByPk($tag_id);
     $antraege_tag = $tag->antraege;
     $this->render("tag", ["tag" => $tag, "antraege_tag" => $antraege_tag]);
 }
示例#26
0
 public function actionLatest($count = 20)
 {
     $criteria = new CDbCriteria();
     $criteria->limit = (int) $count;
     $criteria->order = 'id desc';
     $tags = Tag::model()->findAll($criteria);
     user()->setFlash('table_caption', t('latest_tags_list', 'admin') . ':Top ' . $count);
     $this->render('list', array('models' => $tags, 'pages' => null));
 }
示例#27
0
 public function testRename()
 {
     $from = 'iphone';
     $to = 'iphone5';
     $tag = Tag::fetch($from);
     $this->assertTrue($tag->rename($to));
     $this->assertEquals($to, $tag->name);
     $tag2 = Tag::model()->findByPk($tag->id);
     $this->assertEquals($to, $tag2->name);
 }
示例#28
0
 public function init()
 {
     parent::init();
     //导航标示
     $this->_menu_unique = 'soft';
     //一级栏目
     $this->_catalog = Catalog::getTopCatalog(true, $this->_type_ids['soft']);
     //标签
     $this->_tags = Tag::model()->findAll(array('order' => 'data_count DESC', 'limit' => 20));
 }
示例#29
0
 public function run()
 {
     $criteria = new CDbCriteria();
     $criteria->order = 'name';
     $tags = Tag::model()->with('approvedQuotesCount')->findAll($criteria);
     // Delete tags with empty quotesCount (With PHP > 5.3 e can use closure here).
     // TODO: Rewrite this code for PHP 5.3 when it will be avaliable.
     /*
      * PHP > 5.3 version.
      * 
      * $tags = array_filter($tags, function ($t) { 
      * 	return (boolean)$t->quotesCount; 
      * }); 
      */
     function tagsFilter($tag)
     {
         return (bool) $tag->quotesCount;
     }
     $tags = array_filter($tags, 'tagsFilter');
     // Sort tags by their weights (quotesCount).
     /*function tagsSort($a, $b)
     		{
     			if($a->quotesCount == $b->quotesCount)
     				return 0;
     
     			return ($a->quotesCount > $b->quotesCount) ? -1 : 1;
     		}
     		usort($tags, 'tagsSort');*/
     /*
      * Calculate tags weights algorythm from http://en.wikipedia.org/wiki/Tag_cloud
      */
     // Find minimum and maximum weights.
     $minWeight = $maxWeight = 0;
     foreach ($tags as $tag) {
         if ($tag->approvedQuotesCount > $maxWeight) {
             $maxWeight = $tag->approvedQuotesCount;
         }
         if (!$minWeight || $minWeight > $tag->approvedQuotesCount) {
             $minWeight = $tag->approvedQuotesCount;
         }
     }
     $fontSizeMin = 100;
     // Minimum tag font size (in percents).
     $fontSizeMax = 200;
     // Maximum tag font size (in percents).
     $tagWeights = array();
     foreach ($tags as $tag) {
         if ($tag->approvedQuotesCount > $minWeight) {
             $tagWeights[$tag->id] = (int) ($fontSizeMax * ($tag->approvedQuotesCount - $minWeight) / $maxWeight - $minWeight);
         } else {
             $tagWeights[$tag->id] = 1;
         }
     }
     $this->render('tagsCloud', array('tags' => $tags, 'tagWeights' => $tagWeights));
 }
示例#30
0
 public function run()
 {
     $criteria = new CDbCriteria();
     $criteria->select = 'tag_name, data_count';
     $criteria->order = 'data_count DESC';
     $tags = Tag::model()->findAll($criteria);
     //SEO
     $this->controller->_seoTitle = Yii::t('common', 'All Tags') . ' - ' . $this->controller->_setting['site_name'];
     $navs[] = array('url' => Yii::app()->request->getUrl(), 'name' => Yii::t('common', 'All Tags'));
     $this->controller->render('all', array('navs' => $navs, 'tags' => $tags));
 }