/** * Handle on_project_user_removed event * * @param Project $project * @param User $user * @return null */ function resources_handle_on_project_user_removed($project, $user) { $rows = db_execute('SELECT id FROM ' . TABLE_PREFIX . 'project_objects WHERE project_id = ?', $project->getId()); if (is_foreachable($rows)) { $object_ids = array(); foreach ($rows as $row) { $object_ids[] = (int) $row['id']; } // foreach $user_id = $user->getId(); // Assignments cleanup db_execute('DELETE FROM ' . TABLE_PREFIX . 'assignments WHERE user_id = ? AND object_id IN (?)', $user_id, $object_ids); cache_remove('object_starred_by_' . $user_id); cache_remove('object_assignments_*'); cache_remove('object_assignments_*_rendered'); // Starred objects cleanup db_execute('DELETE FROM ' . TABLE_PREFIX . 'starred_objects WHERE user_id = ? AND object_id IN (?)', $user_id, $object_ids); cache_remove('object_starred_by_' . $user_id); // Subscriptions cleanup db_execute('DELETE FROM ' . TABLE_PREFIX . 'subscriptions WHERE user_id = ? AND parent_id IN (?)', $user_id, $object_ids); cache_remove('user_subscriptions_' . $user_id); // remove pinned project PinnedProjects::unpinProject($project, $user); } // if }
/** * Mobile Access Homepage * */ function index() { $pinned_project_ids = PinnedProjects::findProjectIdsByUser($this->logged_user); if (is_foreachable($pinned_project_ids)) { $pinned_projects = Projects::findByIds($pinned_project_ids); } else { $pinned_projects = null; } // if $this->smarty->assign(array("pinned_projects" => $pinned_projects)); }
/** * Show dashboard overview * * @param void * @return null */ function index() { // Welcome message, displayed only to administrators if ($this->logged_user->isAdministrator() && ConfigOptions::getValue('show_welcome_message')) { $this->wireframe->addPageAction(lang('Hide Welcome Message'), assemble_url('admin_settings_hide_welcome_message'), null, array('method' => 'post', 'confirm' => lang('You are about to hide welcome message. If you wish to bring it back later on you can do it from General settings page in Administration. Hide now?'))); $this->smarty->assign(array('show_welcome_message' => true, 'available_modules' => Modules::findNotInstalled())); //BOF: task 05 | AD $this->wireframe->addPageAction(lang('View All'), assemble_url('view_projects_info')); //EOF: task 05 | AD // Regular dashboard } else { if (Project::canAdd($this->logged_user)) { $this->wireframe->addPageAction(lang('New Project'), assemble_url('projects_add')); //BOF: task 05 | AD $this->wireframe->addPageAction(lang('View All'), assemble_url('view_projects_info')); //EOF: task 05 | AD } // if $this->wireframe->addRssFeed($this->owner_company->getName() . ' - ' . lang('Recent activities'), assemble_url('rss', array('token' => $this->logged_user->getToken(true))), FEED_RSS); $pinned_project_ids = PinnedProjects::findProjectIdsByUser($this->logged_user); if (is_foreachable($pinned_project_ids)) { $pinned_projects = Projects::findByIds($pinned_project_ids); } else { $pinned_projects = null; } // if $dashboard_sections = new NamedList(); event_trigger('on_dashboard_sections', array(&$dashboard_sections, &$this->logged_user)); $important_items = new NamedList(); event_trigger('on_dashboard_important_section', array(&$important_items, &$this->logged_user)); $this->smarty->assign(array('show_welcome_message' => false, 'important_items' => $important_items, 'pinned_projects' => $pinned_projects, 'dashboard_sections' => $dashboard_sections, 'online_users' => Users::findWhoIsOnline($this->logged_user), 'grouped_activities' => group_by_date(ActivityLogs::findActiveProjectsActivitiesByUser($this->logged_user, 20), $this->logged_user))); } // if //BOF:mod 20110623 $tabs = new NamedList(); $tabs->add('dashboard', array('text' => 'Active Teams', 'url' => assemble_url('dashboard'))); $tabs->add('home_page', array('text' => 'Home Page', 'url' => assemble_url('goto_home_tab'))); $tabs->add('assigned_action_request', array('text' => 'Assigned Action Requests', 'url' => assemble_url('assigned_action_request'))); $tabs->add('owned_tickets', array('text' => 'Owned Tickets', 'url' => assemble_url('my_tickets'))); $tabs->add('subscribed_tickets', array('text' => 'Subscribed Tickets', 'url' => assemble_url('my_subscribed_tickets'))); $this->smarty->assign('page_tabs', $tabs); $this->smarty->assign('page_tab', 'dashboard'); //EOF:mod 20110623 }
/** * Render pin/unpin icon * * Parameters: * * - project - Selected project * - user - Check pinned state agains this user * * @param array $params * @param Smarty $smarty * @return string */ function smarty_function_project_pinned($params, &$smarty) { $project = array_var($params, 'project'); if (!instance_of($project, 'Project')) { return new InvalidParamError('project', $project, '$project is expected to be an instance of Project class', true); } // if $user = array_var($params, 'user'); if (!instance_of($user, 'User')) { return new InvalidParamError('user', $user, '$user is expected to be an instance of User class', true); } // if require_once SMARTY_PATH . '/plugins/block.link.php'; $repeat = false; if (PinnedProjects::isPinned($project, $user)) { return smarty_block_link(array('href' => $project->getUnpinUrl(), 'title' => lang('Unpin'), 'class' => lang('unpin'), 'method' => 'post'), '<img src="' . get_image_url('icons/pinned.16x16.gif') . '" alt="" />', $smarty, $repeat); } else { return smarty_block_link(array('href' => $project->getPinUrl(), 'title' => lang('Pin to Top'), 'class' => lang('pin_to_top'), 'method' => 'post'), '<img src="' . get_image_url('icons/not-pinned.16x16.gif') . '" alt="" />', $smarty, $repeat); } // if }
/** * Delete from database * * @param void * @return boolean */ function delete() { db_begin_work(); $delete = parent::delete(); if ($delete && !is_error($delete)) { unlink($this->getAvatarPath()); unlink($this->getAvatarPath(true)); ProjectUsers::deleteByUser($this); Assignments::deleteByUser($this); Subscriptions::deleteByUser($this); StarredObjects::deleteByUser($this); PinnedProjects::deleteByUser($this); UserConfigOptions::deleteByUser($this); Reminders::deleteByUser($this); search_index_remove($this->getId(), 'User'); $cleanup = array(); event_trigger('on_user_cleanup', array(&$cleanup)); if (is_foreachable($cleanup)) { foreach ($cleanup as $table_name => $fields) { foreach ($fields as $field) { $condition = ''; if (is_array($field)) { $id_field = array_var($field, 'id'); $name_field = array_var($field, 'name'); $email_field = array_var($field, 'email'); $condition = array_var($field, 'condition'); } else { $id_field = $field . '_id'; $name_field = $field . '_name'; $email_field = $field . '_email'; } // if if ($condition) { db_execute('UPDATE ' . TABLE_PREFIX . "{$table_name} SET {$id_field} = 0, {$name_field} = ?, {$email_field} = ? WHERE {$id_field} = ? AND {$condition}", $this->getName(), $this->getEmail(), $this->getId()); } else { db_execute('UPDATE ' . TABLE_PREFIX . "{$table_name} SET {$id_field} = 0, {$name_field} = ?, {$email_field} = ? WHERE {$id_field} = ?", $this->getName(), $this->getEmail(), $this->getId()); } // if } // foreach } // foreach } // if db_commit(); return true; } else { db_rollback(); return $delete; } // if }
/** * Unpin project * * @param void * @return null */ function unpin() { if ($this->active_project->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if if ($this->request->isSubmitted()) { $unpin = PinnedProjects::unpinProject($this->active_project, $this->logged_user); if ($unpin && !is_error($unpin)) { if ($this->request->isAsyncCall()) { die($this->active_project->getPinUrl()); } else { flash_success("Project ':name' has been removed from list of favorite projects", array('name' => $this->active_project->getName())); } // if } else { if ($this->request->isAsyncCall()) { $this->httpError(HTTP_ERR_OPERATION_FAILED); } else { flash_error("Failed to remove ':name' project from list of favorite projects", array('name' => $this->active_project->getName())); } // if } // if $this->redirectToReferer(assemble_url('dashboard')); } else { $this->httpError(HTTP_ERR_BAD_REQUEST); } // if }
/** * Rebuild user cache * * @param User $user * @return array */ function rebuildUserCache($user) { $value = PinnedProjects::findProjectIdsByUser($user, false); if (empty($value)) { $value = array(); } // if cache_set('user_pinned_projects_' . $user->getId(), $value); return $value; }
/** * Delete project and all realted data * * @param void * @return null */ function delete() { db_begin_work(); $delete = parent::delete(); if ($delete && !is_error($delete)) { ProjectObjects::deleteByProject($this); ProjectUsers::deleteByProject($this); PinnedProjects::deleteByProject($this); search_index_remove($this->getId(), 'Project'); clean_project_permissions_cache($this); event_trigger('on_project_deleted', array($this)); db_commit(); } else { db_rollback(); } // if return $delete; }
/** * Render jump to projects page * * @param void * @return null */ function jump_to_project() { $pinned_projects = null; $active_projects = Projects::findNamesByUser($this->logged_user, PROJECT_STATUS_ACTIVE); if (is_foreachable($active_projects)) { $pinned_project_ids = PinnedProjects::findProjectIdsByUser($this->logged_user); if (is_foreachable($pinned_project_ids)) { $pinned_projects = array(); foreach ($pinned_project_ids as $id) { if (isset($active_projects[$id])) { $pinned_projects[$id] = $active_projects[$id]; unset($active_projects[$id]); } // if } // if } // if } // if $this->smarty->assign(array('active_projects' => $active_projects, 'pinned_projects' => $pinned_projects)); }