示例#1
0
文件: Tag.php 项目: hersoncruz/ppma
    /**
     * @return void
     */
    public function afterDelete()
    {
        // remove Entry relations
        EntryHasTag::model()->deleteAllByAttributes(array('tagId' => $this->id));

        parent::afterDelete();
    }
示例#2
0
文件: Entry.php 项目: humantech/ppma
 /**
  *
  * @return void
  */
 public function deleteTags()
 {
     $relations = EntryHasTag::model()->entryId($this->id)->findAll();
     foreach ($relations as $relation) {
         $relation->delete();
     }
 }
示例#3
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));
    }
示例#4
0
 /**
  * (non-PHPdoc)
  * @see yii/CWidget#run()
  */
 public function run()
 {
     $models = Tag::model()->userId(Yii::app()->user->id)->findAll();
     $tagCount = EntryHasTag::model()->userId(Yii::app()->user->id)->count();
     $tags = array();
     foreach ($models as $model) {
         $entryCount = 0;
         foreach ($model->entries as $entry) {
             if ($entry->userId == Yii::app()->user->id) {
                 $entryCount++;
             }
         }
         if ($entryCount > 0) {
             $tags[] = array('name' => $model->name, 'weight' => ceil($entryCount / $tagCount * 10));
         }
     }
     $this->render('cloud', array('tags' => $tags));
 }
示例#5
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();
        }
    }