예제 #1
0
 /**
  * Fetch related, foreign rows for one record's ManyToMany relationships.
  * @param  string $table_name
  * @param  string $foreign_table
  * @param  string $junction_table
  * @param  string $junction_key_left
  * @param  string $junction_key_right
  * @param  string $column_equals
  * @return array                      Foreign rowset
  */
 public function loadManyToManyRelationships($table_name, $foreign_table, $junction_table, $junction_key_left, $junction_key_right, $column_equals)
 {
     $foreign_table_pk = TableSchema::getTablePrimaryKey($foreign_table);
     $foreign_join_column = "{$foreign_table}.{$foreign_table_pk}";
     $junction_join_column = "{$junction_table}.{$junction_key_right}";
     $junction_comparison_column = "{$junction_table}.{$junction_key_left}";
     $junction_table_pk = TableSchema::getTablePrimaryKey($junction_table);
     $junction_id_column = "{$junction_table}." . $junction_table_pk;
     // Less likely name collision:
     $junction_id_column_alias = "directus_junction_id_column_518d31856e131";
     $junction_sort_column_alias = "directus_junction_sort_column_518d318e3f0f5";
     $junctionSelectColumns = array($junction_id_column_alias => $junction_table_pk);
     $sql = new Sql($this->adapter);
     $select = $sql->select();
     // If the Junction Table has a Sort column, do eet.
     // @todo is this the most efficient way?
     // @hint TableSchema#getUniqueColumnName
     $junctionColumns = TableSchema::getAllNonAliasTableColumnNames($junction_table);
     if (in_array('sort', $junctionColumns)) {
         $junctionSelectColumns[$junction_sort_column_alias] = "sort";
         $select->order($junction_sort_column_alias);
     }
     $select->from($foreign_table)->join($junction_table, "{$foreign_join_column} = {$junction_join_column}", $junctionSelectColumns)->where(array($junction_comparison_column => $column_equals))->order("{$junction_id_column} ASC");
     // Only select the fields not on the currently authenticated user group's read field blacklist
     $columns = TableSchema::getAllNonAliasTableColumnNames($foreign_table);
     $select->columns($columns);
     $ForeignTable = new RelationalTableGateway($this->acl, $foreign_table, $this->adapter);
     $results = $ForeignTable->selectWith($select);
     $results = $results->toArray();
     $foreign_data = array();
     $columns = TableSchema::getAllNonAliasTableColumns($foreign_table);
     foreach ($results as $row) {
         $row = $this->parseRecordValuesByMysqlType($row, $columns);
         $junction_table_id = (int) $row[$junction_id_column_alias];
         unset($row[$junction_id_column_alias]);
         $entry = array($junction_table_pk => $junction_table_id);
         if (in_array('sort', $junctionColumns)) {
             // @TODO: check why is this a string instead of an integer.
             $entry['sort'] = (int) $row[$junction_sort_column_alias];
             unset($row[$junction_sort_column_alias]);
         }
         $entry['data'] = $row;
         $foreign_data[] = $entry;
     }
     return array('rows' => $foreign_data);
 }
예제 #2
0
            $get_new = $GroupsTableGateway->getEntries();
            $outputData = $get_new;
    }
    JsonView::render($outputData);
})->via('GET', 'POST');
$app->get("/{$v}/groups/:id/?", function ($id = null) use($ZendDb, $acl) {
    // @TODO need POST and PUT
    // Hardcoding ID temporarily
    is_null($id) ? $id = 1 : null;
    $tableName = 'directus_groups';
    $Groups = new TableGateway($acl, $tableName, $ZendDb);
    $response = $Groups->find($id);
    if (!$response) {
        $response = ['message' => __t('unable_to_find_group_with_id_x', ['id' => $id]), 'success' => false];
    }
    $columns = TableSchema::getAllNonAliasTableColumns($tableName);
    $response = SchemaManager::parseRecordValuesByType($response, $columns);
    JsonView::render($response);
});
/**
 * FILES COLLECTION
 */
