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; }
public function Save($PostValues, $PreviousValues = False) { ReplaceEmpty($PostValues, Null); $RowID = GetValue($this->PrimaryKey, $PostValues); $Insert = $RowID === False; $URI = GetValue('URI', $PostValues, Null); if ($URI !== Null) { $this->Validation->ApplyRule('URI', 'UrlPath'); } if ($Insert && !$this->CheckUniqueURI($URI)) { $this->Validation->AddValidationResult('URI', '%s: Already exists.'); } if (GetValue('ParentID', $PostValues) === Null) { SetValue('ParentID', $PostValues, 1); } if (array_key_exists('Mask', $PostValues)) { $PostValues['Mask'] = self::CalculateMask($PostValues['Mask']); } $this->DefineSchema(); $this->AddUpdateFields($PostValues); if ($Insert) { $this->AddInsertFields($PostValues); } if ($this->Validate($PostValues, $Insert) === True) { $Fields = $this->Validation->SchemaValidationFields(); if ($Insert) { $ParentID = GetValue('ParentID', $PostValues); $RowID = parent::InsertNode($ParentID, $Fields); if (!$RowID) { $this->Validation->AddValidationResult('RowID', '%s: InsertNode operation failed.'); } } else { $this->Update($Fields, array('SectionID' => $RowID)); } if (count($this->Validation->Results()) == 0) { CandyModel::SaveRoute($PostValues); } } else { $RowID = False; } return $RowID; }