ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilCalendarCategories Class Reference

class for calendar categories More...

+ Collaboration diagram for ilCalendarCategories:

Public Member Functions

 initialize ($a_mode, $a_source_ref_id=0, $a_use_cache=false)
 initialize visible categories
 getCategoryInfo ($a_cat_id)
 public
 getCategoriesInfo ()
 get categories
 getCategories ($a_include_subitem_calendars=false)
 get categories
 getSubitemCategories ($a_cat_id)
 get subitem categories for a specific category
 prepareCategoriesOfUserForSelection ()
 prepare categories of users for selection
 isEditable ($a_cat_id)
 check if category is editable
 isVisible ($a_cat_id)
 check if category is visible

Static Public Member Functions

static _getInstance ($a_usr_id=0)
 get singleton instance
static _lookupCategoryIdByObjId ($a_obj_id)
 lookup category by obj_id
static _isOwner ($a_usr_id, $a_cal_id)
 check if user is owner of a category
static deletePDItemsCache ($a_usr_id)
 Delete cache (add remove desktop item)
static deleteRepositoryCache ($a_usr_id)
 Delete cache.

Data Fields

const MODE_REPOSITORY = 2
const MODE_REMOTE_ACCESS = 3
const MODE_PERSONAL_DESKTOP_MEMBERSHIP = 4
const MODE_PERSONAL_DESKTOP_ITEMS = 5

Protected Member Functions

 __construct ($a_usr_id=0)
 Singleton instance.
 sleep ()
 Serialize categories.
 wakeup ($a_ser)
 Load from serialize string.
 readPDCalendars ()
 Read categories of user.
 readSelectedItemCalendars ()
 Read categories of selected items.
 readReposCalendars ()
 Read available repository calendars.
 readPublicCalendars ()
 Read public calendars.
 readPrivateCalendars ()
 Read private calendars.
 readSelectedCategories ($a_obj_ids)
 read selected categories
 addSubitemCalendars ()
 Add subitem calendars E.g.

Protected Attributes

 $db
 $user_id
 $categories = array()
 $categories_info = array()
 $subitem_categories = array()
 $root_ref_id = 0
 $root_obj_id = 0

Static Protected Attributes

static $instance = null

Detailed Description

class for calendar categories

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 37 of file class.ilCalendarCategories.php.

Constructor & Destructor Documentation

ilCalendarCategories::__construct (   $a_usr_id = 0)
protected

Singleton instance.

protected

Parameters
int$a_usr_iduser id
Returns

Definition at line 65 of file class.ilCalendarCategories.php.

References $ilDB.

{
global $ilUser,$ilDB;
$this->user_id = $a_usr_id;
if(!$this->user_id)
{
$this->user_id = $ilUser->getId();
}
$this->db = $ilDB;
}

Member Function Documentation

static ilCalendarCategories::_isOwner (   $a_usr_id,
  $a_cal_id 
)
static

check if user is owner of a category

public

Parameters
intusr_id
intcal_id
Returns
bool

Definition at line 127 of file class.ilCalendarCategories.php.

References $ilDB, $query, $res, and ilCalendarCategory\TYPE_USR.

Referenced by ilCalendarShared\getSharedCalendarsForUser().

{
global $ilDB;
$query = "SELECT * FROM cal_categories ".
"WHERE cat_id = ".$ilDB->quote($a_cal_id ,'integer')." ".
"AND obj_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
"AND type = ".$ilDB->quote(ilCalendarCategory::TYPE_USR ,'integer')." ";
$res = $ilDB->query($query);
return $res->numRows() ? true : false;
}

+ Here is the caller graph for this function:

static ilCalendarCategories::_lookupCategoryIdByObjId (   $a_obj_id)
static

lookup category by obj_id

public

Parameters
intobj_id
Returns
int cat_id

Definition at line 102 of file class.ilCalendarCategories.php.

References $ilDB, $query, $res, $row, DB_FETCHMODE_OBJECT, and ilCalendarCategory\TYPE_OBJ.

Referenced by ilCalendarAppEventListener\createAppointments(), ilCalendarAppEventListener\deleteCategory(), ilDataLoader\generateCalendarEntries(), and ilCalendarAppointmentGUI\initForm().

{
global $ilDB;
$query = "SELECT cat_id FROM cal_categories ".
"WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
"AND type = ".$ilDB->quote(ilCalendarCategory::TYPE_OBJ ,'integer')." ";
$res = $ilDB->query($query);
while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
{
return $row->cat_id;
}
return 0;
}

