UserTableMap::initialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 18
rs 9.4285
cc 1
eloc 14
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 461.

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 Core\Models\User\Map;
4
5
use Core\Models\User\User;
6
use Core\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 = '\\Core\\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('\\Core\\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
     *
177
     * Gets the list of behaviors registered for this table
178
     *
179
     * @return array Associative array (name => parameters) of behaviors
180
     */
181
    public function getBehaviors()
182
    {
183
        return array(
184
            'validate' => array('rule1' => array ('column' => 'email','validator' => 'Email','options' => array ('message' => 'поле Email не заполнено',),), 'rule2' => array ('column' => 'email','validator' => 'Unique','options' => array ('message' => 'Email должен быть уникален',),), ),
185
        );
186
    } // getBehaviors()
187
188
    /**
189
     * 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.
190
     *
191
     * For tables with a single-column primary key, that simple pkey value will be returned.  For tables with
192
     * a multi-column primary key, a serialize()d version of the primary key will be returned.
193
     *
194
     * @param array  $row       resultset row.
195
     * @param int    $offset    The 0-based offset for reading from the resultset row.
196
     * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
197
     *                           TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM
198
     *
199
     * @return string The primary key hash of the row
200
     */
201 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...
202
    {
203
        // If the PK cannot be derived from the row, return NULL.
204
        if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null) {
205
            return null;
206
        }
207
208
        return (string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)];
209
    }
210
211
    /**
212
     * Retrieves the primary key from the DB resultset row
213
     * For tables with a single-column primary key, that simple pkey value will be returned.  For tables with
214
     * a multi-column primary key, an array of the primary key columns will be returned.
215
     *
216
     * @param array  $row       resultset row.
217
     * @param int    $offset    The 0-based offset for reading from the resultset row.
218
     * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
219
     *                           TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM
220
     *
221
     * @return mixed The primary key of the row
222
     */
223 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...
224
    {
225
        return (int) $row[
226
            $indexType == TableMap::TYPE_NUM
227
                ? 0 + $offset
228
                : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)
229
        ];
230
    }
231
232
    /**
233
     * The class that the tableMap will make instances of.
234
     *
235
     * If $withPrefix is true, the returned path
236
     * uses a dot-path notation which is translated into a path
237
     * relative to a location on the PHP include_path.
238
     * (e.g. path.to.MyClass -> 'path/to/MyClass.php')
239
     *
240
     * @param boolean $withPrefix Whether or not to return the path with the class name
241
     * @return string path.to.ClassName
242
     */
243
    public static function getOMClass($withPrefix = true)
244
    {
245
        return $withPrefix ? UserTableMap::CLASS_DEFAULT : UserTableMap::OM_CLASS;
246
    }
247
248
    /**
249
     * Populates an object of the default type or an object that inherit from the default.
250
     *
251
     * @param array  $row       row returned by DataFetcher->fetch().
252
     * @param int    $offset    The 0-based offset for reading from the resultset row.
253
     * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType().
254
                                 One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
255
     *                           TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
256
     *
257
     * @throws PropelException Any exceptions caught during processing will be
258
     *                         rethrown wrapped into a PropelException.
259
     * @return array           (User object, last column rank)
260
     */
261 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...
262
    {
263
        $key = UserTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType);
264
        if (null !== ($obj = UserTableMap::getInstanceFromPool($key))) {
265
            // We no longer rehydrate the object, since this can cause data loss.
266
            // See http://www.propelorm.org/ticket/509
267
            // $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...
268
            $col = $offset + UserTableMap::NUM_HYDRATE_COLUMNS;
269
        } else {
270
            $cls = UserTableMap::OM_CLASS;
271
            /** @var User $obj */
272
            $obj = new $cls();
273
            $col = $obj->hydrate($row, $offset, false, $indexType);
274
            UserTableMap::addInstanceToPool($obj, $key);
275
        }
276
277
        return array($obj, $col);
278
    }
279
280
    /**
281
     * The returned array will contain objects of the default type or
282
     * objects that inherit from the default.
283
     *
284
     * @param DataFetcherInterface $dataFetcher
285
     * @return array
286
     * @throws PropelException Any exceptions caught during processing will be
287
     *                         rethrown wrapped into a PropelException.
288
     */
289 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...
290
    {
291
        $results = array();
292
293
        // set the class once to avoid overhead in the loop
294
        $cls = static::getOMClass(false);
295
        // populate the object(s)
296
        while ($row = $dataFetcher->fetch()) {
297
            $key = UserTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType());
298
            if (null !== ($obj = UserTableMap::getInstanceFromPool($key))) {
299
                // We no longer rehydrate the object, since this can cause data loss.
300
                // See http://www.propelorm.org/ticket/509
301
                // $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...
302
                $results[] = $obj;
303
            } else {
304
                /** @var User $obj */
305
                $obj = new $cls();
306
                $obj->hydrate($row);
307
                $results[] = $obj;
308
                UserTableMap::addInstanceToPool($obj, $key);
309
            } // if key exists
310
        }
311
312
        return $results;
313
    }
314
    /**
315
     * Add all the columns needed to create a new object.
316
     *
317
     * Note: any columns that were marked with lazyLoad="true" in the
318
     * XML schema will not be added to the select list and only loaded
319
     * on demand.
320
     *
321
     * @param Criteria $criteria object containing the columns to add.
322
     * @param string   $alias    optional table alias
323
     * @throws PropelException Any exceptions caught during processing will be
324
     *                         rethrown wrapped into a PropelException.
325
     */
326
    public static function addSelectColumns(Criteria $criteria, $alias = null)
