Search

Thanks Nick - So I simply hope for 2.0.2 to be released soon...

Allen's latest tweet:

Symphony 2.0.2 bug fix marathon Mon-Wed. Three-day Symphony 3 sessions Thurs-Sat. It's going to be a fun filled Symphony week.

So hopefully middle of next week!

The Select Box Link field sorts entries on the publish page descending (by system ID). Is there any simple way to make it sort 'em alphabetically (ascending)?

I think it would be great to make sorting configurable! A great step would be to have a checkbox for "sort alphabetically" (which should correspond to the field you want to display, of course).

Would the Bi-Link work?

I will test the Bi_link field on the weekend. Nevertheless an improvement of the standard Select Box Link field like stated above would surely be nice for many people.

I have to agree with Michael regarding the sorting of the Select Box Link select options. The default might work for a list of blog entries, but for anything else where the expected order is ascending, the descending order of these values just seems wrong. I’ve been trying to look through the field.selectbox_link.php file to see where the ordering of the values is set. I can’t figure out what I could change. Here’s the portion of the code that controls the display of the Select Box Link field on the publish pages:

    function displayPublishPanel(&$wrapper, $data=NULL, $flagWithError=NULL, $fieldnamePrefix=NULL, $fieldnamePostfix=NULL){

        if(!is_array($data['relation_id'])){
            $entry_ids = array($data['relation_id']);
        }

        else{
            $entry_ids = array_values($data['relation_id']);
        }

        $states = $this->findOptions($entry_ids);

        $options = array();

        if($this->get('required') != 'yes') $options[] = array(NULL, false, NULL);

        if(!empty($states)){
            foreach($states as $s){
                $group = array('label' => $s['name'], 'options' => array());
                foreach($s['values'] as $id => $v){
                    $group['options'][] = array($id, in_array($id, $entry_ids), $v);
                }
                $options[] = $group;
            }
        }

        $fieldname = 'fields'.$fieldnamePrefix.'['.$this->get('element_name').']'.$fieldnamePostfix;
        if($this->get('allow_multiple_selection') == 'yes') $fieldname .= '[]';

        $label = Widget::Label($this->get('label'));
        $label->appendChild(Widget::Select($fieldname, $options, ($this->get('allow_multiple_selection') == 'yes' ? array('multiple' => 'multiple') : NULL)));

        if($flagWithError != NULL) $wrapper->appendChild(Widget::wrapFormElementWithError($label, $flagWithError));
        else $wrapper->appendChild($label); 
    }

Can anyone point me in the right direction to change the order of the values to ascending?

Here’s how a PHP noob thinks: if I change the variable $v to a hard coded value, I can tell that this is where the values are being generated.

        if(!empty($states)){
            foreach($states as $s){
                $group = array('label' => $s['name'], 'options' => array());
                foreach($s['values'] as $id => $v){
                    $group['options'][] = array($id, in_array($id, $entry_ids), 'value');
                }
                $options[] = $group;
            }
        }

How can the $states array be sorted?

How can the $states array be sorted?

The structure of $states is array('name' => XXX, 'values' => array()). I assume you are hoping to sort $states[X]['values'] correct?

Try throwing a sort() just above the foreach. E.G.:

sort($s['values']);
foreach($s['values'] as $id => $v){
    $group['options'][] = array($id, in_array($id, $entry_ids), 'value');
}

Pretty sure that’s what you’re after.

That’s exactly what I’m after. Thanks, Alistair. So, that will sort the values in alphabetical order.

