~xibo-maintainers/xibo/tempel

« back to all changes in this revision

Viewing changes to lib/Entity/Playlist.php

  • Committer: Dan Garner
  • Date: 2016-02-04 14:13:07 UTC
  • mto: (454.4.101)
  • mto: This revision was merged to the branch mainline in revision 483.
  • Revision ID: git-v1:f9078f575b16a62a51e2f3d7bc15581058fb0747
Problem with DataSet form putting a 0 in library image references (should be empty)

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
use Xibo\Factory\PermissionFactory;
28
28
use Xibo\Factory\RegionFactory;
29
29
use Xibo\Factory\WidgetFactory;
30
 
use Xibo\Service\DateServiceInterface;
31
 
use Xibo\Service\LogServiceInterface;
32
 
use Xibo\Storage\StorageServiceInterface;
 
30
use Xibo\Helper\Date;
 
31
use Xibo\Helper\Log;
 
32
use Xibo\Storage\PDOConnect;
33
33
 
34
34
/**
35
35
 * Class Playlist
89
89
     */
90
90
    public $displayOrder;
91
91
 
92
 
    /**
93
 
     * @var DateServiceInterface
94
 
     */
95
 
    private $dateService;
96
 
 
97
 
    /**
98
 
     * @var PermissionFactory
99
 
     */
100
 
    private $permissionFactory;
101
 
 
102
 
    /**
103
 
     * @var WidgetFactory
104
 
     */
105
 
    private $widgetFactory;
106
 
 
107
 
    /**
108
 
     * @var RegionFactory
109
 
     */
110
 
    private $regionFactory;
111
 
 
112
 
    /**
113
 
     * Entity constructor.
114
 
     * @param StorageServiceInterface $store
115
 
     * @param LogServiceInterface $log
116
 
     * @param DateServiceInterface $date
117
 
     * @param PermissionFactory $permissionFactory
118
 
     * @param WidgetFactory $widgetFactory
119
 
     */
120
 
    public function __construct($store, $log, $date, $permissionFactory, $widgetFactory)
 
92
    public function __construct()
121
93
    {
122
 
        $this->setCommonDependencies($store, $log);
123
 
 
124
 
        $this->dateService = $date;
125
 
        $this->permissionFactory = $permissionFactory;
126
 
        $this->widgetFactory = $widgetFactory;
127
 
 
 
94
        // Exclude properties that will cause recursion
128
95
        $this->excludeProperty('regions');
129
96
    }
130
97
 
131
 
    /**
132
 
     * @param $regionFactory
133
 
     * @return $this
134
 
     */
135
 
    public function setChildObjectDependencies($regionFactory)
136
 
    {
137
 
        $this->regionFactory = $regionFactory;
138
 
        return $this;
139
 
    }
140
 
 
141
98
    public function __clone()
142
99
    {
143
100
        $this->hash = null;
235
192
            'loadWidgets' => true
236
193
        ], $loadOptions);
237
194
 
238
 
        $this->getLog()->debug('Load Playlist with %s', json_encode($options));
 
195
        Log::debug('Load Playlist with %s', json_encode($options));
239
196
 
240
197
        // Load permissions
241
198
        if ($options['loadPermissions'])
242
 
            $this->permissions = $this->permissionFactory->getByObjectId(get_class(), $this->playlistId);
 
199
            $this->permissions = PermissionFactory::getByObjectId(get_class(), $this->playlistId);
243
200
 
244
201
        // Load the widgets
245
202
        if ($options['loadWidgets']) {
246
 
            foreach ($this->widgetFactory->getByPlaylistId($this->playlistId) as $widget) {
 
203
            foreach (WidgetFactory::getByPlaylistId($this->playlistId) as $widget) {
247
204
                /* @var Widget $widget */
248
205
                $widget->load();
249
206
                $this->widgets[] = $widget;
252
209
 
253
210
        if ($options['playlistIncludeRegionAssignments']) {
254
211
            // Load the region assignments
255
 
            foreach ($this->regionFactory->getByPlaylistId($this->playlistId) as $region) {
 
212
            foreach (RegionFactory::getByPlaylistId($this->playlistId) as $region) {
256
213
                /* @var Region $region */
257
214
                $this->regions[] = $region;
258
215
            }
305
262
        if (!$this->loaded)
306
263
            $this->load();
307
264
 
308
 
        $this->getLog()->debug('Deleting ' . $this);
 
265
        Log::debug('Deleting ' . $this);
309
266
 
310
267
        // Delete Permissions
311
268
        foreach ($this->permissions as $permission) {
330
287
        }
331
288
 
332
289
        // Delete this playlist
333
 
        $this->getStore()->update('DELETE FROM `playlist` WHERE playlistId = :playlistId', array('playlistId' => $this->playlistId));
 
290
        PDOConnect::update('DELETE FROM `playlist` WHERE playlistId = :playlistId', array('playlistId' => $this->playlistId));
334
291
    }
335
292
 
336
293
    /**
338
295
     */
339
296
    private function add()
340
297
    {
341
 
        $this->getLog()->debug('Adding Playlist ' . $this->name);
 
298
        Log::debug('Adding Playlist ' . $this->name);
342
299
 
343
300
        $sql = 'INSERT INTO `playlist` (`name`, `ownerId`) VALUES (:name, :ownerId)';
344
 
        $this->playlistId = $this->getStore()->insert($sql, array(
 
301
        $this->playlistId = PDOConnect::insert($sql, array(
345
302
            'name' => $this->name,
346
303
            'ownerId' => $this->ownerId
347
304
        ));
352
309
     */
353
310
    private function update()
354
311
    {
355
 
        $this->getLog()->debug('Updating Playlist ' . $this->name . '. Id = ' . $this->playlistId);
 
312
        Log::debug('Updating Playlist ' . $this->name . '. Id = ' . $this->playlistId);
356
313
 
357
314
        $sql = 'UPDATE `playlist` SET `name` = :name WHERE `playlistId` = :playlistId';
358
 
        $this->getStore()->update($sql, array(
 
315
        PDOConnect::update($sql, array(
359
316
            'playlistId' => $this->playlistId,
360
317
            'name' => $this->name
361
318
        ));
370
327
     */
371
328
    public function notifyLayouts()
372
329
    {
373
 
        $this->getStore()->update('
 
330
        PDOConnect::update('
374
331
            UPDATE `layout` SET `status` = 3, `modifiedDT` = :modifiedDt WHERE layoutId IN (
375
332
              SELECT `region`.layoutId
376
333
                FROM `lkregionplaylist`
380
337
            )
381
338
        ', [
382
339
            'playlistId' => $this->playlistId,
383
 
            'modifiedDt' => $this->dateService->getLocalDate()
 
340
            'modifiedDt' => Date::getLocalDate()
384
341
        ]);
385
342
    }
386
343
 
390
347
     */
391
348
    public function hasLayouts()
392
349
    {
393
 
        $results = $this->getStore()->select('SELECT COUNT(*) AS qty FROM `lkregionplaylist` WHERE playlistId = :playlistId', ['playlistId' => $this->playlistId]);
 
350
        $results = PDOConnect::select('SELECT COUNT(*) AS qty FROM `lkregionplaylist` WHERE playlistId = :playlistId', ['playlistId' => $this->playlistId]);
394
351
 
395
352
        return ($results[0]['qty'] > 0);
396
353
    }