Items

What does items class do

Functions

Item::getUserClass

Definition

Name
_functionname_
Shorthand
_functionshorthand_
Syntax
_returntype_ = _functionname_( String format [, Mixed timestamp ] );

Description

_description_

Parameters

_var_
_type_ _summary_
Options
_value_
_description_
identifier
_type_ _summary_

Return values

_type_ _returnsummary_

Examples

Dependencies

PHP
  • _function_
Janitor
  • _function_

Item::getItem

Definition

Name
getItem
Syntax
Array|false = Item::getItem( Array $_options );

Description

getItem() fetches the data of a single Item from the "items" table in the database. It fetches the first Item that matches the criteria defined by the $_options parameter.

It is also possible to extend the fetched Item with more information from the database.

Parameters

$_options
Array Associative array containing search criteria and the option to extend the fetched Item.
Options
id
id of Item to fetch
sindex
sindex of Item to fetch
tags
Match Item by one or more tags. Separate multiple tags with semicolon. Tag(s) can be combined with an itemtype.
itemtype
Match Item by itemtype. Can only be used in combination with one or more tags.
extend
If set, Janitor's Items::extendItem() function is called on the Item. See documentation for extendItem().

Return values

Array Array of item properties or false if no Item is found.

Examples

Ex. 1a: Get Item with unique identifier
$IC = new Items(); $item = $IC->getItem(array("id" => 13));

Get a single Item based on the id 13. Return value:

Array ( [id] => 13 [sindex] => my-post [status] => 1 [itemtype] => post [user_id] => 2 [created_at] => 2018-06-06 18:51:55 [modified_at] => 2018-06-06 18:52:30 [published_at] => 2018-06-06 18:51:55 )
Ex. 1b: Get Item with unique identifier
$IC = new Items(); $item = $IC->getItem(array("sindex" => "my-post"));

Get a single Item based on the sindex "my-post". Return value:

Array ( [id] => 13 [sindex] => my-post [status] => 1 [itemtype] => post [user_id] => 2 [created_at] => 2018-06-06 18:51:55 [modified_at] => 2018-06-06 18:52:30 [published_at] => 2018-06-06 18:51:55 )
Ex. 2a: Get Item via filtering
$IC = new Items(); $item = $IC->getItem(array("tags" => "subject:cats;genre:thriller"));

Get a single Item based on the tags "subject:cats" and "genre:thriller". Return value:

Array ( [id] => 10 [sindex] => my-thriller-about-cats [status] => 1 [itemtype] => post [user_id] => 2 [created_at] => 2018-06-07 13:45:12 [modified_at] => 2018-06-07 13:52:30 [published_at] => 2018-06-07 13:45:12 )
Ex. 2b: Get Item via filtering
$IC = new Items(); $item = $IC->getItem(array("tags" => "subject:cats", "itemtype" => "gallery"));

Get a single Item based on the tag "subject:cats" and the itemtype "gallery". Return value:

Array ( [id] => 9 [sindex] => my-cats-gallery [status] => 1 [itemtype] => post [user_id] => 2 [created_at] => 2018-06-07 13:15:23 [modified_at] => 2018-06-07 13:32:35 [published_at] => 2018-06-07 13:15:23 )
Ex. 3: Get Item and extend it
$IC = new Items(); $item = $IC->getItem(array("id" => 13, "extend" => true));

Get a single Item based on the id 13 and extend it with its itemtype info (which is default for the extendItem() function). Return value:

Array ( [id] => 13 [sindex] => my-post [status] => 1 [itemtype] => post [user_id] => 2 [created_at] => 2018-06-06 18:51:55 [modified_at] => 2018-06-06 18:52:30 [published_at] => 2018-06-06 18:51:55 [item_id] => 13 [name] => My post [classname] => my_custom_CSS_class [description] => A short description of my post [html] => <p>The content of my post</p> )

Dependencies

Janitor
  • Query

Item::getIdFromSindex

Definition

Name
_functionname_
Shorthand
_functionshorthand_
Syntax
_returntype_ = _functionname_( String format [, Mixed timestamp ] );

Description

_description_

Parameters

_var_
_type_ _summary_
Options
_value_
_description_
identifier
_type_ _summary_

Return values

_type_ _returnsummary_

Examples

Dependencies

