Cherrycake
ExamplesGithub
version 0.x
version 0.x
  • Introduction
  • Status
  • Changelog
  • Migration
  • Architecture
    • Basics
    • Modules
    • Classes
    • Lifecycle
      • Deep lifecycle
    • Performance
    • Security
    • Patterns
      • Files structure
    • Items
    • Server requirements
  • Guide
    • Getting started
      • Skeleton start
      • Docker start
    • Modules guide
    • Classes guide
    • Actions guide
      • Complex actions
      • Variable path components
      • Accept GET or POST parameters
      • Getting the URL of an action
      • Cached actions
      • Brute force attacks
    • Patterns guide
      • Passing variables to a pattern
      • Nested patterns
      • Cached patterns
    • Cache guide
      • Time To Live
      • Using cache
      • Lists
      • Queues
      • Pools
    • Database guide
      • Basic queries
      • Prepared queries
      • Cached queries
      • Cache key naming
      • Removing queries from cache
    • Items guide
      • Item cache
      • Item lists
      • Items custom filters
      • Items custom ordering
      • Mixing filters and ordering
      • Items with relationships
      • Items cache
    • HtmlDocument guide
    • Css and Javascript guide
      • Modules injecting CSS and JavaScript
    • Session guide
    • Login guide
      • Creating a complete login workflow
    • Locale guide
      • Multilingual texts
      • Domain based site localization
    • Log guide
      • Loading Log events from the database
    • Stats guide
      • Stats events with additional dimensions
      • Loading Stats events from the database
    • Janitor guide
      • Janitor tasks configuration files
    • Command line interface
    • Debugging
  • Reference
    • Core modules
      • Actions
        • Actions methods
      • Browser
      • Cache
        • Cache methods
      • Css
        • Css methods
      • Database
      • Email
      • Errors
      • HtmlDocument
        • HtmlDocument methods
      • ItemAdmin
      • Janitor
        • Janitor methods
      • Javascript
        • Javascript methods
      • Locale
        • Locale methods
      • Log
        • Log methods
      • Login
        • Login methods
      • Output
        • Output methods
      • Patterns
        • Patterns methods
      • Security
        • Security methods
      • Session
        • Session methods
      • Stats
        • Stats methods
      • SystemLog
      • TableAdmin
      • Validate
    • Core classes
      • Action
        • Action methods
        • Action properties
      • AjaxResponseJson
      • BasicObject
        • BasicObject methods
      • CacheProvider
        • CacheProvider methods
      • Color
      • DatabaseProvider
        • DatabaseProvider methods
      • DatabaseResult
        • DatabaseResult methods
        • DatabaseResult properties
      • DatabaseRow
      • Engine
        • Engine methods
        • Engine properties
      • Gradient
      • Item
        • Item methods
        • Item properties
      • Items
        • Items methods
        • Items properties
      • Image
      • JanitorTask
        • JanitorTask methods
        • JanitorTask properties
      • LogEvent
        • LogEvent methods
        • LogEvent Properties
      • LogEvents
        • LogEvents methods
      • Module
        • Module methods
        • Module properties
      • Response
      • Request
        • Request methods
      • RequestParameter
        • RequestParameter methods
      • RequestPathComponent
        • RequestPathComponent methods
      • Result
      • StatsEvent
        • StatsEvent properties
      • StatsEvents
        • StatsEvents methods
      • SystemLogEvent
        • SystemLogEvent methods
        • SystemLogEvent properties
      • SystemLogEvents
        • SystemLogEvents methods
  • Code conventions
  • License
  • Extras
Powered by GitBook
On this page
  • __construct( setup )
  • buildCacheKeyNamingOptions( p )
  • clearCache( p )
  • clearCachedKeysPool
  • fillFromParameters( p )

Was this helpful?

  1. Reference
  2. Core classes
  3. Items

Items methods

PreviousItemsNextItems properties

Last updated 3 months ago

Was this helpful?

