Permalink
Browse files

Added selectArray cache to zophTable

The SA cache was missing from zophTable and the call to build it
referred to a wrong function name, causing an error when autocomplete is
switched off.

Also added a simple testcase to test this in the future

fixes #45
  • Loading branch information...
1 parent bf1f5a6 commit 8eec6a55f0d03d13f13915986e8a553da17d0e76 @jeroenrnl committed Jan 9, 2014
Showing with 17 additions and 4 deletions.
  1. +5 −0 php/UnitTests/albumTest.php
  2. +12 −4 php/classes/zophTable.inc.php
@@ -41,10 +41,15 @@ public function testCreateAlbum($id, $name, $parent) {
$this->assertEquals($album->getId(), $id);
}
+ public function testSAcache() {
+ album::setSAcache();
+ }
+
public function getAlbums() {
return array(
array(15, "TestAlbum1", 2),
array(15, "TestAlbum2", 3)
);
}
+
}
@@ -49,6 +49,9 @@
/** @var array Contains the values of attributes that will be stored in the db */
public $fields=array();
+ /** @var array Contains the selectArray cache */
+ protected static $sacache;
+
/**
* Create new object
* @param int object id
@@ -251,14 +254,14 @@ public function insert() {
}
/**
- * Retrieving a the searcharray can take a long time in some cases
+ * Retrieving a the selectarray can take a long time in some cases
* pages that use it multiple times can cache it, so it only needs
* to be retrieved once per page request.
- * @param array searchArray;
+ * @param array selectArray;
*/
public static function setSAcache(array $sa=null) {
if(!$sa) {
- $sa=static::getSearchArray();
+ $sa=static::getSelectArray();
}
static::$sacache=$sa;
}
@@ -764,7 +767,12 @@ public static function createPulldown($name, $value=null) {
if(static::getAutocompPref()) {
return static::createAutoCompPulldown($name, $value);
} else {
- return template::createPulldown($name, $value, static::getSelectArray());
+ if(isset(static::$sacache)) {
+ $sa=static::$sacache;
+ } else {
+ $sa=static::getSelectArray();
+ }
+ return template::createPulldown($name, $value, $sa);
}
}

0 comments on commit 8eec6a5

Please sign in to comment.