Completed
Pull Request — master (#131)
by De Cramer
05:13 queued 02:26
created

RecordTableMap   B

Complexity

Total Complexity 41

Size/Duplication

Total Lines 461
Duplicated Lines 28.63 %

Coupling/Cohesion

Components 2
Dependencies 13

Importance

Changes 0
Metric Value
wmc 41
lcom 2
cbo 13
dl 132
loc 461
rs 8.2769
c 0
b 0
f 0

14 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 21 1
A buildRelations() 10 10 1
A getBehaviors() 0 6 1
B getPrimaryKeyHashFromRow() 9 9 11
A getPrimaryKeyFromRow() 8 8 2
A getOMClass() 0 4 2
A populateObject() 18 18 2
B populateObjects() 25 25 3
B addSelectColumns() 0 26 2
A getTableMap() 0 4 1
A buildTableMap() 7 7 2
C doDelete() 29 29 7
A doDeleteAll() 0 4 1
B doInsert() 26 26 5

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like RecordTableMap often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use RecordTableMap, and based on these observations, apply Extract Interface, too.

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 29 and the first side effect is on line 492.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
namespace eXpansion\Bundle\LocalRecords\Model\Map;
4
5
use Propel\Runtime\Propel;
6
use Propel\Runtime\ActiveQuery\Criteria;
7
use Propel\Runtime\ActiveQuery\InstancePoolTrait;
8
use Propel\Runtime\Connection\ConnectionInterface;
9
use Propel\Runtime\DataFetcher\DataFetcherInterface;
10
use Propel\Runtime\Exception\PropelException;
11
use Propel\Runtime\Map\RelationMap;
12
use Propel\Runtime\Map\TableMap;
13
use Propel\Runtime\Map\TableMapTrait;
14
use eXpansion\Bundle\LocalRecords\Model\Record;
15
use eXpansion\Bundle\LocalRecords\Model\RecordQuery;
16
17
18
/**
19
 * This class defines the structure of the 'record' table.
20
 *
21
 *
22
 *
23
 * This map class is used by Propel to do runtime db structure discovery.
24
 * For example, the createSelectSql() method checks the type of a given column used in an
25
 * ORDER BY clause to know whether it needs to apply SQL to make the ORDER BY case-insensitive
26
 * (i.e. if it's a text column type).
27
 *
28
 */
29
class RecordTableMap extends TableMap
30
{
31
    use InstancePoolTrait;
32
    use TableMapTrait;
33
34
    /**
35
     * The (dot-path) name of this class
36
     */
37
    const CLASS_NAME = 'src.eXpansion.Bundle.LocalRecords.Model.Map.RecordTableMap';
38
39
    /**
40
     * The default database name for this class
41
     */
42
    const DATABASE_NAME = 'expansion';
43
44
    /**
45
     * The table name for this class
46
     */
47
    const TABLE_NAME = 'record';
48
49
    /**
50
     * The related Propel class for this table
51
     */
52
    const OM_CLASS = '\\eXpansion\\Bundle\\LocalRecords\\Model\\Record';
53
54
    /**
55
     * A class that can be returned by this tableMap
56
     */
57
    const CLASS_DEFAULT = 'src.eXpansion.Bundle.LocalRecords.Model.Record';
58
59
    /**
60
     * The total number of columns
61
     */
62
    const NUM_COLUMNS = 10;
63
64
    /**
65
     * The number of lazy-loaded columns
66
     */
67
    const NUM_LAZY_LOAD_COLUMNS = 0;
68
69
    /**
70
     * The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS)
71
     */
72
    const NUM_HYDRATE_COLUMNS = 10;
73
74
    /**
75
     * the column name for the id field
76
     */
77
    const COL_ID = 'record.id';
78
79
    /**
80
     * the column name for the mapUid field
81
     */
82
    const COL_MAPUID = 'record.mapUid';
83
84
    /**
85
     * the column name for the nbLaps field
86
     */
87
    const COL_NBLAPS = 'record.nbLaps';
88
89
    /**
90
     * the column name for the score field
91
     */
92
    const COL_SCORE = 'record.score';
93
94
    /**
95
     * the column name for the nbFinish field
96
     */
97
    const COL_NBFINISH = 'record.nbFinish';
98
99
    /**
100
     * the column name for the avgScore field
101
     */
102
    const COL_AVGSCORE = 'record.avgScore';
103
104
    /**
105
     * the column name for the checkpoints field
106
     */
107
    const COL_CHECKPOINTS = 'record.checkpoints';
108
109
    /**
110
     * the column name for the player_id field
111
     */
112
    const COL_PLAYER_ID = 'record.player_id';
113
114
    /**
115
     * the column name for the created_at field
116
     */
117
    const COL_CREATED_AT = 'record.created_at';
118
119
    /**
120
     * the column name for the updated_at field
121
     */
122
    const COL_UPDATED_AT = 'record.updated_at';
123
124
    /**
125
     * The default string format for model objects of the related table
126
     */
127
    const DEFAULT_STRING_FORMAT = 'YAML';
128
129
    /**
130
     * holds an array of fieldnames
131
     *
132
     * first dimension keys are the type constants
133
     * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
134
     */
135
    protected static $fieldNames = array (
136
        self::TYPE_PHPNAME       => array('Id', 'Mapuid', 'Nblaps', 'Score', 'Nbfinish', 'Avgscore', 'Checkpoints', 'PlayerId', 'CreatedAt', 'UpdatedAt', ),
137
        self::TYPE_CAMELNAME     => array('id', 'mapuid', 'nblaps', 'score', 'nbfinish', 'avgscore', 'checkpoints', 'playerId', 'createdAt', 'updatedAt', ),
138
        self::TYPE_COLNAME       => array(RecordTableMap::COL_ID, RecordTableMap::COL_MAPUID, RecordTableMap::COL_NBLAPS, RecordTableMap::COL_SCORE, RecordTableMap::COL_NBFINISH, RecordTableMap::COL_AVGSCORE, RecordTableMap::COL_CHECKPOINTS, RecordTableMap::COL_PLAYER_ID, RecordTableMap::COL_CREATED_AT, RecordTableMap::COL_UPDATED_AT, ),
139
        self::TYPE_FIELDNAME     => array('id', 'mapUid', 'nbLaps', 'score', 'nbFinish', 'avgScore', 'checkpoints', 'player_id', 'created_at', 'updated_at', ),
140
        self::TYPE_NUM           => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, )
141
    );
142
143
    /**
144
     * holds an array of keys for quick access to the fieldnames array
145
     *
146
     * first dimension keys are the type constants
147
     * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0
148
     */
149
    protected static $fieldKeys = array (
150
        self::TYPE_PHPNAME       => array('Id' => 0, 'Mapuid' => 1, 'Nblaps' => 2, 'Score' => 3, 'Nbfinish' => 4, 'Avgscore' => 5, 'Checkpoints' => 6, 'PlayerId' => 7, 'CreatedAt' => 8, 'UpdatedAt' => 9, ),
151
        self::TYPE_CAMELNAME     => array('id' => 0, 'mapuid' => 1, 'nblaps' => 2, 'score' => 3, 'nbfinish' => 4, 'avgscore' => 5, 'checkpoints' => 6, 'playerId' => 7, 'createdAt' => 8, 'updatedAt' => 9, ),
152
        self::TYPE_COLNAME       => array(RecordTableMap::COL_ID => 0, RecordTableMap::COL_MAPUID => 1, RecordTableMap::COL_NBLAPS => 2, RecordTableMap::COL_SCORE => 3, RecordTableMap::COL_NBFINISH => 4, RecordTableMap::COL_AVGSCORE => 5, RecordTableMap::COL_CHECKPOINTS => 6, RecordTableMap::COL_PLAYER_ID => 7, RecordTableMap::COL_CREATED_AT => 8, RecordTableMap::COL_UPDATED_AT => 9, ),
153
        self::TYPE_FIELDNAME     => array('id' => 0, 'mapUid' => 1, 'nbLaps' => 2, 'score' => 3, 'nbFinish' => 4, 'avgScore' => 5, 'checkpoints' => 6, 'player_id' => 7, 'created_at' => 8, 'updated_at' => 9, ),
154
        self::TYPE_NUM           => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, )
155
    );
