/**
  * Collect, into an array, logged git pushes matching a given git repository for the given duration.
  *
  * @param GitRepository $repository Git repository we want to fetch its pushes
  *
  * @return Array
  */
 private function getRepositoryPushesByWeek(GitRepository $repository)
 {
     $pushes = array();
     $gitLogDao = new Git_LogDao();
     foreach ($this->weekNum as $key => $w) {
         $res = $gitLogDao->getRepositoryPushesByWeek($repository->getId(), $w, $this->year[$key]);
         if ($res && !$res->isError() && $res->valid()) {
             $row = $res->getRow();
             $pushes[$key] = intval($row['pushes']);
             if ($pushes[$key] > 0) {
                 $this->displayChart = true;
                 $this->legend = $repository->getFullName();
             }
         }
         $pushes = array_pad($pushes, $this->weeksNumber, 0);
     }
     return $pushes;
 }
 /**
  * Compute the content of the widget
  *
  * @return String
  */
 public function getContent()
 {
     $dao = new Git_LogDao();
     $um = UserManager::instance();
     $user = $um->getCurrentUser();
     $date = $_SERVER['REQUEST_TIME'] - $this->pastDays * 24 * 60 * 60;
     $result = $dao->getLastPushesRepositories($user->getId(), $date);
     $content = '';
     $project = '';
     $dh = new DateHelper();
     if ($result && !$result->isError()) {
         foreach ($result as $entry) {
             if (!empty($entry['repository_namespace'])) {
                 $namespace = $entry['repository_namespace'] . "/";
             } else {
                 $namespace = '';
             }
             $dar = $dao->getLastPushesByUser($user->getId(), $entry['repository_id'], $this->offset, $date);
             if ($dar && !$dar->isError() && $dar->rowCount() > 0) {
                 if ($project != $entry['group_name']) {
                     if (!empty($project)) {
                         $content .= '</fieldset>';
                     }
                     $project = $entry['group_name'];
                     $content .= '<fieldset>
                                  <legend id="plugin_git_user_pushes_widget_project_' . $project . '" class="' . Toggler::getClassname('plugin_git_user_pushes_widget_project_' . $project) . '">
                                  <span title="' . $GLOBALS['Language']->getText('plugin_git', 'tree_view_project') . '">
                                  <b>' . $project . '</b>
                                  </span>
                                  </legend>
                                  <a href="' . $this->pluginPath . '/index.php?group_id=' . $entry['group_id'] . '">[ ' . $GLOBALS['Language']->getText('plugin_git', 'widget_user_pushes_details') . ' ]</a>';
                 }
                 $content .= '<fieldset>
                              <legend id="plugin_git_user_pushes_widget_repo_' . $project . $namespace . $entry['repository_name'] . '" class="' . Toggler::getClassname('plugin_git_user_pushes_widget_repo_' . $project . $namespace . $entry['repository_name']) . '">
                              <span title="' . $GLOBALS['Language']->getText('plugin_git', 'tree_view_repository') . '">
                              ' . $namespace . $entry['repository_name'] . '
                              </span>
                              </legend>
                              ' . html_build_list_table_top(array($GLOBALS['Language']->getText('plugin_git', 'tree_view_date'), $GLOBALS['Language']->getText('plugin_git', 'tree_view_commits')));
                 $i = 0;
                 $hp = Codendi_HTMLPurifier::instance();
                 foreach ($dar as $row) {
                     $content .= '<tr class="' . html_get_alt_row_color(++$i) . '">
                                      <td><span title="' . $dh->timeAgoInWords($row['push_date'], true) . '">' . $hp->purify(format_date($GLOBALS['Language']->getText('system', 'datefmt'), $row['push_date'])) . '</span></td>
                                      <td>
                                          <a href="' . $this->pluginPath . '/index.php/' . $entry['group_id'] . '/view/' . $entry['repository_id'] . '/">
                                          ' . $hp->purify($row['commits_number']) . '
                                          </a>
                                      </td>
                                  </tr>';
                 }
                 $content .= "</table>\n                                 </fieldset>";
             } else {
                 $content .= $GLOBALS['Language']->getText('plugin_git', 'widget_user_pushes_no_content');
             }
         }
     } else {
         $content = $GLOBALS['Language']->getText('plugin_git', 'widget_user_pushes_no_content');
     }
     return $content;
 }
