Items methods
__construct( setup )
setupAn optional hash array with the following possible setup keys:fillMethodOptionally specifies the method to use to load Item objects right on the construction of the object. From one of the following possible method keys:fromParametersMakes a request to the database with the specification passed via thepkey and loads the resulting Items.fromDatabaseResultLoads the Items that you've queried on your own, from the passeddatabaseResultkey, using the givenitemLoadMethodandkeyFieldfromArrayLoads the Items passed in theitemskey.
pA hash array with the parameters to use for loading Items when thefromParametersfillMethodis used, the same as in the fillFromParameters method.itemLoadMethodThe method to use to load Items when using thefromDatabaseResultfillMethod.databaseResultThe DatabaseResult object containing the Items to load when using thefromDatabaseResultfillMethod.keyFieldThe field name that uniquely identifies each item on the table to use when loading Items when using thefromDatabaseResultfillMethod.itemsAn array of Item objects to load when using thefromArrayfillMethod.
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 fillFromParameters method. Intended to be overloaded.
pA hash array of options, with the same specs as the one passed to the fillFromParameters 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 )
Clears the cache for the query represented by the given p parameters, just as they were passed to buildCacheKeyNamingOptions, the constructor or, most probably, the fillFromParameters method.
pA 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 buildCacheKeyNamingOptions (and also to fillFromParameters, and to the constructor, if that's the case)
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.
pA hash array with parameters for loading ItemskeyFieldThe name of the field on the database table that uniquely identifies each item, most probably the primary key. Default:idselectsAn array of select SQL parts to select from. Example:["tableName.*", "tableName2.id"]. Default: All fields from the object'stableName.tablesAn array of tables to be used on the SQL query. Default: This object'stableName.wheresAn array ofwhereSQL clauses. Default:false. Each item is a hash array containing the following keys:sqlPartThe SQL part of the where, on which each value must represented by a question mark. Example:fieldName = ?valuesAn array specifying each of the values used on thesqlPart, in the same order they're used there. Each item of the array must an array of the following keys:typeThe type of the value, must be one of theDATABASE_FIELD_TYPE_?valueThe value
limitMaximum number of items returned. Default:falseorderAn ordered array of orders to apply to results, on which each item can be one of the configured in theordersparameter. Default:falseordersA hash array of the available orders to be applied to results, where each key is the order name as used in theorderparameter, and the value is the SQL order part. Default: Arandomorder that randomizes results order when used.orderRandomSeedThe seed to use to randomize results when therandomorder is used. Default:falseisPagingWhether to page results based on the givenpageanditemsPerPageparameters. Default:falsepageThe number of page to return when paging is active. Default:0itemsPerPageThe number of items per page when paging is active. Default:10isBuildTotalNumberOfItemsWhether to return the total number of matching items or not in thetotalNumberOfresults key, not taking into account paging configuration. It takes into accountlimit, if specified. Default:falseisFillItemsWhether to return the matching items or not in theitemsresults key. Default:trueisForceNoCacheIf set to true, the query won't use cache, even if the object is configured to do so. Default:falsecacheKeyNamingOptionsIf specified, this cacheKeyNamingOptions will be used instead of the ones built by the buildCacheKeyNamingOptions method. The cache key naming options as specified in Cache::buildCacheKey. Default:falseisStoreInCacheWhenNoResultsWhether to store results in cache even when there are no results. Default:true
Returns: True if everything went ok, false otherwise.
Last updated
Was this helpful?