Esempio n. 1
0
 /**
  * Adds $this->UpdateUserID and $this->DateUpdated fields to an associative
  * array of fieldname/values if those fields exist on the table being
  * updated.
  *
  * @param array $Fields The array of fields to add the values to.
  */
 protected function AddUpdateFields(&$Fields)
 {
     $this->DefineSchema();
     if ($this->Schema->FieldExists($this->Name, $this->DateUpdated)) {
         if (!isset($Fields[$this->DateUpdated])) {
             $Fields[$this->DateUpdated] = Gdn_Format::ToDateTime();
         }
     }
     $Session = Gdn::Session();
     if ($Session->UserID > 0 && $this->Schema->FieldExists($this->Name, $this->UpdateUserID)) {
         if (!isset($Fields[$this->UpdateUserID])) {
             $Fields[$this->UpdateUserID] = $Session->UserID;
         }
     }
     if ($this->Schema->FieldExists($this->Name, 'UpdateIPAddress') && !isset($Fields['UpdateIPAddress'])) {
         $Fields['UpdateIPAddress'] = Gdn::Request()->IpAddress();
     }
 }
Esempio n. 2
0
 /**
  * Set the schema for this validation.
  *
  * @param Gdn_Schema|array $Schema The new schema to set.
  * @return Gdn_Validation Returns `$this` for fluent calls.
  * @throws \Exception Throws an exception when {@link $Schema} isn't an array or {@link Gdn_Schema} object.
  */
 public function setSchema($Schema)
 {
     if ($Schema instanceof Gdn_Schema) {
         $this->_Schema = $Schema->fields();
     } elseif (is_array($Schema)) {
         $this->_Schema = $Schema;
     } else {
         throw new \Exception('Invalid schema of type ' . gettype($Schema) . '.', 500);
     }
     $this->_SchemaRules = null;
     return $this;
 }
Esempio n. 3
0
 /**
  * Adds $this->UpdateUserID and $this->DateUpdated fields to an associative
  * array of fieldname/values if those fields exist on the table being
  * updated.
  *
  * @param array $Fields The array of fields to add the values to.
  */
 protected function AddUpdateFields(&$Fields)
 {
     $this->DefineSchema();
     if ($this->Schema->FieldExists($this->Name, $this->DateUpdated)) {
         $Fields[$this->DateUpdated] = Gdn_Format::ToDateTime();
     }
     $Session = Gdn::Session();
     if ($Session->UserID > 0 && $this->Schema->FieldExists($this->Name, $this->UpdateUserID)) {
         $Fields[$this->UpdateUserID] = $Session->UserID;
     }
 }