156
157
    /**
158
     * Initialize the table attributes and columns
159
     * Relations are not initialized by this method since they are lazy loaded
160
     *
161
     * @return void
162
     * @throws PropelException
163
     */
164
    public function initialize()
165
    {
166
        // attributes
167
        $this->setName('record');
168
        $this->setPhpName('Record');
169
        $this->setIdentifierQuoting(false);
170
        $this->setClassName('\\eXpansion\\Bundle\\LocalRecords\\Model\\Record');
171
        $this->setPackage('src.eXpansion.Bundle.LocalRecords.Model');
172
        $this->setUseIdGenerator(true);
173
        // columns
174
        $this->addPrimaryKey('id', 'Id', 'INTEGER', true, null, null);
175
        $this->addColumn('mapUid', 'Mapuid', 'VARCHAR', false, 255, null);
176
        $this->addColumn('nbLaps', 'Nblaps', 'INTEGER', false, null, null);
177
        $this->addColumn('score', 'Score', 'INTEGER', false, null, null);
178
        $this->addColumn('nbFinish', 'Nbfinish', 'INTEGER', false, null, null);
179
        $this->addColumn('avgScore', 'Avgscore', 'INTEGER', false, null, null);
180
        $this->addColumn('checkpoints', 'Checkpoints', 'LONGVARCHAR', false, null, null);
181
        $this->addForeignKey('player_id', 'PlayerId', 'INTEGER', 'player', 'id', false, null, null);
182
        $this->addColumn('created_at', 'CreatedAt', 'TIMESTAMP', false, null, null);
183
        $this->addColumn('updated_at', 'UpdatedAt', 'TIMESTAMP', false, null, null);
184
    } // initialize()
