PHP Class Bolt\Legacy\Storage

Deprecation: Deprecated since 3.0, to be removed in 4.0.
Show file Open project: bolt/bolt Class Usage Examples

Public Properties

Property Type Description
$images array

Public Methods

Method Description
__construct ( Silex\Application $app )
deleteContent ( string $contenttype, integer $id ) : integer Delete a record.
depublishExpiredRecords ( )
getContent ( string $textquery, string $parameters = '', array &$pager = [], array $whereparameters = [] ) : array getContent based on a 'human readable query'.
getContentByTaxonomy ( string $taxonomyslug, string $name, string $parameters = [] ) : array Retrieve content from the database, filtered on taxonomy.
getContentObject ( array | string $contenttype, array $values = [] ) : Content Get an object for the content of a specific contenttype. This will be \Bolt\Legacy\Content, unless the contenttype defined another class to be used.
getContentType ( string $contenttypeslug ) : boolean | array Get the contenttype as an array, based on the given $contenttypeslug.
getContentTypeFieldType ( string $contenttypeslug, string $fieldname ) : array Get the fieldtype for a given contenttype and fieldname.
getContentTypeFields ( string $contenttypeslug ) : array Get an array of the available fields for a given contenttype.
getContentTypeGrouping ( string $contenttypeslug ) : mixed Check if a given contenttype has a grouping, and if it does, return it.
getContentTypeTaxonomy ( string $contenttypeslug ) : array Get an array of the available taxonomytypes for a given contenttype.
getContentTypes ( ) : array Get an array of the available contenttypes.
getContenttypeTablename ( string | array $contenttype ) : string Get the tablename with prefix from a given Contenttype.
getEmptyContent ( $contenttypeslug )
getLatestId ( $contenttypeslug )
getPager ( string $name = null ) : array Getter of a pager element. Pager can hold a paging snapshot map.
getRepeaters ( $content )
getSortOrder ( string $name = '-datepublish' ) : string Get sorting order of name, stripping possible " DESC" " ASC" etc., and also return the sorting order.
getTablename ( string $name ) : string Get the table name with prefix from a given $name.
getTaxonomyType ( string $taxonomyslug ) : boolean | array Get the taxonomy as an array, based on the given $taxonomyslug.
getUri ( string $title, integer $id, string $contenttypeslug = "", boolean $fulluri = true, boolean $allowempty = true, boolean $slugfield = 'slug' ) : string Get a unique URL for a record
isEmptyPager ( ) : boolean
preFill ( array $contenttypes = [] ) : string Add some records with dummy content.
publishTimedRecords ( )
saveContent ( Content $content, string $comment = null ) : integer Save a record.
searchAllContentTypes ( array $parameters = [], &$pager = [] )
searchContent ( string $q, array $contenttypes = null, array $filters = null, integer $limit = 9999, integer $offset ) : mixed Search through actual content.
searchContentType ( $contenttypename, array $parameters = [], &$pager = [] )
setPager ( string $name, array | Bolt\Pager $pager ) : Storage Setter for pager storage element.
updateSingleValue ( string $contenttype, integer $id, string $field, mixed $value ) : boolean Update a single value from content.

Protected Methods

Method Description
decodePageParameter ( string $context = '', array $inParameters = null ) : mixed Decodes contextual page number from current request url if found.
executeGetContentQueries ( array $decoded ) : array Execute the content queries.
executeGetContentSearch ( array $decoded, array $parameters ) : array Execute the content queries.
findContent ( string $tablename, integer $contentId ) : array Find record from Content Type and Content Id.
getOrderBys ( $order ) : array Get the ORDER BY parameters for the query.
getRelation ( array $content ) : array Get the relations for one or more units of content, return the array with the taxonomy attached.
getTaxonomy ( Content[] $content ) : array Get the taxonomy for one or more units of content, return the array with the taxonomy attached.
hasRecords ( $tablename )
insertContent ( Content $content, string $comment = null ) : boolean Insert a new contenttype record in the database.
isMultiOrderQuery ( $order ) : boolean Check if this query has multiple ORDER BY parameters.
isNotLastItemInArray ( $totalOrderByElements, $index ) : boolean Check if this is the last element in the array.
tableExists ( $name ) : boolean Check if the table $name exists. We use our own queries here, because it's _much_ faster than Doctrine's getSchemaManager().
updateRelation ( string $contenttype, integer $contentId, array $relation ) Update / insert relation for a given content-unit.
updateTaxonomy ( string $contenttype, integer $contentId, array $taxonomy ) Update / insert taxonomy for a given content-unit.