示例#3
0
 /**
  * TREE SUBVIEW
  */
 protected function _tree($params = array())
 {
     if (empty($params)) {
         $params = $this->getData();
     }
     if (!empty($params['repository_list'])) {
         //echo '<h3>'.$this->getText('tree_title_available_repo').' <a href="#" onclick="$(\'help_tree\').toggle();"> [?]</a></h3>';
         if (!empty($params['repositories_owners'])) {
             $current_id = null;
             if (!empty($params['user'])) {
                 $current_id = (int) $params['user'];
             }
             $select = '<select name="user" onchange="this.form.submit()">';
             $uh = UserHelper::instance();
             $selected = 'selected="selected"';
             $select .= '<option value="" ' . ($current_id ? '' : $selected) . '>' . $this->getText('tree_title_available_repo') . '</option>';
             foreach ($params['repositories_owners'] as $owner) {
                 $select .= '<option value="' . (int) $owner['repository_creation_user_id'] . '" ' . ($owner['repository_creation_user_id'] == $current_id ? $selected : '') . '>' . $uh->getDisplayName($owner['user_name'], $owner['realname']) . '</option>';
             }
             $select .= '</select>';
             echo '<form action="" method="GET">';
             echo '<p>';
             echo '<input type="hidden" name="action" value="index" />';
             echo '<input type="hidden" name="group_id" value="' . (int) $this->groupId . '" />';
             echo $select;
             echo '<noscript><input type="submit" value="' . $GLOBALS['Language']->getText('global', 'btn_submit') . '" /></noscript>';
             echo '</p>';
             echo '</form>';
         }
         $this->help('tree', array('display' => 'none'));
         $lastPushes = array();
         $dao = new Git_LogDao();
         foreach ($params['repository_list'] as $repository) {
             $id = $repository['repository_id'];
             $dar = $dao->searchLastPushForRepository($id);
             if ($dar && !$dar->isError() && $dar->rowCount() == 1) {
                 $lastPushes[$id] = $dar->getRow();
             }
         }
         $strategy = new GitViewsRepositoriesTraversalStrategy_Tree($this, $lastPushes);
         echo $strategy->fetch($params['repository_list'], $this->user);
     } else {
         echo "<h3>" . $this->getText('tree_msg_no_available_repo') . "</h3>";
     }
 }
示例#4
0
 /**
  * Retrieve logged pushes statistics for CSV export
  *
  * @param Statistics_Formatter $formatter instance of statistics formatter class
  *
  * @return Void
  */
 private function retrieveLoggedPushesStatistics(Statistics_Formatter $formatter)
 {
     $gitIndex[] = $GLOBALS['Language']->getText('plugin_statistics', 'scm_month');
     $gitPushes[] = $GLOBALS['Language']->getText('plugin_statistics', 'scm_git_total_pushes');
     $gitCommits[] = $GLOBALS['Language']->getText('plugin_statistics', 'scm_git_total_commits');
     $gitUsers[] = $GLOBALS['Language']->getText('plugin_statistics', 'scm_git_users');
     $gitRepo[] = $GLOBALS['Language']->getText('plugin_statistics', 'scm_git_repositories');
     $gitLogDao = new Git_LogDao();
     $dar = $gitLogDao->totalPushes($formatter->startDate, $formatter->endDate, $formatter->groupId);
     if ($dar && !$dar->isError() && $dar->rowCount() > 0) {
         foreach ($dar as $row) {
             $gitIndex[] = $row['month'] . " " . $row['year'];
             $gitPushes[] = intval($row['pushes_count']);
             $gitCommits[] = intval($row['commits_count']);
             $gitUsers[] = intval($row['users']);
             $gitRepo[] = intval($row['repositories']);
         }
         $formatter->addLine($gitIndex);
         $formatter->addLine($gitPushes);
         $formatter->addLine($gitCommits);
         $formatter->addLine($gitUsers);
         $formatter->addLine($gitRepo);
     }
 }
示例#5
0
 /**
  * Returns the SQL request & form field for the Git pushes
  *
  * @param Array $params Log parameters
  *
  * @return Void
  */
 function logsDaily($params)
 {
     $params['logs'][] = array('sql' => $this->_dao->getSqlStatementForLogsDaily($params['group_id'], $params['logs_cond']), 'field' => $GLOBALS['Language']->getText('plugin_git', 'logsdaily_field'), 'title' => $GLOBALS['Language']->getText('plugin_git', 'logsdaily_title'));
 }