Skip to content

Commit

Permalink
PHP 5.2 compatibility (stop using DateTime::sub and is_a()) [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
ginatrapani committed May 14, 2012
1 parent 7a49531 commit 6a6e2c0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
9 changes: 7 additions & 2 deletions webapp/_lib/model/class.Insight.php
Expand Up @@ -55,6 +55,11 @@ class Insight {
* @var int Level of emphasis for insight presentation.
*/
var $emphasis;
/**
* Non-persistent value indicating type of related data, for use in UI.
* @var str
*/
var $related_data_type;
/**
* High emphasis level.
* @var int
Expand All @@ -76,9 +81,9 @@ public function __construct($row = false) {
$this->instance_id = $row['instance_id'];
$this->slug = $row['slug'];
$this->text = $row['text'];
$this->post_key = $row['related_data'];
$this->related_data = $row['related_data'];
$this->date = $row['date'];
$this->emphasis = $row['emphasis'];
}
}
}
}
7 changes: 7 additions & 0 deletions webapp/_lib/model/class.InsightMySQLDAO.php
Expand Up @@ -74,6 +74,13 @@ public function getInsights($instance_id, $page_count=10, $page_number=1) {
$insights = $this->getDataRowsAsObjects($ps, "Insight");
foreach ($insights as $insight) {
$insight->related_data = unserialize($insight->related_data);
if ($insight->related_data instanceof Post) {
$insight->related_data_type = "post";
} elseif (is_array($insight->related_data)) {
if ($insight->related_data[0] instanceof User) {
$insight->related_data_type = "users";
}
}
//assume insight came at same time of day as now for relative day notation
$insight->date = $insight->date. " ".date('H').":".date('i');
}
Expand Down
11 changes: 4 additions & 7 deletions webapp/_lib/view/dashboard.insights.tpl
Expand Up @@ -3,8 +3,7 @@
{assign var='cur_date' value=''}
{foreach from=$insights key=tid item=i name=foo}
{if $cur_date neq $i->date}
<br>
{$i->date|relative_day}
<h2>{$i->date|relative_day}</h2>
{assign var='cur_date' value=$i->date}
{/if}
<div class="alert {if $i->emphasis eq '2'}urgent{else}helpful{/if}">
Expand All @@ -13,18 +12,16 @@
{$i->text}

<!--begin attachment data-->
{if $i->related_data|is_a:'array'}
{if $i->related_data[0]|is_a:'User'}
{if $i->related_data_type eq 'users'}
{foreach from=$i->related_data key=uid item=u name=bar}
<div class="avatar-container" style="float:left;margin:7px;">
<a href="https://twitter.com/intent/user?user_id={$u->user_id}" title="{$u->username} has {$u->follower_count|number_format} followers and {$u->friend_count|number_format} friends"><img src="{$u->avatar}" class="avatar2"/><img src="{$site_root_path}plugins/{$u->network}/assets/img/favicon.png" class="service-icon2"/></a>
</div>
{/foreach}
{/foreach}
<br><br><br>
{/if}
{/if}

{if $i->related_data|is_a:'Post' && isset($i->related_data->post_text)}
{if $i->related_data_type eq 'post'}
<br><br>
<div style="background-color:white">
{$i->related_data->post_text}
Expand Down
4 changes: 3 additions & 1 deletion webapp/plugins/twitter/model/class.TwitterCrawler.php
Expand Up @@ -1903,7 +1903,9 @@ public function generateInsights() {
'twitter', $days_ago);
if (sizeof($least_likely_followers) > 0 ) { //if not null, store insight
$insight_date = new DateTime();
$insight_date->sub(new DateInterval('P'.$days_ago.'D'));
//Not PHP 5.2 compatible
//$insight_date->sub(new DateInterval('P'.$days_ago.'D'));
$insight_date->modify('-'.$days_ago.' day');
$insight_date = $insight_date->format('Y-m-d');
$insight_dao->insertInsight('least_likely_followers', $this->instance->id, $insight_date,
"Good people: ".sizeof($least_likely_followers)." interesting users followed you.",
Expand Down

0 comments on commit 6a6e2c0

Please sign in to comment.