$app->map("/{$v}/files(/:id)/?", function ($id = null) use($app, $ZendDb, $acl, $params, $requestPayload) {
    if (!is_null($id)) {
        $params['id'] = $id;
    }
    $table = 'directus_files';
    $currentUser = Auth::getUserInfo();
    $TableGateway = new TableGateway($acl, $table, $ZendDb);
    $activityLoggingEnabled = !(isset($_GET['skip_activity_log']) && 1 == $_GET['skip_activity_log']);
    $activityMode = $activityLoggingEnabled ? TableGateway::ACTIVITY_ENTRY_MODE_PARENT : TableGateway::ACTIVITY_ENTRY_MODE_DISABLED;
 /**
  * Fetch related, foreign rows for one record's ManyToMany relationships.
  *
  * @param  string $table_name
  * @param  string $foreign_table
  * @param  string $junction_table
  * @param  string $junction_key_left
  * @param  string $junction_key_right
  * @param  string $column_equals
  * @param  string $parentField
  * @param  int    $level
  *
  * @return array                      Foreign rowset
  */
 public function loadManyToManyRelationships($table_name, $foreign_table, $junction_table, $junction_key_left, $junction_key_right, $column_equals, $parentField = null, $level = 0)
 {
     $foreign_table_pk = TableSchema::getTablePrimaryKey($foreign_table);
     $foreign_join_column = $foreign_table . '.' . $foreign_table_pk;
     $junction_join_column = $junction_table . '.' . $junction_key_right;
     $junction_comparison_column = $junction_table . '.' . $junction_key_left;
     // =============================================================================
     // HOTFIX: prevent infinite circle loop
     // =============================================================================
     if ($parentField && $this->hasToManyCallStack($parentField, $foreign_table)) {
         return $column_equals;
     }
     if ($parentField !== null) {
         $this->addToManyCallStack($level, $parentField, $foreign_table);
     }
     $junction_table_pk = TableSchema::getTablePrimaryKey($junction_table);
     $junction_id_column = $junction_table . '.' . $junction_table_pk;
     // Less likely name collision:
     $junction_id_column_alias = 'directus_junction_id_column_518d31856e131';
     $junction_sort_column_alias = 'directus_junction_sort_column_518d318e3f0f5';
     $junctionSelectColumns = [$junction_id_column_alias => $junction_table_pk];
     $sql = new Sql($this->adapter);
     $select = $sql->select();
     // If the Junction Table has a Sort column, do eet.
     // @todo is this the most efficient way?
     // @hint TableSchema#getUniqueColumnName
     $junctionColumns = TableSchema::getAllNonAliasTableColumnNames($junction_table);
     if (in_array('sort', $junctionColumns)) {
         $junctionSelectColumns[$junction_sort_column_alias] = 'sort';
         $select->order($junction_sort_column_alias);
     }
     $select->from($foreign_table)->join($junction_table, $foreign_join_column . '=' . $junction_join_column, $junctionSelectColumns)->where([$junction_comparison_column => $column_equals])->order($junction_id_column . ' ASC');
     // Only select the fields not on the currently authenticated user group's read field blacklist
     $columns = TableSchema::getAllNonAliasTableColumnNames($foreign_table);
     $select->columns($columns);
     $ForeignTable = new RelationalTableGateway($this->acl, $foreign_table, $this->adapter);
     $results = $ForeignTable->selectWith($select);
     $results = $results->toArray();
     $foreign_data = [];
     $columns = TableSchema::getAllNonAliasTableColumns($foreign_table);
     foreach ($results as $row) {
         $row = $recordData = SchemaManager::parseRecordValuesByType($row, $columns);
         $junction_table_id = (int) $row[$junction_id_column_alias];
         unset($row[$junction_id_column_alias]);
         $entry = [$junction_table_pk => $junction_table_id];
         if (in_array('sort', $junctionColumns)) {
             // @TODO: check why is this a string instead of an integer.
             $entry['sort'] = (int) $row[$junction_sort_column_alias];
             unset($row[$junction_sort_column_alias]);
         }
         $schemaArray = TableSchema::getSchemaArray($foreign_table);
         $alias_fields = $this->filterSchemaAliasFields($schemaArray);
         // (fmrly $alias_schema)
         $row = $this->loadToManyRelationships($row, $alias_fields, $parentField, $level + 1);
         $entry['data'] = $row;
         $foreign_data[] = $entry;
     }
     return ['rows' => $foreign_data];
 }
예제 #4
0
 protected function parseRecord($records, $tableName = null)
 {
     if (is_array($records)) {
         $tableName = $tableName === null ? $this->table : $tableName;
         $records = $this->parseRecordValuesByType($records, $tableName);
         $columns = TableSchema::getAllNonAliasTableColumns($tableName);
         $records = $this->convertDates($records, $columns, $tableName);
     }
     return $records;
 }