SelfpriceTableMap::buildRelations()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 1
nc 1
nop 0
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 424.

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 Selfprice\Models\Selfprice\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 Selfprice\Models\Selfprice\Selfprice;
15
use Selfprice\Models\Selfprice\SelfpriceQuery;
16
17
18
/**
19
 * This class defines the structure of the 'selfprice' 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 SelfpriceTableMap extends TableMap
30
{
31
    use InstancePoolTrait;
32
    use TableMapTrait;
33
34
    /**
35
     * The (dot-path) name of this class
36
     */
37
    const CLASS_NAME = 'Models.Selfprice.Map.SelfpriceTableMap';
38
39
    /**
40
     * The default database name for this class
41
     */
42
    const DATABASE_NAME = 'default';
43
44
    /**
45
     * The table name for this class
46
     */
47
    const TABLE_NAME = 'selfprice';
48
49
    /**
50
     * The related Propel class for this table
51
     */
52
    const OM_CLASS = '\\Selfprice\\Models\\Selfprice\\Selfprice';
53
54
    /**
55
     * A class that can be returned by this tableMap
56
     */
57
    const CLASS_DEFAULT = 'Models.Selfprice.Selfprice';
58
59
    /**
60
     * The total number of columns
61
     */
62
    const NUM_COLUMNS = 4;
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 = 4;
73
74
    /**
75
     * the column name for the id field
76
     */
77
    const COL_ID = 'selfprice.id';
78
79
    /**
80
     * the column name for the name field
81
     */
82
    const COL_NAME = 'selfprice.name';
83
84
    /**
85
     * the column name for the datecreate field
86
     */
87
    const COL_DATECREATE = 'selfprice.datecreate';
88
89
    /**
90
     * the column name for the desc field
91
     */
92
    const COL_DESC = 'selfprice.desc';
93
94
    /**
95
     * The default string format for model objects of the related table
96
     */
97
    const DEFAULT_STRING_FORMAT = 'YAML';
98
99
    /**
100
     * holds an array of fieldnames
101
     *
102
     * first dimension keys are the type constants
103
     * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
104
     */
105
    protected static $fieldNames = array (
106
        self::TYPE_PHPNAME       => array('Id', 'Name', 'Datecreate', 'Desc', ),
107
        self::TYPE_CAMELNAME     => array('id', 'name', 'datecreate', 'desc', ),
108
        self::TYPE_COLNAME       => array(SelfpriceTableMap::COL_ID, SelfpriceTableMap::COL_NAME, SelfpriceTableMap::COL_DATECREATE, SelfpriceTableMap::COL_DESC, ),
109
        self::TYPE_FIELDNAME     => array('id', 'name', 'datecreate', 'desc', ),
110
        self::TYPE_NUM           => array(0, 1, 2, 3, )
111
    );
112
113
    /**
114
     * holds an array of keys for quick access to the fieldnames array
115
     *
116
     * first dimension keys are the type constants
117
     * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0
118
     */
119
    protected static $fieldKeys = array (
120
        self::TYPE_PHPNAME       => array('Id' => 0, 'Name' => 1, 'Datecreate' => 2, 'Desc' => 3, ),
121
        self::TYPE_CAMELNAME     => array('id' => 0, 'name' => 1, 'datecreate' => 2, 'desc' => 3, ),
122
        self::TYPE_COLNAME       => array(SelfpriceTableMap::COL_ID => 0, SelfpriceTableMap::COL_NAME => 1, SelfpriceTableMap::COL_DATECREATE => 2, SelfpriceTableMap::COL_DESC => 3, ),
123
        self::TYPE_FIELDNAME     => array('id' => 0, 'name' => 1, 'datecreate' => 2, 'desc' => 3, ),
124
        self::TYPE_NUM           => array(0, 1, 2, 3, )
125
    );
