示例#1
0
 function saveTagsBySubject($tags, $scope, $id)
 {
     $factory_tags = jDao::get($this->dao_tags);
     $factory_objects_tags = jDao::get($this->dao_object_tags);
     // each time we submit a form we :
     // 1) get all the sc_tags_tagged records of the corresponding id
     // 2) check if the tag is still use  in sc_tags (nbuse > 1)
     // 2.1) if yes ; then nbuse-- of this tag
     // 2.2) if no ; remove the tag from sc_tags + sc_tags_tagged
     $cond = jDao::createConditions();
     //find all subject id
     $cond->addCondition('tt_subject_id', '=', $id);
     // 1)
     $tagsToDelete = $factory_objects_tags->findBy($cond);
     foreach ($tagsToDelete as $delete) {
         //2)
         $myTag = $factory_tags->get($delete->tag_id);
         if ($myTag->nbuse > 1) {
             // 2.1)
             // delete the tag from the tag_id found earlier
             $myTag->nbuse--;
             $factory_tags->update($myTag);
         } else {
             $factory_tags->delete($delete->tag_id);
             $factory_objects_tags->delete($delete->tt_id);
         }
     }
     foreach ($tags as $t) {
         $t = trim($t);
         if ($t == "") {
             continue;
         }
         if ($tag = $factory_tags->tagExiste($t)) {
             $idTag = $tag->tag_id;
             $tag->nbuse++;
             $factory_tags->update($tag);
         } else {
             $idTag = $this->createTag($t);
         }
         $objectTags = jDao::get($this->dao_object_tags);
         if (!$objectTags->tagAndsubjectExists($idTag, $id)) {
             // insertion dans objects_tags
             $snippets_tag = jDao::createRecord($this->dao_object_tags);
             $snippets_tag->tag_id = $idTag;
             $snippets_tag->tt_scope_id = $scope;
             $snippets_tag->tt_subject_id = $id;
             $factory_objects_tags->insert($snippets_tag);
         }
     }
     jZone::clear("jtags~tagscloud");
     jZone::clear("jtags~tagsbyobject", array("scope" => $scope, "id" => $id));
 }
示例#2
0
 /**
  * save the Rate to a given source and ID
  * @param integer $id_source the id to link to the source
  * @param string $source the linked source
  * @param integer $rate the rate
  * @return boolean
  */
 function saveRatesBySource($id_source, $source, $rate)
 {
     $dao = jDao::get('hfnurates~rates');
     $id_user = jAuth::isConnected() ? 0 : jAuth::getUserSession()->id;
     $rec = $dao->getByIdSourceSourceRate($id_user, $id_source, $source);
     if ($rec == false) {
         $record = jDao::createRecord('hfnurates~rates');
         $record->id_source = $id_source;
         $record->id_user = $id_user;
         $record->source = $source;
         $record->level = $rate;
         $record->ip = $_SERVER['REMOTE_ADDR'];
         $dao->insert($record);
     } else {
         $rec->level = $rate;
         $dao->update($rec);
     }
     jZone::clear("hfnurates~rates");
     return true;
 }