Now, how would I go about sorting by another field. For example, I have an Order Entries field called “Sort”. I’m guessing that if I wanted to sort the values by this field, I would need to do that before the $states array is populated, so probably in the findOptions method:

    public function findOptions(array $existing_selection=NULL){

        $values = array();
        $limit = $this->get('limit');

        foreach($this->get('related_field_id') as $field_id){

            $section = $this->Database->fetchRow(0, "SELECT s.name, s.id
                                                    FROM `sym_sections` AS `s` 
                                                    LEFT JOIN `sym_fields` AS `f` ON `s`.id = `f`.parent_section
                                                    WHERE `f`.id = '{$field_id}'
                                                    LIMIT 1");

            $group = array('name' => $section['name'], 'section' => $section['id'], 'values' => array());

            $sql = "SELECT DISTINCT `entry_id` 
                    FROM `sym_entries_data_{$field_id}`
                    ORDER BY `entry_id` DESC
                    LIMIT 0, {$limit}";

            $results = $this->Database->fetchCol('entry_id', $sql);

            if(!is_null($existing_selection) && !empty($existing_selection)){
                foreach($existing_selection as $key => $entry_id){
                    $x = $this->findFieldIDFromRelationID($entry_id);

                    if($x == $field_id){
                        $results[] = $entry_id;
                        //unset($existing_selection[$key]);
                    }
                }
            }

            rsort($results);

            if(is_array($results) && !empty($results)){
                foreach($results as $entry_id){
                    $value = $this->__findPrimaryFieldValueFromRelationID($entry_id);
                    $group['values'][$entry_id] = $value['value'];
                }
            }

            $values[] = $group;
        }

        return $values;

    }       

…since the array is populated with this:

        $states = $this->findOptions($entry_ids);

So, my first thought was that the values should be sorted in the SQL query:

            $sql = "SELECT DISTINCT `entry_id` 
                    FROM `sym_entries_data_{$field_id}`
                    ORDER BY `entry_id` DESC
                    LIMIT 0, {$limit}";

By changing it to

    ORDER BY `entry_id`  ASC

But that did nothing. Then I realized that the $results were getting sorted here:

            rsort($results);

So, I figured this must be a reverse order sort function. I changed it to this:

            sort($results);

And the Select Box Link options are now displayed in ascending order by system ID.

If I can figure out how to sort by any of the other fields in the section, I might be able to cobble together a way to configure the sort order for the Select Box Link field values when building sections.

I am using Select Box Link in a Section with non required value. I want to filter the results of this Select Box Link in a Data Source based on the ‘None’ value, when the user has not selected anything. I tried None, 0, null, empty with no luck. Does the extension supports such filtering?

How do I select more than the linked field in my Datasources?

For example: I have albums and bands, each album having a select box link to a band. My DS is only returning the band name, not the other fields (image, homepage, text, anything else). Is there something I am missing?

For example: I have albums and bands, each album having a select box link to a band. My DS is only returning the band name, not the other fields (image, homepage, text, anything else). Is there something I am missing?

You need to pull the other information in with an additional data source. One way to do it is to have the current data source output the select box link field as a parameter and use that to filter the related data source.

I want to filter the results of this Select Box Link in a Data Source based on the ‘None’ value, when the user has not selected anything. I tried None, 0, null, empty with no luck. Does the extension supports such filtering?

Unfortunately, there is either a relationship or there isn’t. Meaning, if the entry has a select box link with nothing selected then there is nothing added to the database; it simply doesn’t exist.

You need to pull the other information in with an additional data source. One way to do it is to have the current data source output the select box link field as a parameter and use that to filter the related data source.

Thats impossible when I want to display a list of items.

Thats impossible when I want to display a list of items.

Why?

Shall I call the second DS 10 times when there are 10 elements in the first DS with the select box link? And how do I associate the corresponding elements from the two XML-nodesets?

If your first DS returns 10 entries, won’t all 10 IDs then be passed in the output param? Thus, when you filter the second DS by that param, won’t you get entries matching all?

Associating the nodesets shouldn’t be that difficult using XPath predicates.

All that being said, though, the Subsection Field extension has the functionality you’re looking for I think.

And what if I am linking two or more sections to one section?

Not sure I follow… Can you explain exactly what you’re trying to do?

A band regularily releases new albums, but not always on the same label.

So I have an album with two select box links: to the band and to the label.

How do I select a list of recently released albums and join all the artist- and label-fields at the same time?

The output parameter only allows me to fetch one of these, the band or the label.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details