Private Methods

Method Description
compareSearchWeights ( Content $a, Content $b ) : integer Compare by search weights.
decodeContentQuery ( string $textquery, array $inParameters = null ) : array Decode a content textquery
decodeContentTypesFromText ( string $text ) : array Decode a contenttypes argument from text.
decodeQueryOrder ( array $contenttype, string $orderValue ) : string Get the parameter for the 'order by' part of a query.
decodeSearchQuery ( $q ) Decode search query into searchable parts.
getBlocksTitle ( ) : string Get the title for a 'Block' contenttype. Check if the desired ones aren't present in the database yet, and return them in order.
getEscapedSortorder ( string $name, string $prefix = 'r' ) : string Get an escaped sortorder for use in SQL, from a fieldname like 'title' or '-id'.
getFieldName ( string $name ) : string Get field name, stripping possible " DESC" " ASC" etc.
getSomeRandomTags ( integer $num = 5 ) : string[] Get an array of random tags
getValidSaveData ( array $fieldvalues, array $contenttype ) : array Get a valid array to commit.
groupingSort ( Content $a, Content $b ) : integer Helper function for sorting Records of content that have a Grouping.
hydrateRows ( array | string $contenttype, array $rows, boolean $getTaxoAndRel = true ) : array Hydrate database rows into objects.
isValidColumn ( string $name, array $contenttype, boolean $allowVariants = false ) : boolean Check if a given name is a valid column, and if it can be used in queries.
logDelete ( string $contenttype, integer $contentid, array $content, string $comment = null ) Writes a content-changelog entry for a deleted entry.
logInsert ( string $contenttype, integer $contentid, array $content, string $comment = null ) Writes a content-changelog entry for a newly-created entry.
logUpdate ( string $contenttype, integer $contentid, array $newContent, array $oldContent = null, string $comment = null ) Writes a content-changelog entry for an updated entry.
organizeQueryParameters ( array | string | null $inParameters = null ) : array Split into meta-parameters and contenttype parameters.
parseTextQuery ( $textquery, array &$decoded, array &$metaParameters, array &$ctypeParameters ) Parse textquery into useable arguments.
parseWhereParameter ( string $key, string $value, mixed $fieldtype = false ) : string Helper function to set the proper 'where' parameter, when getting values like '<2012' or '!bob'.
preFillSingle ( string $key, array $contenttype, array $images ) : string Add a record with dummy content.
prepareDecodedQueryForUse ( &$decoded, &$metaParameters, &$ctypeParameters ) Prepare decoded for actual use.
runContentTypeTableChecks ( array $contenttypes ) : boolean Check for the existence of ContentType tables.
searchSingleContentType ( $query, $contenttype, $fields, array $filter = null, boolean $implode = false ) : Content Search through a single contenttype.
updateContent ( Content $content, string $comment = null ) : boolean Update a Bolt contenttype record.

Method Details

__construct() public method

public __construct ( Silex\Application $app )
$app Silex\Application

decodePageParameter() protected method

Decodes contextual page number from current request url if found.
Deprecation: Not used in core anymore
protected decodePageParameter ( string $context = '', array $inParameters = null ) : mixed
$context string Pager id/name in url which value we find
$inParameters array
return mixed Page number in context

deleteContent() public method

Delete a record.
public deleteContent ( string $contenttype, integer $id ) : integer
$contenttype string
$id integer
return integer The number of affected rows.

depublishExpiredRecords() public method

See also: Bolt\Storage\EventProcessor\TimedRecord::holdExpiredRecords()
Deprecation: Deprecated since 3.0, to be removed in 4.0.

executeGetContentQueries() protected method

This is tightly coupled to $this->getContent()
protected executeGetContentQueries ( array $decoded ) : array
$decoded array
return array

