What is the criteria determining the display order of the content registered in the dynamic playlist? I don't think it's entirely random

Thank you in advance.

They are assigned in name ascending order.

Thank you for your comment.
I using cms 2.3.3.

I had a quick check back to that release, and its still name ascending order. :+1:

Thank you :smiley: , I am aware of that. I appreciate your confirmation. The issue is that when I remove media assigned to the dynamic playlist and re-register it, the order becomes completely chaotic. I am troubled by this matter.:sob:

Ah I see, you are reporting a problem then!

I think the first thing to do would be to see if you have the same issue in a supported release (v4 or v3).

1 Like

I apologize if the intent of my question took a roundabout way. Yes, I will consider updating to a newer version. Thank you!

1 Like

I tried to stick with it while saying I would update it. LOL :sweat_smile:
① I realized that in order to ensure the order through the “name”, basically, if there is any change, we need to rebuild the widget from scratch. This fix is quite primitive, but given that there isn’t much change between the latest source now (link below) and the source in 2.3.3, it feels effective. However, since the method is primitive, I’m soliciting points of concern and supplementary points regarding this fix.

② I slightly wondered whether it is intended to use the $count variable, which indicates the total number of playlists, as a parameter for displayOrder (the displayOrder will become a fixed value). Well, even modifying to increment the count of the displayOrder didn’t fix the issue mentioned in ①. (because there is control on the playlist.php side)
This was just a report.

Thank you for your consideration.

    /** @inheritdoc */
    public function run()
    {
        // If we're in the error state, then always run, otherwise check the dates we modified various triggers
        if ($this->getTask()->lastRunStatus !== Task::$STATUS_ERROR) {
            // Run a little query to get the last modified date from the media table
            $lastMediaUpdate = $this->store->select('SELECT MAX(modifiedDt) AS modifiedDt FROM `media` WHERE 
                `type` <> \'module\'
                AND `type` <> \'genericfile\'
                AND `type` <> \'playersoftware\'
                AND `type` <> \'font\';', [])[0]['modifiedDt'];
            $lastPlaylistUpdate = $this->store->select('SELECT MAX(modifiedDt) AS modifiedDt FROM `playlist`;', [])[0]['modifiedDt'];

            if (empty($lastMediaUpdate) && empty($lastPlaylistUpdate)) {
                $this->appendRunMessage('No library media or Playlists to assess');
                return;
            }

            $this->log->debug('Last media updated date is ' . $lastMediaUpdate);
            $this->log->debug('Last playlist updated date is ' . $lastPlaylistUpdate);

            $lastMediaUpdate = $this->date->parse($lastMediaUpdate);
            $lastPlaylistUpdate = $this->date->parse($lastPlaylistUpdate);
            $lastTaskRun = $this->date->parse($this->getTask()->lastRunDt, 'U');

            if ($lastMediaUpdate->lessThanOrEqualTo($lastTaskRun) && $lastPlaylistUpdate->lessThanOrEqualTo($lastTaskRun)) {
                $this->appendRunMessage('No library media/playlist updates since we last ran');
                return;
            }
        }

        $count = 0;

        // Get all Dynamic Playlists
        foreach ($this->playlistFactory->query(null, ['isDynamic' => 1]) as $playlist) {
            try {
                // We want to detect any differences in what should be assigned to this Playlist.
                $playlist->load();

                $this->log->debug('Assessing Playlist: ' . $playlist->name);

                // Query for media which would be assigned to this Playlist and see if there are any differences
                $media = [];
                $mediaIds = [];
                foreach ($this->mediaFactory->query(null, [
                    'name' => $playlist->filterMediaName,
                    'tags' => $playlist->filterMediaTags
                ]) as $item) {
                    $media[$item->mediaId] = $item;
                    $mediaIds[] = $item->mediaId;
                }

                // Work out if the set of widgets is different or not.
                // This is only the first loose check
                $different = (count($playlist->widgets) !== count($media));

                $this->log->debug('There are ' . count($media) . ' that should be assigned and ' . count($playlist->widgets)
                    . ' currently assigned. First check difference is ' . var_export($different, true));

                if (!$different) {
                    // Try a more complete check, using mediaIds
                    $compareMediaIds = $mediaIds;

                    // ordering should be the same, so the first time we get one out of order, we can stop
                    foreach ($playlist->widgets as $widget) {
                        try {
                            $widgetMediaId = $widget->getPrimaryMediaId();
                            if ($widgetMediaId !== $compareMediaIds[0] || $widget->duration !== $media[$widgetMediaId]->duration) {
                                $different = true;
                                break;
                            }
                        } catch (NotFoundException $notFoundException) {
                            $this->log->error('Playlist ' . $playlist->getId() . ' has a Widget without any associated media. widgetId = ' . $widget->getId());

                            // We ought to recalculate
                            $different = true;
                            break;
                        }

                        array_shift($compareMediaIds);
                    }
                }

                $this->log->debug('Second check difference is ' . var_export($different, true));

                if ($different) {
                    // We will update this Playlist
                    $assignmentMade = false;
                    $count++;

                    ////以下の、更新されたメディアIDの特定処理は行わない(displayOrderを刷新するために、全部ウィジェットを作り直す)
                    
                    // // // Remove the ones no-longer present, add the ones we're missing
                    // // // we don't delete and re-add the lot to avoid regenerating the widgetIds (makes stats harder to
                    // // // interpret)
                    // // foreach ($playlist->widgets as $widget) {
                    // //     try {
                    // //         $widgetMediaId = $widget->getPrimaryMediaId();

                    // //         if (!in_array($widgetMediaId, $mediaIds)) {
                    // //             $playlist->deleteWidget($widget);
                    // //         } else {
                    // //             // It's present in the array
                    // //             // Check to see if the duration is different
                    // //             if ($widget->duration !== $media[$widgetMediaId]->duration) {
                    // //                 // The media duration has changed, so update the widget
                    // //                 $widget->useDuration = 1;
                    // //                 $widget->duration = $media[$widgetMediaId]->duration;
                    // //                 $widget->calculatedDuration = $widget->duration;
                    // //                 $widget->save([
                    // //                     'saveWidgetOptions' => false,
                    // //                     'saveWidgetAudio' => false,
                    // //                     'saveWidgetMedia' => false,
                    // //                     'notify' => false,
                    // //                     'notifyPlaylists' => false,
                    // //                     'notifyDisplays' => false,
                    // //                     'audit' => true,
                    // //                     'alwaysUpdate' => true
                    // //                 ]);
                    // //             }

                    // //             // Pop it off the list of ones to assign.
                    // //             $mediaIds = array_diff($mediaIds, [$widgetMediaId]);

                    // //             // We do want to save the Playlist here.
                    // //             $assignmentMade = true;
                    // //         }

                    // //     } catch (NotFoundException $exception) {
                    // //         // Delete it
                    // //         $playlist->deleteWidget($widget);
                    // //     }
                    // // }

                    // // // Do we have any mediaId's left which should be assigned and aren't?
                    // // // Add the ones we have left
                    // // foreach ($media as $item) {
                    // //     if (in_array($item->mediaId, $mediaIds)) {
                    // //         $assignmentMade = true;
                    // //         $this->createAndAssign($playlist, $item, $count);
                    // //     }
                    // // }

                    //ごっそり既存のwidgetを削除し、刷新する
                    foreach ($playlist->widgets as $widget) {
                            $playlist->deleteWidget($widget);
                    }
                    $assignmentMade = true;
                    $cnt=0;
                    foreach ($media as $item) {
                        $cnt++;
                        $this->createAndAssign($playlist, $item, $cnt);
                    }

                    //以降はそのまま


                    if ($assignmentMade) {
                        // We've made an assignment change, so audit this change
                        // don't audit any downstream save operations
                        $playlist->save([
                            'auditPlaylist' => true,
                            'audit' => false
                        ]);
                    }
                } else {
                    $this->log->debug('No differences detected');
                }

            } catch (XiboException $exception) {
                $this->log->debug($exception->getTraceAsString());
                $this->log->error('Problem with PlaylistId: ' . $playlist->getId() . ', e = ' . $exception->getMessage());
                $this->appendRunMessage('Error with Playlist: ' . $playlist->name);
            }
        }

        $this->appendRunMessage('Updated ' . $count . ' Playlists');
    }

