当前位置: 首页>>代码示例>>PHP>>正文


PHP Gdn_Model类代码示例

本文整理汇总了PHP中Gdn_Model的典型用法代码示例。如果您正苦于以下问题:PHP Gdn_Model类的具体用法?PHP Gdn_Model怎么用?PHP Gdn_Model使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Gdn_Model类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sort

 /**
  * Set the sort order for data on an arbitrary database table.
  *
  * Expect post values TransientKey, Target (redirect URL), Table (database table name),
  * and TableID (an array of sort order => unique ID).
  *
  * @since 2.0.0
  * @access public
  */
 public function sort()
 {
     $this->permission('Garden.Settings.Manage');
     if (Gdn::request()->isAuthenticatedPostBack()) {
         $TableID = Gdn::request()->Post('TableID');
         if ($TableID) {
             $Rows = Gdn::request()->Post($TableID);
             if (is_array($Rows)) {
                 $Table = str_replace(array('Table', '`'), '', $TableID);
                 $ModelName = $Table . 'Model';
                 if (class_exists($ModelName)) {
                     $TableModel = new $ModelName();
                 } else {
                     $TableModel = new Gdn_Model($Table);
                 }
                 foreach ($Rows as $Sort => $ID) {
                     if (strpos($ID, '_') !== false) {
                         list(, $ID) = explode('_', $ID, 2);
                     }
                     if (!$ID) {
                         continue;
                     }
                     $TableModel->setField($ID, 'Sort', $Sort);
                 }
                 $this->setData('Result', true);
             }
         }
     }
     $this->render('Blank');
 }
开发者ID:sitexa,项目名称:vanilla,代码行数:39,代码来源:class.utilitycontroller.php

示例2: Sort

 public function Sort() {
    $Session = Gdn::Session();
    $TransientKey = GetPostValue('TransientKey', '');
    $Target = GetPostValue('Target', '');
    if ($Session->ValidateTransientKey($TransientKey)) {
       $TableID = GetPostValue('TableID', FALSE);
       if ($TableID) {
          $Rows = GetPostValue($TableID, FALSE);
          if (is_array($Rows)) {
             try {
                $Table = str_replace('Table', '', $TableID);
                $TableModel = new Gdn_Model($Table);
                foreach ($Rows as $Sort => $ID) {
                   $TableModel->Update(array('Sort' => $Sort), array($Table.'ID' => $ID));
                }
             } catch (Exception $ex) {
                $this->Form->AddError($ex->getMessage());
             }
          }
       }
    }
    if ($this->DeliveryType() != DELIVERY_TYPE_BOOL)
       Redirect($Target);
       
    $this->Render();
 }
开发者ID:nerdgirl,项目名称:Forums-ILoveBadTV,代码行数:26,代码来源:class.utilitycontroller.php

示例3: SettingsController_EventCalendar_Create

 /**
  * Allows customization of categories which allow new discussions to be events 
  * Sets config value Plugins.EventCalendar.CategoryIDs
  *
  * @param object $Sender SettingsController
  */
 public function SettingsController_EventCalendar_Create($Sender)
 {
     $Sender->Permission('Garden.Settings.Manage');
     $Sender->Title(T('Event Calendar Settings'));
     $Sender->AddSideMenu('settings/EventCalendar');
     $Sender->SetData('Info', T('Event Calendar Info', 'Creation of events can be regulated by category <strong>and</strong> user role. You can set up the categories here, but don\'t forget to assign some permissions in the <a href="/index.php?p=dashboard/role">standard permission section</a> in the dashboard, otherwise you users wouldn\'t be able to use this plugin!'));
     $Sender->SetData('CategoriesLabel', 'Please choose categories in which the creation of events should be allowed');
     $Validation = new Gdn_Validation();
     // $Validation->ApplyRule('Plugins.EventCalendar.CategoryIDs', 'RequiredArray', T('You have to choose at least one category. If you don\'t want to use the plugin any longer, please deactivate it'));
     $ConfigurationModel = new Gdn_ConfigurationModel($Validation);
     $ConfigurationModel->SetField(array('Plugins.EventCalendar.CategoryIDs'));
     $Form = $Sender->Form;
     $Sender->Form->SetModel($ConfigurationModel);
     if ($Sender->Form->AuthenticatedPostBack() != FALSE) {
         if ($Sender->Form->Save() != FALSE) {
             $Sender->StatusMessage = T('Saved');
         }
     } else {
         $Sender->Form->SetData($ConfigurationModel->Data);
     }
     $CategoryModel = new Gdn_Model('Category');
     $Sender->CategoryData = $CategoryModel->GetWhere(array('AllowDiscussions' => 1, 'CategoryID <>' => -1));
     $Sender->EventCategory = C('Plugins.EventCalendar.CategoryIDs');
     $Sender->Render('settings', '', 'plugins/EventCalendar');
 }
开发者ID:shumoo,项目名称:EventCalendar,代码行数:31,代码来源:class.eventcalendar.plugin.php

示例4: Picture

 public function Picture($UserReference = '')
 {
     $this->Permission('Garden.SignIn.Allow');
     $Session = Gdn::Session();
     if (!$Session->IsValid()) {
         $this->Form->AddError('You must be authenticated in order to use this form.');
     }
     $this->GetUserInfo($UserReference);
     $this->Form->SetModel($this->UserModel);
     $this->Form->AddHidden('UserID', $this->User->UserID);
     if ($this->Form->AuthenticatedPostBack() === TRUE) {
         $UploadImage = new Gdn_UploadImage();
         try {
             // Validate the upload
             $TmpImage = $UploadImage->ValidateUpload('Picture');
             // Generate the target image name
             $TargetImage = $UploadImage->GenerateTargetName(PATH_ROOT . DS . 'uploads');
             $ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
             // Delete any previously uploaded images
             @unlink(PATH_ROOT . DS . 'uploads' . DS . 'p' . $this->User->Photo);
             // Don't delete this one because it hangs around in activity streams:
             // @unlink(PATH_ROOT . DS . 'uploads' . DS . 't' . $this->User->Photo);
             @unlink(PATH_ROOT . DS . 'uploads' . DS . 'n' . $this->User->Photo);
             // Save the uploaded image in profile size
             $UploadImage->SaveImageAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . 'p' . $ImageBaseName, Gdn::Config('Garden.Profile.MaxHeight', 1000), Gdn::Config('Garden.Profile.MaxWidth', 250));
             // Save the uploaded image in preview size
             $UploadImage->SaveImageAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . 't' . $ImageBaseName, Gdn::Config('Garden.Preview.MaxHeight', 100), Gdn::Config('Garden.Preview.MaxWidth', 75));
             // Save the uploaded image in thumbnail size
             $ThumbSize = Gdn::Config('Garden.Thumbnail.Size', 50);
             $UploadImage->SaveImageAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . 'n' . $ImageBaseName, $ThumbSize, $ThumbSize, TRUE);
         } catch (Exception $ex) {
             $this->Form->AddError($ex->getMessage());
         }
         // If there were no errors, associate the image with the user
         if ($this->Form->ErrorCount() == 0) {
             $PhotoModel = new Gdn_Model('Photo');
             $PhotoID = $PhotoModel->Insert(array('Name' => $ImageBaseName));
             if (!$this->UserModel->Save(array('UserID' => $this->User->UserID, 'PhotoID' => $PhotoID, 'Photo' => $ImageBaseName))) {
                 $this->Form->SetValidationResults($this->UserModel->ValidationResults());
             }
         }
         // If there were no problems, redirect back to the user account
         if ($this->Form->ErrorCount() == 0) {
             Redirect('garden/profile/' . $UserReference);
         }
     }
     $this->Render();
 }
开发者ID:jhampha,项目名称:Garden,代码行数:48,代码来源:profile.php

示例5: Edit

 public function Edit($UserID)
 {
     $this->Permission('Garden.Users.Edit');
     $this->AddJsFile('user.js');
     $this->AddSideMenu('garden/user');
     $RoleModel = new Gdn_Model('Role');
     $this->RoleData = $RoleModel->Get();
     $UserModel = new Gdn_UserModel();
     $this->User = $UserModel->Get($UserID);
     // Set the model on the form.
     $this->Form->SetModel($UserModel);
     // Make sure the form knows which item we are editing.
     $this->Form->AddHidden('UserID', $UserID);
     if (!$this->Form->AuthenticatedPostBack()) {
         $this->Form->SetData($this->User);
         $this->UserRoleData = $UserModel->GetRoles($UserID);
     } else {
         // If a new password was specified, add it to the form's collection
         $ResetPassword = $this->Form->GetValue('ResetPassword', FALSE);
         $NewPassword = $this->Form->GetValue('NewPassword', '');
         if ($ResetPassword !== FALSE) {
             $this->Form->SetFormValue('Password', $NewPassword);
         }
         if ($this->Form->Save(array('SaveRoles' => TRUE)) !== FALSE) {
             if ($this->Form->GetValue('Password', '') != '') {
                 $UserModel->SendPasswordEmail($UserID, $NewPassword);
             }
             $this->StatusMessage = T('Your changes have been saved successfully.');
         }
         $this->UserRoleData = $this->Form->GetFormValue('RoleID');
     }
     $this->Render();
 }
