示例#1
0
<?php

required_params('tag_name');
$tag = Tag::find_by_name(Request::$params->tag_name);
if ($tag) {
    $tag->delete();
}
unset(Request::$get_params['tag_name']);
respond_to_success('Tag deleted', array('#index', Request::$get_params));
示例#2
0
文件: q2a.php 项目: Osin/Intranet
<?php

include '../../inc/init.inc';
if (isset($tag)) {
    $conditions = array('id in (?)', Questions_Tag::find('all', array('conditions' => array('tag_id' => Tag::find_by_name($tag)->id)))->asQuestion_ID());
}
isset($conditions) ? $args['conditions'] = $conditions : ($args['conditions'] = 'title NOT LIKE ""');
$res->total = isset($args) ? Question::count($args) : Question::count();
$res->currentPage = isset($currentPage) ? $currentPage : 1;
$res->limit = $args['limit'] = isset($limit) ? $limit : 7;
$args['offset'] = ($res->currentPage - 1) * $args['limit'];
$args['order'] = isset($order) ? $order : 'created_at desc';
$res->questions = Question::all($args);
$res->tags = Tag::find('all', array('order' => 'Rand()', 'limit' => 20));
if (!isset($infos)) {
    $infos = array();
}
$res->search_opts = array(0 => array('label' => 'Quelle question vous posez vous ?', 'field' => 'title', 'type' => 'text', 'class' => 'xxlarge'));
$res->useTemplate("Questions - Reponses", $infos);
示例#3
0
<?php

if (!empty(Request::$params->tag['name'])) {
    $tag = Tag::find_by_name(Request::$params->tag['name']);
    if ($tag) {
        $tag->update_attributes(Request::$params->tag);
    }
}
respond_to_success("Tag updated", '#index');
示例#4
0
 static function find_related($tags)
 {
     if (is_array($tags) && count($tags) > 1) {
         return $this->calculate_related($tags);
     } elseif (($tags = current($tags)) && !empty($tags)) {
         $t = Tag::find_by_name($tags);
         if ($t) {
             return $t->related();
         }
     }
     return array();
 }
