guid] = $_SESSION['user']->name . " (" . elgg_echo('portfolio:Myself') . ")"; } foreach( $targets as $target ) { $tgts[$target->guid] = $target->name; } return $tgts; } function getPortfolioLecturer() { $lects = array(); // this row is user self; if (isset($_SESSION['user'])) { $lects[$_SESSION['user']->guid] = $_SESSION['user']->name; } // TODO lecturer list return $lects; } function canReflect($target) { if (!is_array($target)) $target = array($target); if (in_array($_SESSION['user']->getGUID(), $target)) return true; $targets = get_entities_from_relationship('member',page_owner(),false,'group','',0, '', 9999, 0, false, 0); foreach ($targets as $tar) { if (in_array($tar->getGUID(), $target)) return true; } return false; } function saveTargetRealations($task, $targets) { remove_entity_relationships($task, "hasTask", true, ""); foreach ($targets as $target) { add_entity_relationship($target, "hasTask", $task); } } function saveSubTask($tasks, $subtask) { remove_entity_relationships($subtask, "subTasks", true, ""); foreach ($tasks as $task) { add_entity_relationship($task, "subTasks", $subtask); } } function getPossibleParentTasks($guid) { if (!$guid) return false; $parent_tasks = get_entities_from_metadata("hassubtasks", "true", "object", "task", page_owner(), 9999, 0, "", 0, false); $ptid = array(); foreach ($parent_tasks as $parent_task) { if ($parent_task->getGUID() != $guid) { $ptid[$parent_task->getGUID()] = $parent_task->title; } } return $ptid; } function getSubTaskEntities($task) { return get_entities_from_relationship("subTasks", $task, false, "object", "task", page_owner(), "", 9999, 0, false, 0); } function getParentTaskEntities($subtask) { if (!$subtask) return false; return get_entities_from_relationship("subTasks", $subtask, true, "object", "task", page_owner(), "", 9999, 0, false, 0); } function getParentTaskIds($subtask) { if (!$subtask) return false; $parent_tasks = getParentTaskEntities($subtask); if (!$parent_tasks) { return false; } $ptid = array(); foreach ($parent_tasks as $parent_task) { $ptid []= $parent_task->getGUID(); } return $ptid; } function getTaskData($task_guid) { $task = get_entity($task_guid); if ($task && $task->task) { return $task; } return false; } // Shortens text and strips all the tags function shortenTextForCalendar($text, $max_length) { // Let us strip tags at first $text = strip_tags($text); // If the text length is smaller than we need, just return the text if (strlen($text)<=$max_length) return $text; // Shorten the text $text = $text.""; $text = substr($text, 0, $max_length); $text = substr($text, 0, strrpos($text, ' ')); // If the text could not have been shortened, use the force method if (strlen($text)>$max_length) $text = substr($text, 0, $max_length-3); $text = $text."..."; return $text; } // Return all tasks assigned to a user function getDayCalendarEvents($date, $for_whom=null) { if (empty($for_whom)) { return false; } $all_tasks = array(); $tasks_for_myself = get_entities_from_relationship("hasTask", $for_whom, false, "object", "task", 0, "", 9999, 0, false, 0); if (is_array($tasks_for_myself) && sizeof($tasks_for_myself) > 0) { $all_tasks = $tasks_for_myself; } $my_groups = get_entities_from_relationship('member',$for_whom,false,'group','',0, '', 9999, 0, false, 0); foreach ($my_groups as $mg) { $group_tasks = get_entities_from_relationship("hasTask", $mg->getGUID(), false, "object", "task", 0, "", 9999, 0, false, 0); if (is_array($group_tasks) && sizeof($group_tasks) > 0) { foreach ($group_tasks as $single_group_task) { if (!in_array($single_group_task, $all_tasks)) { array_push($all_tasks, $single_group_task); } } } } $suitable_tasks = array(); foreach ($all_tasks as $task) { $startline = $task->startline; $deadline = $task->deadline; if ($startline && $deadline) { if (($date >= $startline) && ($date <= $deadline)) { array_push($suitable_tasks, $task); } } } return $suitable_tasks; } ?>