Пример #1
0
 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);
     }
 }
Пример #2
0
 public function Save($PostValues, $PreviousValues = False)
 {
     ReplaceEmpty($PostValues, Null);
     $URI = GetValue('URI', $PostValues, Null);
     $bCreateSection = GetValue('CreateSection', $PostValues);
     $RowID = GetValue('PageID', $PostValues);
     $Insert = $RowID === False;
     if ($bCreateSection) {
         $SectionModel = Gdn::Factory('SectionModel');
         $this->Validation->ApplyRule('URI', 'UrlPath');
         $this->Validation->ApplyRule('SectionID', 'Required');
         if ($Insert && $URI && CandyModel::GetRoute($URI)) {
             $this->Validation->AddValidationResult('URI', '%s: Already exists.');
         }
     }
     $this->EventArguments['PostValues'] =& $PostValues;
     $this->FireEvent('BeforeSave');
     $RowID = parent::Save($PostValues);
     if ($RowID) {
         if ($URI) {
             CandyModel::SaveRoute($URI, 'candy/content/page/' . $RowID);
         }
         if ($bCreateSection) {
             $this->CreateSection($RowID, $PostValues);
         }
     }
     return $RowID;
 }
Пример #3
0
 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;
 }
Пример #4
0
 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);
         $Application = GetValue(0, $Location, '');
         if (in_array($Application, $this->_SpecialLocations)) {
             $FormPostValues['Application'] = NULL;
             $FormPostValues['Controller'] = $Application;
             $FormPostValues['Method'] = NULL;
         } else {
             $FormPostValues['Application'] = $Application;
             $FormPostValues['Controller'] = GetValue(1, $Location, '');
             $FormPostValues['Method'] = GetValue(2, $Location, '');
         }
     }
     Gdn::Cache()->Remove('Messages');
     return parent::Save($FormPostValues, $Settings);
 }
Пример #5
0
 /**
  * Save data about ban from form.
  *
  * @since 2.0.18
  * @access public
  * 
  * @param array $FormPostValues
  * @param array $Settings
  */
 public function Save($FormPostValues, $Settings = FALSE)
 {
     $CurrentBanID = GetValue('BanID', $FormPostValues);
     // Get the current ban before saving.
     if ($CurrentBanID) {
         $CurrentBan = $this->GetID($CurrentBanID, DATASET_TYPE_ARRAY);
     } else {
         $CurrentBan = NULL;
     }
     $this->SetCounts($FormPostValues);
     $BanID = parent::Save($FormPostValues, $Settings);
     $FormPostValues['BanID'] = $BanID;
     $this->ApplyBan($FormPostValues, $CurrentBan);
 }
 protected function MergeStart($OldUserID, $NewUserID)
 {
     $Model = new Gdn_Model('UserMerge');
     // Grab the users.
     $OldUser = $this->GetID($OldUserID, DATASET_TYPE_ARRAY);
     $NewUser = $this->GetID($NewUserID, DATASET_TYPE_ARRAY);
     // First see if there is a record with the same merge.
     $Row = $Model->GetWhere(array('OldUserID' => $OldUserID, 'NewUserID' => $NewUserID))->FirstRow(DATASET_TYPE_ARRAY);
     if ($Row) {
         $MergeID = $Row['MergeID'];
         // Save this merge in the log.
         if ($Row['Attributes']) {
             $Attributes = unserialize($Row['Attributes']);
         } else {
             $Attributes = array();
         }
         $Attributes['Log'][] = array('UserID' => Gdn::Session()->UserID, 'Date' => Gdn_Format::ToDateTime());
         $Row = array('MergeID' => $MergeID, 'Attributes' => $Attributes);
     } else {
         $Row = array('OldUserID' => $OldUserID, 'NewUserID' => $NewUserID);
     }
     $UserSet = array();
     $OldUserSet = array();
     if (DateCompare($OldUser['DateFirstVisit'], $NewUser['DateFirstVisit']) < 0) {
         $UserSet['DateFirstVisit'] = $OldUser['DateFirstVisit'];
     }
     if (!isset($Row['Attributes']['User']['CountVisits'])) {
         $UserSet['CountVisits'] = $OldUser['CountVisits'] + $NewUser['CountVisits'];
         $OldUserSet['CountVisits'] = 0;
     }
     if (!empty($UserSet)) {
         // Save the user information on the merge record.
         foreach ($UserSet as $Key => $Value) {
             // Only save changed values that aren't already there from a previous merge.
             if ($NewUser[$Key] != $Value && !isset($Row['Attributes']['User'][$Key])) {
                 $Row['Attributes']['User'][$Key] = $NewUser[$Key];
             }
         }
     }
     $MergeID = $Model->Save($Row);
     if (GetValue('MergeID', $Row)) {
         $MergeID = $Row['MergeID'];
     }
     if (!$MergeID) {
         throw new Gdn_UserException($Model->Validation->ResultsText());
     }
     // Update the user with the new user-level data.
     $this->SetField($NewUserID, $UserSet);
     if (!empty($OldUserSet)) {
         $this->SetField($OldUserID, $OldUserSet);
     }
     return $MergeID;
 }
Пример #7
0
 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);
 }
Пример #8
0
 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];
             }
         }
     }
     return parent::Save($FormPostValues, $Settings);
 }
Пример #9
0
 /**
  * Save data about ban from form.
  *
  * @since 2.0.18
  * @access public
  *
  * @param array $FormPostValues
  * @param array $Settings
  */
 public function save($FormPostValues, $Settings = false)
 {
     $CurrentBanID = val('BanID', $FormPostValues);
     // Get the current ban before saving.
     if ($CurrentBanID) {
         $CurrentBan = $this->getID($CurrentBanID, DATASET_TYPE_ARRAY);
     } else {
         $CurrentBan = null;
     }
     $this->SetCounts($FormPostValues);
     $BanID = parent::Save($FormPostValues, $Settings);
     $FormPostValues['BanID'] = $BanID;
     $this->EventArguments['CurrentBan'] = $CurrentBan;
     $this->EventArguments['FormPostValues'] = $FormPostValues;
     $this->fireEvent('AfterSave');
     $this->ApplyBan($FormPostValues, $CurrentBan);
 }
Пример #10
0
 public function Save($Fields, $Settings = False)
 {
     self::SetNullValues($Fields);
     $RowID = parent::Save($Fields, $Settings);
     return $RowID;
 }
Пример #11
0
 public static function Touch($Name, $Value)
 {
     $Model = new Gdn_Model('Pocket');
     $Pockets = $Model->GetWhere(array('Name' => $Name))->ResultArray();
     if (empty($Pockets)) {
         $Pocket = array('Name' => $Name, 'Location' => 'Content', 'Sort' => 0, 'Repeat' => Pocket::REPEAT_BEFORE, 'Body' => $Value, 'Format' => 'Raw', 'Disabled' => Pocket::DISABLED, 'MobileOnly' => 0, 'MobileNever' => 0, 'EmbeddedNever' => 0, 'ShowInDashboard' => 0, 'Type' => 'default');
         $Model->Save($Pocket);
     }
 }