function AMP_add_tags($tag_ids = false, $tag_names = false, $item_id, $item_type) { if ($tag_names) { require_once 'AMP/Content/Tag/Tag.php'; $new_tag_set = AMP_Content_Tag::create_many($tag_names); $new_tag_results = AMP_add_tags($new_tag_set, false, $item_id, $item_type); if (!$tag_ids) { return $new_tag_results; } } if (!$tag_ids) { return false; } if (!is_array($tag_ids)) { $tag_id_set = array($tag_ids); } else { $tag_id_set = $tag_ids; } $related_tags = AMPSystem_Lookup::instance('tagsBy' . ucfirst($item_type), $item_id); if ($related_tags) { $new_tags = array_diff($tag_id_set, array_keys($related_tags)); } else { $new_tags = $tag_id_set; } if (!$new_tags || empty($new_tags)) { return false; } require_once 'AMP/Content/Tag/Item/Item.php'; $action_item = new AMP_Content_Tag_Item(AMP_Registry::getDbcon()); $create_values = array('item_type' => $item_type, 'item_id' => $item_id, 'user_id' => AMP_SYSTEM_USER_ID); $results = 0; foreach ($new_tags as $new_tag_id) { $create_values['tag_id'] = $new_tag_id; $action_item->dropID(); $action_item->setData($create_values); $results += $action_item->save(); } return $results; }
function tag($tag_ids, $tag_names) { $result = AMP_add_tags($tag_ids, $tag_names, $this->id, AMP_SYSTEM_ITEM_TYPE_FORM); return $result ? 1 : 0; }
function tag_set($set) { $record_id_set = split(",", $set); $selected_tag_id = false; $tag_names = false; if (isset($_POST['tag_action_id']) && $_POST['tag_action_id']) { $selected_tag_id = $_POST['tag_action_id']; } if (isset($_POST['tag_action_add']) && $_POST['tag_action_add']) { $tag_names = $_POST['tag_action_add']; } if (!$selected_tag_id && !$tag_names) { return sprintf(AMP_TEXT_ERROR_NO_SELECTION, AMP_TEXT_TAG); } $total_tags = 0; foreach ($record_id_set as $user_id) { $tags_added = AMP_add_tags($selected_tag_id, $tag_names, $user_id, AMP_SYSTEM_ITEM_TYPE_FORM); if (!$tags_added) { continue; } $total_tags++; } return $total_tags; }