示例#5
0
 function commit_tags()
 {
     if ($this->is_empty_model()) {
         return;
     }
     $this->tags = array_filter(explode(' ', str_replace(array("\r", "\n"), '', $this->tags)));
     $this->current_tags = array_keys($this->parsed_cached_tags);
     if (empty($this->old_tags)) {
         $this->old_tags = $this->tags;
     } elseif (!is_array($this->old_tags)) {
         $this->old_tags = array_filter(explode(' ', $this->old_tags));
     }
     $this->commit_metatags();
     foreach ($this->tags as $k => $tag) {
         if (!preg_match('~^(-pool|pool|rating|parent|child):|^[qse]$~', $tag)) {
             continue;
         }
         if (in_array($tag, array('q', 's', 'e'))) {
             $tag = "rating:{$tag}";
         }
         $subparam = explode(':', $tag);
         $metatag = array_shift($subparam);
         $param = array_shift($subparam);
         $subparam = empty($subparam) ? null : array_shift($subparam);
         switch ($metatag) {
             case 'rating':
                 # Change rating. This will override rating selected on radio buttons.
                 if (in_array($param, array('q', 's', 'e'))) {
                     $this->rating = $param;
                 }
                 unset($this->tags[$k]);
                 break;
             case 'pool':
                 try {
                     $name = $param;
                     $seq = $subparam;
                     # Workaround: I don't understand how can the pool be found when finding_by_name
                     # using the id.
                     if (ctype_digit($name)) {
                         $pool = Pool::find_by_id($name);
                     } else {
                         $pool = Pool::find_by_name($name);
                     }
                     # Set :ignore_already_exists, so pool:1:2 can be used to change the sequence number
                     # of a post that already exists in the pool.
                     $options = array('user' => User::find($this->updater_user_id), 'ignore_already_exists' => true);
                     if ($seq) {
                         $options['sequence'] = $seq;
                     }
                     if (!$pool and !ctype_digit($name)) {
                         $pool = Pool::create(array('name' => $name, 'is_public' => false, 'user_id' => $this->updater_user_id));
                     }
                     if (!$pool) {
                         continue;
                     }
                     if (!$pool->can_change(User::$current, null)) {
                         continue;
                     }
                     $pool->add_post($this->id, $options);
                 } catch (PostAlreadyExistsError $e) {
                 } catch (AccessDeniedError $e) {
                 }
                 unset($this->tags[$k]);
                 break;
             case '-pool':
                 unset($this->tags[$k]);
                 $name = $param;
                 $cmd = $subparam;
                 $pool = Pool::find_by_name($name);
                 if (!$pool->can_change(User::$current, null)) {
                     break;
                 }
                 if ($cmd == "parent") {
                     # If we have a parent, remove ourself from the pool and add our parent in
                     # our place.  If we have no parent, do nothing and leave us in the pool.
                     if (!empty($this->parent_id)) {
                         $pool->transfer_post_to_parent($this->id, $this->parent_id);
                         break;
                     }
                 }
                 $pool && $pool->remove_post($id);
                 break;
             case 'source':
                 $this->source = $param;
                 unset($this->tags[$k]);
                 break;
             case 'parent':
                 if (is_numeric($param)) {
                     $this->parent_id = (int) $param;
                 }
                 unset($this->tags[$k]);
                 break;
             case 'child':
                 unset($this->tags[$k]);
                 break;
             default:
                 unset($this->tags[$k]);
                 break;
         }
     }
     $new_tags = array_diff($this->tags, $this->old_tags);
     $new_tags = array_merge($new_tags, TagAlias::to_aliased($new_tags));
     $new_tags = array_merge($new_tags, TagImplication::with_implied($new_tags));
     $new_tags = array_values(array_unique($new_tags));
     $old_tags = array_diff($this->old_tags, $this->tags);
     if (empty($new_tags) && $old_tags == $this->current_tags) {
         if (!in_array('tagme', $new_tags)) {
             $new_tags[] = 'tagme';
         }
         if (in_array('tagme', $old_tags)) {
             unset($old_tags[array_search('tagme', $old_tags)]);
         }
     }
     foreach ($old_tags as $tag) {
         if (array_key_exists($tag, $this->parsed_cached_tags)) {
             unset($this->parsed_cached_tags[$tag]);
         }
         $tag = Tag::find_by_name($tag);
         if ($tag) {
             DB::delete('posts_tags WHERE post_id = ? AND tag_id = ?', $this->id, $tag->id);
         }
     }
     foreach ($new_tags as $tag) {
         $tag = Tag::find_or_create_by_name($tag);
         $this->parsed_cached_tags[$tag->name] = $tag->type_name;
         DB::insert_ignore('posts_tags VALUES (?, ?)', $this->id, $tag->id);
     }
     $this->tags = $this->tag_names();
     $this->generate_cached_tags();
 }
示例#6
0
<?php

include '../../inc/init.inc';
if ((!isset($title) || $title == "") && !isset($question_id) || (!isset($content) || $content == "")) {
    $res->load('questions', array());
} else {
    if (isset($title)) {
        $args['title'] = $title;
    }
    if (isset($question_id)) {
        $args['question_id'] = $question_id;
    }
    $args['content'] = $content;
    $args['user_id'] = $res->user->id;
    $question = Question::create($args);
    if (isset($tag_list_values)) {
        $tags = explode(',', $tag_list_values);
        foreach ($tags as $tagName) {
            $tagName = strtoupper($tagName);
            if (Tag::exists(array('name' => $tagName))) {
                $tag = Tag::find_by_name($tagName);
            } else {
                $tag = Tag::create(array('name' => $tagName));
            }
            Questions_Tag::create(array('question_id' => $question->id, 'tag_id' => $tag->id));
        }
    }
}
$res->load('question', array('id' => $question->id));