modify boolean field value 0/1, can be one or more id

@param  string $field
@param  mixed  $ids int or array
@return \Wslim\Common\ErrorInfo
770138
public function modifyBooleanField($field, $ids, $status=null)
    {
        $ids = !is_numeric($ids) ? StringHelper::toIntArray($ids) : [$ids];
        
        $ret = 0;
        if ($ids) {
            if (is_null($status)) {
                $set = "{$field} = ({$field} + 1) % 2";
            } else {
                $set = "{$field} = " . intval($status);
            }
            
            $query = $this->getQuery();
            
            if (isset($query['table'])) {
                $pk = $this->getPrimaryKey($query['table'][0]);
            } else {
                $pk = $this->getPrimaryKey();
            }
            
            if (!isset($pk)) {
                throw new Exception('Can\'t get primary key of table:' . $this->getTableName());
            }
            
            $ret = $this->formatted(true)->set($set)->where([$pk => ['in', $ids]])->modify();
        }
        
        return ErrorInfo::instance($ret);
    }
1342885
private function addIdPrefix($fields, $idPrefix)
    {
        $result = array();
        foreach ($fields as $key => $field) {
            $newKey = $idPrefix . $key;
            $result[$newKey] = $field;
            if (isset($field['fields'])) {
                $result[$newKey]['fields'] = $this->addIdPrefix($field['fields'], $newKey . '_');
            }
        }
        return $result;
    }
292352
protected function forbidAbilitiesToEveryone(array $ids)
    {
        $attributes = Models::scope()->getAttachAttributes() + ['forbidden' => true];

        $records = array_map(function ($id) use ($attributes) {
            return ['ability_id' => $id] + $attributes;
        }, $ids);

        Models::query('permissions')->insert($records);
    }
1050529
final public function sqlIsNull(string $field, bool $positive = true): string
    {
        if (! $positive) {
            trigger_error(
                __METHOD__ . ' with argument $positive = false is deprecated, use DBAL::sqlIsNotNull',
                E_USER_NOTICE
            );
            return $this->sqlIsNotNull($field);
        }
        return $field . ' IS NULL';
    }
534421
public function insert(array $fields = [])
    {
        $connection = $this->getConnection();

        $this->beforeInsertInternal();

        $connection->beginTransaction();
        try {
            if (($inserted = $this->insertInternal($fields))) {
                $connection->commit();
            } else {
                $connection->rollBack();
            }
        } catch (\Exception $e) {
            $connection->rollBack();
            throw $e;
        }

        $this->afterInsertInternal();

        if ($inserted) {
            $this->setIsNewRecord(false);
            $this->updateRelated();
            $this->attributes->resetOldAttributes();
        }

        return $inserted;
    }
493121
public function deleteFields(array $fields)
    {
        $fields = Validate::arrToLower($fields);
        if (($key = array_search($this->databaseConfig->getIdentifier(), $fields)) !== false)
            throw new \Exception('You can not delete the id field');
        $diff   = array_diff($fields,$this->fields());
        if (!empty($diff))
            throw new \Exception('Field(s) "' . implode(', ', $diff) . '" does not exists in table');
        $config         = $this->getConfig();
        $config->schema = array_diff_key($this->schema(), array_flip($fields));
        $data = $this->getData();
        foreach ($data as $key => $object)
        {
            foreach ($fields as $name)
                unset($data[$key]->{$name});
        }
        $this->databaseDocument->put($data);
        $this->databaseConfig->put($config);
        return true;
    }
1259248
protected function sqlinsert(array $fields, array $nums = null, array $bools = null) {
		$db = $this->db;

		$nums != null or $nums = [];
		$bools != null or $bools = [];

		$keys = array_keys($fields);
		$strs = array_diff($keys, $bools, $nums);

		$key_fields = \hlin\Arr::join(', ', $keys, function ($_, $val) {
			return "`$val`";
		});

		$value_fields = \hlin\Arr::join(', ', $keys, function ($_, $val) {
			return ":$val ";
		});

		$db->prepare
			(
				"	INSERT INTO `[table]`
						   ($key_fields)
					VALUES ($value_fields)
				",
				[ 'table' => $this->constants()['table'] ]
			)
			->strs($fields, $strs)
			->bools($fields, $bools)
			->nums($fields, $nums)
			->execute();

		return $db->lastInsertId();
	}
437573
public function update($ids)
    {
        if (empty($ids)) {
            return false;
        } elseif (empty($this->_ids)) {
            $this->_ids = $ids;
            $change = true;
        } else {
            $change = false;
            foreach ($ids as $k => $v) {
                if (!isset($this->_ids[$k]) || ($this->_ids[$k] != $v)) {
                    $this->_ids[$k] = $v;
                    $change = true;
                }
            }
        }

        if ($change) {
            $this->_sorted = false;
        }

        return $change;
    }
