示例#1
0
 public function _test_should_store_zero_strings_as_intergers()
 {
     $Tag = new Tag(array('name' => 'Ticket #21'));
     $this->assertTrue($Tag->save());
     $this->assertEqual($Tag->get('score'), 100);
     $Tag->setAttributes(array('score' => '0'));
     $this->assertTrue($Tag->save());
     $Tag = $Tag->find($Tag->id);
     $this->assertIdentical($Tag->get('score'), 0);
 }
示例#2
0
 public function executeSaveTag()
 {
     try {
         $parameters = $this->getRequest()->getParameterHolder()->getAll();
         if ($parameters['id']) {
             $obj = Document::getDocumentInstance($parameters['id']);
             $parent = Document::getParentOf($parameters['id']);
         } else {
             $obj = new Tag();
             $parent = Document::getDocumentInstance($parameters['parent']);
         }
         foreach ($parameters as $key => $value) {
             if (!(strpos($key, 'attr') === false)) {
                 $function = 'set' . str_replace('attr', '', $key);
                 $obj->{$function}($value);
             }
         }
         if (!$parameters['attrExclusive']) {
             $obj->setExclusive(0);
         }
         $obj->save(null, $parent);
         UtilsHelper::setBackendMsg("Saved");
     } catch (Exception $e) {
         UtilsHelper::setBackendMsg("Error while saving: " . $e->getMessage(), "error");
     }
     PanelService::redirect('tag');
     exit;
 }
示例#3
0
 /**
  * @param sfGuardUser $user
  * @param integer $element_id
  * @param string $name
  * @param string $type
  */
 public static function newTag($user, $element_id, $name, $type)
 {
     $tag = TagTable::getInstance()->findOneByNameAndUserId($name, $user->id);
     if (!$tag) {
         $tag = new Tag();
         $tag->setName(substr($name, 0, self::MAX_LENGTH));
         $tag->setUserId($user->id);
         $tag->save();
     }
     if ($type == 'decision') {
         $tagDecision = new TagDecision();
         $tagDecision->setDecisionId($element_id);
         $tagDecision->setTagId($tag->id);
         $tagDecision->save();
     } else {
         if ($type == 'release') {
             $tagRelease = new TagRelease();
             $tagRelease->setReleaseId($element_id);
             $tagRelease->setTagId($tag->id);
             $tagRelease->save();
         } else {
             $tagAlternative = new TagAlternative();
             $tagAlternative->setAlternativeId($element_id);
             $tagAlternative->setTagId($tag->id);
             $tagAlternative->save();
             Doctrine_Query::create()->delete('Graph')->where('decision_id = ?', $tagAlternative->Alternative->decision_id)->execute();
         }
     }
     return;
 }
示例#4
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();
     }
 }
示例#5
0
 public static function savePostTags($postid, $tags)
 {
     $postid = (int) $postid;
     if (0 === $postid || empty($tags)) {
         return false;
     }
     if (is_string($tags)) {
         $tags = self::filterTagsArray($tags);
     }
     $count = 0;
     foreach ((array) $tags as $v) {
         $model = self::model()->findByAttributes(array('name' => $v));
         if ($model === null) {
             $model = new Tag();
             $model->name = $v;
             if ($model->save()) {
                 $count++;
             }
         }
         $row = app()->getDb()->createCommand()->select('id')->from(TABLE_POST_TAG)->where(array('and', 'post_id = :postid', 'tag_id = :tagid'), array(':postid' => $postid, ':tagid' => $model->id))->queryScalar();
         if ($row === false) {
             $columns = array('post_id' => $postid, 'tag_id' => $model->id);
             $count = app()->getDb()->createCommand()->insert(TABLE_POST_TAG, $columns);
             if ($count > 0) {
                 $model->post_nums = $model->post_nums + 1;
                 $model->save(true, array('post_nums'));
             }
         }
         unset($model);
     }
     return $count;
 }
示例#6
0
文件: Model.php 项目: peacq/picorm
 public static function createAndSaveRawModelWithManyToManyRelation()
 {
     include_once __DIR__ . '/../scripts/tested_models.php';
     $car = new \Car();
     $car->nameCar = 'AcmeCar';
     $car->noteCar = '10';
     $car->idBrand = 1;
     $car->save();
     $tags = array();
     $tag1 = new \Tag();
     $tag1->libTag = 'Sport';
     $tag1->save();
     $tag2 = new \Tag();
     $tag2->libTag = 'Family';
     $tag2->save();
     $tag3 = new \Tag();
     $tag3->libTag = 'Crossover';
     $tag3->save();
     $tags[] = $tag1;
     $tags[] = $tag2;
     $tags[] = $tag3;
     $car->setTag($tags);
     $car->save();
     // create test
     $req = \PicORM\Model::getDataSource()->prepare('SELECT count(*) as nb FROM car_have_tag WHERE idCar = ?');
     $req->execute(array($car->idCar));
     $resultBDD = $req->fetch(\PDO::FETCH_ASSOC);
     return array(array($car, $tags, $resultBDD));
 }