PHP
  • _function_
Janitor
  • _function_

Item::getSimpleType

Definition

Name
_functionname_
Shorthand
_functionshorthand_
Syntax
_returntype_ = _functionname_( String format [, Mixed timestamp ] );

Description

Get item data from items db

Parameters

_var_
_type_ _summary_
Options
_value_
_description_
identifier
_type_ _summary_

Return values

_type_ _returnsummary_

Examples

Dependencies

PHP
  • _function_
Janitor
  • _function_

Item::getRelatedItems

Definition

Name
_functionname_
Shorthand
_functionshorthand_
Syntax
_returntype_ = _functionname_( String format [, Mixed timestamp ] );

Description

_description_

Parameters

_var_
_type_ _summary_
Options
_value_
_description_
identifier
_type_ _summary_

Return values

_type_ _returnsummary_

Examples

Dependencies

PHP
  • _function_
Janitor
  • _function_

Item::extendItem

Definition

Name
extendItem
Syntax
Array = Item::extendItem( Array item [, Array $_options ] );

Description

Extend item after already having base information. Defined to be able to limit queries when getting information. Default only gets type data. Optional data.

Parameters

$item
Array Array of an item
$_options
Array Array of extra options
Options
tags
Extend your item with tags
prices
Extend your item with prices
ratings
Extend your item with ratings
comments
Extend your item with comments
everything
Extend your item with tags, prices, ratings, comments

Return values

Array returns array with the full item

Examples

$IC = new Item(); $item = $IC->getItem(array("sindex" => "my_name")); $item = $IC->extendItem($item);

Get an item and then extend it.

Dependencies

Janitor
  • _function_

Item::extendItems

Definition

Name
_functionname_
Shorthand
_functionshorthand_
Syntax
_returntype_ = _functionname_( String format [, Mixed timestamp ] );

Description

_description_

Parameters

_var_
_type_ _summary_
Options
_value_
_description_
identifier
_type_ _summary_

Return values

_type_ _returnsummary_

Examples

Dependencies

PHP
  • _function_
Janitor
  • _function_

Item::getItems

Definition

Name
getItems
Syntax
Array = Item::GetItems( Array $_options );

Description

Get all matching items, and put them into an array.

Parameters

$_options
Array Array of options
Options
itemtype
Returns post based on an itemtype
status
Returns items with a status of 1 or 0
tags
Returns all items with specific tag
sindex
Returns items with specific sindex
where
Add additional WHERE sql statement to query
order
Any Sql to order
limit
The amount of items to return
no_readstate
Returns items that current user has not marked at read
user_id
Returns items with given user_id
exclude
Excludes item id's seperated via semi-colons(;) from query
extend
Extend items with itemtype info before returning by using janitor function "Item::extendItem". Documentation for extendItem()

Return values

Array Array of items

Examples

$IC = new Item(); $items = $IC->getItems(array("itemtype" => "post", "status" => 1, "order" => "created_at DESC"));

Get all items with itemtype "post", status 1 (published), and order by created_at date.

$IC = new Item(); $items = $IC->getItems(array("tags" => "javascript", "limit" => 99));

Get all items with tag javascript, but don't get more than 99st.

$IC = new Item(); $items = $IC->getItems(["itemtype" => "people", "where" => "name = peter", "extend" => ["tags" => "true"]]);

Get all items with itemtype "people", where table row "name" has the value "peter" and extend those items with specific itemtype definitions (in this case for "people") and tags.

Dependencies

Janitor
  • _function_

Item::getNext

Definition

Name
getNext
Syntax
Array = Item::getNext( Number $item_id [, Array $_options ] );

Description

Can receive items array to use for finding next item(s) or receive query syntax to perform getItems request on it own

Parameters

$item_id
Number The id of the item
$_options
Array Array of options
Options
items
Array of item(s)
count
Max number of items

Return values

Array List of next items

Examples

$items = $IC->getItems(array("itemtype" => $itemtype, "status" => 1, "order" => "items.created_at DESC")); $next = $IC->getNext(1, array("items" => $items));

Return Next item array

Array ( [0] => Array ( [id] => 50 [sindex] => new_project [status] => 1 [itemtype] => project [user_id] => [created_at] => 2014-07-28 14:01:40 [modified_at] => 2014-07-28 14:27:01 [published_at] => 2014-07-28 14:01:40 ) )

