| Class | Item |
| In: |
app/models/item.rb
|
| Parent: | ActiveRecord::Base |
| Original by: | Sysphonic |
| Authors: | MORITA Shintaro |
| Copyright: | Copyright (c) 2007 MORITA Shintaro, Sysphonic. All rights reserved. |
| License: | New BSD License (See LICENSE file) |
| URL: | http://sysphonic.com/ |
Item is the most elemental object on this system. It contains description(expected HTML-formatted by FCKeditor), Images and Attachments and can be added Comments as response from readers. Items can have different means by its xtype attribute, such as a workflow or a project (this type of Item is often called ‘Mission’ on this system).
*
| XTYPE_UNKNOWN | = | nil |
| XTYPE_PROJECT | = | 'project' |
| XTYPE_WORKFLOW | = | 'workflow' |
| XTYPE_INFO | = | 'info' |
| XTYPE_PROFILE | = | 'profile' |
| XTYPE_RESEARCH | = | 'research' |
| FILTER_ALL | = | 'all' |
| FILTER_OPEN | = | 'open' |
| FILTER_SELF | = | 'self' |
| FOLDER_ALL | = | 'all' |
| FOLDER_CURRENT | = | 'current' |
| FOLDER_LOWER | = | 'lower' |
| DEF_SORT_FIELD | = | 'updated_at' |
| DEF_SORT_DIRECTION | = | 'DESC' |
| HUMANIZED_ATTRIBUTE_KEY_NAMES | = | { "title" => 'Title' |
Checks user authority to read or write contents of the Item. (Without considering about User‘s authority.)
| item_id: | Item-ID. |
| user: | Target User. |
| rxw: | Specify ‘r’ to check read-authority, ‘w’ to write-authority. |
| check_admin: | Flag to consider about User‘s authority. |
| return: | true if specified user has authority, false otherwise. |
Gets SQL for list of Items. Here is the sample of return.
select distinct Item.* from items Item, folders Folder
where
(Item.user_id = 1 or Item.public = true)
and
(
(Item.folder_id = 0) or (
(Item.folder_id = Folder.id) and (
(
(
(Folder.read_users like '%|1|%')
)
or
(
(Folder.read_teams like '%|1|%')
)
)
or
(
(Folder.read_users is null)
and
(Folder.read_groups is null)
and
(Folder.read_teams is null)
)
)
)
)
and
(
(Item.folder_id = 0)
or
(Folder.owner_id is null)
or
(Folder.owner_id = 0)
)
order by updated_at DESC
| user: | User Instance for whom list will be made. If not required, specify nil. |
| filter: | Filter. Specify from FILTER_OPEN, FILTER_SELF or FILTER_ALL. |
| keyword: | Search keyword. If not required, specify nil. |
| folder_ids: | Array of Folder-IDs. If not required, specify nil. |
| sort_col: | Column to be used to sort list. If specified nil, uses default(‘updated_at’). |
| sort_type: | Sort type. Specify ‘ASC’ , ‘DESC’. If specified nil, uses default(‘DESC’). |
| limit_num: | Limit count to get. If without limit, specify 0. |
| admin: | Optional flag to apply Administrative Authority. Default = false. |
| add_con: | Additional condition. This parameter is added to ‘where’ clause with ‘and’. Default = nil. |
| return: | SQL for list of Items. |
Creates an Item instance with specified type(xtype) and Folder-ID.
Its xorder attribute is also automatically calicurated from Folder-ID, but note that if you don‘t save it immediately (that means, in a critical section), you should update xorder before saving it.
| type: | Type of the Item. |
| folder_id: | Parent Folder-ID. |
| return: | An Item instance. |
Creates an info-type instance of Item.
Its xorder attribute is also automatically calicurated from Folder-ID, but note that if you don‘t save it immediately (that means, in a critical section), you should update xorder before saving it.
| folder_id: | Parent Folder-ID. |
| return: | Instance of the Item. |
Creates an profile-type instance of Item.
Its xorder attribute is also automatically calicurated from Folder-ID, but note that if you don‘t save it immediately (that means, in a critical section), you should update xorder before saving it.
| folder_id: | Parent Folder-ID. |
| return: | Instance of the Item. |
Creates an project-type instance of Item.
Its xorder attribute is also automatically calicurated from Folder-ID, but note that if you don‘t save it immediately (that means, in a critical section), you should update xorder before saving it.
| folder_id: | Parent Folder-ID. |
| return: | Instance of the Item. |
Creates an research-type instance of Item.
Its xorder attribute is also automatically calicurated from Folder-ID, but note that if you don‘t save it immediately (that means, in a critical section), you should update xorder before saving it.
| folder_id: | Parent Folder-ID. |
| return: | Instance of the Item. |
Creates an workflow-type instance of Item.
Its xorder attribute is also automatically calicurated from Folder-ID, but note that if you don‘t save it immediately (that means, in a critical section), you should update xorder before saving it.
| folder_id: | Parent Folder-ID. |
| return: | Instance of the Item. |
Returns default title of the Profile-sheet.
| return: | Default title of the Profile-sheet. |
Returns sort options of the Items.
| excepts: | Array of the fields to exclude (ex. [:xorder]). |
| return: | Array of options. |
Gets Attachments related to this Item without content.
| return: | Array of Attachments without content. |
Checks user authority to read or write contents of the Item. (Without considering about User‘s authority.)
| user: | Target User. |
| rxw: | Specify ‘r’ to check read-authority, ‘w’ to write-authority. |
| check_admin: | Flag to consider about User‘s authority. |
| return: | true if specified user has authority, false otherwise. |
Checks if the Item can be deleted by specified User.
| user_id: | Operating User. |
| admin: | Specify administrative authority if necessary. |
| return: | true if the Item can be deleted, false otherwise. |
Gets Folder path in which this Item located.
| return: | Folder path like "/folder_name1/folder_name2". |
Gets Images related to this Item without content.
| return: | Array of Images without content. |
Updates attributes of the Item.
This method overrides ActionRecord::Base.update_attribute() to control updating ‘update_at’ attribute. We need to change orders to display (xorder) without updating it.
And also calicurates order(xorder) in the parent Folder if required.
| name: | Name of the attribute to update. |
| value: | New value of the attribute. |
Updates attributes of the Item.
This method overrides ActionRecord::Base.update_attributes() to control updating ‘update_at’ attribute. We need to chage orders to display (xorder) without updating it.
And also calicurates order(xorder) in the parent Folder if required.
| attrs: | Hash of attributes to update. |