Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improve InsightDAO API

* Add support for header_image in getInsight, insertInsight, and
updateInsight
* Add support for empty text field
  • Loading branch information...
commit 24f224d089f56c9c47a5e1eddc03281a8c89f268 1 parent bd16e7b
@ginatrapani ginatrapani authored
View
13 tests/TestOfInsightMySQLDAO.php
@@ -39,7 +39,7 @@ protected function buildData() {
$time_now = date("Y-m-d H:i:s");
$builders[] = FixtureBuilder::build('insights', array('date'=>'2012-05-01', 'slug'=>'avg_replies_per_week',
'instance_id'=>'1', 'headline'=>'Booyah!', 'text'=>'Retweet spike! Your post got retweeted 110 times',
- 'emphasis'=>Insight::EMPHASIS_HIGH, 'time_generated'=>$time_now));
+ 'emphasis'=>Insight::EMPHASIS_HIGH, 'time_generated'=>$time_now, 'header_image'=>'headerme.jpg'));
//Set up array of owner objects
$o1["id"] = 10;
@@ -101,6 +101,7 @@ public function testGetInsight() {
$this->assertEqual($result->headline, 'Booyah!');
$this->assertEqual($result->text, 'Retweet spike! Your post got retweeted 110 times');
$this->assertEqual($result->emphasis, Insight::EMPHASIS_HIGH);
+ $this->assertEqual($result->header_image, 'headerme.jpg');
$result = $dao->getInsight('avg_replies_per_week', 1, '2012-05-02');
$this->assertNull($result);
@@ -203,18 +204,22 @@ public function testInsertInsight() {
$this->assertEqual($result->filename, 'test_filename');
$this->assertNull($result->related_data);
$this->assertEqual($result->emphasis, Insight::EMPHASIS_MED);
+ $this->assertEqual($result->header_image, null);
//inserting existing insight should update
$insight->headline = "Ohai updated headline";
$insight->text = 'Updated: You rock';
+ $insight->header_image = 'my_image.png';
$result = $dao->insertInsight($insight);
$this->assertTrue($result);
//assert update was successful
$result = $dao->getInsight('avg_replies_per_week', 1, '2012-05-05');
+ $this->debug(Utils::varDumpToString($result));
$this->assertEqual($result->headline, 'Ohai updated headline' );
$this->assertEqual($result->text, 'Updated: You rock');
- //Filename shouldn't change on update
+ $this->assertEqual($result->header_image, 'my_image.png');
+ //Filename and emphasis shouldn't change on update
$this->assertEqual($result->filename, 'test_filename');
$this->assertEqual($result->emphasis, Insight::EMPHASIS_MED);
@@ -444,9 +449,9 @@ public function testGetAllOwnerInstanceInsightsSince() {
$builders[] = FixtureBuilder::build('insights', array('date'=>'2012-05-01', 'slug'=>'another_slug',
'instance_id'=>'1', 'text'=>'Retweet spike! Your post got retweeted 110 times',
'emphasis'=>Insight::EMPHASIS_HIGH, 'time_generated'=>$time_now));
- //insight with no text shouldn't be returned
+ //insight with filename set to 'dashboard' shouldn't be returned
$builders[] = FixtureBuilder::build('insights', array('date'=>'2012-05-01', 'slug'=>'another_slug',
- 'instance_id'=>'1', 'text'=>'',
+ 'instance_id'=>'1', 'text'=>'', 'filename'=>'dashboard',
'emphasis'=>Insight::EMPHASIS_HIGH, 'time_generated'=>$time_now));
//assert that page of insights includes from both private and public
View
13 webapp/_lib/dao/class.InsightMySQLDAO.php
@@ -28,7 +28,7 @@
*/
class InsightMySQLDAO extends PDODAO implements InsightDAO {
public function getInsight($slug, $instance_id, $date) {
- $q = "SELECT date, instance_id, slug, headline, text, related_data, filename, emphasis ";
+ $q = "SELECT date, instance_id, slug, headline, text, related_data, filename, emphasis, header_image ";
$q .= "FROM #prefix#insights WHERE ";
$q .= "slug=:slug AND date=:date AND instance_id=:instance_id";
$vars = array(
@@ -130,14 +130,15 @@ public function insertInsight(Insight $insight) {
$existing_insight = self::getInsight($insight->slug, $insight->instance_id, $insight->date);
if ($existing_insight == null) {
$q = "INSERT INTO #prefix#insights SET slug=:slug, date=:date, instance_id=:instance_id, ";
- $q .= "headline=:headline, text=:text, filename=:filename, emphasis=:emphasis, ";
- $q .= "related_data=:related_data, time_generated=:time_generated";
+ $q .= "headline=:headline, text=:text, header_image=:header_image, filename=:filename, ";
+ $q .= "emphasis=:emphasis, related_data=:related_data, time_generated=:time_generated";
$vars = array(
':slug'=>$insight->slug,
':date'=>$insight->date,
':instance_id'=>$insight->instance_id,
':headline'=>$insight->headline,
':text'=>$insight->text,
+ ':header_image'=>$insight->header_image,
':filename'=>$insight->filename,
':emphasis'=>$insight->emphasis,
':related_data'=>((isset($insight->related_data))?serialize($insight->related_data):null),
@@ -207,12 +208,14 @@ public function updateInsightDeprecated($slug, $instance_id, $date, $headline, $
private function updateInsight(Insight $insight) {
$q = "UPDATE #prefix#insights SET headline=:headline, text=:text, related_data=:related_data, ";
- $q .= "emphasis=:emphasis WHERE slug=:slug AND date=:date AND instance_id=:instance_id";
+ $q .= "emphasis=:emphasis, header_image=:header_image ";
+ $q .= "WHERE slug=:slug AND date=:date AND instance_id=:instance_id";
$vars = array(
':slug'=>$insight->slug,
':date'=>$insight->date,
':instance_id'=>$insight->instance_id,
':headline'=>$insight->headline,
+ ':header_image'=>$insight->header_image,
':text'=>$insight->text,
':related_data'=>((isset($insight->related_data))?serialize($insight->related_data):null),
':emphasis'=>$insight->emphasis
@@ -315,7 +318,7 @@ public function getAllOwnerInstanceInsightsSince($owner_id, $since) {
$q .= "INNER JOIN #prefix#owner_instances oi ON su.id = oi.instance_id ";
$q .= "LEFT JOIN #prefix#users u ON (su.network_user_id = u.user_id AND su.network = u.network) ";
$q .= "WHERE su.is_active = 1 AND oi.owner_id = :owner_id AND time_generated > :since ";
- $q .= "AND i.text != '' ORDER BY date DESC, emphasis DESC, i.id;";
+ $q .= "AND i.filename != 'dashboard' ORDER BY date DESC, emphasis DESC, i.id;";
$vars = array(
":owner_id"=>(int)$owner_id,
':since'=>$since
Please sign in to comment.
Something went wrong with that request. Please try again.