126
127
    /**
128
     * Initialize the table attributes and columns
129
     * Relations are not initialized by this method since they are lazy loaded
130
     *
131
     * @return void
132
     * @throws PropelException
133
     */
134
    public function initialize()
135
    {
136
        // attributes
137
        $this->setName('selfprice');
138
        $this->setPhpName('Selfprice');
139
        $this->setIdentifierQuoting(false);
140
        $this->setClassName('\\Selfprice\\Models\\Selfprice\\Selfprice');
141
        $this->setPackage('Models.Selfprice');
142
        $this->setUseIdGenerator(true);
143
        // columns
144
        $this->addPrimaryKey('id', 'Id', 'INTEGER', true, null, null);
145
        $this->addColumn('name', 'Name', 'VARCHAR', false, 50, null);
146
        $this->addColumn('datecreate', 'Datecreate', 'TIMESTAMP', false, null, null);
147
        $this->addColumn('desc', 'Desc', 'VARCHAR', false, 255, null);
148
    } // initialize()
149
150
    /**
151
     * Build the RelationMap objects for this table relationships
152
     */
153
    public function buildRelations()
154
    {
155
    } // buildRelations()
156
157
    /**
158
     * 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.
159
     *
160
     * For tables with a single-column primary key, that simple pkey value will be returned.  For tables with
161
     * a multi-column primary key, a serialize()d version of the primary key will be returned.
162
     *
163
     * @param array  $row       resultset row.
164
     * @param int    $offset    The 0-based offset for reading from the resultset row.
165
     * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
166
     *                           TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM
167
     *
168
     * @return string The primary key hash of the row
169
     */
170 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...
171
    {
172
        // If the PK cannot be derived from the row, return NULL.
173
        if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null) {
174
            return null;
175
        }
176
177
        return (string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)];
178
    }
179
180
    /**
181
     * Retrieves the primary key from the DB resultset row
182
     * For tables with a single-column primary key, that simple pkey value will be returned.  For tables with
183
     * a multi-column primary key, an array of the primary key columns will be returned.
184
     *
185
     * @param array  $row       resultset row.
186
     * @param int    $offset    The 0-based offset for reading from the resultset row.
187
     * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
188
     *                           TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM
189
     *
190
     * @return mixed The primary key of the row
191
     */
192 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...
193
    {
194
        return (int) $row[
195
            $indexType == TableMap::TYPE_NUM
196
                ? 0 + $offset
197
                : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)
198
        ];
199
    }
200
201
    /**
202
     * The class that the tableMap will make instances of.
203
     *
204
     * If $withPrefix is true, the returned path
205
     * uses a dot-path notation which is translated into a path
206
     * relative to a location on the PHP include_path.
207
     * (e.g. path.to.MyClass -> 'path/to/MyClass.php')
208
     *
209
     * @param boolean $withPrefix Whether or not to return the path with the class name
210
     * @return string path.to.ClassName
211
     */
212
    public static function getOMClass($withPrefix = true)
213
    {
214
        return $withPrefix ? SelfpriceTableMap::CLASS_DEFAULT : SelfpriceTableMap::OM_CLASS;
215
    }
216
217
    /**
218
     * Populates an object of the default type or an object that inherit from the default.
219
     *
220
     * @param array  $row       row returned by DataFetcher->fetch().
221
     * @param int    $offset    The 0-based offset for reading from the resultset row.
222
     * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType().
223
                                 One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
224
     *                           TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
225
     *
226
     * @throws PropelException Any exceptions caught during processing will be
227
     *                         rethrown wrapped into a PropelException.
228
     * @return array           (Selfprice object, last column rank)
229
     */
230 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...
231
    {
232
        $key = SelfpriceTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType);