+ Here is the caller graph for this function:

ilCalendarCategories::addSubitemCalendars ( )
protected

Add subitem calendars E.g.

session calendars in courses

Parameters
@return

Definition at line 645 of file class.ilCalendarCategories.php.

References $ilDB, $query, $res, $row, and DB_FETCHMODE_OBJECT.

Referenced by readPDCalendars(), and readSelectedItemCalendars().

{
global $ilDB;
$course_ids = array();
foreach($this->categories as $cat_id)
{
if($this->categories_info[$cat_id]['obj_type'] == 'crs')
{
$course_ids[] = $this->categories_info[$cat_id]['obj_id'];
}
}
$query = "SELECT od2.obj_id sess_id, od1.obj_id crs_id,cat_id FROM object_data od1 ".
"JOIN object_reference or1 ON od1.obj_id = or1.obj_id ".
"JOIN tree t ON or1.ref_id = t.parent ".
"JOIN object_reference or2 ON t.child = or2.ref_id ".
"JOIN object_data od2 ON or2.obj_id = od2.obj_id ".
"JOIN cal_categories cc ON od2.obj_id = cc.obj_id ".
"WHERE od2.type = 'sess' ".
"AND od1.type = 'crs' ".
"AND ".$ilDB->in('od1.obj_id',$course_ids,false,'integer').' '.
"AND or2.deleted IS NULL";
$res = $ilDB->query($query);
$cat_ids = array();
$course_sessions = array();
while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
{
$cat_ids[] = $row->cat_id;
$course_sessions[$row->crs_id][] = $row->cat_id;
$this->subitem_categories[] = $row->cat_id;
}
foreach($this->categories as $cat_id)
{
if($this->categories_info[$cat_id]['obj_type'] == 'crs' and
is_array($course_sessions[$this->categories_info[$cat_id]['obj_id']]))
{
foreach($course_sessions[$this->categories_info[$cat_id]['obj_id']] as $sess_cat_id)
{
$this->categories_info[$cat_id]['subitem_ids'][] = $sess_cat_id;
}
}
else
{
$this->categories_info[$cat_id]['subitem_ids'] = array();
}
}
}

+ Here is the caller graph for this function:

static ilCalendarCategories::deletePDItemsCache (   $a_usr_id)
static

Delete cache (add remove desktop item)

Parameters
object$a_usr_id
Returns

Definition at line 144 of file class.ilCalendarCategories.php.

References ilCalendarCache\getInstance().

Referenced by ilObjUser\_addDesktopItem(), ilObjUser\_dropDesktopItem(), and ilCalendarAppEventListener\handleEvent().

