/** * 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 }
/** * 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 }