本文整理汇总了PHP中Utils::relativeTime方法的典型用法代码示例。如果您正苦于以下问题:PHP Utils::relativeTime方法的具体用法?PHP Utils::relativeTime怎么用?PHP Utils::relativeTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Utils
的用法示例。
在下文中一共展示了Utils::relativeTime方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: entries
public function entries()
{
$worklist_entries = array_reverse($this->read('entries'));
$gh_events = $this->read('gh_events');
$entries = array_merge($worklist_entries, $gh_events);
usort($entries, array('StatusView', 'sortEntries'));
$ret = '';
$now = 0;
foreach ($entries as $entry) {
if (!$now) {
$now = strtotime(Model::now());
}
if (get_class($entry) == 'EntryModel') {
$id = $entry->id;
$type = 'worklist';
$date = strtotime($entry->date);
$content = self::formatWorklistEntry($entry);
} else {
// github event
if (!preg_match('/^(Fork|PullRequest(ReviewComment)?|IssueComment)Event$/', $entry['type'])) {
continue;
}
$id = $entry['id'];
$type = 'github' . preg_replace('/Event$/', '', $entry['type']);
$date = strtotime($entry['created_at']);
$content = self::formatGithubEntry($entry);
}
$ret .= '<li entryid="' . $id . '" date="' . $date . '" type="' . $type . '">' . '<h4>' . Utils::relativeTime($date - $now) . '</h4>' . $content . '</li>';
}
return $ret;
}
示例2: longpoll
/**
* Worklist entries longpoll, retrieves new entries by simulating server pushes
* to the status page. Refer to client side code at js/status.js to clarify.
*/
public function longpoll()
{
$this->view = new JsonView();
$ret = array();
try {
$since = $_POST['since'];
$entry = new EntryModel();
$ret = array();
// this is a 30 seconds timeout long poll, so let's loop up to 25 times
// with 1 sec delays at the end of each iteration
$fromTime = (int) $since;
for ($i = 0; $i < 25; $i++) {
$toTime = strtotime(Model::now());
$seconds_ago = abs($toTime - $fromTime);
// we are searching for new worklist entries
$entries = $entry->latest($seconds_ago, 90);
if ($entries) {
$now = 0;
foreach ($entries as $entry) {
if (!$now) {
$now = strtotime(Model::now());
}
$date = strtotime($entry->date);
$relativeDate = Utils::relativeTime($date - $now);
$mention_regex = '/(^|\\s)@([a-zA-Z0-9][a-zA-Z0-9-]+)/';
$task_regex = '/(^|\\s)\\*\\*#(\\d+)\\*\\*/';
$content = preg_replace($mention_regex, '\\1[\\2](./user/\\2)', $entry->entry);
$content = preg_replace($task_regex, '\\1[\\\\#\\2](./\\2)', $content);
// proccesed entries are returned as markdown-processed html
$content = Markdown::defaultTransform($content);
$ret[] = array('id' => $entry->id, 'date' => $date, 'relativeDate' => $relativeDate, 'content' => $content);
}
// if we found new entries, no need to keep looping so we can return data inmediatly
break;
}
sleep(1);
}
$ret = array('success' => true, 'data' => $ret);
} catch (Exception $e) {
$ret = array('success' => false, 'message' => $e->getMessage());
}
$this->write('output', $ret);
}
示例3: getLoveHistory
public function getLoveHistory($page, $justUser = false)
{
$front = Frontend::getInstance();
$page--;
$l = $this->getLimit() * $page;
$where = '';
$sql = "SELECT count(*) " . "FROM " . LOVE_LOVE;
$res = mysql_query($sql);
$row = mysql_fetch_row($res);
$loves = $row[0];
$sql = "SELECT count(*) " . "FROM " . LOVE_LOVE . " " . "WHERE " . LOVE_LOVE . ".receiver = '" . $front->getUser()->getUsername() . "' " . "OR " . LOVE_LOVE . ".giver = '" . $front->getUser()->getUsername() . "' " . ($sql .= $justUser ? '' : "OR " . LOVE_LOVE . ".company_id = '" . $front->getUser()->getCompany_id() . "' ");
$sql .= $where . " " . "ORDER BY id DESC";
$res = mysql_query($sql);
$row = mysql_fetch_row($res);
$count = $row[0];
$cPages = ceil($count / $this->getLimit());
$sql = "SELECT id,giver,receiver,why,private,TIMESTAMPDIFF(SECOND,at,NOW()) as delta " . "FROM " . LOVE_LOVE . " " . "WHERE " . LOVE_LOVE . ".receiver = '" . $front->getUser()->getUsername() . "' " . "OR " . LOVE_LOVE . ".giver = '" . $front->getUser()->getUsername() . "' ";
$sql .= $justUser ? '' : "OR " . LOVE_LOVE . ".company_id = '" . $front->getUser()->getCompany_id() . "' ";
$sql .= $where . " " . "ORDER BY id DESC " . "LIMIT " . $l . "," . $this->getLimit();
$res = mysql_query($sql);
// Construct json for history
$this->pages = array(array($page, $cPages, number_format($loves)));
for ($i = 1; $row = mysql_fetch_assoc($res); $i++) {
$givernickname = getNickName($row['giver']);
$givernickname = !empty($givernickname) ? $givernickname : $row['giver'];
$receivernickname = getNickName($row['receiver']);
$receivernickname = !empty($receivernickname) ? $receivernickname : $row['receiver'];
$why = $row['why'];
if ($row['private']) {
$why .= " (love sent quietly)";
}
$history[] = array("id" => $row['id'], "giver" => $row['giver'], "giverNickname" => $givernickname, "receiver" => $row['receiver'], "receiverNickname" => $receivernickname, "why" => $why, "delta" => Utils::relativeTime($row['delta']));
}
return $history;
}
示例4: lastSeen
public function lastSeen()
{
return Utils::relativeTime($this->profileUser->getTimeLastSeen(), false);
}
示例5: getLoveHistory
public function getLoveHistory($user, $page, $justUser = false, $when = true)
{
$front = Frontend::getInstance();
$mycompany = $front->getUser()->getCompany_id() || MAIN_COMPANY;
$page--;
$l = $this->getLimit() * $page;
if ($l < 0) {
$l = 0;
}
$where = '';
$order_by = $when == "true" ? " ORDER BY id DESC " : " ORDER BY id ASC ";
// query to count company love including user private love
$sql = "SELECT count(*) FROM " . LOVE . " WHERE private=0 OR giver='" . $user . "' OR receiver='" . $user . "'";
$res = mysql_query($sql);
$row = mysql_fetch_row($res);
$loves = $row[0];
// if username is different from user that is currently logged in
// - show only public love for user
$private_flag = $user != $front->getUser()->getUsername() ? ' AND private = 0 ' : '';
// query to count user love
$sql = "SELECT count(*) FROM " . LOVE . " WHERE (receiver = '{$user}' OR giver = '{$user}') ";
$sql .= $justUser ? '' . $private_flag : "OR company_id = " . $mycompany . " AND private=0 ";
$sql .= $where . $order_by;
$res = mysql_query($sql);
$row = mysql_fetch_row($res);
$count = $row[0];
$cPages = ceil($count / $this->getLimit());
$sql = "SELECT id,giver,receiver,why,private,TIMESTAMPDIFF(SECOND,at,NOW()) as delta " . "FROM " . LOVE . " WHERE (receiver = '{$user}' OR giver = '{$user}') ";
$sql .= $justUser ? '' . $private_flag : "OR company_id = " . $mycompany . " AND private=0 OR giver='" . $user . "' OR receiver='" . $user . "' ";
$sql .= $where . $order_by . "LIMIT " . $l . "," . $this->getLimit();
$res = mysql_query($sql) or error_log('GetLoveHistory;' . mysql_error() . "\n" . $sql);
// Construct json for history
$this->pages = array(array($page, $cPages, number_format($loves)));
if (isset($res) && mysql_num_rows($res) === 0) {
return array();
}
$history = array();
for ($i = 1; $row = mysql_fetch_assoc($res); $i++) {
$givernickname = getNickName($row['giver']);
$givernickname = !empty($givernickname) ? $givernickname : $row['giver'];
$receivernickname = getNickName($row['receiver']);
$receivernickname = !empty($receivernickname) ? $receivernickname : $row['receiver'];
$why = $row['why'];
if ($row['private']) {
$why .= " (love sent quietly)";
}
$history[] = array("id" => $row['id'], "giver" => $row['giver'], "giverNickname" => $givernickname, "receiver" => $row['receiver'], "receiverNickname" => $receivernickname, "why" => stripslashes($why), "delta" => Utils::relativeTime($row['delta']));
}
return $history;
}
示例6: getMultipleBidList
function getMultipleBidList()
{
$job_id = isset($_REQUEST['job_id']) ? (int) $_REQUEST['job_id'] : 0;
if ($job_id == 0) {
echo $job_id;
return;
}
$workItem = new WorkItem();
$bids = $workItem->getBids($job_id);
$ret = array();
foreach ($bids as $bid) {
$bid['expired'] = $bid['expires'] <= BID_EXPIRE_WARNING;
$bid['expires_text'] = Utils::relativeTime($bid['expires'], false, false, false, false);
$ret[] = $bid;
}
echo json_encode(array('bids' => $ret));
return;
}
示例7: getAvgJobTime
public function getAvgJobTime()
{
$query = "SELECT AVG(TIME_TO_SEC(TIMEDIFF(doneDate, workingDate))) as avgJobTime FROM\n (SELECT w.id, s.change_date AS doneDate,\n ( SELECT MAX(`date`) AS workingDate FROM fees\n WHERE worklist_id = w.id AND `desc` = 'Accepted Bid') as workingDate\n FROM status_log s\n LEFT JOIN worklist w ON s.worklist_id = w.id\n LEFT JOIN projects p on p.project_id = w.project_id\n WHERE s.status = 'Done' AND p.project_id = " . $this->getProjectId() . ") AS x";
if ($result = mysql_query($query)) {
$row = mysql_fetch_array($result);
return $row['avgJobTime'] > 0 ? Utils::relativeTime($row['avgJobTime'], false, true, false) : '';
} else {
return false;
}
}
示例8: getRelativeDate
public function getRelativeDate()
{
return Utils::relativeTime(strtotime($this->date) - strtotime(Model::now()));
}
示例9: avgJobRunTime
public function avgJobRunTime()
{
$query = "\n SELECT AVG(TIME_TO_SEC(TIMEDIFF(`x`.`doneDate`, `x`.`workingDate`))) AS `avgJobRunTime`\n FROM (\n SELECT\n `w`.id,\n `s`.change_date AS doneDate,\n (\n SELECT MAX(`date`) AS `workingDate`\n FROM `fees`\n WHERE `worklist_id`=`w`.`id`\n AND `desc` = 'Accepted Bid'\n ) as `workingDate`\n FROM `status_log` `s`\n LEFT JOIN `" . WORKLIST . "` `w`\n ON `s`.`worklist_id`=`w`.`id`\n WHERE `s`.`status` = 'Done'\n AND `w`.`runner_id` = " . $this->getId() . "\n ) `x`";
if ($result = mysql_query($query)) {
$row = mysql_fetch_array($result);
return $row['avgJobRunTime'] > 0 ? Utils::relativeTime($row['avgJobRunTime'], false, true, false) : '';
}
return false;
}
示例10:
echo $checked;
?>
/>
<input type = "hidden" class = "love_id" value = "<?php
echo $love['id'];
?>
">
<input type = "hidden" class = "review_love_id" value = "<?php
echo $love['review_love_id'];
?>
">
</td>
<td class = "headFrom"><?php
echo $love['nickname'];
?>
</td>
<td class = "headFor"><?php
echo $love['why'];
?>
</td>
<td class = "headWhen"><?php
echo Utils::relativeTime($love['delta']);
?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
示例11: view
//.........这里部分代码省略.........
$worklist_id = (int) $_REQUEST['worklist_id'];
$user_id = (int) $_REQUEST['user_id'];
$comment = $_REQUEST['comment'];
$rt = $this->addComment($worklist_id, $user_id, $comment, $parent_comment);
// Send journal notification
if ($workitem->getStatus() != 'Draft') {
$related = $this->getRelated($comment);
$journal_message .= '@' . $_SESSION['nickname'] . ' posted a comment on #' . $worklist_id . $related;
$options = array('type' => 'comment', 'workitem' => $workitem, 'recipients' => array('creator', 'runner', 'mechanic', 'followers'), 'emails' => $rt['correspondent']);
$data = array('who' => $_SESSION['nickname'], 'comment' => $comment, 'related' => $related, 'comment-id' => $rt['id']);
Notification::workitemNotify($options, $data, false);
Notification::workitemNotifyHipchat($options, $data);
// workitem mentions
$matches = array();
if (preg_match_all('/@(\\w+)/', $comment, $matches, PREG_SET_ORDER)) {
foreach ($matches as $mention) {
// validate the username actually exists
if ($recipient = User::find($mention[1])) {
// exclude creator, designer, developer and followers
if ($recipient->getId() != $workitem->getRunnerId() && $recipient->getId() != $workitem->getMechanicId() && $recipient->getId() != $workitem->getCreatorId() && !$workitem->isUserFollowing($recipient->getId())) {
$emailTemplate = 'workitem-mention';
$comment_url = WORKLIST_URL . $workitem->getId() . '#comment-' . $rt['id'];
$data = array('job_id' => $workitem->getId(), 'summary' => $workitem->getSummary(), 'author' => $_SESSION['nickname'], 'text' => $comment, 'link' => '<a href="' . $comment_url . '">See the comment</a>');
$senderEmail = 'Worklist - ' . $_SESSION['nickname'] . ' <contact@worklist.net> ';
Utils::sendTemplateEmail($recipient->getUsername(), $emailTemplate, $data, $senderEmail);
}
}
}
}
}
Utils::systemNotification($journal_message);
$comment = new Comment();
$comment->findCommentById((int) $rt['id']);
$result = array('success' => true, 'id' => $rt['id'], 'comment' => str_replace(array('\\n\\r', '\\r\\n', '\\n', '\\r'), '<br/>', Utils::linkify($comment->getComment())), 'avatar' => $comment->getUser()->getAvatar(), 'nickname' => $comment->getUser()->getNickname(), 'userid' => $comment->getUser()->getId(), 'date' => Utils::relativeTime(strtotime($comment->getDate()) - strtotime(Model::now())));
ob_start();
$json = json_encode($result);
} else {
$json = json_encode(array('success' => false));
}
$this->view = null;
echo $json;
ob_end_flush();
exit;
}
if ($action == 'status-switch') {
$status = $_REQUEST['quick-status'];
$status_error = '';
if ($status == 'Done' && $workitem->getProjectId() == 0) {
$status_error = "No project associated with workitem. Could not set to DONE.";
} else {
if ($this->changeStatus($workitem, $status, $user)) {
if ($workitem->save() == false) {
$status_error = "Error in save workitem process. Could not change the status.";
} else {
if ($status == 'Merged') {
$workitem->addFeesToCompletedJob();
}
if ($status != 'Draft') {
$new_update_message = "Status set to *{$status}*. ";
$notifyEmpty = false;
$status_change = '-' . ucfirst(strtolower($status));
if ($status == 'QA Ready') {
Notification::workitemNotify(array('type' => 'new_qa', 'workitem' => $workitem, 'status_change' => $status_change, 'job_changes' => $job_changes, 'recipients' => array($workitem->getRunnerId(), 'creator', 'mechanic', 'followers')), array('changes' => $new_update_message));
$notifyEmpty = true;
}
if ($status == 'Code Review') {
示例12: taskEntries
public function taskEntries()
{
// we don't need comments from status entries cause
// we are mixing them with real comments
$worklist_entries = self::removeCommentsEntries($this->read('entries'));
// let's group reply comments so they get rendered toghether, no matter their
// date according to the rest of the entries of other groups (only the first
// level comment date is taken for orfering)
$comments = self::groupComments($this->read('comments'));
$entries = array_merge($worklist_entries, $comments);
usort($entries, array('JobView', 'sortEntries'));
$ret = '';
$now = 0;
foreach ($entries as $entry) {
if (!$now) {
$now = strtotime(Model::now());
}
if (is_object($entry) && get_class($entry) == 'EntryModel') {
$id = $entry->id;
$type = 'worklist';
$date = strtotime($entry->date);
$content = self::formatEntry($entry);
$ret .= '<li entryid="' . $id . '" date="' . $date . '" type="' . $type . '">' . '<h4>' . Utils::relativeTime($date - $now) . '</h4>' . $content . '</li>';
} else {
foreach ($entry['content'] as $comment) {
$commentObj = $comment['comment'];
$ret .= '<li id="comment-' . $comment['id'] . '" class="depth-' . $comment['depth'] . '">' . ' <div class="comment">' . ' <a class="commenter-avatar" href="./user/' . $commentObj->getUser()->getId() . '">' . ' <img class="picture profile-link" src="' . $commentObj->getUser()->getAvatar() . '" title="Profile Picture - ' . $commentObj->getUser()->getNickname() . '" />' . ' </a>' . ' <div class="comment-container">' . ' <div class="comment-info">' . ' <a class="author profile-link" href="./user/' . $commentObj->getUser()->getId() . '">' . ' ' . $commentObj->getUser()->getNickname() . ' </a>' . ' <a class="date" href="./' . $this->worklist['id'] . '#comment-' . $comment['id'] . '">' . ' ' . $commentObj->getRelativeDate() . ' </a>' . ' </div>' . ' <div class="comment-text">' . ' ' . $commentObj->getCommentWithLinks() . ' </div>' . ' </div>' . ' </div>' . '</li>';
}
}
}
return $ret;
}