185
186
    /**
187
     * Build the RelationMap objects for this table relationships
188
     */
189 View Code Duplication
    public function buildRelations()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
190
    {
191
        $this->addRelation('Player', '\\eXpansion\\Framework\\PlayersBundle\\Model\\Player', RelationMap::MANY_TO_ONE, array (
192
  0 =>
193
  array (
194
    0 => ':player_id',
195
    1 => ':id',
196
  ),
197
), null, null, null, false);
198
    } // buildRelations()
199
200
    /**
201
     *
202
     * Gets the list of behaviors registered for this table
203
     *
204
     * @return array Associative array (name => parameters) of behaviors
205
     */
206
    public function getBehaviors()
207
    {
208
        return array(
209
            'timestampable' => array('create_column' => 'created_at', 'update_column' => 'updated_at', 'disable_created_at' => 'false', 'disable_updated_at' => 'false', ),
210
        );
211
    } // getBehaviors()
212
213
    /**
214
     * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table.
215
     *
216
     * For tables with a single-column primary key, that simple pkey value will be returned.  For tables with
217
     * a multi-column primary key, a serialize()d version of the primary key will be returned.
218
     *
219
     * @param array  $row       resultset row.
220
     * @param int    $offset    The 0-based offset for reading from the resultset row.
221
     * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
222
     *                           TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM
223
     *
224
     * @return string The primary key hash of the row
225
     */
226 View Code Duplication
    public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
227
    {
228
        // If the PK cannot be derived from the row, return NULL.
229
        if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null) {
230
            return null;
231
        }
232
233
        return null === $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] || is_scalar($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]) || is_callable([$row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)], '__toString']) ? (string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] : $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)];
234
    }
235
236
    /**
237
     * Retrieves the primary key from the DB resultset row
238
     * For tables with a single-column primary key, that simple pkey value will be returned.  For tables with
239
     * a multi-column primary key, an array of the primary key columns will be returned.
240
     *
241
     * @param array  $row       resultset row.
242
     * @param int    $offset    The 0-based offset for reading from the resultset row.
243
     * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
244
     *                           TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM
245
     *
246
     * @return mixed The primary key of the row
247
     */
248 View Code Duplication
    public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
249
    {
250
        return (int) $row[
251
            $indexType == TableMap::TYPE_NUM
252
                ? 0 + $offset
253
                : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)
254
        ];
255
    }
256
257
    /**
258
     * The class that the tableMap will make instances of.
259
     *
260
     * If $withPrefix is true, the returned path
261
     * uses a dot-path notation which is translated into a path
262
     * relative to a location on the PHP include_path.
263
     * (e.g. path.to.MyClass -> 'path/to/MyClass.php')
264
     *
265
     * @param boolean $withPrefix Whether or not to return the path with the class name
266
     * @return string path.to.ClassName
267
     */
268
    public static function getOMClass($withPrefix = true)
269
    {
270
        return $withPrefix ? RecordTableMap::CLASS_DEFAULT : RecordTableMap::OM_CLASS;
271
    }
272
273
    /**
274
     * Populates an object of the default type or an object that inherit from the default.
275
     *
276
     * @param array  $row       row returned by DataFetcher->fetch().
277
     * @param int    $offset    The 0-based offset for reading from the resultset row.
278
     * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType().
279
                                 One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
280
     *                           TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
281
     *
282
     * @throws PropelException Any exceptions caught during processing will be
283
     *                         rethrown wrapped into a PropelException.
284
     * @return array           (Record object, last column rank)
285
     */
286 View Code Duplication
    public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
287
    {
288
        $key = RecordTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType);