1306410
public function addField($field, $defaults = [])
    {
        // compatibility: for field types
        $class = $this->_default_seed_addField;
        if (is_array($defaults) && isset($defaults['type'])) {
            switch (strtolower($defaults['type'])) {
                case 'boolean':
                    $class = 'Boolean';
                    break;
            }
        }

        $field_object = $this->factory($this->mergeSeeds($defaults, $class), null, '\atk4\data\Field');
        $this->add($field_object, $field);

        return $field_object;
    }
631649
public function in($field, $values) {
		// Transform $values to an array if needed
		if ( false == is_array( $values ) )
			$values = array($values);

		// Translate ids into MongoIds if needed
		if ( 'id' == $field ):
			$field = '_id';
			$values = array_map(function($value) {
				return ( $value instanceof \MongoId ) ? $value : new \MongoId($value);
			}, $values);
		endif;
		
		// Add operator to the query
		return $this->addOperator('in', $field, $values);
	}
1059260
public function ensure2dIndex($field)
    {
        if (is_array($field)) {
            $keys = array_fill_keys($field, '2d');
        } else {
            $keys = array(
                $field => '2d',
            );
        }

        $this->getMongoCollection()->createIndex($keys);

        return $this;
    }
345689
function delete($ids, $force = true)
    {
        if (!is_array($ids)) {
            $ids = explode(self::SEPARATOR, $ids);
        }

        $ids = $this->db->array2list($ids, 'integer');

        // flag record as deleted (always)
        $this->db->query(
            "UPDATE " . $this->db->table_name($this->db_name, true).
            " SET `del` = 1, `changed` = ".$this->db->now().
            " WHERE `user_id` = ?".
                " AND `contact_id` IN ($ids)",
            $this->user_id
        );

        $this->cache = null;

        return $this->db->affected_rows();
    }
1324618
protected function updateInternal(array $fields = [])
    {
        $values = $this->getChangedAttributes($fields);
        if (empty($values)) {
            return true;
        }

        $rows = $this->objects()
            ->filter($this->getPrimaryKeyValues())
            ->update($values);

        foreach ($values as $name => $value) {
            $this->setAttribute($name, $value);
        }
        $this->updateRelated();

        return $rows >= 0;
    }
275184
public function delete($ids) {
		if (URequest::isAjax ()) {
			$instance = $this->getModelInstance ( $ids );
			$instanceString = $this->getInstanceToString ( $instance );
			if (sizeof ( $_POST ) > 0) {
				try {
					if (DAO::remove ( $instance )) {
						$message = new CRUDMessage ( "Deletion of `<b>" . $instanceString . "</b>`", "Deletion", "info", "info circle", 4000 );
						$message = $this->_getEvents ()->onSuccessDeleteMessage ( $message, $instance );
						$this->jquery->exec ( "$('._element[data-ajax={$ids}]').remove();", true );
					} else {
						$message = new CRUDMessage ( "Can not delete `" . $instanceString . "`", "Deletion", "warning", "warning circle" );
						$message = $this->_getEvents ()->onErrorDeleteMessage ( $message, $instance );
					}
				} catch ( \Exception $e ) {
					$message = new CRUDMessage ( "Exception : can not delete `" . $instanceString . "`", "Exception", "warning", "warning" );
					$message = $this->_getEvents ()->onErrorDeleteMessage ( $message, $instance );
				}
				$message = $this->_showSimpleMessage ( $message );
			} else {
				$message = new CRUDMessage ( "Do you confirm the deletion of `<b>" . $instanceString . "</b>`?", "Remove confirmation", "error", "question circle" );
				$message = $this->_getEvents ()->onConfDeleteMessage ( $message, $instance );
				$message = $this->_showConfMessage ( $message, $this->_getBaseRoute () . "/delete/{$ids}", "#table-messages", $ids );
			}
			echo $message;
			echo $this->jquery->compile ( $this->view );
		} else {
			$this->jquery->execAtLast ( "$('._delete[data-ajax={$ids}]').trigger('click');" );
			$this->index ();
		}
	}
108689
public function fields(array $fields)
    {
        foreach ($fields as $field => &$value) {
            $value = $value ? 1 : -1;
        }

        $this->fields = array_merge($this->fields, $fields);

        return $this;
    }
413748
public function update($id, $fields)
    {
        $fields = $this->makeJsonReady($fields);
        return $this->put('users/users/'.rawurlencode($id), $fields);
    }
103704
public function updateEventTypeById($id, $fields) {
        $event = new \CEventType();
        if ($event->Update(array('ID' => $id), $fields)) {
            return $id;
        }

        $this->throwException(__METHOD__, 'event type not updated');
    }