ILIAS  Release_3_10_x_branch Revision 61812
 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)
 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

Data Fields

const MODE_PERSONAL_DESKTOP = 1
const MODE_REPOSITORY = 2

Protected Member Functions

 __construct ($a_usr_id=0)
 Singleton instance.
 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 36 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 62 of file class.ilCalendarCategories.php.

{
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 124 of file class.ilCalendarCategories.php.

References $res, and ilCalendarCategory\TYPE_USR.

Referenced by ilCalendarShared\getSharedCalendarsForUser().

{
global $ilDB;
$query = "SELECT * FROM cal_categories ".
"WHERE cat_id = ".$ilDB->quote($a_cal_id)." ".
"AND obj_id = ".$ilDB->quote($a_usr_id)." ".
"AND type = ".$ilDB->quote(ilCalendarCategory::TYPE_USR)." ";
$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 99 of file class.ilCalendarCategories.php.

References $res, 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)." ".
"AND type = ".$ilDB->quote(ilCalendarCategory::TYPE_OBJ)." ";
$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 553 of file class.ilCalendarCategories.php.

References $res, DB_FETCHMODE_OBJECT, and ilUtil\quoteArray().

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 od1.obj_id IN (".implode(',',ilUtil::quoteArray($course_ids)).') '.
"AND or2.deleted = '0000-00-00 00:00:00'";
$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 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 213 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 202 of file class.ilCalendarCategories.php.

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

public

Parameters
@return

Definition at line 175 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 229 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 
)

initialize visible categories

public

Parameters
intmode
intref_id of root node
Returns

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

References ilCalendarUserSettings\_getInstance(), ilObject\_lookupObjId(), ilCalendarUserSettings\CAL_SELECTION_MEMBERSHIP, readPDCalendars(), readReposCalendars(), and readSelectedItemCalendars().

{
switch($a_mode)
{
case self::MODE_PERSONAL_DESKTOP:
include_once('./Services/Calendar/classes/class.ilCalendarUserSettings.php');
{
$this->readPDCalendars();
}
else
{
}
break;
case self::MODE_REPOSITORY:
$this->root_ref_id = $a_source_ref_id;
$this->root_obj_id = ilObject::_lookupObjId($this->root_ref_id);
break;
}
}

+ 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 282 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 294 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 246 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 310 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 445 of file class.ilCalendarCategories.php.

References $res, DB_FETCHMODE_OBJECT, ilCalendarSharedStatus\getAcceptedCalendars(), ilUtil\quoteArray(), and ilCalendarCategory\TYPE_USR.

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

{
global $ilUser;
// First read private calendars of user
$query = "SELECT cat_id FROM cal_categories ".
"WHERE type = ".$this->db->quote(ilCalendarCategory::TYPE_USR)." ".
"AND obj_id = ".$this->db->quote($this->user_id)." ";
$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)." ".
"AND cat_id IN (".implode(',',ilUtil::quoteArray($cat_ids)).') '.
"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 415 of file class.ilCalendarCategories.php.

References $res, 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)." ".
"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 379 of file class.ilCalendarCategories.php.

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

Referenced by initialize().

{
global $ilAccess,$tree;
$query = "SELECT ref_id,obd.obj_id AS obj_id FROM tree AS t1 ".
"JOIN object_reference AS obr ON t1.child = obr.ref_id ".
"JOIN object_data AS obd ON obd.obj_id = obr.obj_id ".
"WHERE t1.lft >= (SELECT lft FROM tree WHERE child = ".$this->db->quote($this->root_ref_id)." ) ".
"AND t1.lft <= (SELECT rgt FROM tree WHERE child = ".$this->db->quote($this->root_ref_id)." ) ".
"AND type IN('crs','grp','sess') ".
"AND tree = 1";
$res = $this->db->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 494 of file class.ilCalendarCategories.php.

References $ref_id, $res, ilObject\_getAllReferences(), ilObject\_lookupType(), DB_FETCHMODE_OBJECT, ilUtil\quoteArray(), and ilCalendarCategory\TYPE_OBJ.

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

{
global $ilAccess,$tree;
if(!count($a_obj_ids))
{
return true;
}
$query = "SELECT * FROM cal_categories ".
"WHERE type = ".$this->db->quote(ilCalendarCategory::TYPE_OBJ)." ".
"AND obj_id IN (".implode(',',ilUtil::quoteArray($a_obj_ids)).') '.
"ORDER BY title ";
$res = $this->db->query($query);
while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
{
$editable = false;
$exists = false;
foreach(ilObject::_getAllReferences($row->obj_id) as $ref_id)
{
if($tree->isDeleted($ref_id))
{
continue;
}
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 331 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:

Field Documentation

ilCalendarCategories::$categories = array()
protected

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

ilCalendarCategories::$categories_info = array()
protected

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

ilCalendarCategories::$db
protected

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

ilCalendarCategories::$instance = null
staticprotected

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

Referenced by _getInstance().

ilCalendarCategories::$root_obj_id = 0
protected

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

ilCalendarCategories::$root_ref_id = 0
protected

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

ilCalendarCategories::$subitem_categories = array()
protected

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

ilCalendarCategories::$user_id
protected

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

const ilCalendarCategories::MODE_PERSONAL_DESKTOP = 1
const ilCalendarCategories::MODE_REPOSITORY = 2

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

Referenced by ilCalendarBlockGUI\initCategories().


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