root/ip/trunk/includes/class_topics_tags.php

133156
95
	/*
95
	/*
96
	* Update tag entry
96
	* Update tag entry
97
	*/
97
	*/
98
	function update_tag_entry($tag_id)
98
	function update_tag_entry($tag_ids_array, $remove_zero_tags = false)
99
	{
99
	{
100
		global $db, $lang;
100
		global $db, $lang;
101
101
102
		$tag_count = 0;
102
		if (!is_array($tag_ids_array))
103
		$sql = "SELECT COUNT(tag_id) as tag_count FROM " . TOPICS_TAGS_MATCH_TABLE . " WHERE tag_id = " . $tag_id;
104
		$result = $db->sql_query($sql);
105
		if ($row = $db->sql_fetchrow($result))
106
		{
103
		{
107
			$tag_count = $row['tag_count'];
104
			$tag_ids_array = array($tag_ids_array);
108
			$db->sql_freeresult($result);
109
		}
105
		}
110
106
111
		$sql = "UPDATE " . TOPICS_TAGS_LIST_TABLE . " SET tag_count = " . $tag_count . " WHERE tag_id = " . $tag_id;
107
		for ($i = 0; $i < sizeof($tag_ids_array); $i++)
112
		$db->sql_query($sql);
108
		{
109
			$tag_count = 0;
110
			$sql = "SELECT COUNT(tag_id) as tag_count FROM " . TOPICS_TAGS_MATCH_TABLE . " WHERE tag_id = " . $tag_ids_array[$i];
111
			$result = $db->sql_query($sql);
112
			if ($row = $db->sql_fetchrow($result))
113
			{
114
				$tag_count = $row['tag_count'];
115
				$db->sql_freeresult($result);
116
			}
113
117
114
		$this->remove_zero_tags();
118
			$sql = "UPDATE " . TOPICS_TAGS_LIST_TABLE . " SET tag_count = " . $tag_count . " WHERE tag_id = " . $tag_ids_array[$i];
119
			$db->sql_query($sql);
120
		}
115
121
122
		if ($remove_zero_tags)
123
		{
124
			$this->remove_zero_tags();
125
		}
126
116
		return $tag_id;
127
		return $tag_id;
117
	}
128
	}
118
129
...
...
171
				$db->sql_query($sql);
182
				$db->sql_query($sql);
172
				if (!$tag_created)
183
				if (!$tag_created)
173
				{
184
				{
174
					$tag_id = $this->update_tag_entry($tag_id);
185
					$tag_id = $this->update_tag_entry($tag_id, false);
175
				}
186
				}
176
			}
187
			}
177
		}
188
		}
189
		$this->remove_zero_tags();
178
190
179
		return true;
191
		return true;
180
	}
192
	}
...
...
356
				$tag_id = $row['tag_id'];
368
				$tag_id = $row['tag_id'];
357
				$tags_ids_array = array($tag_id);
369
				$tags_ids_array = array($tag_id);
358
				$this->remove_tag_from_match($tags_ids_array, $topic_id);
370
				$this->remove_tag_from_match($tags_ids_array, $topic_id);
359
				$tag_id = $this->update_tag_entry($tag_id);
371
				$tag_id = $this->update_tag_entry($tag_id, false);
360
			}
372
			}
361
		}
373
		}
374
		$this->remove_zero_tags();
362
375
363
		return true;
376
		return true;
364
	}
377
	}
...
...
383
				$tag_id = $row['tag_id'];
396
				$tag_id = $row['tag_id'];
384
				$tags_ids_array = array($tag_id);
397
				$tags_ids_array = array($tag_id);
385
				$this->remove_tag_from_match($tags_ids_array, $topic_id);
398
				$this->remove_tag_from_match($tags_ids_array, $topic_id);
386
				$tag_id = $this->update_tag_entry($tag_id);
399
				$tag_id = $this->update_tag_entry($tag_id, false);
387
			}
400
			}
388
		}
401
		}
402
		$this->remove_zero_tags();
389
403
390
		return true;
404
		return true;
391
	}
405
	}