Checks if the row is a valid \DBScribe\Row row
@param array|object $row
@param boolean $preSave Indicates whether to call the presave function of the row
@throws Exception
@return array|boolean
511046
private function checkModel($row, $preSave = false) {
        if (!is_array($row) && !is_object($row))
                throw new Exception('Each element of param $where must be an object of, or one that extends, "DBScribe\Row", or an array of [column => value]: ' . print_r($row,
                    true));

        if (empty($this->columns)) return array();

        if (is_array($row)) {
            return $row;
        }
        elseif (is_object($row) && get_class($row) === 'DBScribe\Row' || in_array('DBScribe\Row',
                        class_parents($row))) {
            if ($preSave) $row->preSave();

            $this->rowModelInUse = $row;
            return $row->toArray(($this->current !== self::OP_SELECT));
        }
    }
99998
public function beforeSave($insert)
    {
        if(parent::beforeSave($insert))
        {
            if($this->isNewRecord)
            {
                $this->created_at = time();
            }
            return true;
        }
        else
            return false;
    }
1206445
public function commit()
    {
        try {
            $prepared = Agl::app()->getDb()->getConnection()->prepare("
                INSERT INTO
                    `" . $this->getDbPrefix() . $this->_dbContainer . "`
                (" . $this->_getFields() . ")
                VALUES
                (" . $this->_getPreparedFields() . ")
            ");

            if (! $prepared->execute($this->_fields)) {
                $error = $prepared->errorInfo();
                throw new Exception("The insert query failed (table '" . $this->getDbPrefix() . $this->_dbContainer . "') with message '" . $error[2] . "'");
            }

            if (Agl::app()->isDebugMode()) {
                Agl::app()->getDb()->incrementCounter();
            }

            $this->_setId(Agl::app()->getDb()->getConnection()->lastInsertId());

            return $prepared->rowCount();
        } catch (Exception $e) {
            throw new Exception($e);
        }

        return true;
    }
57717
function Set(&$row)
	{
	global $ACTIVE_RECORD_SAFETY;

		$db = $this->DB();

		if (!$row) {
			$this->_saved = false;
			return false;
		}

		$this->_saved = true;

		$table = $this->TableInfo();
		if ($ACTIVE_RECORD_SAFETY && sizeof($table->flds) != sizeof($row)) {
			# <AP>
			$bad_size = TRUE;
			if (sizeof($row) == 2 * sizeof($table->flds)) {
				// Only keep string keys
				$keys = array_filter(array_keys($row), 'is_string');
				if (sizeof($keys) == sizeof($table->flds)) {
					$bad_size = FALSE;
				}
			}
			if ($bad_size) {
			$this->Error("Table structure of $this->_table has changed","Load");
			return false;
		}
			# </AP>
		}
		else
			$keys = array_keys($row);

		# <AP>
		reset($keys);
		$this->_original = array();
		foreach($table->flds as $name=>$fld) {
			$value = $row[current($keys)];
			$this->$name = $value;
			$this->_original[] = $value;
			next($keys);
		}

		# </AP>
		return true;
	}
276894
public function preSave(Event $event, Query $query, $id, array &$data) {
        $repo = $this->getRepository();
        $converters = $this->getConverters();

        foreach ($data as $key => $value) {
            if (empty($converters[$key])) {
                continue;
            }

            $converter = $converters[$key];

            // Exit if encoding should not happen
            if (!$converter['encode']) {
                continue;
            }

            switch ($converter['type']) {
                case self::SERIALIZE:   $value = $this->toSerialize($value, $converter); break;
                case self::JSON:        $value = $this->toJson($value, $converter); break;
                case self::BASE64:      $value = $this->toBase64($value, $converter); break;
                case self::CUSTOM:
                    if (method_exists($repo, $converter['encode'])) {
                        $value = call_user_func_array([$repo, $converter['encode']], [$value, $converter]);
                    }
                break;
            }

            $data[$key] = $value;
        }

        return true;
    }
302246
public function beforeSave($insert)
    {
        if (parent::beforeSave($insert)) {
            $attachments = upload_img('WarehouseVoucher[attachments]', true);
            if (!empty($attachments)) {
                $this->attachments = json_encode($attachments);
            } elseif (empty($attachments) && !$this->isNewRecord) {
                $model = static::findOne(['id' => $this->id]);
                if ($model) {
                    $this->attachments = $model->attachments;
                }
            }

            if (!$this->isNewRecord) {
                $this->total_price = WarehouseVoucherItems::find()
                    ->where(['warehouse_voucher' => $this->id])
                    ->sum('total_price');
            }

            return true;
        }

        return false;
    }
1289345
public function preSave(Event $event, Query $query, $id, array &$data) {
        $data[$this->getConfig($query->getType() === Query::UPDATE ? 'updateField' : 'createField')] = time();

        return true;
    }
925740
protected function validateRow(array $row)
    {
        foreach ($row as $k => $v)
        {
            if (WF::is_array_like($v))
                throw new InvalidArgumentException("CSVWriter does not support nested arrays");
        }
    }
933848
public function addRow($row)
    {
        if ($row instanceof TableSeparator) {
            $this->rowsCopy[] = $row;

            return parent::addRow($row);
        }

        if (!is_array($row)) {
            throw new \InvalidArgumentException('A row must be an array or a TableSeparator instance.');
        }

        $this->rowsCopy[] = array_values($row);

        return parent::addRow($row);
    }
759877
public function castRow($row)
    {
        $outRow = [];
        $validationErrors = [];
        foreach ($this->fields() as $fieldName => $field) {
            $value = array_key_exists($fieldName, $row) ? $row[$fieldName] : null;
            if (in_array($value, $this->missingValues())) {
                $value = null;
            }
            try {
                $outRow[$fieldName] = $field->castValue($value);
            } catch (Exceptions\FieldValidationException $e) {
                $validationErrors = array_merge($validationErrors, $e->validationErrors);
            }
        }
        if (count($validationErrors) > 0) {
            throw new Exceptions\FieldValidationException($validationErrors);
        }

        return $outRow;
    }
1112692
protected function isAllHeadingValuesPresentInRow(?array $row){

        if (true === empty($row)) {
            return false;
        }

        foreach($this->targettedHeadingValues as $headerValue){

            if (false === in_array(trim($headerValue), $row)) {
                //print($headerValue . ' not in ' . print_r($row,true));
                return false;
            }

        }

        return true;
    }
630417
protected function filterColumns ($row, $stripPrimary = true)
		{
			$columns = $this->database->getFields($this->table);

			if ($stripPrimary) {
				$columns = array_filter($columns, function ($column) {
					if ($this->database->primaryKey($this->table) == $column) {
						return false;
					} else {
						return true;
					}
				});
			}

			return array_intersect_key($row, array_flip($columns));
		}
1300100
public function beforeSave($insert)
    {
        if (!parent::beforeSave($insert)) {
            return false;
        }

        $this->setAttribute(static::dynamicColumn(), static::dynColExpression($this->_dynamicAttributes));

        return true;
    }
1097863
public function preSave(Event $event, Query $query, $id, array &$data) {
        $filters = $this->getFilters();

        foreach ($data as $key => $value) {
            if (empty($filters[$key])) {
                continue;
            }

            $filter = $filters[$key];

            // HTML escape
            if (isset($filter['html'])) {
                $value = Sanitize::html($value, $filter['html']);
            }

            // Newlines
            if (isset($filter['newlines'])) {
                $value = Sanitize::newlines($value, $filter['newlines']);
            }

            // Whitespace
            if (isset($filter['whitespace'])) {
                $value = Sanitize::whitespace($value, $filter['whitespace']);
            }

            // XSS
            if (isset($filter['xss'])) {
                $value = Sanitize::xss($value, $filter['xss']);
            }

            $data[$key] = $value;
        }

        return true;
    }
32056
private function passesFilter(array $row)
    {
        foreach ($row as $name => $value) {
            if (isset($this->rules[$name])) {
                // check all rules for a given attribute
                foreach ($this->rules[$name] as $rule) {
                    /* @var $rule MatcherInterface */
                    if (!$rule->match($value)) {
                        return false;
                    }
                }
            }
        }

        return true;
    }
274421
public function save($validate = true)
	{
		if ($this->frozen())
		{
			throw new \Exception('Cannot modify a frozen row.');
		}

		$vars = $this->_data;

		// Set default if there are any
		isset(static::$_defaults) and $vars = $vars + static::$_defaults;

		if ($validate and isset(static::$_rules) and ! empty(static::$_rules))
		{
			$vars = $this->pre_validate($vars);
			$validated = $this->post_validate($this->run_validation($vars));

			if ($validated)
			{
				$validated = array_filter($this->validation()->validated(), function($val){
					return ($val !== null);
				});

				$vars = $validated + $vars;
			}
			else
			{
				return false;
			}
		}

		$vars = $this->prep_values($vars);

		if (isset(static::$_properties))
		{
			$vars = \Arr::filter_keys($vars, static::$_properties);
		}

		if(isset(static::$_updated_at))
		{
			if(isset(static::$_mysql_timestamp) and static::$_mysql_timestamp === true)
			{
				$vars[static::$_updated_at] = \Date::forge()->format('mysql');
			}
			else
			{
				$vars[static::$_updated_at] = \Date::forge()->get_timestamp();
			}
		}

		if ($this->is_new())
		{
			if(isset(static::$_created_at))
			{
				if(isset(static::$_mysql_timestamp) and static::$_mysql_timestamp === true)
				{
					$vars[static::$_created_at] = \Date::forge()->format('mysql');
				}
				else
				{
					$vars[static::$_created_at] = \Date::forge()->get_timestamp();
				}
			}

			$query = \DB::insert(static::$_table_name)
			            ->set($vars);

			$this->pre_save($query);
			$result = $query->execute(static::get_connection(true));

			if ($result[1] > 0)
			{
				// workaround for PDO connections not returning the insert_id
				if ($result[0] === false and isset($vars[static::primary_key()]))
				{
					$result[0] = $vars[static::primary_key()];
				}
				$this->set($vars);
				empty($result[0]) or $this->{static::primary_key()} = $result[0];
				$this->is_new(false);
			}

			return $this->post_save($result);
		}

		$query = \DB::update(static::$_table_name)
		         ->set($vars)
		         ->where(static::primary_key(), '=', $this->{static::primary_key()});

		$this->pre_update($query);
		$result = $query->execute(static::get_connection(true));
		$result > 0 and $this->set($vars);

		return $this->post_update($result);
	}
95154
public function rowSave($id, $data)
    {
        if (!$data || !is_array($data)) return false;

        if (is_null($id)) {
            $row = $this->getModel()->createRow();
        } else {
            $row = $this->getModel()->getRow($id);
        }

        if (!$row) return false;

        foreach ($data as $col => $value) {
            $row->$col = $value;
        }
        $row->save();

        if ($this->_columns) {
            $ret = array();
            foreach ($this->_columns as $c) {
                $ret[$c] = $row->$c;
            }
            return $ret;
        } else {
            return $row->toArray();
        }
    }