327
    {
328
        if (null === $alias) {
329
            $criteria->addSelectColumn(UserTableMap::COL_ID);
330
            $criteria->addSelectColumn(UserTableMap::COL_NAME);
331
            $criteria->addSelectColumn(UserTableMap::COL_EMAIL);
332
            $criteria->addSelectColumn(UserTableMap::COL_PASSWORD);
333
            $criteria->addSelectColumn(UserTableMap::COL_REMEMBER_TOKEN);
334
            $criteria->addSelectColumn(UserTableMap::COL_CREATED_AT);
335
            $criteria->addSelectColumn(UserTableMap::COL_UPDATED_AT);
336
        } else {
337
            $criteria->addSelectColumn($alias . '.id');
338
            $criteria->addSelectColumn($alias . '.name');
339
            $criteria->addSelectColumn($alias . '.email');
340
            $criteria->addSelectColumn($alias . '.password');
341
            $criteria->addSelectColumn($alias . '.remember_token');
342
            $criteria->addSelectColumn($alias . '.created_at');
343
            $criteria->addSelectColumn($alias . '.updated_at');
344
        }
345
    }
346
347
    /**
348
     * Returns the TableMap related to this object.
349
     * This method is not needed for general use but a specific application could have a need.
350
     * @return TableMap
351
     * @throws PropelException Any exceptions caught during processing will be
352
     *                         rethrown wrapped into a PropelException.
353
     */
354
    public static function getTableMap()
355
    {
356
        return Propel::getServiceContainer()->getDatabaseMap(UserTableMap::DATABASE_NAME)->getTable(UserTableMap::TABLE_NAME);
357
    }
358
359
    /**
360
     * Add a TableMap instance to the database for this tableMap class.
361
     */
362 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...
363
    {
364
        $dbMap = Propel::getServiceContainer()->getDatabaseMap(UserTableMap::DATABASE_NAME);
365
        if (!$dbMap->hasTable(UserTableMap::TABLE_NAME)) {
366
            $dbMap->addTableObject(new UserTableMap());
367
        }
368
    }
369
370
    /**
371
     * Performs a DELETE on the database, given a User or Criteria object OR a primary key value.
372
     *
373
     * @param mixed               $values Criteria or User object or primary key or array of primary keys
374
     *              which is used to create the DELETE statement
375
     * @param  ConnectionInterface $con the connection to use
376
     * @return int             The number of affected rows (if supported by underlying database driver).  This includes CASCADE-related rows
377
     *                         if supported by native driver or if emulated using Propel.
378
     * @throws PropelException Any exceptions caught during processing will be
379
     *                         rethrown wrapped into a PropelException.
380
     */
381 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...
382
     {
383
        if (null === $con) {
384
            $con = Propel::getServiceContainer()->getWriteConnection(UserTableMap::DATABASE_NAME);
385
        }
386
387
        if ($values instanceof Criteria) {
388
            // rename for clarity
389
            $criteria = $values;
390
        } elseif ($values instanceof \Core\Models\User\User) { // it's a model object
391
            // create criteria based on pk values
392
            $criteria = $values->buildPkeyCriteria();
393
        } else { // it's a primary key, or an array of pks
394
            $criteria = new Criteria(UserTableMap::DATABASE_NAME);
395
            $criteria->add(UserTableMap::COL_ID, (array) $values, Criteria::IN);
396
        }
397
398
        $query = UserQuery::create()->mergeWith($criteria);
399
400
        if ($values instanceof Criteria) {
401
            UserTableMap::clearInstancePool();
402
        } elseif (!is_object($values)) { // it's a primary key, or an array of pks
403
            foreach ((array) $values as $singleval) {
404
                UserTableMap::removeInstanceFromPool($singleval);
405
            }
406
        }
407
408
        return $query->delete($con);
409
    }
410
411
    /**
412
     * Deletes all rows from the users table.
413
     *
414
     * @param ConnectionInterface $con the connection to use
415
     * @return int The number of affected rows (if supported by underlying database driver).
416
     */
417
    public static function doDeleteAll(ConnectionInterface $con = null)
418
    {
419
        return UserQuery::create()->doDeleteAll($con);
420
    }
421
422
    /**
423
     * Performs an INSERT on the database, given a User or Criteria object.
424
     *
425
     * @param mixed               $criteria Criteria or User object containing data that is used to create the INSERT statement.
426
     * @param ConnectionInterface $con the ConnectionInterface connection to use
427
     * @return mixed           The new primary key.
428
     * @throws PropelException Any exceptions caught during processing will be
429
     *                         rethrown wrapped into a PropelException.
430
     */
431 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...
432
    {
433
        if (null === $con) {
434
            $con = Propel::getServiceContainer()->getWriteConnection(UserTableMap::DATABASE_NAME);
435
        }
436
437
        if ($criteria instanceof Criteria) {
438
            $criteria = clone $criteria; // rename for clarity
439
        } else {
440
            $criteria = $criteria->buildCriteria(); // build Criteria from User object
441
        }
442
443
        if ($criteria->containsKey(UserTableMap::COL_ID) && $criteria->keyContainsValue(UserTableMap::COL_ID) ) {
444
            throw new PropelException('Cannot insert a value for auto-increment primary key ('.UserTableMap::COL_ID.')');
445
        }
446
447
448
        // Set the correct dbName
449
        $query = UserQuery::create()->mergeWith($criteria);
450
451
        // use transaction because $criteria could contain info
452
        // for more than one table (I guess, conceivably)
453
        return $con->transaction(function () use ($con, $query) {
454
            return $query->doInsert($con);
455
        });
456
    }
457
458
} // UserTableMap
459
// This is the static code needed to register the TableMap for this table with the main Propel class.
460
//
461
UserTableMap::buildTableMap();
462