Completed
Branch master (691237)
by dima
02:39
created

UserTableMap::addSelectColumns()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 20
rs 9.4285
cc 2
eloc 17
nc 2
nop 2
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 448.

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