/** * Adds a general (site-wide) comment. Returns true * if comment was successfully added, false if an error occurred in which case the errors will be available * via the standard error methods (getErrors() and friends.) * * Most of the parameters are optional with the exception of $ps_comment - the text of the comment. Note that * comment text is monolingual; if you want to do multilingual comments (which aren't really comments then, are they?) then * you should add multiple comments. * * The parameters are: * * @param $ps_comment [string] Text of the comment (mandatory) * @param $pn_rating [integer] A number between 1 and 5 indicating the user's rating of the row; larger 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 unless app.conf setting dont_moderate_comments = 1 (optional - default is null) */ public function addComment($ps_comment, $pn_rating = null, $pn_user_id = null, $pn_locale_id = null, $ps_name = null, $ps_email = null, $pn_access = 0, $pn_moderator = null) { global $g_ui_locale_id; if (!$pn_locale_id) { $pn_locale_id = $g_ui_locale_id; } $t_comment = new ca_item_comments(); $t_comment->setMode(ACCESS_WRITE); $t_comment->set('table_num', 255); $t_comment->set('row_id', 0); $t_comment->set('user_id', $pn_user_id); $t_comment->set('locale_id', $pn_locale_id); $t_comment->set('comment', $ps_comment); $t_comment->set('rating', $pn_rating); $t_comment->set('email', $ps_email); $t_comment->set('name', $ps_name); $t_comment->set('access', $pn_access); if (!is_null($pn_moderator)) { $t_comment->set('moderated_by_user_id', $pn_moderator); $t_comment->set('moderated_on', 'now'); } elseif ($this->opo_config->get("dont_moderate_comments")) { $t_comment->set('moderated_on', 'now'); } $t_comment->insert(); if ($t_comment->numErrors()) { $this->errors = $t_comment->errors; return false; } return true; }
/** * Add comment to specified item * * @param string $type can be one of: ["ca_objects", "ca_entities", "ca_places", "ca_occurrences", "ca_collections", "ca_list_items", "ca_object_representations", "ca_storage_locations", "ca_movements", "ca_loans", "ca_tours", "ca_tour_stops"] * @param int $item_id primary key * @param array $comment_info_array * @return boolean * @throws SoapFault */ public function addComment($type, $item_id, $comment_info_array) { if (!($t_subject_instance = $this->getTableInstance($type, $item_id))) { throw new SoapFault("Server", "Invalid type or item_id"); } $t_comment = new ca_item_comments(); $t_comment->setMode(ACCESS_WRITE); $t_comment->set($comment_info_array); $t_comment->set('table_num', $t_subject_instance->tableNum()); $t_comment->set('row_id', $t_subject_instance->getPrimaryKey()); $t_comment->set('user_id', $this->getUserID()); $vn_id = $t_comment->insert(); if ($t_comment->numErrors() == 0) { return $vn_id; } else { throw new SoapFault("Server", "There were errors while adding the comment: " . join(";", $t_comment->getErrors())); } }
/** * Adds a comment to currently loaded row. Returns null if no row is loaded. Otherwise returns true * if comment was successfully added, false if an error occurred in which case the errors will be available * via the model's standard error methods (getErrors() and friends. * * Most of the parameters are optional with the exception of $ps_comment - the text of the comment. Note that * comment text is monolingual; if you want to do multilingual comments (which aren't really comments then, are they?) then * you should add multiple comments. * * @param $ps_comment [string] Text of the comment (mandatory) * @param $pn_rating [integer] A number between 1 and 5 indicating the user's rating of the row; larger 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 unless app.conf setting dont_moderate_comments = 1 (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" * @param $ps_location [string] = location of user * @return ca_item_comments BaseModel representation of newly created comment, false on error or null if parameters are invalid */ public function addComment($ps_comment, $pn_rating = null, $pn_user_id = null, $pn_locale_id = null, $ps_name = null, $ps_email = null, $pn_access = 0, $pn_moderator = null, $pa_options = null, $ps_media1 = null, $ps_media2 = null, $ps_media3 = null, $ps_media4 = null, $ps_location = 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; } if (!isset($pa_options['purify'])) { $pa_options['purify'] = true; } 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 = new ca_item_comments(); $t_comment->purify($this->purify() || $pa_options['purify']); $t_comment->setMode(ACCESS_WRITE); $t_comment->set('table_num', $this->tableNum()); $t_comment->set('row_id', $vn_row_id); $t_comment->set('user_id', $pn_user_id); $t_comment->set('locale_id', $pn_locale_id); $t_comment->set('comment', $ps_comment); $t_comment->set('rating', $pn_rating); $t_comment->set('email', $ps_email); $t_comment->set('name', $ps_name); $t_comment->set('access', $pn_access); $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'])); $t_comment->set('location', $ps_location); if (!is_null($pn_moderator)) { $t_comment->set('moderated_by_user_id', $pn_moderator); $t_comment->set('moderated_on', 'now'); } elseif ($this->_CONFIG->get("dont_moderate_comments")) { $t_comment->set('moderated_on', 'now'); } $t_comment->insert(); if ($t_comment->numErrors()) { $this->errors = $t_comment->errors; return false; } return $t_comment; }