Dependencies

Janitor
  • _function_

Item::getPrev

Definition

Name
getPrev
Syntax
Array = Item::getPrev( Number $item_id [, Array $_options ] );

Description

Can receive items array to use for finding previous item(s) or receive query syntax to perform getItems request on its own.

Parameters

$item_id
Number The item id
$_options
Array Array of options
Options
items
Array of item(s)
count
Max number of items

Return values

Array List of previous items

Examples

$items = $IC->getItems(array("itemtype" => $itemtype, "status" => 1, "order" => "items.created_at ASC")); $prev = $IC->getPrev(20, array("items" => $items));

Return previous item array

Array ( [0] => Array ( [id] => 51 [sindex] => this_is_the_new_headline [status] => 1 [itemtype] => project [user_id] => [created_at] => 2014-07-28 14:29:01 [modified_at] => 2014-07-28 14:31:52 [published_at] => 2014-07-28 14:29:01 ) )

Dependencies

Janitor
  • _function_

Item::paginate

Definition

Name
Item::paginate
Syntax
Array = Item::paginate( Array $_options );

Description

Splits a list of items into smaller fragments and returns information required to create meaningful pagination.

Parameters

$_options
Array Array of options
Options
pattern
Array of options to be sent to Item::getItems, which returns the items to be paginated.
limit
Maximal number of items per page. Default: 5.
sindex
If passed without the direction parameter, the pagination will start with the associated item.
direction
Can be passed in combination with the sindex parameter. If value is next, pagination will start with the item that comes after the item with the specified sindex. If value is prev, will show the items that come immediately before the item with the specified sindex.

Return values

Array Array of items. Contains the subarrays range_items (items in the specified range), next (next items), and prev (previous items). Also contains first_id and last_id, as well as first_sindex and last_sindex, for the items within the specified range. Lastly, it contains the total number of items in the whole list.

Examples

Example 1
$sindex = "test-item-aaa"; $items = $IC->paginate([ "limit" => 2, "pattern" => [ "itemtype" => "tests", "order" => "sindex ASC" ], "sindex" => $sindex ]);

Returns fragmented list of items with a limit of 2 items per fragment. The beginning of range_items is based on sindex. Sorting order is according to ascending sindex.

Array ( ["range_items"] => Array ( [0] => Array ( [id] => 420, [sindex] => test-item-aaa, [status] => 0, [itemtype] => tests, [user_id] => [created_at] => 2019-04-28 19:15:13, [modified_at] => 2019-04-28 19:15:13, [published_at] => 2019-04-28 19:15:13 ) [1] => Array ( [id] => 421, [sindex] => test-item-bbb, [status] => 0, [itemtype] => tests, [user_id] => [created_at] => 2019-04-28 19:15:13, [modified_at] => 2019-04-28 19:15:13, [published_at] => 2019-04-28 19:15:13, ) ) ["next"] => Array ( [0] => Array ( [id] => 422, [sindex] => test-item-ccc, [status] => 0, [itemtype] => tests, [user_id] => [created_at] => 2019-04-28 19:15:13, [modified_at] => 2019-04-28 19:15:13, [published_at] => 2019-04-28 19:15:13 ) ) ["prev"] => Array () [first_id] => 420, [last_id] => 421, [first_sindex] => test-item-aaa, [last_sindex] => test-item-bbb, [total] => 3 )
Example 2
$sindex = "test-item-bbb"; $items = $IC->paginate(array( "limit" => 2, "pattern" => array( "itemtype" => "tests", "order" => "sindex ASC" ), "sindex" => $sindex, "direction" => "prev" ));

Returns fragmented list of items with a limit of 2 items per fragment. Sorting order of all items is according to ascending sindex. The item in range_items precedes the item with the specified sindex.

