/** * Edits an existing comment as specified by $pn_comment_id. Will only edit comments that are attached to the * currently loaded row. If called with no row loaded editComment() will return null. If you attempt to modify * a comment not associated with the currently loaded row editComment() will return false and post an error. * Note that all parameters are mandatory in the sense that the value passed (or the default value if not passed) * will be written into the comment. For example, if you don't bother passing $ps_name then it will be set to null, even * if there's an existing name value in the field. The only exception is $pn_locale_id; if set to null or omitted then * editComment() will attempt to use the locale value in the global $g_ui_locale_id variable. If this is not set then * an error will be posted and editComment() will return false. * * @param $pn_comment_id [integer] a valid comment_id to be edited; must be related to the currently loaded row (mandatory) * @param $ps_comment [string] the text of the comment (mandatory) * @param $pn_rating [integer] a number between 1 and 5 indicating the user's rating of the row; higher is better (optional - default is null) * @param $pn_user_id [integer] A valid ca_users.user_id indicating the user who posted the comment; is null for comments from non-logged-in users (optional - default is null) * @param $pn_locale_id [integer] A valid ca_locales.locale_id indicating the language of the comment. If omitted or left null then the value in the global $g_ui_locale_id variable is used. If $g_ui_locale_id is not set and $pn_locale_id is not set then an error will occur (optional - default is to use $g_ui_locale_id) * @param $ps_name [string] Name of user posting comment. Only needs to be set if $pn_user_id is *not* set; used to identify comments posted by non-logged-in users (optional - default is null) * @param $ps_email [string] E-mail address of user posting comment. Only needs to be set if $pn_user_id is *not* set; used to identify comments posted by non-logged-in users (optional - default is null) * @param $pn_access [integer] Determines public visibility of comments; if set to 0 then comment is not visible to public; if set to 1 comment is visible (optional - default is 0) * @param $pn_moderator [integer] A valid ca_users.user_id value indicating who moderated the comment; if omitted or set to null then moderation status will not be set (optional - default is null) * @param array $pa_options Array of options. Supported options are: * purify = if true, comment, name and email are run through HTMLPurifier before being stored in the database. Default is true. * media1_original_filename = original file name to set for comment "media1" * media2_original_filename = original file name to set for comment "media2" * media3_original_filename = original file name to set for comment "media3" * media4_original_filename = original file name to set for comment "media4" */ public function editComment($pn_comment_id, $ps_comment, $pn_rating = null, $pn_user_id = null, $pn_locale_id = null, $ps_name = null, $ps_email = null, $pn_access = null, $pn_moderator = null, $pa_options = null, $ps_media1 = null, $ps_media2 = null, $ps_media3 = null, $ps_media4 = null) { global $g_ui_locale_id; if (!($vn_row_id = $this->getPrimaryKey())) { return null; } if (!$pn_locale_id) { $pn_locale_id = $g_ui_locale_id; } $t_comment = new ca_item_comments($pn_comment_id); if (!$t_comment->getPrimaryKey()) { $this->postError(2800, _t('Comment id is invalid'), 'BaseModel->editComment()', 'ca_item_comments'); return false; } if ($t_comment->get('table_num') != $this->tableNum() || $t_comment->get('row_id') != $vn_row_id) { $this->postError(2810, _t('Comment is not part of the current row'), 'BaseModel->editComment()', 'ca_item_comments'); return false; } if (!isset($pa_options['purify'])) { $pa_options['purify'] = true; } $t_comment->purify($this->purify() || $pa_options['purify']); if ((bool) $pa_options['purify']) { $ps_comment = BaseModel::getPurifier()->purify($ps_comment); $ps_name = BaseModel::getPurifier()->purify($ps_name); $ps_email = BaseModel::getPurifier()->purify($ps_email); } $t_comment->setMode(ACCESS_WRITE); $t_comment->set('comment', $ps_comment); $t_comment->set('rating', $pn_rating); $t_comment->set('user_id', $pn_user_id); $t_comment->set('name', $ps_name); $t_comment->set('email', $ps_email); $t_comment->set('media1', $ps_media1, array('original_filename' => $pa_options['media1_original_filename'])); $t_comment->set('media2', $ps_media2, array('original_filename' => $pa_options['media2_original_filename'])); $t_comment->set('media3', $ps_media3, array('original_filename' => $pa_options['media3_original_filename'])); $t_comment->set('media4', $ps_media4, array('original_filename' => $pa_options['media4_original_filename'])); if (!is_null($pn_moderator)) { $t_comment->set('moderated_by_user_id', $pn_moderator); $t_comment->set('moderated_on', 'now'); } if (!is_null($pn_locale_id)) { $t_comment->set('locale_id', $pn_locale_id); } $t_comment->update(); if ($t_comment->numErrors()) { $this->errors = $t_comment->errors; return false; } return true; }