I am sorry but I don’t understand.

Please can you give us simple and clear steps to recreate the problem you’re experiencing. I have tried to recreate it myself on a test CMS and my dynamic playlist always comes in name ascending order.

Thank for your reply and your research !

  • I will provide you with images numbered 0 to 9 as test data.
  • Please create one dynamic playlist and one layout. Assign the dynamic playlist to the layout.
  • Set the filter for the dynamic playlist to “TestRenban_”.
  • Please upload the images numbered 0 to 9 from the test data, excluding the black version ones.
  • Once linked to the dynamic playlist, please check the layout and confirm that the images numbered 0 to 9 are arranged in proper order.
  • From here, we will enter the phase of reproducing the phenomenon.
  • Remove the image of number 0 from the media, and immediately add the image of number 0 (the black version with the same name).
  • Please do the same for the images numbered 1 to 4.
  • Now, if you preview on the layout, you should be able to confirm a phenomenon where the order is disrupted.

I am enclosing a record of verification conducted by myself. It might be too lengthy and tiresome to read, but I hope it can be of some assistance.

Thank for your reply and your research!

TestRenban_0
TestRenban_1
TestRenban_2
TestRenban_3
TestRenban_4
TestRenban_5
TestRenban_6
TestRenban_7
TestRenban_8
TestRenban_9
TestRenban_0
TestRenban_1
TestRenban_2
TestRenban_3
TestRenban_4
TestRenban_5
TestRenban_6
TestRenban_7
TestRenban_8
TestRenban_9

researchResult-21-43.pdf (2.5 MB)
researchResult-1-20.pdf (2.9 MB)

The naming convention for the numerical images does not necessarily have to be “TestRenban_”; any naming convention will do.
As always, I apologize for the roundabout way of conveying this, and at the same time, I am grateful for Dan’s generous understanding!
Thank you in advance!

I think this is the most comprehensive bug report we’ve ever received, by a long way! I have created an issue for us to investigate:

As you have said, it seems likely this is something to do with the display order set on assignment.

Thanks!

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.