Array ( ["range_items"] => Array ( [0] => Array ( [id] => 420, [sindex] => test-item-aaa, [status] => 0, [itemtype] => tests, [user_id] => [created_at] => 2019-04-28 19:15:13, [modified_at] => 2019-04-28 19:15:13, [published_at] => 2019-04-28 19:15:13 ) ) ["next"] => Array ( [0] => array ( [id] => 421, [sindex] => test-item-bbb, [status] => 0, [itemtype] => tests, [user_id] => [created_at] => 2019-04-28 19:15:13, [modified_at] => 2019-04-28 19:15:13, [published_at] => 2019-04-28 19:15:13, ) [1] => array ( [id] => 422, [sindex] => test-item-ccc, [status] => 0, [itemtype] => tests, [user_id] => [created_at] => 2019-04-28 19:15:13, [modified_at] => 2019-04-28 19:15:13, [published_at] => 2019-04-28 19:15:13 ) ) ["prev"] => Array ( ) [first_id] => 420, [last_id] => 420, [first_sindex] => test-item-aaa, [last_sindex] => test-item-aaa, [total] => 3 )

Dependencies

PHP
  • array
  • count
  • isset
  • unset
Janitor
  • Items::extendItem
  • Items::getIdFromSindex
  • Items::getItems
  • Items::getNext
  • Items::getPrev

Item::getMediae

Definition

Name
_functionname_
Shorthand
_functionshorthand_
Syntax
_returntype_ = _functionname_( String format [, Mixed timestamp ] );

Description

_description_

Parameters

_var_
_type_ _summary_
Options
_value_
_description_
identifier
_type_ _summary_

Return values

_type_ _returnsummary_

Examples

Dependencies

PHP
  • _function_
Janitor
  • _function_

Item::sliceMedia

Definition

Name
_functionname_
Shorthand
_functionshorthand_
Syntax
_returntype_ = _functionname_( String format [, Mixed timestamp ] );

Description

_description_

Parameters

_var_
_type_ _summary_
Options
_value_
_description_
identifier
_type_ _summary_

Return values

_type_ _returnsummary_

Examples

Dependencies

PHP
  • _function_
Janitor
  • _function_

Item::getOwners

Definition

Name
_functionname_
Shorthand
_functionshorthand_
Syntax
_returntype_ = _functionname_( String format [, Mixed timestamp ] );

Description

_description_

Parameters

_var_
_type_ _summary_
Options
_value_
_description_
identifier
_type_ _summary_

Return values

_type_ _returnsummary_

Examples

Dependencies

PHP
  • _function_
Janitor
  • _function_

Item::getTags

Definition

Name
getTags
Syntax
Array|false = Item::getTags( Array $_options );

Description

Get tag, optionally based on item_id, limited to context, or just check if specific tag exists

Parameters

$_options
Array Array of options
Options
$item_id
Get tag based on $item_id
$tag_id
Get tag based on it's id
context
The tag context.
value
The tag value.

Return values

Array|false Array of tags or false if nothing found.

Examples

$IC = new Item(); $item = $IC->getItem(array("sindex" => "test-name")); $tag = $IC->getTags(array("item" => $item[id]));

Get the tag based on item.

$IC = new Item(); $tag = $IC->getTags(array("context" => "hello"));

Get list of tags with the context of "hello".

$IC = new Item(); $tag = $IC->getTags(array("value" => "javascript"));

Get list of tags with the value of "javascript".

Dependencies

Janitor
  • Query

Item::getComments

Definition

Name
_functionname_
Shorthand
_functionshorthand_
Syntax
_returntype_ = _functionname_( String format [, Mixed timestamp ] );

Description

_description_

Parameters

_var_
_type_ _summary_
Options
_value_
_description_
identifier
_type_ _summary_

Return values

_type_ _returnsummary_

Examples

Dependencies

PHP
  • _function_
Janitor
  • _function_

Item::getPrices

Definition

Name
getPrices
Syntax
Array = Item::getPrices( Array $_options );

Description

Get the price of item.

Parameters

$_options
Array Array of options
Options
$item_id
Fetch the price from this item
$country
Get price based on country
currency
Get price based on currency

Return values

Array of prices

Examples

_blank for now

Get price in Euro from $item_id

Dependencies

Janitor
  • _function_

Item::getSubscriptionMethod

Definition

Name
_functionname_
Shorthand
_functionshorthand_
Syntax
_returntype_ = _functionname_( String format [, Mixed timestamp ] );

Description

_description_

Parameters

_var_
_type_ _summary_
Options
_value_
_description_
identifier
_type_ _summary_

Return values

_type_ _returnsummary_

Examples

Dependencies

PHP
  • _function_
Janitor
  • _function_