[TASK] Re-work/simplify copyright header in PHP files - Part 3
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Resource / Collection / CategoryBasedFileCollection.php
1 <?php
2 namespace TYPO3\CMS\Core\Resource\Collection;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * A collection containing a set files belonging to certain categories.
19 * This collection is persisted to the database with the accordant category identifiers.
20 */
21 class CategoryBasedFileCollection extends \TYPO3\CMS\Core\Resource\Collection\AbstractFileCollection {
22
23 /**
24 * @var string
25 */
26 static protected $storageTableName = 'sys_file_collection';
27
28 /**
29 * @var string
30 */
31 static protected $type = 'categories';
32
33 /**
34 * @var string
35 */
36 static protected $itemsCriteriaField = 'category';
37
38 /**
39 * @var string
40 */
41 protected $itemTableName = 'sys_category';
42
43 /**
44 * Populates the content-entries of the collection
45 *
46 * @return void
47 */
48 public function loadContents() {
49
50 $resource = $this->getDatabaseConnection()->exec_SELECT_mm_query(
51 'sys_file_metadata.file',
52 'sys_category',
53 'sys_category_record_mm',
54 'sys_file_metadata',
55 'AND sys_category.uid=' . (int)$this->getItemsCriteria() .
56 ' AND sys_category_record_mm.tablenames = \'sys_file_metadata\''
57 );
58
59 $resourceFactory = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance();
60 if ($resource) {
61 while (($record = $this->getDatabaseConnection()->sql_fetch_assoc($resource)) !== FALSE) {
62 $this->add($resourceFactory->getFileObject((int)$record['file']));
63 }
64 $this->getDatabaseConnection()->sql_free_result($resource);
65 }
66 }
67
68 /**
69 * Gets the database object.
70 *
71 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
72 */
73 protected function getDatabaseConnection() {
74 return $GLOBALS['TYPO3_DB'];
75 }
76
77 }