开发者ID:nbudin,项目名称:Garden,代码行数:33,代码来源:user.php

示例6: deletePicture

 /**
  * Delete a screenshot from an addon.
  *
  * @param string $AddonPictureID Picture id to remove.
  * @throws Gdn_UserException No permission to delete this picture.
  */
 public function deletePicture($AddonPictureID = '')
 {
     $AddonPictureModel = new Gdn_Model('AddonPicture');
     $Picture = $AddonPictureModel->getWhere(array('AddonPictureID' => $AddonPictureID))->firstRow();
     $AddonModel = new AddonModel();
     $Addon = $AddonModel->getID($Picture->AddonID);
     $Session = Gdn::session();
     if ($Session->UserID != $Addon['InsertUserID'] && !$Session->checkPermission('Addons.Addon.Manage')) {
         throw permissionException();
     }
     if ($this->Form->authenticatedPostBack() && $this->Form->getFormValue('Yes')) {
         if ($Picture) {
             $Upload = new Gdn_Upload();
             $Upload->delete(changeBasename($Picture->File, 'ao%s'));
             $Upload->delete(changeBasename($Picture->File, 'at%s'));
             $AddonPictureModel->delete(array('AddonPictureID' => $AddonPictureID));
         }
         $this->RedirectUrl = url('/addon/' . $Picture->AddonID);
     }
     $this->render('deletepicture');
 }
开发者ID:vanilla,项目名称:community,代码行数:27,代码来源:class.addoncontroller.php

示例7: Save

 public function Save($FormPostValues, $Settings = FALSE)
 {
     // Get the ID of an existing tag with the same name.
     $ExistingTag = $this->GetWhere(array('Name' => $FormPostValues['Name'], 'TagID <>' => GetValue('TagID', $FormPostValues)))->FirstRow(DATASET_TYPE_ARRAY);
     if ($ExistingTag) {
         if (!GetValue('TagID', $FormPostValues)) {
             return $ExistingTag['TagID'];
         }
         // This tag will be merged with the existing one.
         $Px = $this->Database->DatabasePrefix;
         $FromID = $FormPostValues['TagID'];
         $ToID = $ExistingTag['TagID'];
         try {
             $this->Database->BeginTransaction();
             // Delete all of the overlapping tags.
             $Sql = "delete tg.*\n               from {$Px}TagDiscussion tg\n               join {$Px}TagDiscussion tg2\n                 on tg.DiscussionID = tg2.DiscussionID\n                   and tg.TagID = :FromID and tg2.TagID = :ToID";
             $this->Database->Query($Sql, array(':FromID' => $FromID, ':ToID' => $ToID));
             // Update the tagged discussions.
             $Sql = "update {$Px}TagDiscussion\n               set TagID = :ToID\n               where TagID = :FromID";
             $this->Database->Query($Sql, array(':FromID' => $FromID, ':ToID' => $ToID));
             // Update the counts.
             $Sql = "update {$Px}Tag t\n               set CountDiscussions = (\n                  select count(DiscussionID)\n                  from {$Px}TagDiscussion td\n                  where td.TagID = t.TagID)\n                where t.TagID = :ToID";
             $this->Database->Query($Sql, array(':ToID' => $ToID));
             // Delete the old tag.
             $Sql = "delete from {$Px}Tag where TagID = :FromID";
             $this->Database->Query($Sql, array(':FromID' => $FromID));
             $this->Database->CommitTransaction();
         } catch (Exception $Ex) {
             $this->Database->RollbackTransaction();
             throw $Ex;
         }
     } else {
         parent::Save($FormPostValues, $Settings);
     }
 }
开发者ID:seedbank,项目名称:old-repo,代码行数:35,代码来源:class.tagmodel.php

示例8: __construct

 /**
  * Class constructor. Defines the related database table name.
  */
 public function __construct()
 {
     self::$MemoryCache = array();
     parent::__construct('UserMeta');
     $this->SQL = clone Gdn::sql();
     $this->SQL->reset();
 }
开发者ID:korelstar,项目名称:vanilla,代码行数:10,代码来源:class.usermetamodel.php

示例9: Save

 public function Save($PostValues, $EditingData = False)
 {
     ReplaceEmpty($PostValues, Null);
     $Insert = GetValue('ChunkID', $PostValues) === False;
     if ($Insert) {
         $this->AddUpdateFields($PostValues);
     }
     $RowID = parent::Save($PostValues);
     return $RowID;
 }
开发者ID:unlight,项目名称:Candy,代码行数:10,代码来源:class.chunkmodel.php

