/** * Get recent activity for a repository * * @param Repository $repository * @param int $from_days_before * @return array */ function getRecentActivity($repository, $from_days_before = 15) { $from = new DateTimeValue($from_days_before - 1 . ' days ago'); $last_commit = $repository->getLastcommit(); $beginning_of_day = $from->beginningOfDay(); $max_commits = Commits::count(array("parent_id = ? AND created_on >= ? GROUP BY DAY(created_on) ORDER BY row_count DESC LIMIT 1", $repository->getId(), $beginning_of_day)); $from_days_before--; for ($i = $from_days_before; $i >= 0; $i--) { $date = new DateTimeValue($i . 'days ago'); $this_date_beginning = $date->beginningOfDay(); $this_date_end = $date->endOfDay(); $commits_count = Commits::count(array("parent_id = ? AND created_on >= ? AND created_on <= ?", $repository->getId(), $this_date_beginning, $this_date_end)); $activity[$i]['commits'] = $commits_count; $activity[$i]['created_on'] = date('F d, Y', $date->getTimestamp()); $activity[$i]['percentage'] = round($commits_count * 100 / $max_commits); } return $activity; }
/** * Return upcoming objects in a given projects * * @param User $user * @param Project $project * @param array $types * @param integer $page * @param integer $per_page * @return array */ function findUpcoming($user, $project = null, $types = null, $page = null, $per_page = null) { if (instance_of($project, 'Project')) { $type_filter = ProjectUsers::getVisibleTypesFilterByProject($user, $project, $types); } else { $type_filter = ProjectUsers::getVisibleTypesFilter($user, array(PROJECT_STATUS_ACTIVE), $types); } if ($type_filter) { $today = new DateTimeValue(); $today->advance(get_user_gmt_offset()); $newer_than = $today->endOfDay(); $conditions = array($type_filter . ' AND due_on > ? AND state >= ? AND visibility >= ? AND completed_on IS NULL', $newer_than, STATE_VISIBLE, $user->getVisibility()); if ($page !== null && $per_page !== null) { return ProjectObjects::paginate(array('conditions' => $conditions, 'order' => 'due_on, priority DESC'), $page, $per_page); } else { return ProjectObjects::find(array('conditions' => $conditions, 'order' => 'due_on, priority DESC')); } // if } // if return null; }
function getRangeContactsByBirthday($from, $to, $tags = '', $project = null) { if (!$from instanceof DateTimeValue || !$to instanceof DateTimeValue || $from->getTimestamp() > $to->getTimestamp()) { return array(); } $from = new DateTimeValue($from->getTimestamp()); $from->beginningOfDay(); $to = new DateTimeValue($to->getTimestamp()); $to->endOfDay(); $year1 = $from->getYear(); $year2 = $to->getYear(); if ($year1 == $year2) { $condition = 'DAYOFYEAR(`birthday`) >= DAYOFYEAR(' . DB::escape($from) . ')' . ' AND DAYOFYEAR(`birthday`) <= DAYOFYEAR(' . DB::escape($to) . ')'; } else { if ($year2 - $year1 == 1) { $condition = 'DAYOFYEAR(`birthday`) >= DAYOFYEAR(' . DB::escape($from) . ')' . ' OR DAYOFYEAR(`birthday`) <= DAYOFYEAR(' . DB::escape($to) . ')'; } else { $condition = "`birthday` <> '0000-00-00 00:00:00'"; } } return $this->getAllowedContacts($condition); }
function getRangeContactsByBirthday($from, $to, $member_ids = null) { if (!$from instanceof DateTimeValue || !$to instanceof DateTimeValue || $from->getTimestamp() > $to->getTimestamp()) { return array(); } $from = new DateTimeValue($from->getTimestamp()); $from->beginningOfDay(); $to = new DateTimeValue($to->getTimestamp()); $to->endOfDay(); $year1 = $from->getYear(); $year2 = $to->getYear(); if ($year1 == $year2) { $condition = 'DAYOFYEAR(`birthday`) >= DAYOFYEAR(' . DB::escape($from) . ')' . ' AND DAYOFYEAR(`birthday`) <= DAYOFYEAR(' . DB::escape($to) . ')'; } else { if ($year2 - $year1 == 1) { $condition = '(DAYOFYEAR(`birthday`) >= DAYOFYEAR(' . DB::escape($from) . ')' . ' OR DAYOFYEAR(`birthday`) <= DAYOFYEAR(' . DB::escape($to) . '))'; } else { $condition = "`birthday` <> '0000-00-00 00:00:00'"; } } if (!is_null($member_ids) && count($member_ids) > 0) { $condition .= " AND object_id IN (SELECT om.object_id FROM " . TABLE_PREFIX . "object_members om WHERE om.member_id IN (" . implode(',', $member_ids) . "))"; } return $this->getAllowedContacts($condition); }