/** * Insert new term (tag or category in database) * @param string/array $term_manes string with terms adding by ajax autocompliter * @param string/array $task_tags string comma separated new terms * @param int $project_id id of terms project * @param int $group_id id of terms group * @param string $term_type this is tag or cat * @return bool true if insert are success and false if not */ protected function bp_gtm_insert_term($term_manes, $task_tags, $project_id = 0, $term_type = 'tag', $task_id = 0, $existing_terms = array()) { global $wpdb, $bp; if (!is_array($term_manes) && !is_array($task_tags)) { $tags = $this->bp_gtm_split_string($term_manes, $task_tags); /// split terms into array of values if (!empty($existing_terms)) { $tags = array_unique(array_merge($tags, $existing_terms)); } } else { if (empty($term_manes)) { $term_manes = array(); } if (empty($task_tags)) { $task_tags = array(); } $tags = array_unique(array_merge($term_manes, $task_tags)); } if (!empty($tags)) { foreach ($tags as $tag) { $tag_id = BP_GTM_Taxon::get_term_id_by_name($tag, $term_type); if (bp_gtm_is_belong_2group(bp_get_current_group_id(), $tag_id, $term_type) != 1) { $wpdb->query($wpdb->prepare("\n INSERT INTO " . $bp->gtm->table_terms . " ( `name`, `group_id`, `taxon` )\n VALUES ( %s, %d, '{$term_type}')\n ", $tag, bp_get_current_group_id())); $tag_id = $wpdb->insert_id; } $wpdb->query($wpdb->prepare("\n INSERT INTO " . $bp->gtm->table_taxon . " ( `task_id`, `project_id`, `group_id`, `term_id`, `taxon` )\n VALUES ( %d, %d, %d, %d, '{$term_type}')\n ", $task_id, $project_id, bp_get_current_group_id(), $tag_id)); } return TRUE; } else { return FALSE; } }