示例#7
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;
            }
        }
    }
示例#8
0
 public static function recordTags($phrase, $model, $obj)
 {
     $tags = TagTools::splitPhrase($phrase);
     foreach ($tags as $settag) {
         $tag = new Tag();
         if ($model == "etime") {
             $modelTag = new EtimeTag();
         } else {
             $modelTag = new EventTag();
         }
         $tag->setTag($settag);
         $c = new Criteria();
         $c->add(TagPeer::NORMALIZED_TAG, $tag->getNormalizedTag());
         $tag_exists = TagPeer::doSelectOne($c);
         if (!$tag_exists) {
             $tag->save();
         } else {
             $tag = $tag_exists;
         }
         if ($model == "etime") {
             $modelTag->setEtime($obj);
         } else {
             $modelTag->setEvent($obj);
         }
         $modelTag->setTag($tag);
         $modelTag->save();
     }
     return true;
 }
示例#9
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $user_id = Auth::id();
     $comment = Input::get('comment');
     $tags = Input::get('tagged_uid');
     $rating = Input::get('rating');
     $type = Input::get('media_type');
     $imdb_id = Input::get('imdb_id');
     $post = new Post();
     $post->user_id = $user_id;
     $post->type = $type;
     $post->imdb_id = $imdb_id;
     $post->rating = $rating;
     $post->comment = $comment;
     $post->save();
     if (sizeof($tags) > 0) {
         foreach ($tags as $tagged_uid) {
             $tag = new Tag();
             $tag->post_id = $post->id;
             $tag->user_tagging = $user_id;
             $tag->user_tagged = $tagged_uid;
             $tag->save();
         }
     }
     return Redirect::to('/media/' . $imdb_id);
 }
示例#10
0
 public static function add($id, $meta)
 {
     $desc = Description::create(['id' => $id, 'name' => $meta->name, 'market_name' => $meta->market_name ?: $meta->name, 'icon_url' => $meta->icon_url, 'icon_url_large' => isset($meta->icon_url_large) ? $meta->icon_url_large : '', 'name_color' => $meta->name_color ?: '000000']);
     if (!empty($meta->actions)) {
         foreach ($meta->actions as $idx => $action) {
             if ($action->name == 'Inspect in Game...') {
                 $desc->inspect_url_template = $action->link;
                 $desc->save();
                 break;
             }
         }
     }
     foreach ($meta->tags as $idx => $tag_data) {
         $tag = Tag::find('all', array('conditions' => array('category = ? AND category_name = ? AND internal_name = ? AND name = ?', $tag_data->category, $tag_data->category_name, $tag_data->internal_name, $tag_data->name)));
         if (empty($tag)) {
             $tag = new Tag(['category' => $tag_data->category, 'category_name' => $tag_data->category_name, 'internal_name' => $tag_data->internal_name, 'name' => $tag_data->name]);
             if (!$tag->is_valid()) {
                 $desc->delete();
                 return null;
             } else {
                 $tag->save();
             }
         } else {
             $tag = $tag[0];
         }
         if ($tag_data->category == 'Rarity') {
             $desc->name_color = $tag_data->color;
             $desc->save();
         }
         Descriptiontag::create(['description_id' => $desc->id, 'tag_id' => $tag->id]);
     }
     return $desc;
 }
示例#11
0
 /**
  * Private! Please do not call this function directly, just let the Tag library use it.
  * Increment count of tag by one. This function will create tag record if it does not exist.
  *
  * @param string $tagString
  */
 public static function incrementCount($tagString, $tagSlug, $count)
 {
     if ($count <= 0) {
         return;
     }
     $tag = Tag::where('slug', '=', $tagSlug)->first();
     if (!$tag) {
         $tag = new Tag();
         $tag->name = $tagString;
         $tag->slug = $tagSlug;
         $tag->suggest = false;
         $tag->save();
     }
     $tag->count = $tag->count + $count;
     $tag->save();
 }
示例#12
0
文件: Tag.php 项目: Sywooch/noteapp
 /**
  * @param String $tag
  * @return Tag
  */
 public function createNew($tag)
 {
     $tagInstance = new Tag();
     $tagInstance->name = $tag;
     $tagInstance->save();
     return $tagInstance;
 }