示例10: Delete

 public function Delete($ActivityID)
 {
     // Get the activity first
     $Activity = $this->GetID($ActivityID);
     if (is_object($Activity)) {
         $Users = array();
         $Users[] = $Activity->ActivityUserID;
         if (is_numeric($Activity->RegardingUserID) && $Activity->RegardingUserID > 0) {
             $Users[] = $Activity->RegardingUserID;
         }
         // Update the user's dateupdated field so that profile pages will not
         // be cached and will reflect this deletion.
         $this->SQL->Update('User')->Set('DateUpdated', Gdn_Format::ToDateTime())->WhereIn('UserID', $Users)->Put();
         // Delete comments on the activity item
         parent::Delete(array('CommentActivityID' => $ActivityID), FALSE, TRUE);
         // Delete the activity item
         parent::Delete(array('ActivityID' => $ActivityID));
     }
 }
开发者ID:tautomers,项目名称:knoopvszombies,代码行数:19,代码来源:class.activitymodel.php

示例11: __construct

 /**
  * Class constructor. Defines the related database table name.
  *
  * @since 2.0.0
  * @access public
  *
  * @param string $Name Database table name.
  */
 public function __construct($Name = '')
 {
     parent::__construct($Name);
 }
开发者ID:3marproof,项目名称:vanilla,代码行数:12,代码来源:class.vanillamodel.php

示例12: __construct

 /**
  * Class constructor. Defines the related database table name.
  */
 public function __construct()
 {
     parent::__construct('Regarding');
 }
开发者ID:sitexa,项目名称:vanilla,代码行数:7,代码来源:class.regardingmodel.php

示例13: __construct

 public function __construct($ImportPath = '')
 {
     $this->ImportPath = $ImportPath;
     parent::__construct();
 }
开发者ID:elpum,项目名称:TgaForumBundle,代码行数:5,代码来源:class.importmodel.php

示例14: getID

 /**
  * Get a user by ID.
  *
  * @param int $ID The ID of the user.
  * @param string|false $DatasetType Whether to return an array or object.
  * @param array $Options Additional options to affect fetching. Currently unused.
  * @return array|object|false Returns the user or **false** if the user wasn't found.
  */
 public function getID($ID, $DatasetType = false, $Options = [])
 {
     if (!$ID) {
         return false;
     }
     $DatasetType = $DatasetType ?: DATASET_TYPE_OBJECT;
     // Check page cache, then memcached
     $User = $this->getUserFromCache($ID, 'userid');
     // If not, query DB
     if ($User === Gdn_Cache::CACHEOP_FAILURE) {
         $User = parent::getID($ID, DATASET_TYPE_ARRAY);
         // We want to cache a non-existent user no-matter what.
         if (!$User) {
             $User = null;
         }
         $this->userCache($User, $ID);
     } elseif (!$User) {
         return false;
     }
     // Apply calculated fields
     $this->setCalculatedFields($User);
     // Allow FALSE returns
     if ($User === false || is_null($User)) {
         return false;
     }
     if (is_array($User) && $DatasetType == DATASET_TYPE_OBJECT) {
         $User = (object) $User;
     }
     if (is_object($User) && $DatasetType == DATASET_TYPE_ARRAY) {
         $User = (array) $User;
     }
     $this->EventArguments['LoadedUser'] =& $User;
     $this->fireEvent('AfterGetID');
     return $User;
 }
开发者ID:vanilla,项目名称:vanilla,代码行数:43,代码来源:class.usermodel.php

示例15: Save

 public function Save($FormPostValues, $Settings = FALSE)
 {
     // The "location" is packed into a single input with a / delimiter. Need to explode it into three different fields for saving
     $Location = ArrayValue('Location', $FormPostValues, '');
     if ($Location != '') {
         $Location = explode('/', $Location);
         if ($Location[0] == 'Base') {
             $FormPostValues['Controller'] = 'Base';
         } else {
             if (count($Location) >= 1) {
                 $FormPostValues['Application'] = $Location[0];
             }
             if (count($Location) >= 2) {
                 $FormPostValues['Controller'] = $Location[1];
             }
             if (count($Location) >= 3) {
                 $FormPostValues['Method'] = $Location[2];
             }
         }
     }
     // Make sure that messages on the dashboard get dropped below the page heading.
     if ($FormPostValues['Application'] == 'Garden' && $FormPostValues['Controller'] == 'Settings' && $FormPostValues['Method'] == 'Index') {
         $FormPostValues['AssetTarget'] = 'Messages';
     }
     return parent::Save($FormPostValues, $Settings);
 }
开发者ID:Beyzie,项目名称:Garden,代码行数:26,代码来源:class.messagemodel.php


注:本文中的Gdn_Model类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。