ModifierTrait::updateRecordStatusManyBy

@param array $ids
@param array $conditions

@return bool|int
546934
private function updateRecordStatusManyBy($conditions = [], $recordStatus, $method)
    {
        if (count($conditions)) {
            $sets[ 'record_status' ] = $recordStatus;

            if (method_exists($this, 'updateRecordSets')) {
                $this->updateRecordSets($sets);
            }

            if (method_exists($this, $beforeMethod = 'before' . ucfirst($method))) {
                call_user_func_array([&$this, $beforeMethod], [$sets]);
            }

            if ($this->qb->table($this->table)->update($sets, $conditions)) {
                if (method_exists($this, $afterMethod = 'after' . ucfirst($method))) {
                    return call_user_func([&$this, $beforeMethod]);
                }

                return $this->getAffectedRows();
            }
        }

        return false;
    }
1150814
public function update($table, $columns, $condition = [], array $params = [])
    {
        $request = $this->db->getQueryBuilder()->update($table, $columns, $condition, $params);

        return $this->setRequest($request);
    }
772264
public function update($table, array $data, array $conditions, $filter = true)
    {
        if ($filter) {
            $data = $this->filterValues($table, $data);
        }

        if (empty($data)) {
            return 0;
        }

        $farray = array();
        foreach (array_keys($data) as $key) {
            $farray[] = "$key=:$key";
        }

        $carray = array();
        foreach (array_keys($conditions) as $key) {
            $carray[] = "$key=:$key";
        }

        $fields = implode(',', $farray);
        $sql = "UPDATE $table SET $fields WHERE " . implode(' AND ', $carray);

        $stmt = $this->pdo->prepare($sql);

        foreach ($data as $key => $value) {
            $stmt->bindValue(":$key", $value);
        }

        foreach ($conditions as $key => $value) {
            $stmt->bindValue(":$key", $value);
        }

        $stmt->execute();
        $this->executed[] = $sql;
        return $stmt->rowCount();
    }
337749
public function updateMany($filters, $update, $options = [])
    {
        $result = $this->collection->updateMany($this->castQuery($filters), $update, $options);

        if ($result->isAcknowledged()) {
            return true;
        } else {
            return false;
        }
    }
1006783
public function count($conditions = '', $params = array()){
        return $this->db->builder()->select('COUNT(*)')->from($this->table)->where($conditions, $params)->queryValue();
    }
250297
public function updateMany(array $ids = []): self
    {
        foreach ($ids as $id => $callback) {
            $this->update($id, $callback);
        }

        return $this;
    }
193288
public function update($table, array $data, array $conditions)
    {
        $table = $this->getTable($table);
        $set = $this->buildSqlObject($data, ', ');
        $where = $this->buildSqlObject($conditions, ' AND ');

        $query = "UPDATE $table SET $set WHERE $where";
        $params = array_merge(array_values($data), array_values($conditions));
        return $this->executeUpdate($query, $params);
    }
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;
    }
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);
    }
700048
public function deleteMany(array $ids)
    {
        $primaryKey = isset($this->primaryKey) ? $this->primaryKey : 'id';

        if (method_exists($this, 'beforeDelete')) {
            $this->beforeDelete();
        }

        $this->qb->whereIn($primaryKey, $ids);

        if ($this->qb->table($this->table)->delete()) {
            if (method_exists($this, 'afterDelete')) {
                return $this->afterDelete();
            }

            return $this->db->getAffectedRows();
        }

        return false;
    }
1356051
public function where($conditions, array $values){
        if($this->where != ''){$this->where.='AND ';}
        $this->where.= $conditions . ' ';
        $this->where_values = array_merge($this->where_values, $values);
    }
879216
public static function updateByIds($ids, array $record, array $params = [])
    {
        if (!is_array($ids)) {
            $ids = explode(",", $ids);
        }

        $records = [];

        $m = new static;
        $pk = $m->getPrimaryKey();
        foreach ($ids as $id) {
            $record[$pk] = $id;
            $records[] = $record;
        }

        return static::bulkUpdate($records, $params);
    }
