Datasets for K2: User Manual

  • Comments:View comments

Datasets for K2 plugin will help you to create multiple sets of K2 extra fields for the same K2 item, where original K2 only support one extra fields group for a specific item.

Features:
  • Easy management of field sets.
  • Separate tab for the data sets, so you can use the extra fields tab at the same time without any confusion.
  • Each set/row can be of a different extra fields group.
  • Supports displaying sets with extra field alias method, except that the output is in nested associative arrays, an example is explained with code below.
  • Almost all extra field types are supported.
Installation & Upgrade:

Install/Update the plugin normally like any other Joomla extension, using Extension Manager.
Then make sure to publish/enable the plugin.

How it works?

The plugin creates a separate tab to manage the data sets, the tab is labeled "Data Sets", and it is divided into 2 vertical areas, the Toolbar and the sets listing areas.

To create a new data set/row, click on the New button and select the group which will populate the extra fields of this new data set/row.

To Delete a data set/row, tick the checkbox on the left of the groups drop down list and click on the Delete button.

Due to the variant and multiple layouts available to display datasets, the plugin outputs them in nested associative arrays, with some php code you can display the layout which is suitable for your case.

Output Example:

In this example, a group of 5 extra fields is created and used to populate the data sets/rows, the field aliases are:
DaY, FirstInterval, SecondInterval, ThirdInterval and FourthInterval.

The item edit form view of with Data Sets tab is shown below:

Using the code segment below, the item view page on front end is shown in the following screenshot.

   

<?php if($this->item->extraFieldsDataSets): ?>
                <?php $style="float: left; width: 20%;font-weight:bold;color:white;background-color: rgb(112, 196, 105);"?>
                <div class="extraFieldsDataSets">
                    <div style="<?php echo $style; ?>">Days</div>
                    <div style="<?php echo $style; ?>">7:45 - 8:25</div>
                    <div style="<?php echo $style; ?>">8:25 - 9:35</div>
                    <div style="<?php echo $style; ?>">9:35 - 10:20</div>
                    <div style="<?php echo $style; ?>">10:20 - 10:45</div>                   
                    <?php foreach($this->item->extraFieldsDataSets as $key=>$dataSet): ?>
                        <?php
                        $style = "float: left; width: 20%;" . ($i?"":"background-color:#f0f0f0;");
                        $i = 1 - $i;
                        ?>
                        <div style="<?php echo $style; ?>font-weight:bold;"><?php echo $dataSet['fields']['DaY']; ?></div>
                        <div style="<?php echo $style; ?>"><?php echo $dataSet['fields']['FirstInterval']; ?></div>
                        <div style="<?php echo $style; ?>"><?php echo $dataSet['fields']['SecondInterval']; ?></div>
                        <div style="<?php echo $style; ?>"><?php echo $dataSet['fields']['ThirdInterval']; ?></div>
                        <div style="<?php echo $style; ?>"><?php echo $dataSet['fields']['FourthInterval']; ?></div>
                    <?php endforeach ;?>
                </div>
                <div class="clr"></div>
        <?php endif; ?>
<?php echo $this->item->extraFieldsDataSets[2]['fields']['SecondInterval']; ?>

For example, to access the "Second Interval" field of the 3rd data set/row you can use the above statement

Read 3467 times
Mohamed Abdelaziz

Joomla and PHP developer since 2006, working as freelancer to develop and customize Joomla extensions. Technically reviewed the books: Joomla! 2.5 Beginner's Guide and Joomla! 3 Beginner's Guide for Packt Publishing.

More in this category: AutoMeta for K2: User Manual »