示例#13
0
文件: post.php 项目: xfra35/fabulog
 /**
  * set and add new tags to the post entity
  * @param string $val
  * @return array
  */
 public function set_tags($val)
 {
     if (!empty($val)) {
         $tagsArr = \Base::instance()->split($val);
         $tag_res = new Tag();
         $tags = array();
         // find IDs of known Tags
         $known_tags = $tag_res->find(array('title IN ?', $tagsArr));
         if ($known_tags) {
             foreach ($known_tags as $tag) {
                 $tags[$tag->_id] = $tag->title;
             }
             $newTags = array_diff($tagsArr, array_values($tags));
         } else {
             $newTags = $tagsArr;
         }
         // create remaining new Tags
         foreach ($newTags as $tag) {
             $tag_res->reset();
             $tag_res->title = $tag;
             $out = $tag_res->save();
             $tags[$out->_id] = $out->title;
         }
         // set array of IDs to current Post
         $val = array_keys($tags);
     }
     return $val;
 }
示例#14
0
 /**
  * This function will create a new user object and return the newly created user object.
  *
  * @param array $userInfo This should have the properties: username, firstname, lastname, password, ui_language
  *
  * @return mixed
  */
 public function registerUser(array $userInfo, $userLanguage)
 {
     $user = \User::create($userInfo);
     //make the first user an admin
     if (\User::all()->count() <= 1) {
         $user->is_admin = 1;
     }
     // Trim trailing whitespace from user first and last name.
     $user->firstname = trim($user->firstname);
     $user->lastname = trim($user->lastname);
     $user->save();
     \Setting::create(['ui_language' => $userLanguage, 'user_id' => $user->id]);
     /* Add welcome note to user - create notebook, tag and note */
     //$notebookCreate = Notebook::create(array('title' => Lang::get('notebooks.welcome_notebook_title')));
     $notebookCreate = new \Notebook();
     $notebookCreate->title = Lang::get('notebooks.welcome_notebook_title');
     $notebookCreate->save();
     $notebookCreate->users()->attach($user->id, ['umask' => \PaperworkHelpers::UMASK_OWNER]);
     //$tagCreate = Tag::create(array('title' => Lang::get('notebooks.welcome_note_tag'), 'visibility' => 0));
     $tagCreate = new \Tag();
     $tagCreate->title = Lang::get('notebooks.welcome_note_tag');
     $tagCreate->visibility = 0;
     $tagCreate->user_id = $user->id;
     $tagCreate->save();
     //$tagCreate->users()->attach($user->id);
     $noteCreate = new \Note();
     $versionCreate = new \Version(['title' => Lang::get('notebooks.welcome_note_title'), 'content' => Lang::get('notebooks.welcome_note_content'), 'content_preview' => mb_substr(strip_tags(Lang::get('notebooks.welcome_note_content')), 0, 255), 'user_id' => $user->id]);
     $versionCreate->save();
     $noteCreate->version()->associate($versionCreate);
     $noteCreate->notebook_id = $notebookCreate->id;
     $noteCreate->save();
     $noteCreate->users()->attach($user->id, ['umask' => \PaperworkHelpers::UMASK_OWNER]);
     $noteCreate->tags()->sync([$tagCreate->id]);
     return $user;
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $tag = new Tag();
     $tag->name = Input::get('name');
     $tag->save();
     return Redirect::action('TagController@index')->with('flash_message', 'Your tag been added.');
 }
