public function testPickItems() { $items = ['name' => 'Jim', 'age' => 79, 'sex' => 'M', 'country' => 'N/A']; $this->assertEquals(count(ArrayUtils::pick($items, ['name', 'age'])), 2); $this->assertEquals(count(ArrayUtils::pick($items, ['name', 'age', 'city'])), 2); $this->assertEquals(ArrayUtils::pick($items, 'name'), ['name' => 'Jim']); $this->assertEquals(count(ArrayUtils::filterByKey($items, ['name', 'age'])), 2); $this->assertEquals(count(ArrayUtils::filterByKey($items, ['name', 'age', 'city'])), 2); $this->assertEquals(ArrayUtils::filterByKey($items, 'name'), ['name' => 'Jim']); $this->assertEquals(count(ArrayUtils::filterByKey($items, ['name', 'age'], false)), 2); $this->assertEquals(count(ArrayUtils::filterByKey($items, ['name', 'age', 'city'], false)), 2); $this->assertEquals(ArrayUtils::filterByKey($items, 'name'), ['name' => 'Jim'], false); }
public function setValues($collection, $data) { $whiteList = array('files' => array('file_naming', 'thumbnail_quality', 'thumbnail_crop_enabled', 'youtube_api_key'), 'global' => array('project_name', 'project_url', 'cms_color', 'cms_user_auto_sign_out', 'rows_per_page', 'cms_thumbnail_url')); if ($collection !== 'files' && $collection !== 'global') { throw new \Exception("The settings collection {$collection} is not supported"); } $data = ArrayUtils::pick($data, $whiteList[$collection]); foreach ($data as $key => $value) { $parameters[] = '(' . $this->adapter->platform->quoteValue($collection) . ',' . $this->adapter->platform->quoteValue($key) . ',' . $this->adapter->platform->quoteValue($value) . ')'; } $sql = 'INSERT INTO directus_settings (`collection`, `name`, `value`) VALUES ' . implode(',', $parameters) . ' ' . 'ON DUPLICATE KEY UPDATE `collection` = VALUES(collection), `name` = VALUES(name), `value` = VALUES(value)'; $query = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE); }
public static function createConfigFileContent($data) { $configStub = file_get_contents(__DIR__ . '/stubs/config.stub'); $data = ArrayUtils::pick($data, ['db_type', 'db_host', 'db_port', 'db_name', 'db_user', 'db_password', 'directus_path']); return static::replacePlaceholderValues($configStub, $data); }
/** * Get all Directus core tables name * * @param array $filterNames * @return array */ public static function getDirectusTables(array $filterNames = []) { $tables = static::$directusTables; if ($filterNames) { $tables = ArrayUtils::pick($tables, $filterNames); } return static::addCoreTablePrefix($tables); }
unset($requestPayload['type']); // Add table name to dataset. @TODO more clarification would be useful // Also This would return an Error because of $row not always would be an array. if ($requestPayload) { foreach ($requestPayload as &$row) { if (is_array($row)) { $row['table_name'] = $table; } } } if ($app->request()->isPut()) { $TableGateway = new TableGateway($acl, 'directus_columns', $ZendDb); $columnData = $TableGateway->select(['table_name' => $table, 'column_name' => $column])->current(); if ($columnData) { $columnData = $columnData->toArray(); $requestPayload = ArrayUtils::pick($requestPayload, ['data_type', 'ui', 'hidden_input', 'hidden_list', 'required', 'relationship_type', 'related_table', 'junction_table', 'junction_key_left', 'junction_key_right', 'sort', 'comment']); $requestPayload['id'] = $columnData['id']; $TableGateway->updateCollection($requestPayload); } } $response = TableSchema::getSchemaArray($table, $params); if (!$response) { $response = ['message' => __t('unable_to_find_column_x', ['column' => $column]), 'success' => false]; } JsonView::render($response); })->via('GET', 'PUT', 'DELETE'); $app->post("/{$v}/tables/:table/columns/:column/?", function ($table, $column) use($ZendDb, $acl, $requestPayload, $app) { $TableGateway = new TableGateway($acl, 'directus_columns', $ZendDb); $data = $requestPayload; // @TODO: check whether this condition is still needed if (isset($data['type'])) {