本文整理汇总了PHP中Notice::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP Notice::insert方法的具体用法?PHP Notice::insert怎么用?PHP Notice::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Notice
的用法示例。
在下文中一共展示了Notice::insert方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveStatus
function saveStatus($status)
{
$profile = $this->ensureProfile($status->user);
if (empty($profile)) {
common_log(LOG_ERR, $this->name() . ' - Problem saving notice. No associated Profile.');
return null;
}
$statusId = twitter_id($status);
$statusUri = $this->makeStatusURI($status->user->screen_name, $statusId);
// check to see if we've already imported the status
$n2s = Notice_to_status::staticGet('status_id', $statusId);
if (!empty($n2s)) {
common_log(LOG_INFO, $this->name() . " - Ignoring duplicate import: {$statusId}");
return Notice::staticGet('id', $n2s->notice_id);
}
// If it's a retweet, save it as a repeat!
if (!empty($status->retweeted_status)) {
common_log(LOG_INFO, "Status {$statusId} is a retweet of " . twitter_id($status->retweeted_status) . ".");
$original = $this->saveStatus($status->retweeted_status);
if (empty($original)) {
return null;
} else {
$author = $original->getProfile();
// TRANS: Message used to repeat a notice. RT is the abbreviation of 'retweet'.
// TRANS: %1$s is the repeated user's name, %2$s is the repeated notice.
$content = sprintf(_m('RT @%1$s %2$s'), $author->nickname, $original->content);
if (Notice::contentTooLong($content)) {
$contentlimit = Notice::maxContent();
$content = mb_substr($content, 0, $contentlimit - 4) . ' ...';
}
$repeat = Notice::saveNew($profile->id, $content, 'twitter', array('repeat_of' => $original->id, 'uri' => $statusUri, 'is_local' => Notice::GATEWAY));
common_log(LOG_INFO, "Saved {$repeat->id} as a repeat of {$original->id}");
Notice_to_status::saveNew($repeat->id, $statusId);
return $repeat;
}
}
$notice = new Notice();
$notice->profile_id = $profile->id;
$notice->uri = $statusUri;
$notice->url = $statusUri;
$notice->created = strftime('%Y-%m-%d %H:%M:%S', strtotime($status->created_at));
$notice->source = 'twitter';
$notice->reply_to = null;
$replyTo = twitter_id($status, 'in_reply_to_status_id');
if (!empty($replyTo)) {
common_log(LOG_INFO, "Status {$statusId} is a reply to status {$replyTo}");
$n2s = Notice_to_status::staticGet('status_id', $replyTo);
if (empty($n2s)) {
common_log(LOG_INFO, "Couldn't find local notice for status {$replyTo}");
} else {
$reply = Notice::staticGet('id', $n2s->notice_id);
if (empty($reply)) {
common_log(LOG_INFO, "Couldn't find local notice for status {$replyTo}");
} else {
common_log(LOG_INFO, "Found local notice {$reply->id} for status {$replyTo}");
$notice->reply_to = $reply->id;
$notice->conversation = $reply->conversation;
}
}
}
if (empty($notice->conversation)) {
$conv = Conversation::create();
$notice->conversation = $conv->id;
common_log(LOG_INFO, "No known conversation for status {$statusId} so making a new one {$conv->id}.");
}
$notice->is_local = Notice::GATEWAY;
$notice->content = html_entity_decode($status->text, ENT_QUOTES, 'UTF-8');
$notice->rendered = $this->linkify($status);
if (Event::handle('StartNoticeSave', array(&$notice))) {
$id = $notice->insert();
if (!$id) {
common_log_db_error($notice, 'INSERT', __FILE__);
common_log(LOG_ERR, $this->name() . ' - Problem saving notice.');
}
Event::handle('EndNoticeSave', array($notice));
}
Notice_to_status::saveNew($notice->id, $statusId);
$this->saveStatusMentions($notice, $status);
$this->saveStatusAttachments($notice, $status);
$notice->blowOnInsert();
return $notice;
}
示例2: saveActivity
//.........这里部分代码省略.........
foreach ($replyGroups as $group) {
if ($actor->isMember($group)) {
$groups[] = $group->id;
}
}
}
if (is_null($scope)) {
$scope = $reply->scope;
}
}
if ($act->context instanceof ActivityContext) {
$location = $act->context->location;
if ($location) {
$stored->lat = $location->lat;
$stored->lon = $location->lon;
if ($location->location_id) {
$stored->location_ns = $location->location_ns;
$stored->location_id = $location->location_id;
}
}
} else {
$act->context = new ActivityContext();
}
$stored->scope = self::figureOutScope($actor, $groups, $scope);
foreach ($act->categories as $cat) {
if ($cat->term) {
$term = common_canonical_tag($cat->term);
if (!empty($term)) {
$tags[] = $term;
}
}
}
foreach ($act->enclosures as $href) {
// @todo FIXME: Save these locally or....?
$urls[] = $href;
}
if (Event::handle('StartNoticeSave', array(&$stored))) {
// XXX: some of these functions write to the DB
try {
$stored->insert();
// throws exception on error
$orig = clone $stored;
// for updating later in this try clause
$object = null;
Event::handle('StoreActivityObject', array($act, $stored, $options, &$object));
if (empty($object)) {
throw new ServerException('Unsuccessful call to StoreActivityObject ' . $stored->uri . ': ' . $act->asString());
}
// If it's not part of a conversation, it's
// the beginning of a new conversation.
if (empty($stored->conversation)) {
// $act->context->conversation will be null if it was not provided
$conv = Conversation::create($stored, $act->context->conversation);
$stored->conversation = $conv->id;
}
$stored->update($orig);
} catch (Exception $e) {
if (empty($stored->id)) {
common_debug('Failed to save stored object entry in database (' . $e->getMessage() . ')');
} else {
common_debug('Failed to store activity object in database (' . $e->getMessage() . '), deleting notice id ' . $stored->id);
$stored->delete();
}
throw $e;
}
}
if (!$stored instanceof Notice) {
throw new ServerException('StartNoticeSave did not give back a Notice');
}
// Save per-notice metadata...
$mentions = array();
$groups = array();
// This event lets plugins filter out non-local recipients (attentions we don't care about)
// Used primarily for OStatus (and if we don't federate, all attentions would be local anyway)
Event::handle('GetLocalAttentions', array($actor, $act->context->attention, &$mentions, &$groups));
if (!empty($mentions)) {
$stored->saveKnownReplies($mentions);
} else {
$stored->saveReplies();
}
if (!empty($tags)) {
$stored->saveKnownTags($tags);
} else {
$stored->saveTags();
}
// Note: groups may save tags, so must be run after tags are saved
// to avoid errors on duplicates.
// Note: groups should always be set.
$stored->saveKnownGroups($groups);
if (!empty($urls)) {
$stored->saveKnownUrls($urls);
} else {
$stored->saveUrls();
}
if ($distribute) {
// Prepare inbox delivery, may be queued to background.
$stored->distribute();
}
return $stored;
}
示例3: saveActivity
//.........这里部分代码省略.........
$conv = Conversation::create($act->context->conversation, $stored->created);
}
$stored->conversation = $conv->getID();
unset($conv);
}
}
// If it's not part of a conversation, it's the beginning of a new conversation.
if (empty($stored->conversation)) {
$conv = Conversation::create();
$stored->conversation = $conv->getID();
unset($conv);
}
$notloc = null;
if ($act->context instanceof ActivityContext) {
if ($act->context->location instanceof Location) {
$notloc = Notice_location::fromLocation($act->context->location);
}
} else {
$act->context = new ActivityContext();
}
$stored->scope = self::figureOutScope($actor, $groups, $scope);
foreach ($act->categories as $cat) {
if ($cat->term) {
$term = common_canonical_tag($cat->term);
if (!empty($term)) {
$tags[] = $term;
}
}
}
foreach ($act->enclosures as $href) {
// @todo FIXME: Save these locally or....?
$urls[] = $href;
}
if (ActivityUtils::compareVerbs($stored->verb, array(ActivityVerb::POST))) {
if (empty($act->objects[0]->type)) {
// Default type for the post verb is 'note', but we know it's
// a 'comment' if it is in reply to something.
$stored->object_type = empty($stored->reply_to) ? ActivityObject::NOTE : ActivityObject::COMMENT;
} else {
//TODO: Is it safe to always return a relative URI? The
// JSON version of ActivityStreams always use it, so we
// should definitely be able to handle it...
$stored->object_type = ActivityUtils::resolveUri($act->objects[0]->type, true);
}
}
if (Event::handle('StartNoticeSave', array(&$stored))) {
// XXX: some of these functions write to the DB
try {
$result = $stored->insert();
// throws exception on error
if ($notloc instanceof Notice_location) {
$notloc->notice_id = $stored->getID();
$notloc->insert();
}
$orig = clone $stored;
// for updating later in this try clause
$object = null;
Event::handle('StoreActivityObject', array($act, $stored, $options, &$object));
if (empty($object)) {
throw new ServerException('Unsuccessful call to StoreActivityObject ' . $stored->getUri() . ': ' . $act->asString());
}
// If something changed in the Notice during StoreActivityObject
$stored->update($orig);
} catch (Exception $e) {
if (empty($stored->id)) {
common_debug('Failed to save stored object entry in database (' . $e->getMessage() . ')');
} else {
common_debug('Failed to store activity object in database (' . $e->getMessage() . '), deleting notice id ' . $stored->id);
$stored->delete();
}
throw $e;
}
}
if (!$stored instanceof Notice) {
throw new ServerException('StartNoticeSave did not give back a Notice');
}
// Only save 'attention' and metadata stuff (URLs, tags...) stuff if
// the activityverb is a POST (since stuff like repeat, favorite etc.
// reasonably handle notifications themselves.
if (ActivityUtils::compareVerbs($stored->verb, array(ActivityVerb::POST))) {
if (!empty($tags)) {
$stored->saveKnownTags($tags);
} else {
$stored->saveTags();
}
// Note: groups may save tags, so must be run after tags are saved
// to avoid errors on duplicates.
$stored->saveAttentions($act->context->attention);
if (!empty($urls)) {
$stored->saveKnownUrls($urls);
} else {
$stored->saveUrls();
}
}
if ($distribute) {
// Prepare inbox delivery, may be queued to background.
$stored->distribute();
}
return $stored;
}
示例4: showNotice
function showNotice()
{
global $connector;
global $result;
$notice = new Notice();
$notice->setConnector($connector);
$student = new Student();
$student->setConnector($connector);
if (isset($_POST['operation'])) {
list($operation, $params) = explode("#", $_POST['operation']);
switch ($operation) {
case 'saveChanges':
$notice->storeFormValues($_POST);
$error_msg = $notice->insert();
break;
case 'delete':
$error_msg = $notice->delete($params);
break;
default:
$error_msg = "Operazione non valida";
}
if ($error_msg != "") {
$result["errorMessage"] = $error_msg;
} elseif ($operation != 'edit') {
$result["statusMessage"] = "Operazione completata!";
}
}
$result['students'] = $student->getList();
$result['notices'] = $notice->getList();
$page = "notice.php";
include_once BASE_PATH . "template.php";
}