示例#16
0
 public function createPostAction()
 {
     if ($this->request->isPost()) {
         $post = new Post();
         $post->topic = $this->request->getPost('title');
         $post->content = str_replace('</div>', '\\n', str_replace('<div>', '', $this->request->getPost('post')));
         $post->is_service = $this->request->getPost('is_service');
         $post->created_at = date('d.m.Y, h:i');
         if ($post->save()) {
             $tt = explode(',', $this->request->getPost('tags'));
             foreach ($tt as $t) {
                 $tag = Tag::findFirst(array('conditions' => 'name = ?1', 'bind' => array(1 => $t)));
                 if ($tag) {
                     $tag_post = new PostTag();
                     $tag_post->post_id = $post->id;
                     $tag_post->tag_id = $tag->id;
                     if (!$tag_post->save()) {
                         message($this, 'd', 'Ошибка привязки категории к посту');
                         return $this->response->redirect();
                     }
                 } else {
                     $tag = new Tag();
                     $tag->name = $t;
                     if ($tag->save()) {
                         $tag_post = new PostTag();
                         $tag_post->post_id = $post->id;
                         $tag_post->tag_id = $tag->id;
                         if (!$tag_post->save()) {
                             message($this, 'd', 'Ошибка привязки категории к посту');
                             return $this->response->redirect();
                         }
                     } else {
                         message($this, 'd', 'Ошибка сохранения новой категории');
                         return $this->response->redirect();
                     }
                 }
             }
             message($this, 's', 'Новость успешно добавлена');
             return $this->response->redirect();
         } else {
             foreach ($post->getMessages() as $message) {
                 message($this, "d", "Ошибка: " . $message->getMessage() . " в поле " . $message->getField() . ". Тип: " . $message->getType());
             }
             return $this->response->redirect();
         }
     } else {
         $this->assets->collection('headerJs')->addJs("js/jquery-ui.min.js");
         $this->assets->collection('headerCss')->addCss("css/jquery-ui.min.css")->addCss("css/jquery-ui.structure.min.css");
         $tt = Tag::find();
         $tags = "";
         foreach ($tt as $tag) {
             $tags .= '"' . $tag->name . '", ';
         }
         $tags = substr($tags, 0, -2);
         $this->view->setParamToView('tags', $tags);
     }
 }
示例#17
0
文件: Tag.php 项目: VoDongMy/VoDongMy
 public static function addNew($array)
 {
     $value = new Tag();
     $value->name = $array['name'];
     $value->slug = Str::slug($array['name']);
     $value->template = $array['template'];
     $value->save();
     return;
 }
示例#18
0
 public function addTags($tagsStr)
 {
     foreach (explode(",", $tagsStr) as $tag) {
         $tag = trim($tag);
         $tO = new Tag();
         $tO->pid = $this->id;
         $tO->name = $tag;
         $tO->save();
     }
 }
 public static function createOrGetTags($tagsArray, $noteId, $noteUmask)
 {
     $tagsPublicPrefixCharacter = Config::get('paperwork.tagsPublicPrefixCharacter')[0];
     $createdOrFoundIds = array();
     if (is_null($tagsArray)) {
         return null;
     }
     $userId = Auth::user()->id;
     foreach ($tagsArray as $tagItem) {
         $tagTitle = '';
         $tagVisibility = 0;
         if ($tagItem[0] === $tagsPublicPrefixCharacter) {
             $tagTitle = strtolower(substr($tagItem, 1));
             $tagVisibility = 1;
             $tag = Tag::where('tags.title', '=', $tagTitle)->where('tags.visibility', '=', $tagVisibility)->first();
         } else {
             $tagTitle = strtolower($tagItem);
             $tagVisibility = 0;
             $tag = Tag::where('tags.title', '=', $tagTitle)->where('tags.visibility', '=', $tagVisibility)->where('tags.user_id', '=', $userId)->first();
         }
         // ->where('tags.title', '=', $tagTitle)
         // ->where('tags.visibility', '=', $tagVisibility)
         // ->select('tags.id')
         // ->first();
         if (is_null($tag) && ($tagVisibility == 0 || $tagVisibility == 1 && $noteUmask > PaperworkHelpers::UMASK_READONLY)) {
             $newTag = new Tag();
             $newTag->title = $tagTitle;
             $newTag->visibility = $tagVisibility;
             $newTag->user_id = $userId;
             $newTag->save();
             //$newTag->users()->attach(Auth::user()->id);
             $createdOrFoundIds[] = $newTag->id;
         } else {
             if ($tagVisibility == 0 || $tagVisibility == 1 && $noteUmask > PaperworkHelpers::UMASK_READONLY) {
                 /*if(is_null($tag->users()->where('users.id', '=', Auth::user()->id)->first())) {
                 			$tag->users()->attach(Auth::user()->id);
                 		}*/
                 $createdOrFoundIds[] = $tag->id;
             }
         }
     }
     //we need to add the other user's private tags to the list.
     $addtags = Note::find($noteId)->tags()->where('tags.visibility', '=', 0)->where('tags.user_id', '!=', $userId)->get();
     foreach ($addtags as $addtag) {
         $createdOrFoundIds[] = $addtag->id;
     }
     //if the user is not writer, he cannot change public tags.
     if ($noteUmask < PaperworkHelpers::UMASK_READWRITE) {
         $addpubtags = Note::find($noteId)->tags()->where('tags.visibility', '=', 1)->get();
         foreach ($addpubtags as $addtag) {
             $createdOrFoundIds[] = $addtag->id;
         }
     }
     return $createdOrFoundIds;
 }
