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; }