'text', 'description' => 'plaintext' )); // Register custom profile fields to config elgg_set_config('digimina:profile_fields', array( 'description' => 'longtext', 'homepage' => 'url', 'eportfolio' => 'url', 'taughtsubjects' => 'digimina_subjects' )); // Profile fields override elgg_register_plugin_hook_handler('profile:fields', 'profile', 'digimina_profile_fields_setup'); // Add admin menu items elgg_register_admin_menu_item('administer', 'digimina'); elgg_register_admin_menu_item('administer', 'competencymodel', 'digimina', 100); elgg_register_admin_menu_item('administer', 'items', 'digimina', 200); elgg_register_admin_menu_item('administer', 'items_import', 'digimina', 300); // Register actions $action_base = elgg_get_plugins_path() . 'digimina/actions/digimina'; elgg_register_action("digimina/edit", "$action_base/edit.php"); elgg_register_action("digimina/dmgroup_delete", "$action_base/dmgroup_delete.php"); elgg_register_action("digimina/dmitem_delete", "$action_base/dmitem_delete.php"); $test_action_base = "$action_base/test"; elgg_register_action("digimina/test/new", "$test_action_base/new.php"); elgg_register_action("digimina/test/estimate", "$test_action_base/estimate.php"); elgg_register_action("digimina/test/item", "$test_action_base/item.php"); elgg_register_action("digimina/test/competency_choice", "$test_action_base/competency_choice.php"); elgg_register_action("digimina/test/review", "$test_action_base/review.php"); elgg_register_action("digimina/test/find_reviewer", "$test_action_base/find_reviewer.php"); elgg_register_action("digimina/test/continue_subcompetency", "$test_action_base/continue_subcompetency.php"); $review_action_base = "$action_base/review"; elgg_register_action("digimina/accept_review", "$review_action_base/accept.php"); elgg_register_action("digimina/reject_review", "$review_action_base/reject.php"); $membership_action_base = "$action_base/membership"; elgg_register_action("digimina/join", "$membership_action_base/join.php"); elgg_register_action("digimina/leave", "$membership_action_base/leave.php"); elgg_register_action("digimina/remove", "$membership_action_base/remove.php"); elgg_register_action("digimina/killrequest", "$membership_action_base/delete_request.php"); elgg_register_action("digimina/addtogroup", "$membership_action_base/add.php"); $admin_action_base = "$action_base/admin"; elgg_register_action("digimina/competencymodel", "$admin_action_base/import_competency_model.php", 'admin'); elgg_register_action("digimina/items_import", "$admin_action_base/items_import.php", "admin"); elgg_register_action("digimina/item_connect", "$admin_action_base/item_connect.php", "admin"); // Replace the default index page elgg_register_plugin_hook_handler('index', 'system', 'digimina_custom_index'); // Permission override elgg_register_plugin_hook_handler('permissions_check', 'object', 'digimina_permissions_check'); // Delete event hook elgg_register_event_handler('delete', 'object', 'digimina_delete_handler'); } /** * Dispatches digimina pages. * URLs take the form of * Competencies: digimina/competencies * Examples: digimina/examples * Help: digimina/help * Desk: digimina/desk * Competency profile: digimina/profile/ * All groups: digimina/all * Member of groups: digimina/member/ * View group: digimina/view// * View test: digimina/viewtest/<guid> * Membership requests: digimina/requests/<guid> * New group: digimina/add/<guid> * Edit group: digimina/edit/<guid> * Index: digimina/index * Test: digimina/test * Review: digimina/review * * Title is ignored * * @param array $page * @return true */ function digimina_page_handler($page) { elgg_load_library('elgg:digimina'); if (!isset($page[0])) { $page[0] = 'index'; } $base_dir = elgg_get_plugins_path() . 'digimina/pages/digimina'; $page_type = $page[0]; switch ($page_type) { case 'competencies': include "{$base_dir}/competencies.php"; break; case 'examples': include "{$base_dir}/examples.php"; break; case 'help': include "{$base_dir}/help.php"; break; case 'desk': include "{$base_dir}/desk.php"; break; case 'profile': set_input('user', $page[1]); include "{$base_dir}/profile.php"; break; case 'all': include "{$base_dir}/world.php"; break; case 'member': set_input('username', $page[1]); include "$base_dir/member.php"; break; case 'view': set_input('guid', $page[1]); include "{$base_dir}/view.php"; break; case 'viewtest': set_input('guid', $page[1]); include "{$base_dir}/viewtest.php"; break; case 'requests': set_input('guid', $page[1]); include "{$base_dir}/requests.php"; break; case 'add': set_input('guid', $page[1]); include "{$base_dir}/add.php"; break; case 'edit': set_input('guid', $page[1]); include "{$base_dir}/edit.php"; break; case 'test': include "{$base_dir}/test.php"; break; case 'review': include "{$base_dir}/review.php"; break; case 'index': default: include "{$base_dir}/index.php"; break; } return true; } /** * Format and return the URL for dmgroups. * * @param ElggObject $entity DigiMina Group object * @return setting URL of dmgroup. */ function digimina_dmgroup_url_handler($entity) { if (!$entity->getOwnerEntity()) { // default to standard view if no owner. return FALSE; } $friendly_title = elgg_get_friendly_title($entity->title); return "digimina/view/{$entity->guid}/$friendly_title"; } /** * Format and return the URL for dmitem. * * @param ElggObject $entity DigiMina Item object * @return URL for dmitem. */ function digimina_dmitem_url_handler($entity) { $friendly_title = elgg_get_friendly_title($entity->title); return "admin/digimina/item_view?guid={$entity->guid}"; } /** * Format and return the URL for dmtests. * * @param ElggObject $entity DigiMinaTest object * @return setting URL of dmtest */ function digimina_dmtest_url_handler($entity) { if (!$entity->getOwnerEntity()) { // default to standard view if no owner return FALSE; } if ($entity->isFinished()) { return "digimina/viewtest/{$entity->getGUID()}"; } else { return "digimina/test"; } } /** * Configure the DigiMina sidebar menu. Triggered on page setup */ function digimina_setup_sidebar_menus() { // Get the page owner entity $page_owner = elgg_get_page_owner_entity(); if (elgg_get_context() == 'digimina') { if (elgg_is_logged_in()) { $url = elgg_get_site_url() . "digimina/desk"; elgg_register_menu_item('page', array( 'name' => 'digimina:1:dashboard', /*translation:Dashboard*/ 'text' => elgg_echo('digimina:dashboard'), 'href' => $url )); $user = elgg_get_logged_in_user_entity(); $url = digimina_competency_profile_url($user); /*translation:My Competency Profile*/ $item = new ElggMenuItem('digimina:2:my:profile', elgg_echo('digimina:my:competency:profile'), $url); elgg_register_menu_item('page', $item); $url = elgg_get_site_url() . "digimina/member/{$user->username}"; $options = array( 'name' => 'digimina:3:dmgroups:member', /*translation:My Groups*/ 'text' => elgg_echo('digimina:my:groups'), 'href' => $url ); elgg_register_menu_item('page', ElggMenuItem::factory($options)); } if ($page_owner instanceof DigiMinaGroup) { if (elgg_is_logged_in() && $page_owner->canEdit() && !$page_owner->isPublicMembership()) { $url = elgg_get_site_url() . "digimina/requests/{$page_owner->getGUID()}"; elgg_register_menu_item('page', array( 'name' => 'digimina:5:gmgroup:requests', /*translation:Manage join requests*/ 'text' => elgg_echo('digimina:dmgroup:membershiprequests'), 'href' => $url )); } } } } /** * Configure the DigiMina footer menu. Triggered on page setup */ function digimina_setup_footer_menus() { $url = elgg_get_site_url() . "digimina/competencies"; /*translation:Competency Model*/ $item = new ElggMenuItem('digimina:competency:model', elgg_echo('digimina:competency:model'), $url); $item->setPriority(100); elgg_register_menu_item('footer', $item); $url = elgg_get_site_url() . "digimina/examples"; /*translation:Example Questions*/ $item = new ElggMenuItem('digimina:examples', elgg_echo('digimina:example:questions'), $url); $item->setPriority(200); elgg_register_menu_item('footer', $item); $url = elgg_get_site_url() . "digimina/help"; /*translation:Help*/ $item = new ElggMenuItem('digimina:help', elgg_echo('digimina:help'), $url); $item->setPriority(300); elgg_register_menu_item('footer', $item); // Register supporter text to footer alternative menu elgg_register_menu_item('footer', array( 'name' => 'digimina:educo_esf', 'href' => false, /*translation:The project has been supported by Eduko programme.*/ 'text' => elgg_echo('digimina:footer:eduko_esf_support'), 'priority' => 10, 'section' => 'alt' )); } /** * Add links/info to entity menu particular to digimina plugin */ function digimina_entity_menu_setup($hook, $type, $return, $params) { if (elgg_in_context('widgets')) { return $return; } $entity = $params['entity']; $handler = elgg_extract('handler', $params, false); if ($handler != 'digimina') { return $return; } $action_base = elgg_get_site_url() . 'action/digimina'; $entity_subtype = $entity->getSubtype(); foreach ($return as $index => $item) { if ($item->getName() == 'delete') { $item->setHref("$action_base/{$entity_subtype}_delete?guid={$entity->guid}"); } else if ($item->getName() == "edit" && $entity->getSubtype() == "dmitem") { unset($return[$index]); if (!$entity->locked) { $options = array( 'name' => 'digimina:dmitem:connect', 'text' => "<span class='elgg-icon digimina-dmitem-connect-icon'></span>", "title" => "Connect with performance level", 'href' => elgg_get_site_url()."admin/digimina/item_connect?guid={$entity->guid}", 'priority' => 50 ); $return[] = ElggMenuItem::factory($options); } } } // Remove access from entity menu foreach ($return as $index => $item) { if ($item->getName() == 'access') { unset($return[$index]); } } if ($entity->subtype != "dmgroup") { return $return; } if (!$entity->isPublicMembership()) { /*translation:closed*/ $membership = elgg_echo('digimina:membership:closed'); } else { /*translation:opened*/ $membership = elgg_echo('digimina:membership:opened'); } $options = array( 'name' => 'digimina:dmgroup:membership', 'text' => ucfirst($membership), 'href' => false, 'priority' => 50 ); $return[] = ElggMenuItem::factory($options); /*translation: %s members*/ $members_count_text = elgg_echo('digimina:dmgroup:members:count', array($entity->getMembers(10, 0, true))); $options = array( 'name' => 'digimina:dmgroup:members:count', 'text' => $members_count_text, 'href' => false, 'priority' => 60 ); $return[] = ElggMenuItem::factory($options); return $return; } /** * Unregistered some of the unwanted menus */ function digimina_unregister_menu_items() { elgg_unregister_menu_item('site', 'activity'); elgg_unregister_menu_item('topbar', 'elgg_logo'); elgg_unregister_menu_item('topbar', 'friends'); } /** * Competency profile URL * * @param ElggUser $user * @return string Competency profile URL */ function digimina_competency_profile_url($user) { return elgg_get_site_url() . "digimina/profile/" . $user->username; } /** * Override default index page */ function digimina_custom_index($hook, $type, $return, $params) { if ($return == true) { // another hook has already replaced the front page return $return; } if (!include_once(dirname(__FILE__) . "/pages/digimina/index.php")) { return false; } // return true to signify that we have handled the front page return true; } /** * Join a user to a dmgroup, clean-up requests * * @param DigiMinaGroup $dmgroup * @param ElggUser $user * * @return bool */ function digimina_join_dmgroup($dmgroup, $user) { $result = $dmgroup->join($user); if ($result) { // Remove join request flags remove_entity_relationship($user->guid, 'dmmembership_request', $dmgroup->guid); return true; } return false; } /** * Replace profile fields with our own. * * @param unknown_type $hook * @param unknown_type $type * @param unknown_type $return * @param unknown_type $params */ function digimina_profile_fields_setup($hook, $type, $return, $params) { return elgg_get_config('digimina:profile_fields'); } /** * Extend htmlawed config to allow iframe. * * @param unknown_type $hook * @param unknown_type $type * @param unknown_type $return * @param unknown_type $params */ function digimina_htmlawed_config($hook, $type, $return, $params) { // Allow iframe $return['elements'] = "*i +iframe"; return $return; } /** * Extend permissions checking to allow reviewer to edit test and answers. * * @param unknown_type $hook * @param unknown_type $entity_type * @param unknown_type $returnvalue * @param unknown_type $params */ function digimina_permissions_check($hook, $entity_type, $returnvalue, $params) { global $CONFIG; if (elgg_get_context() == 'dmreview') { if (elgg_is_logged_in()) { if (($params['entity']->getSubtype() == 'dmtest')) { $user_guid = elgg_get_logged_in_user_guid(); $query = "SELECT * FROM {$CONFIG->dbprefix}digimina_review WHERE user_guid = $user_guid AND test_guid = {$params['entity']->guid} AND status = 'accepted'"; if (get_data($query)) { return true; } } elseif ($params['entity']->getSubtype() == 'dmanswer') { $user_guid = elgg_get_logged_in_user_guid(); $query = "SELECT * FROM {$CONFIG->dbprefix}digimina_review WHERE user_guid = $user_guid AND test_guid = {$params['entity']->getContainerGUID()} AND status = 'accepted'"; if (get_data($query)) { return true; } } } } } /** * Remove data from review table if test is deleted. * * @param unknown_type $event * @param unknown_type $object_type * @param unknown_type $object_type */ function digimina_delete_handler($event, $object_type, $object) { global $CONFIG; if ($object_type == 'object') { if ($object instanceof DigiMinaTest) { $query = "DELETE FROM {$CONFIG->dbprefix}digimina_review WHERE test_guid = {$object->guid}"; delete_data($query); } } }