{
ilCalendarCache::getInstance()->deleteByAdditionalKeys(
$a_usr_id,
self::MODE_PERSONAL_DESKTOP_ITEMS,
'categories'
);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ilCalendarCategories::deleteRepositoryCache (   $a_usr_id)
static

Delete cache.

Parameters
object$a_usr_id
Returns

Definition at line 158 of file class.ilCalendarCategories.php.

References ilCalendarCache\getInstance().

Referenced by ilCalendarAppEventListener\handleEvent().

{
ilCalendarCache::getInstance()->deleteByAdditionalKeys(
$a_usr_id,
self::MODE_REPOSITORY,
'categories'
);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCalendarCategories::getCategories (   $a_include_subitem_calendars = false)

get categories

Parameters
$a_include_subitemsinclude subitem calendars public
Returns

Definition at line 306 of file class.ilCalendarCategories.php.

{
if($a_include_subitem_calendars)
{
return array_merge((array) $this->categories, (array) $this->subitem_categories);
}
return $this->categories ? $this->categories : array();
}
ilCalendarCategories::getCategoriesInfo ( )

get categories

public

Parameters
@return

Definition at line 295 of file class.ilCalendarCategories.php.

{
return $this->categories_info ? $this->categories_info : array();
}
ilCalendarCategories::getCategoryInfo (   $a_cat_id)

public

Parameters
@return

Definition at line 268 of file class.ilCalendarCategories.php.

{
if(isset($this->categories_info[$a_cat_id]))
{
return $this->categories_info[$a_cat_id];
}
if(in_array($a_cat_id,(array) $this->subitem_categories))
{
foreach($this->categories as $cat_id)
{
if(in_array($a_cat_id,$this->categories_info[$cat_id]['subitem_ids']))
{
return $this->categories_info[$cat_id];
}
}
}
}
ilCalendarCategories::getSubitemCategories (   $a_cat_id)

get subitem categories for a specific category

Parameters
int$a_category_idId of category in question
Returns
array Array of category ids

Definition at line 322 of file class.ilCalendarCategories.php.

{
if(!isset($this->categories_info[$a_cat_id]['subitem_ids']))
{
return array($a_cat_id);
}
return array_merge((array) $this->categories_info[$a_cat_id]['subitem_ids'],array($a_cat_id));
}
ilCalendarCategories::initialize (   $a_mode,
  $a_source_ref_id = 0,
  $a_use_cache = false 
)

initialize visible categories

public

Parameters
intmode
intref_id of root node
Returns

Definition at line 206 of file class.ilCalendarCategories.php.

References $user_id, ilCalendarUserSettings\_getInstance(), ilObject\_lookupObjId(), ilCalendarUserSettings\CAL_SELECTION_MEMBERSHIP, ilCalendarCache\getInstance(), readPDCalendars(), readReposCalendars(), readSelectedItemCalendars(), and wakeup().

{
if($a_use_cache)
{
// Read categories from cache
if($cats = ilCalendarCache::getInstance()->getEntry($this->user_id.':'.$a_mode.':categories:'.(int) $a_source_ref_id))
{
$this->wakeup($cats);
return;
}
}
switch($a_mode)
{
case self::MODE_REMOTE_ACCESS:
include_once('./Services/Calendar/classes/class.ilCalendarUserSettings.php');
{
$this->readPDCalendars();
}
else
{
}
break;
case self::MODE_PERSONAL_DESKTOP_MEMBERSHIP:
$this->readPDCalendars();
break;
case self::MODE_PERSONAL_DESKTOP_ITEMS:
break;
case self::MODE_REPOSITORY:
$this->root_ref_id = $a_source_ref_id;
$this->root_obj_id = ilObject::_lookupObjId($this->root_ref_id);
break;
}
if($a_use_cache)
{
// Store in cache
$this->user_id.':'.$a_mode.':categories:'.(int) $a_source_ref_id,
$this->sleep(),
$a_mode,
'categories'
);
}
}

+ Here is the call graph for this function:

ilCalendarCategories::isEditable (   $a_cat_id)

check if category is editable

public

Parameters
int$a_cat_idcategory id
Returns

Definition at line 375 of file class.ilCalendarCategories.php.

{
return isset($this->categories_info[$a_cat_id]['editable']) and $this->categories_info[$a_cat_id]['editable'];
}
ilCalendarCategories::isVisible (   $a_cat_id)

check if category is visible

public

Parameters
int$a_cat_idcategory id
Returns

Definition at line 387 of file class.ilCalendarCategories.php.

{
return in_array($a_cat_id,$this->categories) or
in_array($a_cat_id,(array) $this->subitem_categories);
}
ilCalendarCategories::prepareCategoriesOfUserForSelection ( )

prepare categories of users for selection

public

Parameters
intuser id
Returns

Definition at line 339 of file class.ilCalendarCategories.php.

References $lng, and ilCalendarCategory\TYPE_USR.

{
global $lng;
$has_personal_calendar = false;
foreach($this->categories_info as $info)
{
if($info['obj_type'] == 'sess')
{
continue;
}
if($info['type'] == ilCalendarCategory::TYPE_USR and $info['editable'])
{
$has_personal_calendar = true;
}
if($info['editable'])
{
$cats[$info['cat_id']] = $info['title'];
}
}
// If there
if(!$has_personal_calendar)
{
$cats[0] = $lng->txt('cal_default_calendar');
}
return $cats ? $cats : array();
}
ilCalendarCategories::readPDCalendars ( )
protected

Read categories of user.

protected

Parameters
@returnvoid

Definition at line 403 of file class.ilCalendarCategories.php.

References ilParticipants\_getMembershipByType(), addSubitemCalendars(), readPrivateCalendars(), readPublicCalendars(), and readSelectedCategories().

Referenced by initialize().

{
global $rbacsystem;
include_once('./Services/Membership/classes/class.ilParticipants.php');
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCalendarCategories::readPrivateCalendars ( )
protected

Read private calendars.

protected

Returns

Definition at line 539 of file class.ilCalendarCategories.php.

References $ilDB, $query, $res, $row, DB_FETCHMODE_OBJECT, ilCalendarSharedStatus\getAcceptedCalendars(), and ilCalendarCategory\TYPE_USR.

Referenced by readPDCalendars(), readReposCalendars(), and readSelectedItemCalendars().

{
global $ilUser;
global $ilDB;
// First read private calendars of user
$query = "SELECT cat_id FROM cal_categories ".
"WHERE type = ".$this->db->quote(ilCalendarCategory::TYPE_USR ,'integer')." ".
"AND obj_id = ".$this->db->quote($this->user_id ,'integer')." ";
$res = $this->db->query($query);
while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
{
$cat_ids[] = $row->cat_id;
}
// Read shared calendars
include_once('./Services/Calendar/classes/class.ilCalendarSharedStatus.php');
if(!$cat_ids = array_merge((array) $cat_ids,ilCalendarSharedStatus::getAcceptedCalendars($ilUser->getId())))
{
return true;
}
// user categories
$query = "SELECT * FROM cal_categories ".
"WHERE type = ".$this->db->quote(ilCalendarCategory::TYPE_USR ,'integer')." ".
"AND ".$ilDB->in('cat_id',$cat_ids,false,'integer')." ".
"ORDER BY title ";
$res = $this->db->query($query);
while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
{
$this->categories[] = $row->cat_id;
$this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
$this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
$this->categories_info[$row->cat_id]['title'] = $row->title;
$this->categories_info[$row->cat_id]['color'] = $row->color;
$this->categories_info[$row->cat_id]['type'] = $row->type;
$this->categories_info[$row->cat_id]['editable'] = $row->obj_id == $ilUser->getId();
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCalendarCategories::readPublicCalendars ( )
protected

Read public calendars.

protected

Returns

Definition at line 509 of file class.ilCalendarCategories.php.

References $query, $res, $row, ilCalendarSettings\_getInstance(), DB_FETCHMODE_OBJECT, and ilCalendarCategory\TYPE_GLOBAL.

Referenced by readPDCalendars(), readReposCalendars(), and readSelectedItemCalendars().

{
global $rbacsystem,$ilAccess;
// global categories
$query = "SELECT * FROM cal_categories ".
"WHERE type = ".$this->db->quote(ilCalendarCategory::TYPE_GLOBAL ,'integer')." ".
"ORDER BY title ";
$res = $this->db->query($query);
while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
{
$this->categories[] = $row->cat_id;
$this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
$this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
$this->categories_info[$row->cat_id]['title'] = $row->title;
$this->categories_info[$row->cat_id]['color'] = $row->color;
$this->categories_info[$row->cat_id]['type'] = $row->type;
$this->categories_info[$row->cat_id]['editable'] = $rbacsystem->checkAccess('edit_event',ilCalendarSettings::_getInstance()->getCalendarSettingsId());
}
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCalendarCategories::readReposCalendars ( )
protected

Read available repository calendars.

protected

Parameters
@return

Definition at line 472 of file class.ilCalendarCategories.php.

References $ilDB, $query, $res, $row, DB_FETCHMODE_OBJECT, readPrivateCalendars(), readPublicCalendars(), and readSelectedCategories().

Referenced by initialize().

{
global $ilAccess,$tree;
global $ilDB;
$query = "SELECT ref_id,obd.obj_id obj_id FROM tree t1 ".
"JOIN object_reference obr ON t1.child = obr.ref_id ".
"JOIN object_data obd ON obd.obj_id = obr.obj_id ".
"WHERE t1.lft >= (SELECT lft FROM tree WHERE child = ".$this->db->quote($this->root_ref_id,'integer')." ) ".
"AND t1.lft <= (SELECT rgt FROM tree WHERE child = ".$this->db->quote($this->root_ref_id,'integer')." ) ".
"AND ".$ilDB->in('type',array('crs','grp','sess'),false,'text')." ".
"AND tree = 1";
$res = $ilDB->query($query);
$obj_ids = array();
while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
{
if($tree->isDeleted($row->ref_id))
{
continue;
}
if($ilAccess->checkAccess('read','',$row->ref_id))
{
$obj_ids[] = $row->obj_id;
}
}
$this->readSelectedCategories($obj_ids);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCalendarCategories::readSelectedCategories (   $a_obj_ids)
protected

read selected categories

protected

Returns

Definition at line 589 of file class.ilCalendarCategories.php.

References $ilDB, $query, $ref_id, $res, $row, ilObject\_getAllReferences(), ilObject\_lookupType(), DB_FETCHMODE_OBJECT, elseif(), and ilCalendarCategory\TYPE_OBJ.

Referenced by readPDCalendars(), readReposCalendars(), and readSelectedItemCalendars().

{
global $ilAccess,$tree;
global $ilDB;
if(!count($a_obj_ids))
{
return true;
}
$query = "SELECT * FROM cal_categories ".
"WHERE type = ".$this->db->quote(ilCalendarCategory::TYPE_OBJ ,'integer')." ".
"AND ".$ilDB->in('obj_id',$a_obj_ids,false,'integer')." ".
"ORDER BY title ";
$res = $this->db->query($query);
while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
{
$editable = false;
$exists = false;
{
if($ilAccess->checkAccess('edit_event','',$ref_id))
{
$exists = true;
$editable = true;
break;
}
elseif($ilAccess->checkAccess('read','',$ref_id))
{
$exists = true;
}
}
if(!$exists)
{
continue;
}
$this->categories_info[$row->cat_id]['editable'] = $editable;
$this->categories[] = $row->cat_id;
$this->categories_info[$row->cat_id]['obj_id'] = $row->obj_id;
$this->categories_info[$row->cat_id]['cat_id'] = $row->cat_id;
$this->categories_info[$row->cat_id]['color'] = $row->color;
#$this->categories_info[$row->cat_id]['title'] = ilObject::_lookupTitle($row->obj_id);
$this->categories_info[$row->cat_id]['title'] = $row->title;
$this->categories_info[$row->cat_id]['obj_type'] = ilObject::_lookupType($row->obj_id);
$this->categories_info[$row->cat_id]['type'] = $row->type;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCalendarCategories::readSelectedItemCalendars ( )
protected

Read categories of selected items.

Parameters
@return

Definition at line 424 of file class.ilCalendarCategories.php.

References ilObjUser\_lookupDesktopItems(), addSubitemCalendars(), readPrivateCalendars(), readPublicCalendars(), and readSelectedCategories().

Referenced by initialize().

{
global $ilUser,$ilAccess;
$obj_ids = array();
$courses = array();
$groups = array();
$sessions = array();
foreach(ilObjUser::_lookupDesktopItems($ilUser->getId(),array('crs','grp','sess')) as $item)
{
if($ilAccess->checkAccess('read','',$item['ref_id']))
{
switch($item['type'])
{
case 'crs':
$courses[] = $item['obj_id'];
break;
case 'sess':
$sessions[] = $item['obj_id'];
break;
case 'grp':
$groups[] = $item['obj_id'];
break;
}
}
}
$this->readSelectedCategories($courses);
$this->readSelectedCategories($sessions);
$this->readSelectedCategories($groups);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCalendarCategories::sleep ( )
protected

Serialize categories.

Returns

Definition at line 173 of file class.ilCalendarCategories.php.

{
return serialize(
array(
'categories' => $this->categories,
'categories_info' => $this->categories_info,
'subitem_categories'=> $this->subitem_categories
)
);
}
ilCalendarCategories::wakeup (   $a_ser)
protected

Load from serialize string.

Parameters
stringserialize categories
Returns

Definition at line 189 of file class.ilCalendarCategories.php.

Referenced by initialize().

{
$info = unserialize($a_ser);
$this->categories = $info['categories'];
$this->categories_info = $info['categories_info'];
$this->subitem_categories = $info['subitem_categories'];
}

+ Here is the caller graph for this function:

Field Documentation

ilCalendarCategories::$categories = array()
protected

Definition at line 50 of file class.ilCalendarCategories.php.

ilCalendarCategories::$categories_info = array()
protected

Definition at line 51 of file class.ilCalendarCategories.php.

ilCalendarCategories::$db
protected

Definition at line 46 of file class.ilCalendarCategories.php.

ilCalendarCategories::$instance = null
staticprotected

Definition at line 44 of file class.ilCalendarCategories.php.

Referenced by _getInstance().

ilCalendarCategories::$root_obj_id = 0
protected

Definition at line 55 of file class.ilCalendarCategories.php.

ilCalendarCategories::$root_ref_id = 0
protected

Definition at line 54 of file class.ilCalendarCategories.php.

ilCalendarCategories::$subitem_categories = array()
protected

Definition at line 52 of file class.ilCalendarCategories.php.

ilCalendarCategories::$user_id
protected

Definition at line 48 of file class.ilCalendarCategories.php.

Referenced by initialize().

const ilCalendarCategories::MODE_PERSONAL_DESKTOP_MEMBERSHIP = 4
const ilCalendarCategories::MODE_REMOTE_ACCESS = 3
const ilCalendarCategories::MODE_REPOSITORY = 2

The documentation for this class was generated from the following file: