Coding conventions, PHPDoc cleanup

This commit is contained in:
Will Rossiter 2013-06-08 20:28:15 +12:00
parent 40eed9e902
commit 0129e185b8
4 changed files with 69 additions and 11 deletions

View File

@ -427,10 +427,13 @@ class DataList extends ViewableData implements SS_List, SS_Filterable, SS_Sortab
} }
/** /**
* Translates a Object relation name to a Database name and apply the relation join to * Translates a {@link Object} relation name to a Database name and apply
* the query. Throws an InvalidArgumentException if the $field doesn't correspond to a relation * the relation join to the query. Throws an InvalidArgumentException if
* the $field doesn't correspond to a relation.
* *
* @throws InvalidArgumentException
* @param string $field * @param string $field
*
* @return string * @return string
*/ */
public function getRelationName($field) { public function getRelationName($field) {
@ -446,9 +449,11 @@ class DataList extends ViewableData implements SS_List, SS_Filterable, SS_Sortab
if(strpos($field,'.') === false) { if(strpos($field,'.') === false) {
return '"'.$field.'"'; return '"'.$field.'"';
} }
$relations = explode('.', $field); $relations = explode('.', $field);
$fieldName = array_pop($relations); $fieldName = array_pop($relations);
$relationModelName = $this->dataQuery->applyRelation($field); $relationModelName = $this->dataQuery->applyRelation($field);
return '"'.$relationModelName.'"."'.$fieldName.'"'; return '"'.$relationModelName.'"."'.$fieldName.'"';
} }
@ -467,10 +472,13 @@ class DataList extends ViewableData implements SS_List, SS_Filterable, SS_Sortab
} else { } else {
$className = 'ExactMatchFilter'; $className = 'ExactMatchFilter';
} }
if(!class_exists($className)) { if(!class_exists($className)) {
$className = 'ExactMatchFilter'; $className = 'ExactMatchFilter';
array_unshift($modifiers, $filter); array_unshift($modifiers, $filter);
} }
$t = new $className($field, $value, $modifiers); $t = new $className($field, $value, $modifiers);
return $this->alterDataQuery(array($t, 'apply')); return $this->alterDataQuery(array($t, 'apply'));

View File

