本文整理汇总了PHP中ActivityModel::save方法的典型用法代码示例。如果您正苦于以下问题:PHP ActivityModel::save方法的具体用法?PHP ActivityModel::save怎么用?PHP ActivityModel::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActivityModel
的用法示例。
在下文中一共展示了ActivityModel::save方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: post
public function post($data = [])
{
if (empty($data)) {
throw new Exception('Some data is needed to be posted.');
} else {
$activity = new ActivityModel();
if (array_key_exists('user_id', $data)) {
$activity->setUserId($data['user_id']);
}
if (array_key_exists('exercise_name', $data)) {
$activity->setExerciseName($data['exercise_name']);
}
if (array_key_exists('exercise_duration', $data)) {
$activity->setExerciseDuration($data['exercise_duration']);
}
if (array_key_exists('exercise_calories', $data)) {
$activity->setExerciseCalories($data['exercise_calories']);
}
if (array_key_exists('exercise_distance', $data)) {
$activity->setExerciseDistance($data['exercise_distance']);
}
if (array_key_exists('exercise_timestamp', $data)) {
$activity->setExerciseTimestamp($data['exercise_timestamp']);
}
if ($activity->save()) {
return true;
} else {
return false;
}
}
}
示例2: post
/**
*
*
* @param bool $Notify
* @param bool $UserID
*/
public function post($Notify = false, $UserID = false)
{
if (is_numeric($Notify)) {
$UserID = $Notify;
$Notify = false;
}
if (!$UserID) {
$UserID = Gdn::session()->UserID;
}
switch ($Notify) {
case 'mods':
$this->permission('Garden.Moderation.Manage');
$NotifyUserID = ActivityModel::NOTIFY_MODS;
break;
case 'admins':
$this->permission('Garden.Settings.Manage');
$NotifyUserID = ActivityModel::NOTIFY_ADMINS;
break;
default:
$this->permission('Garden.Profiles.Edit');
$NotifyUserID = ActivityModel::NOTIFY_PUBLIC;
break;
}
$Activities = array();
if ($this->Form->authenticatedPostBack()) {
$Data = $this->Form->formValues();
$Data = $this->ActivityModel->filterForm($Data);
if (!isset($Data['Format']) || strcasecmp($Data['Format'], 'Raw') == 0) {
$Data['Format'] = c('Garden.InputFormatter');
}
if ($UserID != Gdn::session()->UserID) {
// This is a wall post.
$Activity = array('ActivityType' => 'WallPost', 'ActivityUserID' => $UserID, 'RegardingUserID' => Gdn::session()->UserID, 'HeadlineFormat' => t('HeadlineFormat.WallPost', '{RegardingUserID,you} → {ActivityUserID,you}'), 'Story' => $Data['Comment'], 'Format' => $Data['Format'], 'Data' => array('Bump' => true));
} else {
// This is a status update.
$Activity = array('ActivityType' => 'Status', 'HeadlineFormat' => t('HeadlineFormat.Status', '{ActivityUserID,user}'), 'Story' => $Data['Comment'], 'Format' => $Data['Format'], 'NotifyUserID' => $NotifyUserID, 'Data' => array('Bump' => true));
$this->setJson('StatusMessage', Gdn_Format::plainText($Activity['Story'], $Activity['Format']));
}
$Activity = $this->ActivityModel->save($Activity, false, array('CheckSpam' => true));
if ($Activity == SPAM || $Activity == UNAPPROVED) {
$this->StatusMessage = t('ActivityRequiresApproval', 'Your post will appear after it is approved.');
$this->render('Blank', 'Utility');
return;
}
if ($Activity) {
if ($UserID == Gdn::session()->UserID && $NotifyUserID == ActivityModel::NOTIFY_PUBLIC) {
Gdn::userModel()->setField(Gdn::session()->UserID, 'About', Gdn_Format::plainText($Activity['Story'], $Activity['Format']));
}
$Activities = array($Activity);
ActivityModel::joinUsers($Activities);
$this->ActivityModel->calculateData($Activities);
} else {
$this->Form->setValidationResults($this->ActivityModel->validationResults());
$this->StatusMessage = $this->ActivityModel->Validation->resultsText();
// $this->render('Blank', 'Utility');
}
}
if ($this->deliveryType() == DELIVERY_TYPE_ALL) {
$Target = $this->Request->get('Target', '/activity');
if (isSafeUrl($Target)) {
redirect($Target);
} else {
redirect(url('/activity'));
}
}
$this->setData('Activities', $Activities);
$this->render('Activities');
}
示例3: approve
/**
* Approve a membership applicant.
*
* @param int $UserID
* @param string $Email
* @return bool
* @throws Exception
*/
public function approve($UserID, $Email)
{
$applicantRoleIDs = RoleModel::getDefaultRoles(RoleModel::TYPE_APPLICANT);
// Make sure the $UserID is an applicant
$RoleData = $this->getRoles($UserID);
if ($RoleData->numRows() == 0) {
throw new Exception(t('ErrorRecordNotFound'));
} else {
$AppRoles = $RoleData->result(DATASET_TYPE_ARRAY);
$ApplicantFound = false;
foreach ($AppRoles as $AppRole) {
if (in_array(val('RoleID', $AppRole), $applicantRoleIDs)) {
$ApplicantFound = true;
}
}
}
if ($ApplicantFound) {
// Retrieve the default role(s) for new users
$RoleIDs = RoleModel::getDefaultRoles(RoleModel::TYPE_MEMBER);
// Wipe out old & insert new roles for this user
$this->saveRoles($UserID, $RoleIDs, false);
// Send out a notification to the user
$User = $this->getID($UserID);
if ($User) {
$Email = new Gdn_Email();
$Email->subject(sprintf(t('[%1$s] Membership Approved'), c('Garden.Title')));
$Email->to($User->Email);
$message = sprintf(t('Hello %s!'), val('Name', $User)) . ' ' . t('You have been approved for membership.');
$emailTemplate = $Email->getEmailTemplate()->setMessage($message)->setButton(externalUrl(signInUrl()), t('Sign In Now'))->setTitle(t('Membership Approved'));
$Email->setEmailTemplate($emailTemplate);
try {
$Email->send();
} catch (Exception $e) {
if (debug()) {
throw $e;
}
}
// Report that the user was approved.
$ActivityModel = new ActivityModel();
$ActivityModel->save(['ActivityUserID' => $UserID, 'ActivityType' => 'Registration', 'HeadlineFormat' => t('HeadlineFormat.Registration', '{ActivityUserID,You} joined.'), 'Story' => t('Welcome Aboard!')], false, ['GroupBy' => 'ActivityTypeID']);
// Report the approval for moderators.
$ActivityModel->save(['ActivityType' => 'Registration', 'ActivityUserID' => Gdn::session()->UserID, 'RegardingUserID' => $UserID, 'NotifyUserID' => ActivityModel::NOTIFY_MODS, 'HeadlineFormat' => t('HeadlineFormat.RegistrationApproval', '{ActivityUserID,user} approved the applications for {RegardingUserID,user}.')], false, ['GroupBy' => ['ActivityTypeID', 'ActivityUserID']]);
Gdn::userModel()->saveAttribute($UserID, 'ApprovedByUserID', Gdn::session()->UserID);
}
}
return true;
}
示例4: discussionController_QnA_create
/**
*
*
* @param DiscussionController $sender Sending controller instance.
* @param array $args Event arguments.
*
* @throws notFoundException
*/
public function discussionController_QnA_create($sender, $args)
{
$Comment = Gdn::SQL()->getWhere('Comment', array('CommentID' => $sender->Request->get('commentid')))->firstRow(DATASET_TYPE_ARRAY);
if (!$Comment) {
throw notFoundException('Comment');
}
$Discussion = Gdn::SQL()->getWhere('Discussion', array('DiscussionID' => $Comment['DiscussionID']))->firstRow(DATASET_TYPE_ARRAY);
// Check for permission.
if (!(Gdn::session()->UserID == val('InsertUserID', $Discussion) || Gdn::session()->checkPermission('Garden.Moderation.Manage'))) {
throw permissionException('Garden.Moderation.Manage');
}
if (!Gdn::session()->validateTransientKey($sender->Request->get('tkey'))) {
throw permissionException();
}
switch ($args[0]) {
case 'accept':
$QnA = 'Accepted';
break;
case 'reject':
$QnA = 'Rejected';
break;
}
if (isset($QnA)) {
$DiscussionSet = array('QnA' => $QnA);
$CommentSet = array('QnA' => $QnA);
if ($QnA == 'Accepted') {
$CommentSet['DateAccepted'] = Gdn_Format::toDateTime();
$CommentSet['AcceptedUserID'] = Gdn::session()->UserID;
if (!$Discussion['DateAccepted']) {
$DiscussionSet['DateAccepted'] = Gdn_Format::toDateTime();
$DiscussionSet['DateOfAnswer'] = $Comment['DateInserted'];
}
}
// Update the comment.
Gdn::SQL()->put('Comment', $CommentSet, array('CommentID' => $Comment['CommentID']));
// Update the discussion.
if ($Discussion['QnA'] != $QnA && (!$Discussion['QnA'] || in_array($Discussion['QnA'], array('Unanswered', 'Answered', 'Rejected')))) {
Gdn::SQL()->put('Discussion', $DiscussionSet, array('DiscussionID' => $Comment['DiscussionID']));
}
// Determine QnA change
if ($Comment['QnA'] != $QnA) {
$Change = 0;
switch ($QnA) {
case 'Rejected':
$Change = -1;
if ($Comment['QnA'] != 'Accepted') {
$Change = 0;
}
break;
case 'Accepted':
$Change = 1;
if (!$this->Reactions && c('QnA.Points.Enabled', false) && $Discussion['InsertUserID'] != $Comment['InsertUserID']) {
UserModel::givePoints($Comment['InsertUserID'], c('QnA.Points.AcceptedAnswer', 1), 'QnA');
}
break;
default:
if ($Comment['QnA'] == 'Rejected') {
$Change = 0;
}
if ($Comment['QnA'] == 'Accepted') {
$Change = -1;
}
break;
}
}
// Apply change effects
if ($Change) {
// Update the user
$UserID = val('InsertUserID', $Comment);
$this->recalculateUserQnA($UserID);
// Update reactions
if ($this->Reactions) {
include_once Gdn::controller()->fetchViewLocation('reaction_functions', '', 'plugins/Reactions');
$Rm = new ReactionModel();
// If there's change, reactions will take care of it
$Rm->react('Comment', $Comment['CommentID'], 'AcceptAnswer', null, true);
}
}
// Record the activity.
if ($QnA == 'Accepted') {
$Activity = array('ActivityType' => 'AnswerAccepted', 'NotifyUserID' => $Comment['InsertUserID'], 'HeadlineFormat' => '{ActivityUserID,You} accepted {NotifyUserID,your} answer.', 'RecordType' => 'Comment', 'RecordID' => $Comment['CommentID'], 'Route' => commentUrl($Comment, '/'), 'Emailed' => ActivityModel::SENT_PENDING, 'Notified' => ActivityModel::SENT_PENDING);
$ActivityModel = new ActivityModel();
$ActivityModel->save($Activity);
$this->EventArguments['Activity'] =& $Activity;
$this->fireEvent('AfterAccepted');
}
}
redirect("/discussion/comment/{$Comment['CommentID']}#Comment_{$Comment['CommentID']}");
}
示例5: approve
/**
* Approve a membership applicant.
*
* @param $UserID
* @param $Email
* @return bool
* @throws Exception
*/
public function approve($UserID, $Email)
{
$applicantRoleIDs = RoleModel::getDefaultRoles(RoleModel::TYPE_APPLICANT);
// Make sure the $UserID is an applicant
$RoleData = $this->GetRoles($UserID);
if ($RoleData->numRows() == 0) {
throw new Exception(t('ErrorRecordNotFound'));
} else {
$AppRoles = $RoleData->result(DATASET_TYPE_ARRAY);
$ApplicantFound = false;
foreach ($AppRoles as $AppRole) {
if (in_array(val('RoleID', $AppRole), $applicantRoleIDs)) {
$ApplicantFound = true;
}
}
}
if ($ApplicantFound) {
// Retrieve the default role(s) for new users
$RoleIDs = RoleModel::getDefaultRoles(RoleModel::TYPE_MEMBER);
// Wipe out old & insert new roles for this user
$this->SaveRoles($UserID, $RoleIDs, false);
// Send out a notification to the user
$User = $this->getID($UserID);
if ($User) {
$Email->subject(sprintf(t('[%1$s] Membership Approved'), c('Garden.Title')));
$Email->message(sprintf(t('EmailMembershipApproved'), $User->Name, ExternalUrl(SignInUrl())));
$Email->to($User->Email);
//$Email->from(c('Garden.SupportEmail'), c('Garden.SupportName'));
$Email->send();
// Report that the user was approved.
$ActivityModel = new ActivityModel();
$ActivityModel->save(array('ActivityUserID' => $UserID, 'ActivityType' => 'Registration', 'HeadlineFormat' => t('HeadlineFormat.Registration', '{ActivityUserID,You} joined.'), 'Story' => t('Welcome Aboard!')), false, array('GroupBy' => 'ActivityTypeID'));
// Report the approval for moderators.
$ActivityModel->save(array('ActivityType' => 'Registration', 'ActivityUserID' => Gdn::session()->UserID, 'RegardingUserID' => $UserID, 'NotifyUserID' => ActivityModel::NOTIFY_MODS, 'HeadlineFormat' => t('HeadlineFormat.RegistrationApproval', '{ActivityUserID,user} approved the applications for {RegardingUserID,user}.')), false, array('GroupBy' => array('ActivityTypeID', 'ActivityUserID')));
Gdn::userModel()->saveAttribute($UserID, 'ApprovedByUserID', Gdn::session()->UserID);
}
}
return true;
}
示例6: save
public function save($sql = '', $id_sql = '')
{
global $phpAnvil;
$isChanged = true;
$return = false;
$now = new DateTime(null, $phpAnvil->regional->dateTimeZone);
// if ($this->isNew() && $this->addSourceID == 0) {
if ($this->isNew()) {
// $this->addDTS = date('Y-m-d H:i:s');
$this->addDTS = $now->format($phpAnvil->regional->dtsFormat);
if (empty($this->addSourceID)) {
$this->addSourceTypeID = $phpAnvil->sourceTypeID;
$this->addSourceID = $phpAnvil->application->user->id;
}
if (empty($this->recordStatusID)) {
$this->recordStatusID = self::RECORD_STATUS_ACTIVE;
}
} else {
$isChanged = $this->isChanged();
}
if ($isChanged) {
// if ($this->fields->field('recordStatusID')->changed)
if ($this->fields->recordStatusID->changed) {
$this->recordStatusDTS = $now->format($phpAnvil->regional->dtsFormat);
$this->recordStatusSourceTypeID = $phpAnvil->sourceTypeID;
$this->recordStatusSourceID = $phpAnvil->application->user->id;
}
if ($this->_saveActivity) {
$activity = new ActivityModel();
$activity->accountID = $this->_core->application->account->id;
$activity->targetTableName = $this->primaryTableName;
$activity->activityTypeID = ActivityModel::TYPE_UPDATED;
$activity->description = $this->activityDescription;
//---- Save Activity
if ($this->activityTypeIDOverride) {
$activity->activityTypeID = $this->activityTypeIDOverride;
$activity->detail = $this->activityDetail;
} elseif ($this->isNew()) {
$activity->activityTypeID = ActivityModel::TYPE_ADDED;
} else {
//---- Get Changed Field Array ---------------------------------
$changedArray = $this->fields->getChangedArray();
// $this->enableLog();
// $this->_logError($changedArray, '$changedArray');
$activity->detail = json_encode($changedArray);
if ($this->fields->recordStatusID->changed) {
switch ($this->recordStatusID) {
case self::RECORD_STATUS_ACTIVE:
$activity->activityTypeID = ActivityModel::TYPE_ENABLED;
break;
case self::RECORD_STATUS_DISABLED:
$activity->activityTypeID = ActivityModel::TYPE_DISABLED;
break;
case self::RECORD_STATUS_DELETED:
$activity->activityTypeID = ActivityModel::TYPE_DELETED;
break;
}
}
}
}
$return = parent::save($sql, $id_sql);
if ($this->_saveActivity) {
$activity->targetID = $this->id;
$activity->save();
$activity->__destruct();
unset($activity);
}
} else {
$this->_logVerbose('No fields have changed, skipping save...', $this->primaryTableName);
}
return $return;
}
示例7: save
/**
* Save the addon data.
*
* @param array $Stub
* @param bool|array $Settings Not used; for signature compatibility.
* @return bool|Gdn_DataSet|mixed|object|string
*/
public function save($Stub, $Settings = false)
{
trace('AddonModel->Save()');
$Session = Gdn::session();
$this->defineSchema();
// Most of the values come from the file itself.
if (isset($Stub['Path'])) {
$Path = $Stub['Path'];
} elseif (val('Checked', $Stub)) {
$Addon = $Stub;
} elseif (isset($Stub['File'])) {
$Path = combinePaths(array(PATH_UPLOADS, $Stub['File']));
} else {
if (!$Session->checkPermission('Addons.Addon.Manage') && isset($Stub['Filename'])) {
// Only admins can modify plugin attributes without the file.
$this->Validation->addValidationResult('Filename', 'ValidateRequired');
return false;
}
}
// Analyze and fix the file.
if (!isset($Addon)) {
if (isset($Path)) {
try {
$Addon = UpdateModel::analyzeAddon($Path, false);
} catch (Exception $Ex) {
$Addon = false;
$this->Validation->addValidationResult('File', '@' . $Ex->getMessage());
}
if (!is_array($Addon)) {
$this->Validation->addValidationResult('File', 'Could not analyze the addon file.');
return false;
}
$Addon = array_merge($Stub, $Addon);
} else {
$Addon = $Stub;
if (isset($Path)) {
$Addon['MD5'] = md5_file($Path);
$Addon['FileSize'] = filesize($Path);
}
}
}
// Get an existing addon.
if (isset($Addon['AddonID'])) {
$CurrentAddon = $this->getID($Addon['AddonID'], false, ['GetVersions' => true]);
} elseif (isset($Addon['AddonKey']) && isset($Addon['AddonTypeID'])) {
$CurrentAddon = $this->getID(array($Addon['AddonKey'], $Addon['AddonTypeID']), false, ['GetVersions' => true]);
} else {
$CurrentAddon = false;
}
trace($CurrentAddon, 'CurrentAddon');
$Insert = !$CurrentAddon;
if ($Insert) {
$this->addInsertFields($Addon);
}
$this->addUpdateFields($Addon);
// always add update fields
if (!$this->validate($Addon, $Insert)) {
trace('Addon did not validate');
return false;
}
// Search for the current version.
$MaxVersion = false;
$CurrentVersion = false;
if ($CurrentAddon && isset($Addon['Version'])) {
// Search for a current version.
foreach ($CurrentAddon['Versions'] as $Index => $Version) {
if (isset($Addon['AddonVersionID'])) {
if ($Addon['AddonVersionID'] == $Version['AddonVersionID']) {
$CurrentVersion = $Version;
}
} elseif (version_compare($Addon['Version'], $Version['Version']) == 0) {
$CurrentVersion = $Version;
}
// Only check for a current version if the version has been checked.
if (!$Version['Checked']) {
continue;
}
if (!$MaxVersion || version_compare($MaxVersion['Version'], $Version['Version'], '<')) {
$MaxVersion = $Version;
}
}
}
// Save the addon.
$Fields = $this->filterSchema($Addon);
if ($Insert) {
$AddonID = $this->SQL->insert($this->Name, $Fields);
// Add the activity.
$ActivityModel = new ActivityModel();
$Activity = array('ActivityType' => 'Addon', 'ActivityUserID' => $Fields['InsertUserID'], 'NotifyUserID' => ActivityModel::NOTIFY_PUBLIC, 'HeadlineFormat' => '{ActivityUserID,user} added the <a href="{Url,html}">{Data.Name}</a> addon.', 'Story' => Gdn_Format::html($Fields['Description']), 'Route' => '/addon/' . rawurlencode(self::slug($Fields, false)), 'Data' => array('Name' => $Fields['Name']));
$ActivityModel->save($Activity);
} else {
$AddonID = val('AddonID', $CurrentAddon);
// Only save the addon if it is the current version.
//.........这里部分代码省略.........
示例8: saveUser
/**
* Change ban data on a user (ban or unban them).
*
* @since 2.0.18
* @access public
*
* @param array $User
* @param bool $BannedValue Whether user is banned.
* @param array|false $Ban An array representing the specific auto-ban.
*/
public function saveUser($User, $BannedValue, $Ban = false)
{
$BannedValue = (bool) $BannedValue;
$Banned = $User['Banned'];
if (static::isBanned($Banned, self::BAN_AUTOMATIC) === $BannedValue) {
return;
}
$NewBanned = static::setBanned($Banned, $BannedValue, self::BAN_AUTOMATIC);
Gdn::userModel()->setField($User['UserID'], 'Banned', $NewBanned);
$BanningUserID = Gdn::session()->UserID;
// This is true when a session is started and the session user has a new ip address and it matches a banning rule ip address
if ($User['UserID'] == $BanningUserID) {
$BanningUserID = val('InsertUserID', $Ban, Gdn::userModel()->GetSystemUserID());
}
// Add the activity.
$ActivityModel = new ActivityModel();
$Activity = array('ActivityType' => 'Ban', 'ActivityUserID' => $User['UserID'], 'RegardingUserID' => $BanningUserID, 'NotifyUserID' => ActivityModel::NOTIFY_MODS);
$BannedString = $BannedValue ? 'banned' : 'unbanned';
if ($Ban) {
$Activity['HeadlineFormat'] = '{ActivityUserID,user} was ' . $BannedString . ' (based on {Data.BanType}: {Data.BanValue}).';
$Activity['Data'] = arrayTranslate($Ban, array('BanType', 'BanValue'));
$Activity['Story'] = $Ban['Notes'];
$Activity['RecordType'] = 'Ban';
if (isset($Ban['BanID'])) {
$Activity['BanID'] = $Ban['BanID'];
}
} else {
$Activity['HeadlineFormat'] = '{ActivityUserID,user} was ' . $BannedString . '.';
}
$ActivityModel->save($Activity);
}