本文整理汇总了PHP中ArtefactTypeComment::commit方法的典型用法代码示例。如果您正苦于以下问题:PHP ArtefactTypeComment::commit方法的具体用法?PHP ArtefactTypeComment::commit怎么用?PHP ArtefactTypeComment::commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArtefactTypeComment
的用法示例。
在下文中一共展示了ArtefactTypeComment::commit方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add_feedback_form_submit
function add_feedback_form_submit(Pieform $form, $values)
{
global $view, $artefact, $USER;
$data = (object) array('title' => get_string('Comment', 'artefact.comment'), 'description' => $values['message']);
if ($artefact) {
$data->onartefact = $artefact->get('id');
$data->owner = $artefact->get('owner');
$data->group = $artefact->get('group');
$data->institution = $artefact->get('institution');
} else {
$data->onview = $view->get('id');
$data->owner = $view->get('owner');
$data->group = $view->get('group');
$data->institution = $view->get('institution');
}
if ($author = $USER->get('id')) {
$anonymous = false;
$data->author = $author;
} else {
$anonymous = true;
$data->authorname = $values['authorname'];
}
if (isset($values['moderate']) && $values['ispublic'] && !$USER->can_edit_view($view)) {
$data->private = 1;
$data->requestpublic = 'author';
$moderated = true;
} else {
$data->private = (int) (!$values['ispublic']);
$moderated = false;
}
$private = $data->private;
if (get_config('licensemetadata')) {
$data->license = $values['license'];
$data->licensor = $values['licensor'];
$data->licensorurl = $values['licensorurl'];
}
if (isset($values['rating'])) {
$data->rating = valid_rating($values['rating']);
}
$comment = new ArtefactTypeComment(0, $data);
db_begin();
$comment->commit();
$url = $comment->get_view_url($view->get('id'), true, false);
$goto = get_config('wwwroot') . $url;
if (isset($data->requestpublic) && $data->requestpublic === 'author' && $data->owner) {
$arg = $author ? display_name($USER, null, true) : $data->authorname;
$moderatemsg = (object) array('subject' => false, 'message' => false, 'strings' => (object) array('subject' => (object) array('key' => 'makepublicrequestsubject', 'section' => 'artefact.comment', 'args' => array()), 'message' => (object) array('key' => 'makepublicrequestbyauthormessage', 'section' => 'artefact.comment', 'args' => array(hsc($arg))), 'urltext' => (object) array('key' => 'Comment', 'section' => 'artefact.comment')), 'users' => array($data->owner), 'url' => $url);
}
if (!empty($values['attachments']) && is_array($values['attachments']) && !empty($data->author)) {
require_once get_config('libroot') . 'uploadmanager.php';
safe_require('artefact', 'file');
$ownerlang = empty($data->owner) ? get_config('lang') : get_user_language($data->owner);
$folderid = ArtefactTypeFolder::get_folder_id(get_string_from_language($ownerlang, 'feedbackattachdirname', 'artefact.comment'), get_string_from_language($ownerlang, 'feedbackattachdirdesc', 'artefact.comment'), null, true, $data->owner, $data->group, $data->institution);
$attachment = (object) array('owner' => $data->owner, 'group' => $data->group, 'institution' => $data->institution, 'author' => $data->author, 'allowcomments' => 0, 'parent' => $folderid, 'description' => get_string_from_language($ownerlang, 'feedbackonviewbyuser', 'artefact.comment', $view->get('title'), display_name($USER)));
foreach ($values['attachments'] as $filesindex) {
$originalname = $_FILES[$filesindex]['name'];
$attachment->title = ArtefactTypeFileBase::get_new_file_title($originalname, $folderid, $data->owner, $data->group, $data->institution);
try {
$fileid = ArtefactTypeFile::save_uploaded_file($filesindex, $attachment);
} catch (QuotaExceededException $e) {
if ($data->owner == $USER->get('id')) {
$form->reply(PIEFORM_ERR, array('message' => $e->getMessage()));
}
redirect($goto);
} catch (UploadException $e) {
$form->reply(PIEFORM_ERR, array('message' => $e->getMessage()));
redirect($goto);
}
$comment->attach($fileid);
}
}
require_once 'activity.php';
$data = (object) array('commentid' => $comment->get('id'), 'viewid' => $view->get('id'));
activity_occurred('feedback', $data, 'artefact', 'comment');
if (isset($moderatemsg)) {
activity_occurred('maharamessage', $moderatemsg);
}
db_commit();
$newlist = ArtefactTypeComment::get_comments(10, 0, 'last', $view, $artefact);
// If you're anonymous and your message is moderated or private, then you won't
// be able to tell what happened to it. So we'll provide some more explanation in
// the feedback message.
if ($anonymous && $moderated) {
$message = get_string('feedbacksubmittedmoderatedanon', 'artefact.comment');
} else {
if ($anonymous && $private) {
$message = get_string('feedbacksubmittedprivateanon', 'artefact.comment');
} else {
$message = get_string('feedbacksubmitted', 'artefact.comment');
}
}
$form->reply(PIEFORM_OK, array('message' => $message, 'goto' => $goto, 'data' => $newlist));
}
示例2: setup_view_relationships_from_request
/**
* Fix comments to point to the right view. Probably more
* appropriate in setup_relationships. To do that we would have
* to change that call to happen after views are created.
*/
public static function setup_view_relationships_from_request(PluginImportLeap $importer)
{
if ($entry_requests = get_records_select_array('import_entry_requests', 'importid = ? AND entrytype = ?', array($importer->get('importertransport')->get('importid'), 'comment'))) {
foreach ($entry_requests as $entry_request) {
$commentids = unserialize($entry_request->artefactmapping);
$comment = new ArtefactTypeComment($commentids[0]);
if ($comment->get('onartefact')) {
continue;
}
$entry = $importer->get_entry_by_id($entry_request->entryid);
$referentid = self::get_referent_entryid($entry, $importer);
if ($viewid = $importer->get_viewid_imported_by_entryid($referentid)) {
$comment->set('onview', $viewid);
$comment->commit();
} else {
// Nothing to link this comment to, so leave it in the temporary view.
self::$savetempview = true;
}
}
}
}
示例3: create_comment
/**
* Creates a comment from the given entry
*
* @param SimpleXMLElement $entry The entry to create the comment from
* @param PluginImportLeap $importer The importer
* @return array A list of artefact IDs created, to be used with the artefact mapping.
*/
private static function create_comment(SimpleXMLElement $entry, PluginImportLeap $importer)
{
$createdartefacts = array();
$comment = new ArtefactTypeComment();
$comment->set('title', (string) $entry->title);
$description = PluginImportLeap::get_entry_content($entry, $importer);
$type = isset($entry->content['type']) ? (string) $entry->content['type'] : 'text';
if ($type == 'text') {
$description = format_whitespace($description);
}
$comment->set('description', $description);
if ($published = strtotime((string) $entry->published)) {
$comment->set('ctime', $published);
}
if ($updated = strtotime((string) $entry->updated)) {
$comment->set('mtime', $updated);
}
$private = PluginImportLeap::is_correct_category_scheme($entry, $importer, 'audience', 'Private');
$comment->set('private', (int) $private);
$comment->set('owner', $importer->get('usr'));
if (isset($entry->author->name) && strlen($entry->author->name)) {
$comment->set('authorname', $entry->author->name);
} else {
$comment->set('author', $importer->get('usr'));
}
if (empty(self::$tempview)) {
self::create_temporary_view($importer->get('usr'));
}
$comment->set('onview', self::$tempview);
$comment->set('tags', PluginImportLeap::get_entry_tags($entry));
$comment->commit();
array_unshift($createdartefacts, $comment->get('id'));
return $createdartefacts;
}
示例4: add_feedback_form_submit
function add_feedback_form_submit(Pieform $form, $values)
{
global $view, $artefact, $USER;
require_once 'embeddedimage.php';
$data = (object) array('title' => get_string('Comment', 'artefact.comment'), 'description' => $values['message']);
if ($artefact) {
$data->onartefact = $artefact->get('id');
$data->owner = $artefact->get('owner');
$data->group = $artefact->get('group');
$data->institution = $artefact->get('institution');
$onvieworartefactstr = "onartefact = {$data->onartefact}";
} else {
$data->onview = $view->get('id');
$data->owner = $view->get('owner');
$data->group = $view->get('group');
$data->institution = $view->get('institution');
$onvieworartefactstr = "onview = {$data->onview}";
}
$owner = $data->owner;
$author = null;
if ($author = $USER->get('id')) {
$anonymous = false;
$data->author = $author;
} else {
$anonymous = true;
$data->authorname = $values['authorname'];
}
if (isset($values['moderate']) && $values['ispublic'] && !$USER->can_edit_view($view)) {
$data->private = 1;
$data->requestpublic = 'author';
$moderated = true;
} else {
$data->private = (int) (!$values['ispublic']);
$moderated = false;
}
$private = $data->private;
if (get_config('licensemetadata')) {
$data->license = $values['license'];
$data->licensor = $values['licensor'];
$data->licensorurl = $values['licensorurl'];
}
if (isset($values['rating'])) {
$data->rating = valid_rating($values['rating']);
}
if ($values['replyto'] && ($pcomment = artefact_instance_from_id($values['replyto']))) {
$data->parent = $pcomment->get('id');
$grandparentid = $pcomment->get('parent');
// Find the position for the new comment
// Find the last offspring of the parent
$parentid = $data->parent;
$data->threadedposition = $pcomment->get('threadedposition');
while ($lastchild = get_records_sql_array('
SELECT c.artefact, c.threadedposition
FROM {artefact_comment_comment} c
INNER JOIN {artefact} a ON a.id = c.artefact
WHERE
' . $onvieworartefactstr . '
AND a.parent = ?
ORDER BY c.threadedposition DESC
LIMIT 1', array($parentid))) {
$parentid = $lastchild[0]->artefact;
$data->threadedposition = $lastchild[0]->threadedposition;
}
$data->threadedposition++;
// Increase the threaded position of following comments by 1
execute_sql('
UPDATE {artefact_comment_comment}
SET threadedposition = threadedposition + 1
WHERE
' . $onvieworartefactstr . '
AND threadedposition >= ?', array($data->threadedposition));
}
if (!isset($data->threadedposition)) {
$lastcomment = get_record_sql('
SELECT max(threadedposition) AS lastposition
FROM {artefact_comment_comment} c
WHERE
' . $onvieworartefactstr);
$data->threadedposition = $lastcomment->lastposition ? $lastcomment->lastposition + 1 : 1;
}
$comment = new ArtefactTypeComment(0, $data);
db_begin();
$comment->commit();
$newdescription = EmbeddedImage::prepare_embedded_images($values['message'], 'comment', $comment->get('id'), $data->group);
if ($newdescription !== $values['message']) {
$updatedcomment = new stdClass();
$updatedcomment->id = $comment->get('id');
$updatedcomment->description = $newdescription;
update_record('artefact', $updatedcomment, 'id');
}
$url = $comment->get_view_url($view->get('id'), true, false);
$goto = get_config('wwwroot') . $url;
if (isset($data->requestpublic) && $data->requestpublic === 'author' && $data->owner) {
$arg = $author ? display_name($USER, null, true) : $data->authorname;
$moderatemsg = (object) array('subject' => false, 'message' => false, 'strings' => (object) array('subject' => (object) array('key' => 'makepublicrequestsubject', 'section' => 'artefact.comment', 'args' => array()), 'message' => (object) array('key' => 'makepublicrequestbyauthormessage', 'section' => 'artefact.comment', 'args' => array(hsc($arg))), 'urltext' => (object) array('key' => 'Comment', 'section' => 'artefact.comment')), 'users' => array($data->owner), 'url' => $url);
}
if (!empty($values['attachments']) && is_array($values['attachments']) && !empty($data->author)) {
require_once get_config('libroot') . 'uploadmanager.php';
safe_require('artefact', 'file');
$ownerlang = empty($data->owner) ? get_config('lang') : get_user_language($data->owner);
//.........这里部分代码省略.........