/** * Add an artefact in the tracker * * @return Tracker_Artifact or false if an error occured */ public function create(Tracker $tracker, array $fields_data, PFUser $user, $submitted_on, $send_notification) { $artifact = $this->getBareArtifact($tracker, $user, $submitted_on); if (!$this->fields_validator->validate($artifact, $fields_data)) { return; } $use_artifact_permissions = 0; $id = $this->artifact_dao->create($tracker->id, $user->getId(), $submitted_on, $use_artifact_permissions); if (!$id) { return; } $artifact->setId($id); $changeset_id = $this->changeset_creator->create($artifact, $fields_data, $user, $submitted_on); if (!$changeset_id) { return; } $changeset = new Tracker_Artifact_Changeset($changeset_id, $artifact, $artifact->getSubmittedBy(), $artifact->getSubmittedOn(), $user->getEmail()); if ($send_notification) { $changeset->notify(); } return $artifact; }
/** * Retrieve all linked artifacts and keep only those that belong to backlog tracker * * We need to keep list of ids we already looked at so we avoid cycles. * * @param int $backlog_tracker_id * @param array $artifacts */ private function filterBacklogIds($backlog_tracker_id, array $artifacts) { $artifacts_to_inspect = array(); foreach ($this->dao->getLinkedArtifactsByIds($artifacts, $this->inspected_ids) as $artifact_row) { $artifacts_to_inspect[] = $artifact_row['id']; if ($artifact_row['tracker_id'] == $backlog_tracker_id) { $this->backlog_ids[$artifact_row['id']] = true; } $this->inspected_ids[] = $artifact_row['id']; } if (count($artifacts_to_inspect) > 0) { $this->filterBacklogIds($backlog_tracker_id, $artifacts_to_inspect); } }
/** * Process the request * * @param Tracker_IDisplayTrackerLayout $layout Displays the page header and footer * @param Codendi_Request $request The data coming from the user * @param User $current_user The user who mades the request * * @return void */ public function process(Tracker_IDisplayTrackerLayout $layout, $request, $current_user) { switch ($request->get('func')) { case 'fetch-artifacts': $read_only = false; $prefill_removed_values = array(); $only_rows = true; $this_project_id = $this->getTracker()->getProject()->getGroupId(); $hp = Codendi_HTMLPurifier::instance(); $ugroups = $current_user->getUgroups($this_project_id, array()); $ids = $request->get('ids'); //2, 14, 15 $tracker = array(); $result = array(); //We must retrieve the last changeset ids of each artifact id. $dao = new Tracker_ArtifactDao(); foreach ($dao->searchLastChangesetIds($ids, $ugroups, $current_user->isSuperUser()) as $matching_ids) { $tracker_id = $matching_ids['tracker_id']; $tracker = $this->getTrackerFactory()->getTrackerById($tracker_id); $project = $tracker->getProject(); if ($tracker->userCanView()) { $trf = Tracker_ReportFactory::instance(); $report = $trf->getDefaultReportsByTrackerId($tracker->getId()); if ($report) { $renderers = $report->getRenderers(); // looking for the first table renderer foreach ($renderers as $renderer) { if ($renderer->getType() === Tracker_Report_Renderer::TABLE) { $key = $this->id . '_' . $report->id . '_' . $renderer->getId(); $result[$key] = $renderer->fetchAsArtifactLink($matching_ids, $this->getId(), $read_only, $prefill_removed_values, $only_rows); $head = '<div>'; $project_name = ''; if ($project->getGroupId() != $this_project_id) { $project_name = ' (<abbr title="' . $hp->purify($project->getPublicName(), CODENDI_PURIFIER_CONVERT_HTML) . '">'; $project_name .= $hp->purify($project->getUnixName(), CODENDI_PURIFIER_CONVERT_HTML); $project_name .= '</abbr>)'; } $head .= '<h2 class="tracker-form-element-artifactlink-tracker_' . $tracker->getId() . '">'; $head .= $hp->purify($tracker->getName(), CODENDI_PURIFIER_CONVERT_HTML) . $project_name; $head .= '</h2>'; //if ($artifact) { // $title = $hp->purify('link a '. $tracker->getItemName(), CODENDI_PURIFIER_CONVERT_HTML); // $head .= '<a href="'.TRACKER_BASE_URL.'/?tracker='.$tracker_id.'&func=new-artifact-link&id='.$artifact->getId().'" class="tracker-form-element-artifactlink-link-new-artifact">'. 'create a new '.$hp->purify($tracker->getItemName(), CODENDI_PURIFIER_CONVERT_HTML) .'</a>'; //} $result[$key]['head'] = $head . $result[$key]['head']; break; } } } } } if ($result) { $head = array(); $rows = array(); foreach ($result as $key => $value) { $head[$key] = $value["head"]; $rows[$key] = $value["rows"]; } header('Content-type: application/json'); echo json_encode(array('head' => $head, 'rows' => $rows)); } exit; break; case 'fetch-aggregates': $read_only = false; $prefill_removed_values = array(); $only_rows = true; $only_one_column = false; $extracolumn = Tracker_Report_Renderer_Table::EXTRACOLUMN_UNLINK; $read_only = true; $use_data_from_db = false; $ugroups = $current_user->getUgroups($this->getTracker()->getGroupId(), array()); $ids = $request->get('ids'); //2, 14, 15 $tracker = array(); $json = array('tabs' => array()); $dao = new Tracker_ArtifactDao(); foreach ($dao->searchLastChangesetIds($ids, $ugroups, $current_user->isSuperUser()) as $matching_ids) { $tracker_id = $matching_ids['tracker_id']; $tracker = $this->getTrackerFactory()->getTrackerById($tracker_id); $project = $tracker->getProject(); if ($tracker->userCanView()) { $trf = Tracker_ReportFactory::instance(); $report = $trf->getDefaultReportsByTrackerId($tracker->getId()); if ($report) { $renderers = $report->getRenderers(); // looking for the first table renderer foreach ($renderers as $renderer) { if ($renderer->getType() === Tracker_Report_Renderer::TABLE) { $key = $this->id . '_' . $report->id . '_' . $renderer->getId(); $columns = $renderer->getTableColumns($only_one_column, $use_data_from_db); $extracted_fields = $renderer->extractFieldsFromColumns($columns); $json['tabs'][] = array('key' => $key, 'src' => $renderer->fetchAggregates($matching_ids, $extracolumn, $only_one_column, $columns, $extracted_fields, $use_data_from_db, $read_only)); break; } } } } } header('Content-type: application/json'); echo json_encode($json); exit; break; default: parent::process($layout, $request, $current_user); break; } }
public function plugin_statistics_service_usage($params) { $dao = new Tracker_ArtifactDao(); $start_date = strtotime($params['start_date']); $end_date = strtotime($params['end_date']); $number_of_open_artifacts_between_two_dates = $dao->searchSubmittedArtifactBetweenTwoDates($start_date, $end_date); $number_of_closed_artifacts_between_two_dates = $dao->searchClosedArtifactBetweenTwoDates($start_date, $end_date); $params['csv_exporter']->buildDatas($number_of_open_artifacts_between_two_dates, "Trackers v5 - Opened Artifacts"); $params['csv_exporter']->buildDatas($number_of_closed_artifacts_between_two_dates, "Trackers v5 - Closed Artifacts"); }
/** * get all children of a given type of any of the parent items */ private function getIdsOfChildItemsOfOneTrackerType($ids_of_parent_items_to_search_in, $tracker_id) { $search = $this->artifact_dao->getLinkedArtifactsOfArtifactsOfTrackerTypeAsString($ids_of_parent_items_to_search_in, $tracker_id); return (string) $search['artifact_ids']; }
/** * get stats for this tracker * * @return array */ public function getStats() { if (!isset($this->cache_stats)) { $dao = new Tracker_ArtifactDao(); $this->cache_stats = $dao->searchStatsForTracker($this->id)->getRow(); } return $this->cache_stats; }
/** * Get artifacts that responds to some criteria * * @param date $date The date criteria * @param Integer $trackerId The Tracker Id * * @return Array */ public function getArtifactsByCriterias($date, $trackerId = null) { $artifacts = array(); $dao = new Tracker_ArtifactDao(); $dar = $dao->getArtifactsBySubmittedOnDate($trackerId, $date); if ($dar && !$dar->isError()) { $artifactFactory = Tracker_ArtifactFactory::instance(); foreach ($dar as $row) { $artifacts[] = $artifactFactory->getArtifactById($row['artifact_id']); } } return $artifacts; }
private function unsubscribe(PFUser $user) { $this->artifact_dao->createUnsubscribeNotification($this->artifact->getId(), $user->getId()); }
private function getPaginatedChildrenOfArtifact(Tracker_Artifact $artifact, $limit, $offset) { return $this->artifact_dao->getPaginatedChildren($artifact->getId(), $limit, $offset)->instanciateWith(array($this->getArtifactFactory(), 'getInstanceFromRow')); }