233
        if (null !== ($obj = SelfpriceTableMap::getInstanceFromPool($key))) {
234
            // We no longer rehydrate the object, since this can cause data loss.
235
            // See http://www.propelorm.org/ticket/509
236
            // $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...
237
            $col = $offset + SelfpriceTableMap::NUM_HYDRATE_COLUMNS;
238
        } else {
239
            $cls = SelfpriceTableMap::OM_CLASS;
240
            /** @var Selfprice $obj */
241
            $obj = new $cls();
242
            $col = $obj->hydrate($row, $offset, false, $indexType);
243
            SelfpriceTableMap::addInstanceToPool($obj, $key);
244
        }
245
246
        return array($obj, $col);
247
    }
248
249
    /**
250
     * The returned array will contain objects of the default type or
251
     * objects that inherit from the default.
252
     *
253
     * @param DataFetcherInterface $dataFetcher
254
     * @return array
255
     * @throws PropelException Any exceptions caught during processing will be
256
     *                         rethrown wrapped into a PropelException.
257
     */
258 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...
259
    {
260
        $results = array();
261
262
        // set the class once to avoid overhead in the loop
263
        $cls = static::getOMClass(false);
264
        // populate the object(s)
265
        while ($row = $dataFetcher->fetch()) {
266
            $key = SelfpriceTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType());
267
            if (null !== ($obj = SelfpriceTableMap::getInstanceFromPool($key))) {
268
                // We no longer rehydrate the object, since this can cause data loss.
269
                // See http://www.propelorm.org/ticket/509
270
                // $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...
271
                $results[] = $obj;
272
            } else {
273
                /** @var Selfprice $obj */
274
                $obj = new $cls();
275
                $obj->hydrate($row);
276
                $results[] = $obj;
277
                SelfpriceTableMap::addInstanceToPool($obj, $key);
278
            } // if key exists
279
        }
280
281
        return $results;
282
    }
283
    /**
284
     * Add all the columns needed to create a new object.
285
     *
286
     * Note: any columns that were marked with lazyLoad="true" in the
287
     * XML schema will not be added to the select list and only loaded
288
     * on demand.
289
     *
290
     * @param Criteria $criteria object containing the columns to add.
291
     * @param string   $alias    optional table alias
292
     * @throws PropelException Any exceptions caught during processing will be
293
     *                         rethrown wrapped into a PropelException.
294
     */
295
    public static function addSelectColumns(Criteria $criteria, $alias = null)
296
    {
297
        if (null === $alias) {
298
            $criteria->addSelectColumn(SelfpriceTableMap::COL_ID);
299
            $criteria->addSelectColumn(SelfpriceTableMap::COL_NAME);
300
            $criteria->addSelectColumn(SelfpriceTableMap::COL_DATECREATE);
301
            $criteria->addSelectColumn(SelfpriceTableMap::COL_DESC);
302
        } else {
303
            $criteria->addSelectColumn($alias . '.id');
304
            $criteria->addSelectColumn($alias . '.name');
305
            $criteria->addSelectColumn($alias . '.datecreate');
306
            $criteria->addSelectColumn($alias . '.desc');
307
        }
308
    }
309
310
    /**
311
     * Returns the TableMap related to this object.
312
     * This method is not needed for general use but a specific application could have a need.
313
     * @return TableMap
314
     * @throws PropelException Any exceptions caught during processing will be
315
     *                         rethrown wrapped into a PropelException.
316
     */
317
    public static function getTableMap()
318
    {
319
        return Propel::getServiceContainer()->getDatabaseMap(SelfpriceTableMap::DATABASE_NAME)->getTable(SelfpriceTableMap::TABLE_NAME);
320
    }
321
322
    /**
323
     * Add a TableMap instance to the database for this tableMap class.
324
     */
325 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...
326
    {
327
        $dbMap = Propel::getServiceContainer()->getDatabaseMap(SelfpriceTableMap::DATABASE_NAME);
328
        if (!$dbMap->hasTable(SelfpriceTableMap::TABLE_NAME)) {
329
            $dbMap->addTableObject(new SelfpriceTableMap());
330
        }
331
    }
