/** * Update one or more fields of table row * * @param string $table * @param string $idField * @param string|integer $rowId * @param string|array $field * @param mixed|null $value * @param string $parentField * @param string|integer $parentId * @return $this * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function updateTableRow($table, $idField, $rowId, $field, $value = null, $parentField = null, $parentId = 0) { $table = $this->getTable($table); if (is_array($field)) { $data = $field; } else { $data = [$field => $value]; } $connection = $this->getConnection(); $where = [$connection->quoteIdentifier($idField) . '=?' => $rowId]; $connection->update($table, $data, $where); if (is_array($field)) { $oldRow = $this->setupCache->has($table, $parentId, $rowId) ? $this->setupCache->get($table, $parentId, $rowId) : []; $newRowData = array_merge($oldRow, $field); $this->setupCache->setRow($table, $parentId, $rowId, $newRowData); } else { $this->setupCache->setField($table, $parentId, $rowId, $field, $value); } return $this; }
/** * @dataProvider hasDataProvider * @param string $table * @param string $parentId * @param string $rowId * @param string $field * @param bool $expected */ public function testHas($table, $parentId, $rowId, $field, $expected) { $this->object->setField('table', 'parent', 'row', 'field', 'data'); $this->assertSame($expected, $this->object->has($table, $parentId, $rowId, $field)); }