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
* the query. Throws an InvalidArgumentException if the $field doesn't correspond to a relation
* Translates a {@link Object} relation name to a Database name and apply
* the relation join to the query. Throws an InvalidArgumentException if
* the $field doesn't correspond to a relation.
*
* @throws InvalidArgumentException
* @param string $field
*
* @return string
*/
public function getRelationName($field) {
@ -446,9 +449,11 @@ class DataList extends ViewableData implements SS_List, SS_Filterable, SS_Sortab
if(strpos($field,'.') === false) {
return '"'.$field.'"';
}
$relations = explode('.', $field);
$fieldName = array_pop($relations);
$relationModelName = $this->dataQuery->applyRelation($field);
return '"'.$relationModelName.'"."'.$fieldName.'"';
}
@ -467,10 +472,13 @@ class DataList extends ViewableData implements SS_List, SS_Filterable, SS_Sortab
} else {
$className = 'ExactMatchFilter';
}
if(!class_exists($className)) {
$className = 'ExactMatchFilter';
array_unshift($modifiers, $filter);
}
$t = new $className($field, $value, $modifiers);
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()) {
$this->fullName = $fullName;
// sets $this->name and $this->relation
$this->addRelation($fullName);
$this->value = $value;
@ -161,18 +162,24 @@ abstract class SearchFilter extends Object {
*/
public function getDbName() {
// 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
// Todo: move to somewhere more appropriate, such as DataMapper, the magical class-to-be?
// 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?
$candidateClass = $this->model;
while($candidateClass != 'DataObject') {
if(DataObject::has_own_table($candidateClass)
&& singleton($candidateClass)->hasOwnTableDatabaseField($this->name)) {
break;
}
$candidateClass = get_parent_class($candidateClass);
}
if($candidateClass == 'DataObject') {
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
/**
* @package framework
* @subpackage tests
*/
class DataListTest extends SapphireTest {
// Borrow the model from DataObjectTest

View File

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