executeGetContentSearch() protected method

This is tightly coupled to $this->getContent()
protected executeGetContentSearch ( array $decoded, array $parameters ) : array
$decoded array
$parameters array
return array

findContent() protected method

Find record from Content Type and Content Id.
protected findContent ( string $tablename, integer $contentId ) : array
$tablename string Table name
$contentId integer Content Id
return array

getContent() public method

Used directly by {% setcontent %} but also in other parts. This code has been split into multiple methods in the spirit of separation of concerns, but the situation is still far from ideal. Where applicable each 'concern' notes the coupling in the local documentation.
public getContent ( string $textquery, string $parameters = '', array &$pager = [], array $whereparameters = [] ) : array
$textquery string
$parameters string
$pager array
$whereparameters array
return array

getContentByTaxonomy() public method

Note: we can NOT sort on anything meaningful. Records are fetched from multiple content-types, so we can not do joins. Neither can we sort after fetching, because it would mean fetching _all_ records and _then_ doing the sorting. Instead, we do not sort here. If you need ordering, use the '|order()' in your templates.
public getContentByTaxonomy ( string $taxonomyslug, string $name, string $parameters = [] ) : array
$taxonomyslug string
$name string
$parameters string
return array

getContentObject() public method

Get an object for the content of a specific contenttype. This will be \Bolt\Legacy\Content, unless the contenttype defined another class to be used.
public getContentObject ( array | string $contenttype, array $values = [] ) : Content
$contenttype array | string
$values array
return Content

getContentType() public method

Get the contenttype as an array, based on the given $contenttypeslug.
public getContentType ( string $contenttypeslug ) : boolean | array
$contenttypeslug string
return boolean | array

getContentTypeFieldType() public method

Get the fieldtype for a given contenttype and fieldname.
public getContentTypeFieldType ( string $contenttypeslug, string $fieldname ) : array
$contenttypeslug string
$fieldname string
return array $fields

getContentTypeFields() public method

Get an array of the available fields for a given contenttype.
public getContentTypeFields ( string $contenttypeslug ) : array
$contenttypeslug string
return array $fields

getContentTypeGrouping() public method

Check if a given contenttype has a grouping, and if it does, return it.
public getContentTypeGrouping ( string $contenttypeslug ) : mixed
$contenttypeslug string
return mixed $grouping

getContentTypeTaxonomy() public method

Get an array of the available taxonomytypes for a given contenttype.
public getContentTypeTaxonomy ( string $contenttypeslug ) : array
$contenttypeslug string
return array $taxonomy

getContentTypes() public method

Get an array of the available contenttypes.
public getContentTypes ( ) : array
return array $contenttypes

getContenttypeTablename() public method

Get the tablename with prefix from a given Contenttype.
public getContenttypeTablename ( string | array $contenttype ) : string
$contenttype string | array
return string

getEmptyContent() public method

public getEmptyContent ( $contenttypeslug )

getLatestId() public method

public getLatestId ( $contenttypeslug )

getOrderBys() protected method

Get the ORDER BY parameters for the query.
protected getOrderBys ( $order ) : array
$order
return array

getPager() public method

Getter of a pager element. Pager can hold a paging snapshot map.
Deprecation: Just for keep BC
public getPager ( string $name = null ) : array
$name string Optional name of a pager element. Whole pager map returns if no name given.
return array

getRelation() protected method

Get the relations for one or more units of content, return the array with the taxonomy attached.
protected getRelation ( array $content ) : array
$content array
return array $content

getRepeaters() public method

public getRepeaters ( $content )

getSortOrder() public method

Get sorting order of name, stripping possible " DESC" " ASC" etc., and also return the sorting order.
public getSortOrder ( string $name = '-datepublish' ) : string
$name string
return string

getTablename() public method

Get the table name with prefix from a given $name.
public getTablename ( string $name ) : string
$name string
return string

getTaxonomy() protected method

Get the taxonomy for one or more units of content, return the array with the taxonomy attached.
protected getTaxonomy ( Content[] $content ) : array
$content Content[]
return array $content

getTaxonomyType() public method

Get the taxonomy as an array, based on the given $taxonomyslug.
public getTaxonomyType ( string $taxonomyslug ) : boolean | array
$taxonomyslug string
return boolean | array