332
333
    /**
334
     * Performs a DELETE on the database, given a Selfprice or Criteria object OR a primary key value.
335
     *
336
     * @param mixed               $values Criteria or Selfprice object or primary key or array of primary keys
337
     *              which is used to create the DELETE statement
338
     * @param  ConnectionInterface $con the connection to use
339
     * @return int             The number of affected rows (if supported by underlying database driver).  This includes CASCADE-related rows
340
     *                         if supported by native driver or if emulated using Propel.
341
     * @throws PropelException Any exceptions caught during processing will be
342
     *                         rethrown wrapped into a PropelException.
343
     */
344 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...
345
     {
346
        if (null === $con) {
347
            $con = Propel::getServiceContainer()->getWriteConnection(SelfpriceTableMap::DATABASE_NAME);
348
        }
349
350
        if ($values instanceof Criteria) {
351
            // rename for clarity
352
            $criteria = $values;
353
        } elseif ($values instanceof \Selfprice\Models\Selfprice\Selfprice) { // it's a model object
354
            // create criteria based on pk values
355
            $criteria = $values->buildPkeyCriteria();
356
        } else { // it's a primary key, or an array of pks
357
            $criteria = new Criteria(SelfpriceTableMap::DATABASE_NAME);
358
            $criteria->add(SelfpriceTableMap::COL_ID, (array) $values, Criteria::IN);
359
        }
360
361
        $query = SelfpriceQuery::create()->mergeWith($criteria);
362
363
        if ($values instanceof Criteria) {
364
            SelfpriceTableMap::clearInstancePool();
365
        } elseif (!is_object($values)) { // it's a primary key, or an array of pks
366
            foreach ((array) $values as $singleval) {
367
                SelfpriceTableMap::removeInstanceFromPool($singleval);
368
            }
369
        }
370
371
        return $query->delete($con);
372
    }
373
374
    /**
375
     * Deletes all rows from the selfprice table.
376
     *
377
     * @param ConnectionInterface $con the connection to use
378
     * @return int The number of affected rows (if supported by underlying database driver).
379
     */
380
    public static function doDeleteAll(ConnectionInterface $con = null)
381
    {
382
        return SelfpriceQuery::create()->doDeleteAll($con);
383
    }
384
385
    /**
386
     * Performs an INSERT on the database, given a Selfprice or Criteria object.
387
     *
388
     * @param mixed               $criteria Criteria or Selfprice object containing data that is used to create the INSERT statement.
389
     * @param ConnectionInterface $con the ConnectionInterface connection to use
390
     * @return mixed           The new primary key.
391
     * @throws PropelException Any exceptions caught during processing will be
392
     *                         rethrown wrapped into a PropelException.
393
     */
394 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...
395
    {
396
        if (null === $con) {
397
            $con = Propel::getServiceContainer()->getWriteConnection(SelfpriceTableMap::DATABASE_NAME);
398
        }
399
400
        if ($criteria instanceof Criteria) {
401
            $criteria = clone $criteria; // rename for clarity
402
        } else {
403
            $criteria = $criteria->buildCriteria(); // build Criteria from Selfprice object
404
        }
405
406
        if ($criteria->containsKey(SelfpriceTableMap::COL_ID) && $criteria->keyContainsValue(SelfpriceTableMap::COL_ID) ) {
407
            throw new PropelException('Cannot insert a value for auto-increment primary key ('.SelfpriceTableMap::COL_ID.')');
408
        }
409
410
411
        // Set the correct dbName
412
        $query = SelfpriceQuery::create()->mergeWith($criteria);
413
414
        // use transaction because $criteria could contain info
415
        // for more than one table (I guess, conceivably)
416
        return $con->transaction(function () use ($con, $query) {
417
            return $query->doInsert($con);
418
        });
419
    }
420
421
} // SelfpriceTableMap
422
// This is the static code needed to register the TableMap for this table with the main Propel class.
423
//
424
SelfpriceTableMap::buildTableMap();
425