/** * Unsubscribe specific user from a given object * * @param void * @return null */ function unsubscribe_user() { if (!$this->active_object->canEdit($this->logged_user)) { $this->httpError(HTTP_ERR_NOT_FOUND, null, true, $this->request->isApiCall()); } // if if ($this->request->isSubmitted()) { $user = null; $user_id = (int) $this->request->get('user_id'); if ($user_id) { $user = Users::findById($user_id); } // if if (!instance_of($user, 'User')) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if $subscription = Subscriptions::findById(array('user_id' => $user->getId(), 'parent_id' => $this->active_object->getId())); if (!instance_of($subscription, 'Subscription')) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if $delete = $subscription->delete(); if ($delete && !is_error($delete)) { flash_success(':user_name has been unsubscribed from :object_name :object_type', array('user_name' => $user->getDisplayName(), 'object_name' => $this->active_object->getName(), 'object_type' => $this->active_object->getVerboseType(true))); } else { flash_error('Failed to unsubscribe :user_name from :object_name :object_type', array('user_name' => $user->getDisplayName(), 'object_name' => $this->active_object->getName(), 'object_type' => $this->active_object->getVerboseType(true))); } // if $this->redirectToReferer($this->active_object->getSubscriptionsUrl()); } else { $this->httpError(HTTP_ERR_BAD_REQUEST); } // if }
/** * Show timetracking module homepage * * @param void * @return null */ function index() { if ($this->request->isApiCall()) { $this->serveData(TimeRecords::findByProject($this->active_project, STATE_VISIBLE, $this->logged_user->getVisibility()), 'time_records'); } else { // Content for widget popup if ($this->request->get('for_popup_dialog')) { $this->_render_popup_content(); // Classic page } else { if (instance_of($this->active_object, 'ProjectObject')) { $this->wireframe->addPageMessage(lang('Time spent on <a href=":url">:name</a> :type', array('url' => $this->active_object->getViewUrl(), 'name' => $this->active_object->getName(), 'type' => $this->active_object->getVerboseType(true))), 'info'); } // if $timetracking_data = array('record_date' => new DateValue(time() + get_user_gmt_offset($this->logged_user)), 'user_id' => $this->logged_user->getId()); $per_page = 20; $page = (int) $this->request->get('page'); if ($page < 1) { $page = 1; } // if if (instance_of($this->active_object, 'ProjectObject')) { list($timerecords, $pagination) = TimeRecords::paginateByObject($this->active_object, $page, $per_page, STATE_VISIBLE, $this->logged_user->getVisibility()); } else { list($timerecords, $pagination) = TimeRecords::paginateByProject($this->active_project, $page, $per_page, STATE_VISIBLE, $this->logged_user->getVisibility()); } // if // Mark this objects as read if (is_foreachable($timerecords)) { foreach ($timerecords as $timerecord) { ProjectObjectViews::log($timerecord, $this->logged_user); } // foreach } // if $this->smarty->assign(array('timetracking_data' => $timetracking_data, 'timerecords' => $timerecords, 'pagination' => $pagination, 'can_add' => TimeRecord::canAdd($this->logged_user, $this->active_project))); js_assign('mass_update_url', assemble_url('project_time_mass_update', array('project_id' => $this->active_project->getId()))); } // if } // if }