getUri() public method

Get a unique URL for a record
public getUri ( string $title, integer $id, string $contenttypeslug = "", boolean $fulluri = true, boolean $allowempty = true, boolean $slugfield = 'slug' ) : string
$title string
$id integer
$contenttypeslug string
$fulluri boolean
$allowempty boolean
$slugfield boolean
return string

hasRecords() protected method

protected hasRecords ( $tablename )

insertContent() protected method

Insert a new contenttype record in the database.
protected insertContent ( Content $content, string $comment = null ) : boolean
$content Content Record content to insert
$comment string Editor's comment
return boolean

isEmptyPager() public method

public isEmptyPager ( ) : boolean
return boolean

isMultiOrderQuery() protected method

Check if this query has multiple ORDER BY parameters.
protected isMultiOrderQuery ( $order ) : boolean
$order
return boolean

isNotLastItemInArray() protected method

Check if this is the last element in the array.
protected isNotLastItemInArray ( $totalOrderByElements, $index ) : boolean
$totalOrderByElements
$index
return boolean

preFill() public method

Only fill the contenttypes passed as parameters If the parameters is empty, only fill empty tables
See also: preFillSingle
public preFill ( array $contenttypes = [] ) : string
$contenttypes array
return string

publishTimedRecords() public method

See also: Bolt\Storage\EventProcessor\TimedRecord::publishTimedRecords()
Deprecation: Deprecated since 3.0, to be removed in 4.0.
public publishTimedRecords ( )

saveContent() public method

Save a record.
public saveContent ( Content $content, string $comment = null ) : integer
$content Content
$comment string
return integer

searchAllContentTypes() public method

public searchAllContentTypes ( array $parameters = [], &$pager = [] )
$parameters array

searchContent() public method

Unless the query is invalid it will always return a 'result array'. It may complain in the log but it won't abort.
public searchContent ( string $q, array $contenttypes = null, array $filters = null, integer $limit = 9999, integer $offset ) : mixed
$q string Search string
$contenttypes array Contenttype names to search for: - string: Specific contenttype - null: Every searchable contenttype
$filters array Additional filters for contenttypes - key is contenttype - value is filter
$limit integer limit the number of results
$offset integer skip this number of results
return mixed false if query is invalid, an array with results if query was executed

searchContentType() public method

public searchContentType ( $contenttypename, array $parameters = [], &$pager = [] )
$parameters array

setPager() public method

Setter for pager storage element.
Deprecation: Just for keep BC
public setPager ( string $name, array | Bolt\Pager $pager ) : Storage
$name string
$pager array | Bolt\Pager
return Storage

tableExists() protected method

Check if the table $name exists. We use our own queries here, because it's _much_ faster than Doctrine's getSchemaManager().
protected tableExists ( $name ) : boolean
$name
return boolean

updateRelation() protected method

$relation looks like: arr(2) [ "pages" => arr(1) [ 0 => str(2) "22" ] "showcases" => arr(3) [ 0 => str(2) "15" 1 => str(1) "9" 2 => str(2) "13" ] ] $currentvalues looks like arr(2) [ 0 => arr(3) [ "id" => str(1) "5" "to_contenttype" => str(12) "showcases" "to_id" => str(2) "15" ] 1 => arr(3) [ "id" => str(1) "6" "to_contenttype" => str(12) "showcases" "to_id" => str(1) "9" ] ]
protected updateRelation ( string $contenttype, integer $contentId, array $relation )
$contenttype string
$contentId integer
$relation array

updateSingleValue() public method

It is called in list of contents.
public updateSingleValue ( string $contenttype, integer $id, string $field, mixed $value ) : boolean
$contenttype string Content Type to be edited.
$id integer Id of content to be updated.
$field string Field name of content to be changed.
$value mixed New value to be defined on field.
return boolean Returns true when update is done or false if not.

updateTaxonomy() protected method

Update / insert taxonomy for a given content-unit.
protected updateTaxonomy ( string $contenttype, integer $contentId, array $taxonomy )
$contenttype string
$contentId integer
$taxonomy array

Property Details

$images public property

public array $images
return array