Commit 03d7da84 authored by Volker Krause's avatar Volker Krause
Browse files

When needing active surveys, we already have a Product object

parent 209b82c8
......@@ -50,15 +50,11 @@ class Survey
return $surveys;
}
/** Returns an array of all active surveys for @p productName. */
public function activeSurveysForProduct(Datastore $db, $productName)
/** Returns an array of all active surveys for @p product. */
public function activeSurveysForProduct(Datastore $db, Product $product)
{
$stmt = $db->prepare('
SELECT surveys.id, surveys.name, surveys.url
FROM surveys JOIN products ON (surveys.productId = products.id)
WHERE products.name = :productName AND surveys.active = 1
');
$db->execute($stmt, array('productName' => strval($productName)));
$stmt = $db->prepare('SELECT id, name, url FROM surveys WHERE productId = :productId AND active = 1');
$db->execute($stmt, array(':productId' => intval($product->id())));
$surveys = array();
foreach ($stmt as $row) {
......
......@@ -98,7 +98,9 @@ class SurveyTest extends PHPUnit_Extensions_Database_TestCase
$this->assertEquals($survey2->url, 'http://survey.example/inactive');
$this->assertEquals($survey2->active, false);
$surveys = Survey::activeSurveysForProduct(self::$db, 'org.kde.UnitTest');
$p = Product::productByName(self::$db, 'org.kde.UnitTest');
$this->assertNotNull($p);
$surveys = Survey::activeSurveysForProduct(self::$db, $p);
$this->assertCount(1, $surveys);
$s = $surveys[0];
......@@ -123,7 +125,7 @@ class SurveyTest extends PHPUnit_Extensions_Database_TestCase
$s->insert(self::$db, $p);
$this->assertGreaterThan(0, $s->id);
$surveys = Survey::activeSurveysForProduct(self::$db, 'org.kde.UnitTest');
$surveys = Survey::activeSurveysForProduct(self::$db, $p);
$s = null;
foreach ($surveys as $survey) {
if ($survey->name == 'newSurvey') {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment