本文整理汇总了PHP中TimeHelper类的典型用法代码示例。如果您正苦于以下问题:PHP TimeHelper类的具体用法?PHP TimeHelper怎么用?PHP TimeHelper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TimeHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: item
/**
* Creates an item for the sitemap or sitemap index
*
* @param array $options various options pertaining to the item
* @return string The item
* @author Jose Diaz-Gonzalez
**/
public function item($options = array())
{
$options = array_merge(array('loc' => NULL, 'lastmod' => NULL, 'changefreq' => NULL, 'priority' => NULL, 'encode' => true), $options);
if (!empty($options['loc'])) {
if (!empty($options['lastmod'])) {
$time = new TimeHelper();
$options['lastmod'] = $time->toAtom($options['lastmod']);
}
if ($options['encode']) {
$options['loc'] = $this->_xmlspecialchars($options['loc']);
}
if ($this->sitemap) {
//Construct a sitemapindex item
$item = array();
$item['openEntity'] = "<sitemap>";
$item['loc'] = $this->_entityMaker("loc", $options['loc']);
$item['lastmod'] = $this->_entityMaker("lastmod", $options['lastmod']);
$item['closeEntity'] = "</sitemap>\n";
return $this->_mergeArrayEntities($item);
} else {
//Construct a sitemap item
$item = array();
$item['openEntity'] = "<url>";
$item['loc'] = $this->_entityMaker("loc", $options['loc']);
$item['lastmod'] = $this->_entityMaker("lastmod", $options['lastmod']);
$item['changefreq'] = $this->_entityMaker("changefreq", $options['changefreq']);
$item['priority'] = $this->_entityMaker("priority", $options['priority']);
$item['closeEntity'] = "</url>\n";
return $this->_mergeArrayEntities($item);
}
}
return false;
}
示例2: index
function index()
{
$this->layout = 'cart';
$this->loadModel('MasterCategory');
$masterCategories = $this->MasterCategory->find('all', array('order' => array('MasterCategory.priority'), 'recursive' => -1));
$this->Category->Behaviors->attach('Containable');
foreach ($masterCategories as &$masterCategory) {
$products = $this->Category->find('all', array('contain' => array('Product' => array('conditions' => array('AND' => array('Product.display = ' => '1', 'Product.stock > ' => '0', 'Product.master_category_id' => $masterCategory['MasterCategory']['id'])))), 'order' => 'Category.priority'));
$masterCategory['Products'] = $products;
}
$this->set('products', $masterCategories);
$this->loadModel('Configuration');
$isSiteClosed = $this->Configuration->findByKeyAndOrganizationId('closed', $this->currentUser['User']['organization_id']);
if ($isSiteClosed == "yes") {
$closed = true;
$nextDelivery = $this->Delivery->find('first', array('conditions' => array('Delivery.next_delivery' => true)));
App::import('Helper', 'Time');
$time = new TimeHelper();
$nextDeliveryDate = $time->format($format = 'd-m-Y', $nextDelivery['Delivery']['date'], null, "+7.0");
$this->set('nextDeliveryDate', $nextDeliveryDate);
} else {
$closed = false;
}
$this->set('closed', $closed);
}
示例3: get_recent_orders
function get_recent_orders()
{
$time = new TimeHelper();
$dayAgo = time() - 86400;
$formatedDayAgo = $time->format("Y-m-d H:i:s", $dayAgo);
$result = $this->find('all', array('conditions' => array('od_date >=' => $formatedDayAgo)));
return $result;
}
示例4: _isLastMonth
function _isLastMonth()
{
App::import('Helper', 'Time');
$time = new TimeHelper();
$last_month[0] = date('Y-m-01', strtotime('-1 month'));
$last_month[1] = date(DATE_W3C, mktime(0, 0, 0, date('m'), 0, date('y')));
$q = $time->daysAsSql($last_month[0], $last_month[1], 'modified');
$res = false;
if ($this->SbmRanking->hasAny($q)) {
$res = true;
}
return $res;
}
示例5: testAlternateText
public function testAlternateText()
{
TimeHelper::setTime(3);
// Get data ready that insight requires
$builders = self::buildDataTeens();
$instance = new Instance();
$instance->id = 100;
$instance->network_user_id = 1;
$instance->network_username = 'Teen Dude';
$instance->network = 'facebook';
$post_dao = new PostMySQLDAO();
$last_week_of_posts = $post_dao->getAllPostsByUsernameOrderedBy($instance->network_username, $network = $instance->network, $count = 0, $order_by = "pub_date", $in_last_x_days = $number_days, $iterator = false, $is_public = false);
$insight_plugin = new AgeAnalysisInsight();
$insight_plugin->generateInsight($instance, null, $last_week_of_posts, 5);
// Assert that insight got inserted
$insight_dao = new InsightMySQLDAO();
$today = date('Y-m-d');
$result = $insight_dao->getInsight('age_analysis', 100, $today);
$related_data = unserialize($result->related_data);
$this->assertNotNull($result);
$this->assertIsA($result, "Insight");
$this->assertEqual($result->headline, 'Teens said it all');
$this->assertEqual($result->text, "Teens — people less than 18 years old — wrote 100% of the " . "comments on Teen Dude's Facebook posts this week.");
$this->assertEqual($related_data['age_data']['18'], 2);
$this->assertEqual($related_data['age_data']['18_25'], 0);
$this->assertEqual($related_data['age_data']['25_35'], 0);
$this->assertEqual($related_data['age_data']['35_45'], 0);
$this->assertEqual($related_data['age_data']['45'], 0);
$result->id = 1;
$this->debug($this->getRenderedInsightInHTML($result));
$this->debug($this->getRenderedInsightInEmail($result));
}
示例6: generateInsight
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
{
parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
$this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
$baseline_dao = DAOFactory::getDAO('InsightBaselineDAO');
foreach ($this->getSchedule() as $baseline_slug => $data) {
$now = TimeHelper::getTime();
if ($now >= strtotime($data['start']) && $now <= strtotime($data['end'])) {
$this->logger->logInfo("{$now} is in-schedule", __METHOD__ . ',' . __LINE__);
$baseline = $baseline_dao->getMostRecentInsightBaseline($baseline_slug, $instance->id);
if (!$baseline) {
if ($instance->network == 'facebook' && date('w') == 4 || $instance->network == 'twitter' && date('w') == 1 || Utils::isTest()) {
$found = $this->runInsightForConfig($data, $instance);
$baseline_dao->insertInsightBaseline($baseline_slug, $instance->id, $found);
} else {
$this->logger->logInfo("Not today", __METHOD__ . ',' . __LINE__);
}
} else {
$this->logger->logInfo("Already exists", __METHOD__ . ',' . __LINE__);
}
} else {
$this->logger->logInfo("Not in-schedule", __METHOD__ . ',' . __LINE__);
}
}
$this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
}
示例7: generateInsight
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
{
parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
$this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
$possible_messaging = array(array('headline' => 'Ohai', 'text' => 'Greetings, humans', 'header_image' => 'http://farm3.staticflickr.com/2713/4098259769_725b5fb65b_o.jpg'), array('headline' => 'Hello', 'text' => 'Greetings, earthlings', 'header_image' => 'http://farm9.staticflickr.com/8078/8276342554_5a51725f5f_n.jpg'), array('headline' => 'Yo', 'text' => 'Greetings, peeps', 'header_image' => 'http://farm6.staticflickr.com/5006/5367216303_83c5f2dc39_n.jpg'));
//Instantiate the Insight object
$my_insight = new Insight();
//REQUIRED: Set the insight's required attributes
//We pull some from the options above. But the could just be strings like 'Ohai'
$which_messaging = TimeHelper::getTime() % count($possible_messaging);
foreach ($possible_messaging[$which_messaging] as $field => $value) {
$my_insight->{$field} = $value;
}
$my_insight->slug = 'my_test_insight_hello_thinkup';
//slug to label this insight's content
$my_insight->instance_id = $instance->id;
$my_insight->date = $this->insight_date;
//date is often this or $simplified_post_date
$my_insight->filename = basename(__FILE__, ".php");
//Same for every insight, must be set exactly this way
$my_insight->emphasis = Insight::EMPHASIS_MED;
//Set emphasis optionally, default is Insight::EMPHASIS_LOW
//OPTIONAL: Attach related data of various types using Insight setter functions
//$my_insight->setPosts($my_insight_posts);
//$my_insight->setLinks($my_insight_links);
//$my_insight->setPeople($my_insight_people);
//$my_insight->setMilestones($my_insight_milestones);
//etc
$this->insight_dao->insertInsight($my_insight);
$this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
}
示例8: testHelloThinkUpInsight
public function testHelloThinkUpInsight()
{
$posts = array();
$instance = new Instance();
$instance->id = 1;
$instance->network_username = 'Katniss Everdeen';
$instance->network = 'facebook';
$builders = self::setUpPublicInsight($instance);
// We have three random options, so we'll check each one here.
TimeHelper::setTime(3);
$hello_thinkup_insight_plugin = new HelloThinkUpInsight();
$hello_thinkup_insight_plugin->generateInsight($instance, null, $posts, 3);
$insight_dao = DAOFactory::getDAO('InsightDAO');
$result = $insight_dao->getInsight('my_test_insight_hello_thinkup', 1, date('Y-m-d'));
$this->assertEqual($result->headline, 'Ohai');
$this->assertEqual($result->text, 'Greetings, humans');
$this->assertEqual($result->filename, 'hellothinkupinsight');
$this->assertNull($result->related_data);
$this->assertEqual($result->emphasis, Insight::EMPHASIS_MED);
TimeHelper::setTime(4);
$hello_thinkup_insight_plugin->generateInsight($instance, null, $posts, 3);
$insight_dao = DAOFactory::getDAO('InsightDAO');
$result = $insight_dao->getInsight('my_test_insight_hello_thinkup', 1, date('Y-m-d'));
$this->assertEqual($result->headline, 'Hello');
$this->assertEqual($result->text, 'Greetings, earthlings');
TimeHelper::setTime(5);
$hello_thinkup_insight_plugin->generateInsight($instance, null, $posts, 3);
$insight_dao = DAOFactory::getDAO('InsightDAO');
$result = $insight_dao->getInsight('my_test_insight_hello_thinkup', 1, date('Y-m-d'));
$this->assertEqual($result->headline, 'Yo');
$this->assertEqual($result->text, 'Greetings, peeps');
/**
* Use this code to output the individual insight's fully-rendered HTML to file.
* Then, open the file in your browser to view.
*
* $ TEST_DEBUG=1 php webapp/plugins/insightsgenerator/tests/TestOfHelloThinkUpInsight.php
* -t testHelloThinkUpInsight > webapp/insight.html
*/
$controller = new InsightStreamController();
$_GET['u'] = 'Katniss Everdeen';
$_GET['n'] = 'facebook';
$_GET['d'] = date('Y-m-d');
$_GET['s'] = 'my_test_insight_hello_thinkup';
$results = $controller->go();
//Uncomment this out to see web view of insight
//$this->debug($results);
/**
* Use this code to output the individual insight's fully-rendered email HTML to file.
* Then, open the file in your browser to view.
*
* $ TEST_DEBUG=1 php webapp/plugins/insightsgenerator/tests/TestOfHelloThinkUpInsight.php
* -t testHelloThinkUpInsight > webapp/insight_email.html
*/
$email_insight = $this->getRenderedInsightInEmail($result);
//Uncomment this out to see the email view of insight
//$this->debug($email_insight);
}
示例9: __get
public function __get($format)
{
if (in_array($format, TimeHelper::$formats)) {
return TimeHelper::to_string($format, $this->time);
}
if (in_array($format, DateHelper::$formats)) {
return DateHelper::to_string($format, $this->time);
}
}
示例10: sendEmailSiteReopen
function sendEmailSiteReopen()
{
$User = ClassRegistry::init('User');
$users = $User->find('all', array('conditions' => array('User.status' => 'accepted')));
foreach ($users as $user) {
$to = $to . $user['User']['email'] . ", ";
}
$subject = "GRECOCOS website is now open";
$Delivery = ClassRegistry::init('Delivery');
$nextDelivery = $Delivery->findByNextDelivery(true);
App::import('Helper', 'Time');
$timeHelper = new TimeHelper();
$deliveryDate = $timeHelper->format($format = 'd-m-Y', $nextDelivery['Delivery']['date']);
$body = "<p>Dear member</p>" . "<p>The GRECOCOS website is opened. " . "You can place your orders now for delivery on " . "{$deliveryDate}.</p>" . "<p><a href=\"http://grecocos.co.cc/index.php\">" . "http://grecocos.co.cc/index.php</a></p>";
$AppengineEmail = ClassRegistry::init('AppengineEmail');
$AppengineEmail->sendEmail($to, $subject, $body);
$this->Session->write('sendEmailReOpenSite', true);
}
示例11: reset_user_password
function reset_user_password($key = null)
{
if (!empty($this->data)) {
$user = $this->Ticket->findUser($this->data['Ticket']['email']);
$hasTicket = $this->Ticket->find('first', array('conditions' => array('Ticket.email' => $user['User']['email'])));
//pr($hasTicket);
//die;
if (!empty($user) && empty($hasTicket)) {
App::import('Helper', 'Time');
$time = new TimeHelper();
$key = Security::hash(String::uuid(), 'sha1', true);
$this->data['Ticket']['key'] = $key;
$this->data['Ticket']['creation_date'] = $time->format('Y-m-d H:i:s', time());
$url = Router::url(array('controller' => 'tickets', 'action' => 'reset_user_password'), true) . '/' . $key;
//pr($url);
//die;
//ko se ticket shrani v bazo se poslje email (email element: lost_password_notification.ctp) useru, ki je ticket odprl
if ($this->Ticket->save($this->data)) {
$this->set('url', $url);
$this->MyEmail->sendResetPasswordEmail($user['User']['email']);
$this->Session->setFlash('notification email has been sent to you with reset data');
}
} elseif (!empty($hasTicket)) {
if ($this->Ticket->checkTicketDateValidity($hasTicket)) {
$this->Session->setFlash('We had already sent you a link to your email address! Go get it, lazy ass!');
} else {
$this->Session->setFlash('Your ticket regarding lost password has been deleted due to expiration! Try submitting again');
}
}
//se prozi kadar user klikne link, ki vsebuje generiran key, v svojem mailu in ga redirecta sem
} elseif (isset($key) && !empty($key)) {
$result = $this->Ticket->find('first', array('conditions' => array('Ticket.key' => $key)));
$this->Ticket->checkTicketDateValidity($result);
if (!empty($result)) {
$user = $this->Ticket->findUser($result['Ticket']['email']);
$this->set('userId', $user['User']['id']);
$this->set('key', $key);
$this->Ticket->delete($result['Ticket']['id']);
//$this->redirect(array('controller' => 'users', 'action' => 'changeUserPassword/uid:'.$user['User']['id']));
}
} else {
$this->Session->setFlash('Please provide your email!');
}
}
示例12: time_ago_in_words
public function time_ago_in_words($from_time, $include_seconds = false)
{
$now_gmt = new \DateTime("now", new \DateTimeZone("UTC"));
if (in_array(get_class($from_time), array("DateTime", "ActiveRecord\\DateTime"))) {
$from_gmt = clone $from_time;
$from_gmt->setTimezone(new \DateTimeZone("UTC"));
} elseif (is_int($from_time)) {
$from_gmt = new \DateTime("@" . $from_time, new \DateTimeZone("UTC"));
}
return TimeHelper::distance_of_time_in_words($from_gmt, $now_gmt, $include_seconds);
}
示例13: setUp
public function setUp()
{
parent::setUp();
$instance = new Instance();
$instance->id = 1;
$instance->network_user_id = 42;
$instance->network_username = 'testy';
$instance->network = 'twitter';
$this->instance = $instance;
TimeHelper::setTime(1425329077);
// Set it to the March 2015 words timeframe
}
示例14: setUp
public function setUp()
{
parent::setUp();
$instance = new Instance();
$instance->id = 1;
$instance->network_user_id = 42;
$instance->network_username = 'testy';
$instance->network = 'twitter';
$this->instance = $instance;
TimeHelper::setTime(1418947200);
// Set it to the December 2014 words timeframe
}
示例15: setUp
public function setUp()
{
parent::setUp();
$instance = new Instance();
$instance->id = 1;
$instance->network_user_id = 42;
$instance->network_username = 'bookworm';
$instance->network = 'twitter';
$this->instance = $instance;
$this->insight_dao = DAOFactory::getDAO('InsightDAO');
TimeHelper::setTime(2);
// Force one headline for most tests
}