@ -52,6 +52,7 @@ abstract class SearchFilter extends Object {
*/ */
public function __construct($fullName, $value = false, array $modifiers = array()) { public function __construct($fullName, $value = false, array $modifiers = array()) {
$this->fullName = $fullName; $this->fullName = $fullName;
// sets $this->name and $this->relation // sets $this->name and $this->relation
$this->addRelation($fullName); $this->addRelation($fullName);
$this->value = $value; $this->value = $value;
@ -161,18 +162,24 @@ abstract class SearchFilter extends Object {
*/ */
public function getDbName() { public function getDbName() {
// Special handler for "NULL" relations // Special handler for "NULL" relations
if($this->name == "NULL") return $this->name; if($this->name == "NULL") {
return $this->name;
}
// SRM: This code finds the table where the field named $this->name lives // This code finds the table where the field named $this->name lives
// Todo: move to somewhere more appropriate, such as DataMapper, the magical class-to-be? // Todo: move to somewhere more appropriate, such as DataMapper, the
// magical class-to-be?
$candidateClass = $this->model; $candidateClass = $this->model;
while($candidateClass != 'DataObject') { while($candidateClass != 'DataObject') {
if(DataObject::has_own_table($candidateClass) if(DataObject::has_own_table($candidateClass)
&& singleton($candidateClass)->hasOwnTableDatabaseField($this->name)) { && singleton($candidateClass)->hasOwnTableDatabaseField($this->name)) {
break; break;
} }
$candidateClass = get_parent_class($candidateClass); $candidateClass = get_parent_class($candidateClass);
} }
if($candidateClass == 'DataObject') { if($candidateClass == 'DataObject') {
user_error("Couldn't find field $this->name in any of $this->model's tables.", E_USER_ERROR); user_error("Couldn't find field $this->name in any of $this->model's tables.", E_USER_ERROR);
} }

View File

@ -1,5 +1,9 @@
<?php <?php
/**
* @package framework
* @subpackage tests
*/
class DataListTest extends SapphireTest { class DataListTest extends SapphireTest {
// Borrow the model from DataObjectTest // Borrow the model from DataObjectTest

View File

@ -1,14 +1,16 @@
<?php <?php
/** /**
* This test class will focus on the when an search filter contains relational component, * This test class will focus on the when an search filter contains relational
* such as has_one, has_many, many_many, the SearchFilter::applyRelation($query) will add * component such as has_one, has_many, many_many, the {@link SearchFilter::applyRelation($query)}
* the right "join" clauses to $query without the component parent class missing from * will add the right "join" clauses to $query without the component parent
* "join" chain. * class missing from "join" chain.
* *
* @package framework * @package framework
* @subpackage testing * @subpackage tests
*/ */
class SearchFilterApplyRelationTest extends SapphireTest { class SearchFilterApplyRelationTest extends SapphireTest {
protected static $fixture_file = 'SearchFilterApplyRelationTest.yml'; protected static $fixture_file = 'SearchFilterApplyRelationTest.yml';
protected $extraDataObjects = array( protected $extraDataObjects = array(
@ -109,7 +111,12 @@ class SearchFilterApplyRelationTest extends SapphireTest{
} }
} }
/**
* @package framework
* @subpackage tests
*/
class SearchFilterApplyRelationTest_DO extends DataObject implements TestOnly { class SearchFilterApplyRelationTest_DO extends DataObject implements TestOnly {
private static $has_one = array( private static $has_one = array(
'SearchFilterApplyRelationTest_HasOneGrantChild' => 'SearchFilterApplyRelationTest_HasOneGrantChild' 'SearchFilterApplyRelationTest_HasOneGrantChild' => 'SearchFilterApplyRelationTest_HasOneGrantChild'
); );
@ -123,12 +130,20 @@ class SearchFilterApplyRelationTest_DO extends DataObject implements TestOnly {
); );
} }
/**
* @package framework
* @subpackage tests
*/
class SearchFilterApplyRelationTest_HasOneParent extends DataObject implements TestOnly { class SearchFilterApplyRelationTest_HasOneParent extends DataObject implements TestOnly {
private static $db = array( private static $db = array(
"Title" => "Varchar" "Title" => "Varchar"
); );
} }
/**
* @package framework
* @subpackage tests
*/
class SearchFilterApplyRelationTest_HasOneChild extends SearchFilterApplyRelationTest_HasOneParent class SearchFilterApplyRelationTest_HasOneChild extends SearchFilterApplyRelationTest_HasOneParent
implements TestOnly { implements TestOnly {
// This is to create an seperate Table only. // This is to create an seperate Table only.
@ -137,6 +152,10 @@ class SearchFilterApplyRelationTest_HasOneChild extends SearchFilterApplyRelatio
); );
} }
/**
* @package framework
* @subpackage tests
*/
class SearchFilterApplyRelationTest_HasOneGrantChild extends SearchFilterApplyRelationTest_HasOneChild class SearchFilterApplyRelationTest_HasOneGrantChild extends SearchFilterApplyRelationTest_HasOneChild
implements TestOnly { implements TestOnly {
// This is to create an seperate Table only. // This is to create an seperate Table only.
@ -148,12 +167,20 @@ class SearchFilterApplyRelationTest_HasOneGrantChild extends SearchFilterApplyRe
); );
} }
/**
* @package framework
* @subpackage tests
*/
class SearchFilterApplyRelationTest_HasManyParent extends DataObject implements TestOnly { class SearchFilterApplyRelationTest_HasManyParent extends DataObject implements TestOnly {
private static $db = array( private static $db = array(
"Title" => "Varchar" "Title" => "Varchar"
); );
} }
/**
* @package framework
* @subpackage tests
*/
class SearchFilterApplyRelationTest_HasManyChild extends SearchFilterApplyRelationTest_HasManyParent class SearchFilterApplyRelationTest_HasManyChild extends SearchFilterApplyRelationTest_HasManyParent
implements TestOnly { implements TestOnly {
// This is to create an separate Table only. // This is to create an separate Table only.
@ -162,12 +189,20 @@ class SearchFilterApplyRelationTest_HasManyChild extends SearchFilterApplyRelati
); );
} }
/**
* @package framework
* @subpackage tests
*/
class SearchFilterApplyRelationTest_HasManyGrantChild extends SearchFilterApplyRelationTest_HasManyChild{ class SearchFilterApplyRelationTest_HasManyGrantChild extends SearchFilterApplyRelationTest_HasManyChild{
private static $has_one = array( private static $has_one = array(
"SearchFilterApplyRelationTest_DO" => "SearchFilterApplyRelationTest_DO" "SearchFilterApplyRelationTest_DO" => "SearchFilterApplyRelationTest_DO"
); );
} }
/**
* @package framework
* @subpackage tests
*/
class SearchFilterApplyRelationTest_ManyManyParent extends DataObject implements TestOnly{ class SearchFilterApplyRelationTest_ManyManyParent extends DataObject implements TestOnly{
private static $db = array( private static $db = array(
"Title" => "Varchar" "Title" => "Varchar"
@ -182,6 +217,10 @@ class SearchFilterApplyRelationTest_ManyManyChild extends SearchFilterApplyRelat
); );
} }
/**
* @package framework
* @subpackage tests
*/
class SearchFilterApplyRelationTest_ManyManyGrantChild extends SearchFilterApplyRelationTest_ManyManyChild class SearchFilterApplyRelationTest_ManyManyGrantChild extends SearchFilterApplyRelationTest_ManyManyChild
implements TestOnly { implements TestOnly {
// This is to create an seperate Table only. // This is to create an seperate Table only.