__construct( setup )

  • setup An optional hash array with the following possible setup keys:

    • fillMethod Optionally specifies the method to use to load Item objects right on the construction of the object. From one of the following possible method keys:

      • fromParameters Makes a request to the database with the specification passed via the p key and loads the resulting Items.

      • fromDatabaseResult Loads the Items that you've queried on your own, from the passed databaseResult key, using the given itemLoadMethod and keyField

      • fromArray Loads the Items passed in the items key.

    • p A hash array with the parameters to use for loading Items when the fromParameters fillMethod is used, the same as in the method.

    • itemLoadMethod The method to use to load Items when using the fromDatabaseResult fillMethod.

    • databaseResult The DatabaseResult object containing the Items to load when using the fromDatabaseResult fillMethod.

    • keyField The field name that uniquely identifies each item on the table to use when loading Items when using the fromDatabaseResult fillMethod.

    • items An array of Item objects to load when using the fromArray fillMethod.

Throws: An Exception if the item could not be constructed or loaded.

buildCacheKeyNamingOptions( p )

Builds a suitable cacheKeyNamingOptions array for performing queries and also clearing cache. Takes the same parameters as the method. Intended to be overloaded.

  • p A hash array of options, with the same specs as the one passed to the method. Only the relevant keys will be used.

Returns: A cacheKeyNamingOptions hash array suitable to be used when performing queries to the database or clearing the queries cache.

clearCache( p )

Returns: True if cache was cleared successfully, false otherwise

clearCachedKeysPool

When using the CachedKeysPool mechanism, this method removes all the cache entries corresponding to each stored key from cache, effectively clearing all the cached queries related to this Items object.

Returns: True if the cachedKeysPool could be cleared, false otherwise

fillFromParameters( p )

Fills the list with items loaded according to the given parameters. Intended to be overloaded and called from a parent class.

  • p A hash array with parameters for loading Items

    • keyField The name of the field on the database table that uniquely identifies each item, most probably the primary key. Default: id

    • selects An array of select SQL parts to select from. Example: ["tableName.*", "tableName2.id"]. Default: All fields from the object's tableName.

    • tables An array of tables to be used on the SQL query. Default: This object's tableName.

    • wheres An array of where SQL clauses. Default: false. Each item is a hash array containing the following keys:

      • sqlPart The SQL part of the where, on which each value must represented by a question mark. Example: fieldName = ?

      • values An array specifying each of the values used on the sqlPart, in the same order they're used there. Each item of the array must an array of the following keys:

        • value The value

    • limit Maximum number of items returned. Default: false

    • order An ordered array of orders to apply to results, on which each item can be one of the configured in the orders parameter. Default: false

    • orders A hash array of the available orders to be applied to results, where each key is the order name as used in the order parameter, and the value is the SQL order part. Default: A random order that randomizes results order when used.

    • orderRandomSeed The seed to use to randomize results when the random order is used. Default: false

    • isPaging Whether to page results based on the given page and itemsPerPage parameters. Default: false

    • page The number of page to return when paging is active. Default: 0

    • itemsPerPage The number of items per page when paging is active. Default: 10

    • isBuildTotalNumberOfItems Whether to return the total number of matching items or not in the totalNumberOf results key, not taking into account paging configuration. It takes into account limit, if specified. Default: false

    • isFillItems Whether to return the matching items or not in the items results key. Default: true

    • isForceNoCache If set to true, the query won't use cache, even if the object is configured to do so. Default: false

    • isStoreInCacheWhenNoResults Whether to store results in cache even when there are no results. Default: true

Returns: True if everything went ok, false otherwise.

Clears the cache for the query represented by the given p parameters, just as they were passed to , the or, most probably, the method.

p A hash array of parameters that will be used to build the cache key to clear, so it has to be the same as the parameters passed to (and also to , and to the , if that's the case)

type The type of the value, must be one of the

cacheKeyNamingOptions If specified, this cacheKeyNamingOptions will be used instead of the ones built by the buildCacheKeyNamingOptions method. The cache key naming options as specified in . Default: false

fillFromParameters
fillFromParameters
fillFromParameters
buildCacheKeyNamingOptions
constructor
fillFromParameters
buildCacheKeyNamingOptions
fillFromParameters
constructor
Cache::buildCacheKey
DATABASE_FIELD_TYPE_?