289
        if (null !== ($obj = RecordTableMap::getInstanceFromPool($key))) {
290
            // We no longer rehydrate the object, since this can cause data loss.
291
            // See http://www.propelorm.org/ticket/509
292
            // $obj->hydrate($row, $offset, true); // rehydrate
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
293
            $col = $offset + RecordTableMap::NUM_HYDRATE_COLUMNS;
294
        } else {
295
            $cls = RecordTableMap::OM_CLASS;
296
            /** @var Record $obj */
297
            $obj = new $cls();
298
            $col = $obj->hydrate($row, $offset, false, $indexType);
299
            RecordTableMap::addInstanceToPool($obj, $key);
300
        }
301
302
        return array($obj, $col);
303
    }
304
305
    /**
306
     * The returned array will contain objects of the default type or
307
     * objects that inherit from the default.
308
     *
309
     * @param DataFetcherInterface $dataFetcher
310
     * @return array
311
     * @throws PropelException Any exceptions caught during processing will be
312
     *                         rethrown wrapped into a PropelException.
313
     */
314 View Code Duplication
    public static function populateObjects(DataFetcherInterface $dataFetcher)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
315
    {
316
        $results = array();
317
318
        // set the class once to avoid overhead in the loop
319
        $cls = static::getOMClass(false);
320
        // populate the object(s)
321
        while ($row = $dataFetcher->fetch()) {
322
            $key = RecordTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType());
323
            if (null !== ($obj = RecordTableMap::getInstanceFromPool($key))) {
324
                // We no longer rehydrate the object, since this can cause data loss.
325
                // See http://www.propelorm.org/ticket/509
326
                // $obj->hydrate($row, 0, true); // rehydrate
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
327
                $results[] = $obj;
328
            } else {
329
                /** @var Record $obj */
330
                $obj = new $cls();
331
                $obj->hydrate($row);
332
                $results[] = $obj;
333
                RecordTableMap::addInstanceToPool($obj, $key);
334
            } // if key exists
335
        }
336
337
        return $results;
338
    }
339
    /**
340
     * Add all the columns needed to create a new object.
341
     *
342
     * Note: any columns that were marked with lazyLoad="true" in the
343
     * XML schema will not be added to the select list and only loaded
344
     * on demand.
345
     *
346
     * @param Criteria $criteria object containing the columns to add.
347
     * @param string   $alias    optional table alias
348
     * @throws PropelException Any exceptions caught during processing will be
349
     *                         rethrown wrapped into a PropelException.
350
     */
351
    public static function addSelectColumns(Criteria $criteria, $alias = null)
352
    {
353
        if (null === $alias) {
354
            $criteria->addSelectColumn(RecordTableMap::COL_ID);
355
            $criteria->addSelectColumn(RecordTableMap::COL_MAPUID);
356
            $criteria->addSelectColumn(RecordTableMap::COL_NBLAPS);
357
            $criteria->addSelectColumn(RecordTableMap::COL_SCORE);
358
            $criteria->addSelectColumn(RecordTableMap::COL_NBFINISH);
359
            $criteria->addSelectColumn(RecordTableMap::COL_AVGSCORE);
360
            $criteria->addSelectColumn(RecordTableMap::COL_CHECKPOINTS);
361
            $criteria->addSelectColumn(RecordTableMap::COL_PLAYER_ID);
362
            $criteria->addSelectColumn(RecordTableMap::COL_CREATED_AT);
363
            $criteria->addSelectColumn(RecordTableMap::COL_UPDATED_AT);
364
        } else {
365
            $criteria->addSelectColumn($alias . '.id');
366
            $criteria->addSelectColumn($alias . '.mapUid');
367
            $criteria->addSelectColumn($alias . '.nbLaps');
368
            $criteria->addSelectColumn($alias . '.score');
369
            $criteria->addSelectColumn($alias . '.nbFinish');
370
            $criteria->addSelectColumn($alias . '.avgScore');
371
            $criteria->addSelectColumn($alias . '.checkpoints');
372
            $criteria->addSelectColumn($alias . '.player_id');
373
            $criteria->addSelectColumn($alias . '.created_at');
374
            $criteria->addSelectColumn($alias . '.updated_at');
375
        }
376
    }
377
378
    /**
379
     * Returns the TableMap related to this object.
380
     * This method is not needed for general use but a specific application could have a need.
381
     * @return TableMap
382
     * @throws PropelException Any exceptions caught during processing will be
383
     *                         rethrown wrapped into a PropelException.
384
     */
385
    public static function getTableMap()