1224916
public function update($data, $params, $condition = "id")
	{
		$affected = parent::update($data, $params, $condition);
		$this->recache();
		return $affected;
	}
708975
public function synchronize(array $ids): bool
	{
		$success = true;

		$keys = $this->getJunctionKeys($ids);

		// Fetch existing links

		$existing = $this->junction()->where($this->getForeignKey(), '=', $this->parent->getPrimaryKeyValue())->select([$this->getJunctionKey()])->all()->pluck($this->getJunctionKey());

		// Link new relations

		if(!empty($diff = array_diff($keys, $existing)))
		{
			$success = $success && $this->link($diff);
		}

		// Unlink old relations

		if(!empty($diff = array_diff($existing, $keys)))
		{
			$success = $success && $this->unlink($diff);
		}

		// Return status

		return $success;
	}
142667
public function update(array $values)
    {
        // update timestamps
        $values = $this->addUpdatedAtColumn($values);

        // get version values & values
        $versionValues = $this->getVersionValues($values);
        $values = $this->getValues($values);

        // get records
        $affectedRecords = $this->getAffectedRecords();

        // update main table records
        if (! $this->query->increment($this->model->getLatestVersionColumn(), 1, $values)) {
            return false;
        }

        // update version table records
        $db = $this->model->getConnection();
        foreach ($affectedRecords as $record) {
            // get versioned values from record
            foreach($this->model->getVersionedAttributeNames() as $key) {
                $recordVersionValues[$key] = (isset($versionValues[$key])) ? $versionValues[$key] : $record->{$key};
            }

            // merge versioned values from record and input
            $recordVersionValues = array_merge($recordVersionValues, $versionValues);

            // set version and ref_id
            $recordVersionValues[$this->model->getVersionKeyName()] = $record->{$this->model->getKeyName()};
            $recordVersionValues[$this->model->getVersionColumn()] = $record->{$this->model->getLatestVersionColumn()}+1;

            // insert new version
            if(! $db->table($this->model->getVersionTable())->insert($recordVersionValues)) {
                return false;
            }
        }

        // fill the latest version value
        $this->model->{$this->model->getLatestVersionColumn()} += 1;

        return true;
    }
863350
public function syncCounters($ids) {
        foreach ($this->getCounters() as $alias => $counter) {
            $relation = $this->getModel()->getRelation($alias);

            switch ($relation->getType()) {
                case Relation::MANY_TO_MANY:
                    $this->_syncManyToMany($relation, $ids, $counter);
                break;
                case Relation::MANY_TO_ONE:
                    $this->_syncManyToOne($relation, $ids, $counter);
                break;
            }
        }

        // Reset cache for this sync
        $this->flushCache();

        return $this;
    }
67892
public function sync($ids, $detaching = true)
    {
        $changes = [
            'attached' => [],
            'detached' => [],
            'updated'  => [],
        ];

        $pk = $this->parent->getPk();

        $current = $this->pivot
            ->where($this->localKey, $this->parent->$pk)
            ->column($this->foreignKey);

        $records = [];

        foreach ($ids as $key => $value) {
            if (!is_array($value)) {
                $records[$value] = [];
            } else {
                $records[$key] = $value;
            }
        }

        $detach = array_diff($current, array_keys($records));

        if ($detaching && count($detach) > 0) {
            $this->detach($detach);
            $changes['detached'] = $detach;
        }

        foreach ($records as $id => $attributes) {
            if (!in_array($id, $current)) {
                $this->attach($id, $attributes);
                $changes['attached'][] = $id;
            } elseif (count($attributes) > 0 && $this->attach($id, $attributes)) {
                $changes['updated'][] = $id;
            }
        }

        return $changes;
    }