79 return 'b_forum_topic';
90 (
new IntegerField(
"ID", [
"primary" =>
true,
"autocomplete" =>
true])),
93 (
new StringField(
"TITLE", [
"required" =>
true,
"size" => 255])),
103 (
new StringField(
"USER_START_NAME", [
"required" =>
true,
"size" => 255])),
104 (
new DatetimeField(
"START_DATE", [
"required" =>
true,
"default_value" =>
function(){
return new DateTime();}])),
108 (
new StringField(
"LAST_POSTER_NAME", [
"required" =>
true,
"size" => 255])),
109 (
new DatetimeField(
"LAST_POST_DATE", [
"required" =>
true,
"default_value" =>
function(){
return new DateTime();}])),
111 (
new IntegerField(
"POSTS_UNAPPROVED", [
"default_value" => 0])),
113 (
new StringField(
"ABS_LAST_POSTER_NAME", [
"size" => 255])),
114 (
new DatetimeField(
"ABS_LAST_POST_DATE", [
"required" =>
true,
"default_value" =>
function(){
return new DateTime();}])),
120 (
new Reference(
"FORUM", ForumTable::class, Join::on(
"this.FORUM_ID",
"ref.ID")))
132 "ABS_LAST_POSTER_NAME"
136 public static function onBeforeAdd(
Event $event)
141 if (Main\
Config\Option::get(
"forum",
"FILTER",
"Y") ==
"Y")
144 foreach ($filteredFields as $key)
146 $res[$key] = $val = array_key_exists($key, $data) ? $data[$key] :
"";
149 $res[$key] = \CFilterUnquotableWords::Filter($val);
150 if (empty($res[$key]))
156 $data[
"HTML"] = serialize($res);
159 $data[
"TITLE_SEO"] = array_key_exists(
"TITLE_SEO", $data) ? trim($data[
"TITLE_SEO"],
" -") :
"";
160 if (empty($data[
"TITLE_SEO"]))
162 $data[
"TITLE_SEO"] = \CUtil::translit($data[
"TITLE"], LANGUAGE_ID, array(
"max_len"=>255,
"safe_chars"=>
".",
"replace_space" =>
'-'));
167 $result->modifyFields($data);
170 return self::modifyData($event, $result);
178 public static function onBeforeUpdate(Main\ORM\Event $event)
180 $result =
new Main\ORM\EventResult();
182 $data = $event->getParameter(
"fields");
183 $id = $event->getParameter(
"id");
185 $topic = TopicTable::getById($id)->fetch();
187 if (Main\
Config\Option::get(
"forum",
"FILTER",
"Y") ==
"Y")
190 if (!empty(array_intersect($filteredFields, array_keys($data))))
193 foreach ($filteredFields as $key)
195 $res[$key] = $val = array_key_exists($key, $data) ? $data[$key] : $topic[$key];
198 $res[$key] = \CFilterUnquotableWords::Filter($val);
199 if (empty($res[$key]))
205 $data[
"HTML"] = serialize($res);
208 if (array_key_exists(
"TITLE_SEO", $data) || array_key_exists(
"TITLE", $data))
210 $data[
"TITLE_SEO"] = trim($data[
"TITLE_SEO"],
" -");
211 if ($data[
"TITLE_SEO"] ==
'')
213 $title = array_key_exists(
"TITLE", $data) ? $data[
"TITLE"] : $topic[
"TITLE"];
214 $data[
"TITLE_SEO"] = \CUtil::translit($title, LANGUAGE_ID, array(
"max_len"=>255,
"safe_chars"=>
".",
"replace_space" =>
'-'));
217 if ($data != $event->getParameter(
"fields"))
219 $result->modifyFields($data);
221 return self::modifyData($event, $result);
230 $id = $event->getParameter(
"id");
232 $fields = $event->getParameter(
"fields");
233 if (array_key_exists(
"FORUM_ID", $fields))
235 $connection = Main\Application::getInstance()->getConnection();
236 $connection->queryExecute(
"UPDATE " .
FileTable::getTableName() .
" SET FORUM_ID={$fields["FORUM_ID
"]} WHERE TOPIC_ID={$id}");
237 $connection->queryExecute(
"UPDATE " .
MessageTable::getTableName() .
" SET FORUM_ID={$fields["FORUM_ID
"]} WHERE TOPIC_ID={$id}");
247 private static function modifyData(Main\ORM\
Event $event, Main\ORM\
EventResult $result)
249 $data = array_merge($event->getParameter(
"fields"), $result->getModified());
253 $key = array_key_exists(
"VIEWS", $data) ?
"VIEWS" : (array_key_exists(
"=VIEWS", $data) ?
"=VIEWS" :
null);
254 if ($key !==
null && str_replace(
" ",
"", $data[$key]) ===
"VIEWS+1")
262 $result->modifyFields(array_merge($result->getModified(), $fields));
static getMessage($code, $replace=null, $language=null)