Class Item
In: app/models/item.rb
Parent: ActiveRecord::Base

Item

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).

Note:

*

Methods

Included Modules

ApplicationHelper

Constants

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'

Public Class methods

self.check_user_auth

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.

self.delete

Overrides ActionRecord::Base.delete().

id:Target Item-ID.

self.delete_all

Overrides ActionRecord::Base.delete_all().

conditions:Conditions.

self.destroy

Updates attributes of the Item.

This method overrides ActionRecord::Base.destroy() to handle the related attributes.

id:Target Item-ID.

self.destroy_all

Overrides ActionRecord::Base.delete_all().

conditions:Conditions.

self.get_list_sql

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.

self.get_order_max

Gets the maximum of order value of the specified (parent) Folder.

folder_id:Parent Folder-ID.
return:Current maximum order.

self.get_rss

Gets RSS feed of specified User.

maker:The RSS maker.
user:The target User.
root_url:Root URL.

self.get_title

Gets the title of the specified Item.

item_id:Item-ID.
return:Item title. If not found, prearranged string.

self.get_toys

Gets Toys (desktop items) of specified User.

user:The target User.
return:Toys (desktop items) of specified User.

self.new_by_type

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.

self.new_info

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.

self.new_profile

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.

self.new_project

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.

self.new_research

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.

self.new_workflow

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.

self.profile_title_def

Returns default title of the Profile-sheet.

return:Default title of the Profile-sheet.

self.sort_opts

Returns sort options of the Items.

excepts:Array of the fields to exclude (ex. [:xorder]).
return:Array of options.

Public Instance methods

attachments_without_content

Gets Attachments related to this Item without content.

return:Array of Attachments without content.

check_user_auth

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.

deletable?

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.

delete

Overrides ActionRecord::Base.delete().

destroy

Overrides ActionRecord::Base.destroy().

editable?

Checks if the Item can be edited by specified User.

user_id:Operating User.
return:true if the Item can be edited, false otherwise.

featured?

Checks if the Item is now featured.

return:true if the Item is featured, false otherwise.

get_applicants

Gets applicants for the project.

return:Array of User-IDs of applicants.

get_folder_path

Gets Folder path in which this Item located.

return:Folder path like "/folder_name1/folder_name2".

images_without_content

Gets Images related to this Item without content.

return:Array of Images without content.

update_attribute

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.

update_attributes

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.

[Validate]