Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Filtering by handle works correctly when a SBL is tied to Multiple Se…

…ctions
  • Loading branch information...
commit dad67ded922dcf61e15136b79fad004fda2cb24a 1 parent 8a988eb
@brendo brendo authored
Showing with 33 additions and 36 deletions.
  1. +33 −36 fields/field.selectbox_link.php
View
69 fields/field.selectbox_link.php
@@ -129,7 +129,7 @@ public function prepareTableValue($data, XMLElement $link=NULL){
private function __findPrimaryFieldValueFromRelationID($entry_id){
$field_id = $this->findFieldIDFromRelationID($entry_id);
-
+
if (!isset(self::$cacheFields[$field_id])) {
self::$cacheFields[$field_id] = $this->Database->fetchRow(0, "
SELECT
@@ -148,13 +148,13 @@ private function __findPrimaryFieldValueFromRelationID($entry_id){
LIMIT 1
");
}
-
+
$primary_field = self::$cacheFields[$field_id];
-
+
if(!$primary_field) return NULL;
$field = $this->_Parent->create($primary_field['type']);
-
+
if (!isset(self::$cacheValues[$entry_id])) {
self::$cacheValues[$entry_id] = $this->Database->fetchRow(0,
"SELECT *
@@ -162,27 +162,27 @@ private function __findPrimaryFieldValueFromRelationID($entry_id){
WHERE `entry_id` = '{$entry_id}' ORDER BY `id` DESC LIMIT 1"
);
}
-
+
$data = self::$cacheValues[$entry_id];
-
+
if(empty($data)) return null;
-
+
$primary_field['value'] = $field->prepareTableValue($data);
-
+
return $primary_field;
}
public function checkFields(&$errors, $checkForDuplicates = true) {
parent::checkFields($errors, $checkForDuplicates);
-
+
$related_fields = $this->get('related_field_id');
if(empty($related_fields)){
$errors['related_field_id'] = __('This is a required field.');
}
-
+
return (is_array($errors) && !empty($errors) ? self::__ERROR__ : self::__OK__);
- }
-
+ }
+
public function processRawFieldData($data, &$status, $simulate=false, $entry_id=NULL){
$status = self::__OK__;
if(!is_array($data)) return array('relation_id' => $data);
@@ -231,10 +231,10 @@ public function appendFormattedElement(&$wrapper, $data, $encode=false){
foreach($data['relation_id'] as $relation_id){
$primary_field = $this->__findPrimaryFieldValueFromRelationID($relation_id);
-
+
$value = $primary_field['value'];
if ($encode) $value = General::sanitize($value);
-
+
$item = new XMLElement('item');
$item->setAttribute('id', $relation_id);
$item->setAttribute('handle', Lang::createHandle($primary_field['value']));
@@ -247,12 +247,12 @@ public function appendFormattedElement(&$wrapper, $data, $encode=false){
$wrapper->appendChild($list);
}
-
-
-
+
+
+
public function findFieldIDFromRelationID($id){
if(is_null($id)) return NULL;
-
+
if (isset(self::$cacheRelations[$id])) {
return self::$cacheRelations[$id];
}
@@ -271,19 +271,19 @@ public function findFieldIDFromRelationID($id){
catch(Exception $e){
return NULL;
}
-
+
self::$cacheRelations[$id] = $field_id;
-
+
return $field_id;
}
public function findOptions(array $existing_selection=NULL){
$values = array();
$limit = $this->get('limit');
-
+
// find the sections of the related fields
$sections = $this->Database->fetch("SELECT DISTINCT (s.id), s.name, f.id as `field_id`
- FROM `tbl_sections` AS `s`
+ FROM `tbl_sections` AS `s`
LEFT JOIN `tbl_fields` AS `f` ON `s`.id = `f`.parent_section
WHERE `f`.id IN ('" . implode("','", $this->get('related_field_id')) . "')
ORDER BY s.sortorder ASC");
@@ -418,17 +418,16 @@ public function buildDSRetrivalSQL($data, &$joins, &$where, $andOperation=false)
$where .= " AND `t{$field_id}`.relation_id IS NULL ";
}
- }
-
- else{
+ }
+ else {
foreach($data as $key => &$value) {
// for now, I assume string values are the only possible handles.
// of course, this is not entirely true, but I find it good enough.
- if(!is_numeric($value)){
-
- $related_field_id = $this->get('related_field_id');
+ if(!is_numeric($value) && !is_null($value)){
+ $related_field_ids = $this->get('related_field_id');
+ $id = null;
- if(is_array($related_field_id) && !empty($related_field_id)) {
+ foreach($related_field_ids as $related_field_id) {
$return = Symphony::Database()->fetchCol("id", sprintf(
"SELECT
`entry_id` as `id`
@@ -436,19 +435,17 @@ public function buildDSRetrivalSQL($data, &$joins, &$where, $andOperation=false)
`tbl_entries_data_%d`
WHERE
`handle` = '%s'
- LIMIT 1", $related_field_id[0], Lang::createHandle($value)
+ LIMIT 1", $related_field_id, Lang::createHandle($value)
));
// Skipping returns wrong results when doing an AND operation, return 0 instead.
- if(empty($return)){
- $value = 0;
- }
-
- else{
- $value = $return[0];
+ if(!empty($return)) {
+ $id = $return[0];
+ break;
}
}
+ $value = (is_null($id)) ? 0 : $id;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.