示例#20
0
文件: Craft.php 项目: rituzy/iblog
 public function addTagOrCreateNew($tag, $user_id = 0)
 {
     $tagFound = Tag::where('id', '=', $tag)->first();
     if (!isset($tagFound)) {
         $tagFound = new Tag();
         $tagFound->name = $tag;
         $tagFound->user_id = $user_id;
         $tagFound->save();
     }
     $tagFound->crafts()->save($this);
 }
示例#21
0
 public function executeTag()
 {
     $this->forwardUnless($this->getUser()->getBlog()->getApproved(), 'ucp', 'index');
     if ($this->getRequest()->getMethod() == sfRequest::POST) {
         $tag = new Tag();
         $tag->setName(Tag::tagize($this->getRequestParameter('name')));
         $tag->save();
         $this->setFlash('updated', 'Tag został zgłoszony do dodania.');
         return $this->redirect('ucp/index');
     }
 }
示例#22
0
文件: Tag.php 项目: noahkim/kowop
 public static function findOrCreate($name)
 {
     $name = strtolower($name);
     $tag = Tag::model()->find('Name=:Name', array(':Name' => $name));
     if ($tag == null) {
         $tag = new Tag();
         $tag->Name = $name;
         $tag->save();
     }
     return $tag;
 }
示例#23
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make(Input::all(), array('name' => 'required'));
     if ($validator->fails()) {
         return Response::json($validator->messages(), 400);
     }
     $tag = new Tag();
     $tag->name = Input::get('name');
     $tag->description = Input::get('description');
     $tag->save();
     return Response::json(array('success_code' => 'OK', 'data' => $tag->toArray()), 200);
 }
 /**
  * Store a newly created resource in storage.
  * POST /tags
  *
  * @return Response
  */
 public function store()
 {
     $validator = Tag::validate(Input::only('name'));
     if ($validator->fails()) {
         return Redirect::to('/createTag')->withErrors($validator)->withInput(Input::all());
     } else {
         $tag = new Tag();
         $tag->name = Input::get('name');
         $tag->save();
         return Redirect::to('tags')->with('message', 'Tag was successfully created');
     }
 }
示例#25
0
 public function testCreate()
 {
     $tag = new Tag();
     $tag->setAttributes(array('name' => 'Apple', 'category' => 1));
     $this->assertTrue($tag->save());
     $tag2 = Tag::model()->findByPk($tag->id);
     $this->assertNotNull($tag2);
     $this->assertEquals($tag->name, $tag2->name);
     $this->assertEquals($tag->category, $tag2->category);
     $this->assertEquals(1, $tag2->frequency);
     $this->assertTrue(time() - $tag2->create_time <= 1);
 }
示例#26
0
文件: Tag.php 项目: kyfr59/cg35
 public function findOrNew($name)
 {
     $db = $this->getDb();
     $sql = "\n        SELECT tags.* \n        FROM {$db->Tag} tags\n        WHERE tags.name LIKE ?\n        LIMIT 1";
     $tag = $this->fetchObject($sql, array($name));
     if (!$tag) {
         $tag = new Tag();
         $tag->name = $name;
         $tag->save();
     }
     return $tag;
 }
示例#27
0
 /**
  * Store a newly created User in database.
  *
  * @return Response
  */
 public function store()
 {
     $input = Input::all();
     $tag = new Tag();
     //make sure all tags are lowercase to make searching easier
     $tag->tag = strtolower(['tag']);
     if ($tag->save()) {
         return Redirect::to('/admin/tag')->with('info', 'The new tag has been created.');
     } else {
         return Redirect::to('/admin/tag')->withErrors($tag->errors());
     }
 }
 /** 
  * Find and return the first tag that matches 
  * If it cannot find a match, create the tag
  * @param  String  $tag
  */
 public function firstOrCreate($tag)
 {
     $foundTag = Tag::model()->find('tag=:tag', array(':tag' => $tag));
     if ($foundTag) {
         // found tag
         return $foundTag;
     } else {
         $tagModel = new Tag();
         $tagModel->tag = $tag;
         $tagModel->save();
         return $tagModel;
     }
 }
示例#29
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Tag();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Tag'])) {
         $model->attributes = $_POST['Tag'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 public function addTagsToUser()
 {
     $user = User::find(Auth::id());
     $usertags = Input::has('usertags') ? Input::get('usertags') : array();
     if (Input::has('addtag')) {
         $newtag = new Tag();
         $newtag->name = Input::get('addtag');
         $newtag->save();
         array_push($usertags, $newtag->id);
     }
     $user->tags()->sync($usertags);
     $user->save();
     return Redirect::action('UsersController@show', $user->id);
 }