public function executeEdit()
 {
     // embed javascripts for edit-in-place and auto-completer
     $response = sfContext::getInstance()->getResponse();
     $response->addJavascript('prototype.js');
     $response->addJavascript('effects.js');
     $response->addJavascript('controls.js');
     $response->addJavascript('/deppPropelActAsTaggableBehaviorPlugin/js/tags_cleaner.js');
     $response->addStylesheet('/deppPropelActAsTaggableBehaviorPlugin/css/depp_tagging.css');
     // read some config parameters and defaults
     $anonymous_tagging = sfConfig::get(sprintf('propel_behavior_deppPropelActAsTaggableBehavior_%s_anonymous_tagging', get_class($this->content)), sfConfig::get('app_deppPropelActAsTaggableBehaviorPlugin_anonymous_tagging', true));
     $allows_tagging_removal = sfConfig::get(sprintf('propel_behavior_deppPropelActAsTaggableBehavior_%s_allows_tagging_removal', get_class($this->content)), sfConfig::get('app_deppPropelActAsTaggableBehaviorPlugin_allows_tagging_removal', 'all'));
     $tagging_removal_credentials = sfConfig::get(sprintf('propel_behavior_deppPropelActAsTaggableBehavior_%s_tagging_removal_credentials', get_class($this->content)), sfConfig::get('app_deppPropelActAsTaggableBehaviorPlugin_tagging_removal_credentials', array()));
     $user = @sfContext::getInstance()->getUser();
     $tags = $this->content->getTags(array());
     $user_tags = array();
     $this->editable_tags_as_string = deppPropelActAsTaggableToolkit::getTagsAsString($tags);
     $user_id = deppPropelActAsTaggableToolkit::getUserId();
     if (!$anonymous_tagging && $user->isAuthenticated() && !is_null($user_id) && $user_id !== '') {
         $user_tags = $this->content->getUserTags(array(), $user_id);
         if ($allows_tagging_removal == 'self' && !$user->hasCredential($tagging_removal_credentials, false)) {
             $this->editable_tags_as_string = deppPropelActAsTaggableToolkit::getTagsAsString($user_tags);
         }
     }
     $this->visible_tags_as_string = deppPropelActAsTaggableToolkit::getTagsAsTaggedString(array('other' => array_diff($tags, $user_tags), 'user' => $user_tags));
     $this->anonymous_tagging = $anonymous_tagging;
 }
 public function executeEdit()
 {
     // embed javascripts for edit-in-place and auto-completer
     $response = sfContext::getInstance()->getResponse();
     $response->addJavascript('prototype.js');
     $response->addJavascript('effects.js');
     $response->addJavascript('controls.js');
     $response->addStylesheet('/deppPropelActAsTaggableBehaviorPlugin/css/depp_tagging.css');
     // read some config parameters and defaults
     $anonymous_tagging = sfConfig::get(sprintf('propel_behavior_deppPropelActAsTaggableBehavior_%s_anonymous_tagging', get_class($this->content)), sfConfig::get('app_deppPropelActAsTaggableBehaviorPlugin_anonymous_tagging', true));
     $allows_tagging_removal = sfConfig::get(sprintf('propel_behavior_deppPropelActAsTaggableBehavior_%s_allows_tagging_removal', get_class($this->content)), sfConfig::get('app_deppPropelActAsTaggableBehaviorPlugin_allows_tagging_removal', 'all'));
     $tagging_removal_credentials = sfConfig::get(sprintf('propel_behavior_deppPropelActAsTaggableBehavior_%s_tagging_removal_credentials', get_class($this->content)), sfConfig::get('app_deppPropelActAsTaggableBehaviorPlugin_tagging_removal_credentials', array()));
     // fetch di TUTTI i tag legati al content (come nomi completi di triple)
     $this->tags = $this->content->getTags(array('is_triple' => true));
     // sono considerati teseo_tags tutti i tag con ns teseo e geoteseo
     $teseo_tags = $this->content->getTags(array('is_triple' => true, 'namespace' => 'teseo', 'return' => 'value'));
     $geo_tags = $this->content->getTags(array('is_triple' => true, 'namespace' => 'geoteseo', 'return' => 'value'));
     $this->teseo_tags = array_merge($teseo_tags, $geo_tags);
     // tag aggiunti da utenti reali (user_id in not null)
     $this->user_tags = $this->content->getUserTags(array('is_triple' => true, 'return' => 'value'));
     $user = @sfContext::getInstance()->getUser();
     $user_id = deppPropelActAsTaggableToolkit::getUserId();
     // i removable_tags sono quelli aggiunti dagli utenti (di default)
     if ($user->isAuthenticated()) {
         $this->removable_tags = $this->user_tags;
     } else {
         $this->removable_tags = array();
     }
     // tag aggiunti dall'utente loggato e override eventuale dei removable_tags
     // (se la configurazione lo prevede)
     $this->my_tags = array();
     if (!$anonymous_tagging && $user->isAuthenticated() && !is_null($user_id) && $user_id !== '') {
         $this->my_tags = $this->content->getUserTags(array('is_triple' => true, 'return' => 'value'), $user_id);
         if ($allows_tagging_removal == 'self' && !$user->hasCredential($tagging_removal_credentials, false)) {
             $this->removable_tags = $this->my_tags;
         }
     }
     $this->anonymous_tagging = $anonymous_tagging;
     $this->allows_tagging_removal = $allows_tagging_removal;
     $this->tagging_removal_credentials = $tagging_removal_credentials;
 }
 public function executeEditAjax()
 {
     // fetch request parameters and taggable content
     $content_id = $this->getRequestParameter('content_id');
     $content_peer = $this->getRequestParameter('content_type') . 'Peer';
     $content = call_user_func(array($content_peer, 'retrieveByPK'), $content_id);
     $tags_as_string = deppPropelActAsTaggableToolkit::getTagsAsString(strip_tags($this->getRequestParameter('usertags')));
     // a setTags remove the tags and add them back
     $content->setTags(tags_as_string);
     $content->save();
     // get all tags, forcing the cache override (directly from the DB)
     $tags = $content->getTags(array(), true);
     // if necessary, get users' tags
     $anonymous_tagging = sfConfig::get(sprintf('propel_behavior_deppPropelActAsTaggableBehavior_%s_anonymous_tagging', get_class($content)), sfConfig::get('app_deppPropelActAsTaggableBehaviorPlugin_anonymous_tagging', true));
     $user = @sfContext::getInstance()->getUser();
     $user_tags = array();
     $user_id = deppPropelActAsTaggableToolkit::getUserId();
     if (!$anonymous_tagging && $user->isAuthenticated() && !is_null($user_id) && $user_id !== '') {
         $user_tags = $content->getUserTags(array(), $user_id);
     }
     // set the value to be returned by AJAX
     // it's the visible string, with <spam> tags
     $this->value = deppPropelActAsTaggableToolkit::getTagsAsTaggedString(array('other' => array_diff($tags, $user_tags), 'user' => $user_tags));
 }
 /**
  * Tags saving logic, runned after the object himself has been saved
  *
  * @param      BaseObject  $object
  */
 public function postSave(BaseObject $object)
 {
     $tags = self::get_tags($object);
     $removed_tags = self::get_removed_tags($object);
     // read some config parameters and defaults
     $anonymous_tagging = sfConfig::get(sprintf('propel_behavior_deppPropelActAsTaggableBehavior_%s_anonymous_tagging', get_class($object)), sfConfig::get('app_deppPropelActAsTaggableBehaviorPlugin_anonymous_tagging', true));
     $allows_tagging_removal = sfConfig::get(sprintf('propel_behavior_deppPropelActAsTaggableBehavior_%s_allows_tagging_removal', get_class($object)), sfConfig::get('app_deppPropelActAsTaggableBehaviorPlugin_allows_tagging_removal', 'all'));
     $tagging_removal_credentials = sfConfig::get(sprintf('propel_behavior_deppPropelActAsTaggableBehavior_%s_tagging_removal_credentials', get_class($object)), sfConfig::get('app_deppPropelActAsTaggableBehaviorPlugin_tagging_removal_credentials', array()));
     $use_unique_triple_values = sfConfig::get(sprintf('propel_behavior_deppPropelActAsTaggableBehavior_%s_use_unique_triple_values', get_class($object)), sfConfig::get('app_deppPropelActAsTaggableBehaviorPlugin_use_unique_triple_values', false));
     $user = @sfContext::getInstance()->getUser();
     // save new tags
     foreach ($tags as $tagname) {
         if ($use_unique_triple_values) {
             $tag = TagPeer::retrieveOrCreateByTripleValue($tagname);
         } else {
             $tag = TagPeer::retrieveOrCreateByTagName($tagname);
         }
         $tag->save();
         $tagging = TaggingPeer::retrieveOrCreateByTagAndTaggable($tag->getId(), $object->getPrimaryKey(), get_class($object));
         $user_id = deppPropelActAsTaggableToolkit::getUserId();
         if (!$anonymous_tagging && $user->isAuthenticated() && !is_null($user_id) && $user_id != '') {
             if ($tagging->isNew()) {
                 $tagging->setUserId($user_id);
             }
         }
         $tagging->save();
     }
     // remove removed tags
     $removed_tag_ids = array();
     $c = new Criteria();
     $c->add(TagPeer::NAME, $removed_tags, Criteria::IN);
     if (Propel::VERSION >= '1.3') {
         $rs = TagPeer::doSelectStmt($c);
         while ($row = $rs->fetch(PDO::FETCH_ASSOC)) {
             $removed_tag_ids[] = intval($row['ID']);
         }
     } else {
         $rs = TagPeer::doSelectRS($c);
         while ($rs->next()) {
             $removed_tag_ids[] = $rs->getInt(1);
         }
     }
     $c = new Criteria();
     $c->add(TaggingPeer::TAG_ID, $removed_tag_ids, Criteria::IN);
     $c->add(TaggingPeer::TAGGABLE_ID, $object->getPrimaryKey());
     $c->add(TaggingPeer::TAGGABLE_MODEL, get_class($object));
     $user_id = deppPropelActAsTaggableToolkit::getUserId();
     // for authenticated users that do not have tagging_removal_credentials
     // if the only tags they're allowed to remove are their own
     // then, remove only those tags
     // this only works, if anonymnous_tagging is set to false
     if (!$anonymous_tagging && $user->isAuthenticated() && !is_null($user_id) && $user_id != '' && $allows_tagging_removal == 'self' && !$user->hasCredential($tagging_removal_credentials, false)) {
         $c->add(TaggingPeer::USER_ID, $user_id);
     }
     // delete e non doDelete, in modo che anche sul tagging si possano attivare i behavior (per le news)
     // TaggingPeer::doDelete($c);
     $tags_to_delete = TaggingPeer::doSelect($c);
     foreach ($tags_to_delete as $tag_to_delete) {
         $tag_to_delete->delete();
     }
     $tags = array_merge(self::get_tags($object), $this->getSavedTags($object));
     self::set_saved_tags($object, $tags);
     self::clear_tags($object);
     self::clear_removed_tags($object);
 }
 private function _fetchTags($content)
 {
     // read some config parameters and defaults
     $anonymous_tagging = sfConfig::get(sprintf('propel_behavior_deppPropelActAsTaggableBehavior_%s_anonymous_tagging', get_class($content)), sfConfig::get('app_deppPropelActAsTaggableBehaviorPlugin_anonymous_tagging', true));
     $allows_tagging_removal = sfConfig::get(sprintf('propel_behavior_deppPropelActAsTaggableBehavior_%s_allows_tagging_removal', get_class($content)), sfConfig::get('app_deppPropelActAsTaggableBehaviorPlugin_allows_tagging_removal', 'all'));
     $tagging_removal_credentials = sfConfig::get(sprintf('propel_behavior_deppPropelActAsTaggableBehavior_%s_tagging_removal_credentials', get_class($content)), sfConfig::get('app_deppPropelActAsTaggableBehaviorPlugin_tagging_removal_credentials', array()));
     // fetch the associated tags
     $this->tags = $content->getTags(array('is_triple' => true));
     // sono considerati teseo_tags tutti i tag con ns teseo e geoteseo
     $teseo_tags = $content->getTags(array('is_triple' => true, 'namespace' => 'teseo', 'return' => 'value'));
     $geo_tags = $content->getTags(array('is_triple' => true, 'namespace' => 'geoteseo', 'return' => 'value'));
     $this->teseo_tags = array_merge($teseo_tags, $geo_tags);
     // tag aggiunti da utenti reali (user_id in not null)
     $this->user_tags = $content->getUserTags(array('is_triple' => true, 'return' => 'value'));
     // i removable_tags sono quelli aggiunti dagli utenti (di default)
     $this->removable_tags = $this->user_tags;
     // tag aggiunti dall'utente loggato e override eventuale dei removable_tags
     // (se la configurazione lo prevede)
     $this->my_tags = array();
     $user = @sfContext::getInstance()->getUser();
     $user_id = deppPropelActAsTaggableToolkit::getUserId();
     if (!$anonymous_tagging && $user->isAuthenticated() && !is_null($user_id) && $user_id !== '') {
         $this->my_tags = $content->getUserTags(array('is_triple' => true, 'return' => 'value'), $user_id);
         if ($allows_tagging_removal == 'self' && !$user->hasCredential($tagging_removal_credentials, false)) {
             $this->removable_tags = $this->my_tags;
         }
     }
 }