386
    {
387
        return Propel::getServiceContainer()->getDatabaseMap(RecordTableMap::DATABASE_NAME)->getTable(RecordTableMap::TABLE_NAME);
388
    }
389
390
    /**
391
     * Add a TableMap instance to the database for this tableMap class.
392
     */
393 View Code Duplication
    public static function buildTableMap()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
394
    {
395
        $dbMap = Propel::getServiceContainer()->getDatabaseMap(RecordTableMap::DATABASE_NAME);
396
        if (!$dbMap->hasTable(RecordTableMap::TABLE_NAME)) {
397
            $dbMap->addTableObject(new RecordTableMap());
398
        }
399
    }
400
401
    /**
402
     * Performs a DELETE on the database, given a Record or Criteria object OR a primary key value.
403
     *
404
     * @param mixed               $values Criteria or Record object or primary key or array of primary keys
405
     *              which is used to create the DELETE statement
406
     * @param  ConnectionInterface $con the connection to use
407
     * @return int             The number of affected rows (if supported by underlying database driver).  This includes CASCADE-related rows
408
     *                         if supported by native driver or if emulated using Propel.
409
     * @throws PropelException Any exceptions caught during processing will be
410
     *                         rethrown wrapped into a PropelException.
411
     */
412 View Code Duplication
     public static function doDelete($values, ConnectionInterface $con = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
413
     {
414
        if (null === $con) {
415
            $con = Propel::getServiceContainer()->getWriteConnection(RecordTableMap::DATABASE_NAME);
416
        }
417
418
        if ($values instanceof Criteria) {
419
            // rename for clarity
420
            $criteria = $values;
421
        } elseif ($values instanceof \eXpansion\Bundle\LocalRecords\Model\Record) { // it's a model object
422
            // create criteria based on pk values
423
            $criteria = $values->buildPkeyCriteria();
424
        } else { // it's a primary key, or an array of pks
425
            $criteria = new Criteria(RecordTableMap::DATABASE_NAME);
426
            $criteria->add(RecordTableMap::COL_ID, (array) $values, Criteria::IN);
427
        }
428
429
        $query = RecordQuery::create()->mergeWith($criteria);
430
431
        if ($values instanceof Criteria) {
432
            RecordTableMap::clearInstancePool();
433
        } elseif (!is_object($values)) { // it's a primary key, or an array of pks
434
            foreach ((array) $values as $singleval) {
435
                RecordTableMap::removeInstanceFromPool($singleval);
436
            }
437
        }
438
439
        return $query->delete($con);
440
    }
441
442
    /**
443
     * Deletes all rows from the record table.
444
     *
445
     * @param ConnectionInterface $con the connection to use
446
     * @return int The number of affected rows (if supported by underlying database driver).
447
     */
448
    public static function doDeleteAll(ConnectionInterface $con = null)
449
    {
450
        return RecordQuery::create()->doDeleteAll($con);
451
    }
452
453
    /**
454
     * Performs an INSERT on the database, given a Record or Criteria object.
455
     *
456
     * @param mixed               $criteria Criteria or Record object containing data that is used to create the INSERT statement.
457
     * @param ConnectionInterface $con the ConnectionInterface connection to use
458
     * @return mixed           The new primary key.
459
     * @throws PropelException Any exceptions caught during processing will be
460
     *                         rethrown wrapped into a PropelException.
461
     */
462 View Code Duplication
    public static function doInsert($criteria, ConnectionInterface $con = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
463
    {
464
        if (null === $con) {
465
            $con = Propel::getServiceContainer()->getWriteConnection(RecordTableMap::DATABASE_NAME);
466
        }
467
468
        if ($criteria instanceof Criteria) {
469
            $criteria = clone $criteria; // rename for clarity
470
        } else {
471
            $criteria = $criteria->buildCriteria(); // build Criteria from Record object
472
        }
473
474
        if ($criteria->containsKey(RecordTableMap::COL_ID) && $criteria->keyContainsValue(RecordTableMap::COL_ID) ) {
475
            throw new PropelException('Cannot insert a value for auto-increment primary key ('.RecordTableMap::COL_ID.')');
476
        }
477
478
479
        // Set the correct dbName
480
        $query = RecordQuery::create()->mergeWith($criteria);
481
482
        // use transaction because $criteria could contain info
483
        // for more than one table (I guess, conceivably)
484
        return $con->transaction(function () use ($con, $query) {
485
            return $query->doInsert($con);
486
        });
487
    }
488
489
} // RecordTableMap
490
// This is the static code needed to register the TableMap for this table with the main Propel class.
491
//
492
RecordTableMap::buildTableMap();
493