@@ -2,12 +2,8 @@ |
||
2 | 2 | namespace Mouf\Database\TDBM\Controllers; |
3 | 3 | |
4 | 4 | use Mouf\Composer\ClassNameMapper; |
5 | -use Mouf\MoufUtils; |
|
6 | - |
|
7 | 5 | use Mouf\Actions\InstallUtils; |
8 | - |
|
9 | 6 | use Mouf\MoufManager; |
10 | - |
|
11 | 7 | use Mouf\Html\HtmlElement\HtmlBlock; |
12 | 8 | use Mouf\Mvc\Splash\Controllers\Controller; |
13 | 9 |
@@ -144,7 +144,7 @@ |
||
144 | 144 | * @param string $selfedit |
145 | 145 | * @throws \Mouf\MoufException |
146 | 146 | */ |
147 | - public function generate($daonamespace, $beannamespace, $storeInUtc = 0, $selfedit="false") { |
|
147 | + public function generate($daonamespace, $beannamespace, $storeInUtc = 0, $selfedit = "false") { |
|
148 | 148 | $this->selfedit = $selfedit; |
149 | 149 | |
150 | 150 | if ($selfedit == "true") { |
@@ -1,8 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace Mouf\Database\TDBM\Filters; |
3 | 3 | |
4 | -use Doctrine\DBAL\Driver\Connection; |
|
5 | - |
|
6 | 4 | /* |
7 | 5 | Copyright (C) 2006-2011 David Négrier - THE CODING MACHINE |
8 | 6 |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * |
61 | 61 | * @param string $sqlString |
62 | 62 | */ |
63 | - public function __construct($sqlString=null) { |
|
63 | + public function __construct($sqlString = null) { |
|
64 | 64 | $this->sqlString = $sqlString; |
65 | 65 | } |
66 | 66 | |
@@ -86,8 +86,8 @@ discard block |
||
86 | 86 | $result = -1; |
87 | 87 | while (true) { |
88 | 88 | $result = strrpos($phrase, "'", $result+1); |
89 | - if ($result===false) { |
|
90 | - if ($sentence!='') |
|
89 | + if ($result === false) { |
|
90 | + if ($sentence != '') |
|
91 | 91 | $sentence .= ','; |
92 | 92 | $sentence .= $phrase; |
93 | 93 | |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | else |
103 | 103 | { |
104 | 104 | $valid_result = true; |
105 | - if ($result>0 && $phrase{$result-1}=='\\') { |
|
105 | + if ($result>0 && $phrase{$result-1} == '\\') { |
|
106 | 106 | $valid_result = false; |
107 | 107 | } |
108 | 108 | if ($valid_result) |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | // First, let's remove all the stuff in quotes: |
129 | 129 | |
130 | 130 | // Let's remove all the \' found |
131 | - $work_str = str_replace("\\'",'',$this->sqlString); |
|
131 | + $work_str = str_replace("\\'", '', $this->sqlString); |
|
132 | 132 | // Now, let's split the string using ' |
133 | 133 | $work_table = explode("'", $work_str); |
134 | 134 | |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | return ''; |
137 | 137 | |
138 | 138 | // if we start with a ', let's remove the first text |
139 | - if (strstr($work_str,"'") === 0) |
|
139 | + if (strstr($work_str, "'") === 0) |
|
140 | 140 | array_shift($work_table); |
141 | 141 | |
142 | 142 | if (count($work_table) == 0) |
@@ -147,13 +147,13 @@ discard block |
||
147 | 147 | |
148 | 148 | $i = 0; |
149 | 149 | foreach ($work_table as $str_fragment) { |
150 | - if (($i % 2) == 0) |
|
150 | + if (($i%2) == 0) |
|
151 | 151 | $work_str2 .= $str_fragment.' '; |
152 | 152 | $i++; |
153 | 153 | } |
154 | 154 | |
155 | 155 | // Now, let's run a regexp to find all the strings matching the pattern xxx.yyy |
156 | - preg_match_all('/([a-zA-Z_](?:[a-zA-Z0-9_]*))\.(?:[a-zA-Z_](?:[a-zA-Z0-9_]*))/', $work_str2,$capture_result); |
|
156 | + preg_match_all('/([a-zA-Z_](?:[a-zA-Z0-9_]*))\.(?:[a-zA-Z_](?:[a-zA-Z0-9_]*))/', $work_str2, $capture_result); |
|
157 | 157 | |
158 | 158 | $tables_used = $capture_result[1]; |
159 | 159 | // remove doubles: |
@@ -1,7 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace Mouf\Database\TDBM; |
3 | 3 | |
4 | -use Doctrine\DBAL\Driver\Connection; |
|
5 | 4 | use Doctrine\DBAL\Statement; |
6 | 5 | use Mouf\Database\MagicQuery; |
7 | 6 |
@@ -1,7 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace Mouf\Database\TDBM; |
3 | 3 | |
4 | -use Doctrine\DBAL\Driver\Connection; |
|
5 | 4 | use Doctrine\DBAL\Statement; |
6 | 5 | use Mouf\Database\MagicQuery; |
7 | 6 | use Porpaginas\Page; |
@@ -112,7 +112,7 @@ |
||
112 | 112 | */ |
113 | 113 | public function getCurrentPage() |
114 | 114 | { |
115 | - return floor($this->offset / $this->limit) + 1; |
|
115 | + return floor($this->offset/$this->limit)+1; |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -1,7 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace Mouf\Database\TDBM; |
3 | 3 | |
4 | -use Doctrine\DBAL\Driver\Connection; |
|
5 | 4 | use Doctrine\DBAL\Statement; |
6 | 5 | use Mouf\Database\MagicQuery; |
7 | 6 | use Porpaginas\Result; |
@@ -18,7 +18,6 @@ |
||
18 | 18 | along with this program; if not, write to the Free Software |
19 | 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
20 | 20 | */ |
21 | -use Doctrine\DBAL\Driver\Connection; |
|
22 | 21 | |
23 | 22 | |
24 | 23 | /** |
@@ -108,7 +108,7 @@ |
||
108 | 108 | public function rewind() |
109 | 109 | { |
110 | 110 | $this->_dbLoadIfNotLoaded(); |
111 | - if (count($this->dbRow) > 0) { |
|
111 | + if (count($this->dbRow)>0) { |
|
112 | 112 | $this->_validIterator = true; |
113 | 113 | } else { |
114 | 114 | $this->_validIterator = false; |
@@ -22,16 +22,12 @@ |
||
22 | 22 | use Doctrine\Common\Cache\Cache; |
23 | 23 | use Doctrine\Common\Cache\VoidCache; |
24 | 24 | use Doctrine\DBAL\Connection; |
25 | -use Doctrine\DBAL\DBALException; |
|
26 | -use Doctrine\DBAL\Schema\Column; |
|
27 | 25 | use Doctrine\DBAL\Schema\ForeignKeyConstraint; |
28 | -use Doctrine\DBAL\Schema\Schema; |
|
29 | 26 | use Mouf\Database\MagicQuery; |
30 | 27 | use Mouf\Database\SchemaAnalyzer\SchemaAnalyzer; |
31 | 28 | use Mouf\Database\TDBM\Filters\OrderBySQLString; |
32 | 29 | use Mouf\Database\TDBM\Utils\TDBMDaoGenerator; |
33 | 30 | use Mouf\Utils\Cache\CacheInterface; |
34 | -use SQLParser\Node\ColRef; |
|
35 | 31 | |
36 | 32 | /** |
37 | 33 | * The TDBMService class is the main TDBM class. It provides methods to retrieve TDBMObject instances |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | * @param string $className Optional: The name of the class to instanciate. This class must extend the TDBMObject class. If none is specified, a TDBMObject instance will be returned. |
431 | 431 | * @return TDBMObject |
432 | 432 | */ |
433 | - public function getNewObject($table_name, $auto_assign_id=true, $className = null) { |
|
433 | + public function getNewObject($table_name, $auto_assign_id = true, $className = null) { |
|
434 | 434 | if ($this->connection == null) { |
435 | 435 | throw new TDBMException("Error while calling TDBMObject::getNewObject(): No connection has been established on the database!"); |
436 | 436 | } |
@@ -464,8 +464,8 @@ discard block |
||
464 | 464 | $object = new $className($this, $table_name); |
465 | 465 | |
466 | 466 | if ($auto_assign_id && !$this->isPrimaryKeyAutoIncrement($table_name)) { |
467 | - $pk_table = $this->getPrimaryKeyColumns($table_name); |
|
468 | - if (count($pk_table)==1) |
|
467 | + $pk_table = $this->getPrimaryKeyColumns($table_name); |
|
468 | + if (count($pk_table) == 1) |
|
469 | 469 | { |
470 | 470 | $root_table = $this->connection->findRootSequenceTable($table_name); |
471 | 471 | $id = $this->connection->nextId($root_table); |
@@ -475,7 +475,7 @@ discard block |
||
475 | 475 | $sql = "SELECT MAX(".$this->connection->escapeDBItem($pk_table[0]).") AS maxkey FROM ".$root_table; |
476 | 476 | $res = $this->connection->getAll($sql); |
477 | 477 | // NOTE: this will work only if the ID is an integer! |
478 | - $newid = $res[0]['maxkey'] + 1; |
|
478 | + $newid = $res[0]['maxkey']+1; |
|
479 | 479 | if ($newid>$id) { |
480 | 480 | $id = $newid; |
481 | 481 | } |
@@ -892,9 +892,9 @@ discard block |
||
892 | 892 | // 4-2, let's take all the objects out of the orderby bag, and let's make objects from them |
893 | 893 | $orderby_bag2 = array(); |
894 | 894 | foreach ($orderby_bag as $thing) { |
895 | - if (is_a($thing,'Mouf\\Database\\TDBM\\Filters\\OrderBySQLString')) { |
|
895 | + if (is_a($thing, 'Mouf\\Database\\TDBM\\Filters\\OrderBySQLString')) { |
|
896 | 896 | $orderby_bag2[] = $thing; |
897 | - } elseif (is_a($thing,'Mouf\\Database\\TDBM\\Filters\\OrderByColumn')) { |
|
897 | + } elseif (is_a($thing, 'Mouf\\Database\\TDBM\\Filters\\OrderByColumn')) { |
|
898 | 898 | $orderby_bag2[] = $thing; |
899 | 899 | } elseif (is_string($thing)) { |
900 | 900 | $orderby_bag2[] = new OrderBySQLString($thing); |
@@ -1405,7 +1405,7 @@ discard block |
||
1405 | 1405 | $schemaAnalyzer = $this->schemaAnalyzer; |
1406 | 1406 | |
1407 | 1407 | foreach ($tables as $currentTable) { |
1408 | - $allParents = [ $currentTable ]; |
|
1408 | + $allParents = [$currentTable]; |
|
1409 | 1409 | $currentFk = null; |
1410 | 1410 | while ($currentFk = $schemaAnalyzer->getParentRelationship($currentTable)) { |
1411 | 1411 | $currentTable = $currentFk->getForeignTableName(); |
@@ -1447,7 +1447,7 @@ discard block |
||
1447 | 1447 | // Let's scan the parent tables |
1448 | 1448 | $currentTable = $table; |
1449 | 1449 | |
1450 | - $parentTables = [ ]; |
|
1450 | + $parentTables = []; |
|
1451 | 1451 | |
1452 | 1452 | // Get parent relationship |
1453 | 1453 | while ($currentFk = $schemaAnalyzer->getParentRelationship($currentTable)) { |
@@ -1538,7 +1538,7 @@ discard block |
||
1538 | 1538 | * @return ResultIterator An object representing an array of results. |
1539 | 1539 | * @throws TDBMException |
1540 | 1540 | */ |
1541 | - public function findObjects($mainTable, $filter=null, array $parameters = array(), $orderString=null, array $additionalTablesFetch = array(), $mode = null, $className=null) { |
|
1541 | + public function findObjects($mainTable, $filter = null, array $parameters = array(), $orderString = null, array $additionalTablesFetch = array(), $mode = null, $className = null) { |
|
1542 | 1542 | // $mainTable is not secured in MagicJoin, let's add a bit of security to avoid SQL injection. |
1543 | 1543 | if (!preg_match('/^[a-zA-Z_][a-zA-Z0-9_]*$/', $mainTable)) { |
1544 | 1544 | throw new TDBMException(sprintf("Invalid table name: '%s'", $mainTable)); |
@@ -1607,7 +1607,7 @@ discard block |
||
1607 | 1607 | throw new TDBMException("Unknown fetch mode: '".$this->mode."'"); |
1608 | 1608 | } |
1609 | 1609 | |
1610 | - $mode = $mode?:$this->mode; |
|
1610 | + $mode = $mode ?: $this->mode; |
|
1611 | 1611 | |
1612 | 1612 | return new ResultIterator($sql, $countSql, $parameters, $columnDescList, $this->objectStorage, $className, $this, $this->magicQuery, $mode); |
1613 | 1613 | } |
@@ -1621,7 +1621,7 @@ discard block |
||
1621 | 1621 | * @return AbstractTDBMObject |
1622 | 1622 | * @throws TDBMException |
1623 | 1623 | */ |
1624 | - public function findObjectByPk($table, array $primaryKeys, array $additionalTablesFetch = array(), $lazy = false, $className=null) { |
|
1624 | + public function findObjectByPk($table, array $primaryKeys, array $additionalTablesFetch = array(), $lazy = false, $className = null) { |
|
1625 | 1625 | $primaryKeys = $this->_getPrimaryKeysFromObjectData($table, $primaryKeys); |
1626 | 1626 | $hash = $this->getObjectHash($primaryKeys); |
1627 | 1627 | |
@@ -1641,7 +1641,7 @@ discard block |
||
1641 | 1641 | // Only allowed if no inheritance. |
1642 | 1642 | if (count($tables) === 1) { |
1643 | 1643 | if ($className === null) { |
1644 | - $className = isset($this->tableToBeanMap[$table])?$this->tableToBeanMap[$table]:"Mouf\\Database\\TDBM\\TDBMObject"; |
|
1644 | + $className = isset($this->tableToBeanMap[$table]) ? $this->tableToBeanMap[$table] : "Mouf\\Database\\TDBM\\TDBMObject"; |
|
1645 | 1645 | } |
1646 | 1646 | |
1647 | 1647 | // Let's construct the bean |
@@ -1670,11 +1670,11 @@ discard block |
||
1670 | 1670 | * @return AbstractTDBMObject|null The object we want, or null if no object matches the filters. |
1671 | 1671 | * @throws TDBMException |
1672 | 1672 | */ |
1673 | - public function findObject($mainTable, $filterString=null, array $parameters = array(), array $additionalTablesFetch = array(), $className = null) { |
|
1673 | + public function findObject($mainTable, $filterString = null, array $parameters = array(), array $additionalTablesFetch = array(), $className = null) { |
|
1674 | 1674 | $objects = $this->findObjects($mainTable, $filterString, $parameters, null, $additionalTablesFetch, self::MODE_ARRAY, $className); |
1675 | 1675 | $page = $objects->take(0, 2); |
1676 | 1676 | $count = $page->count(); |
1677 | - if ($count > 1) { |
|
1677 | + if ($count>1) { |
|
1678 | 1678 | throw new DuplicateRowException("Error while querying an object for table '$mainTable': More than 1 row have been returned, but we should have received at most one."); |
1679 | 1679 | } elseif ($count === 0) { |
1680 | 1680 | return null; |
@@ -1694,7 +1694,7 @@ discard block |
||
1694 | 1694 | * @return AbstractTDBMObject The object we want |
1695 | 1695 | * @throws TDBMException |
1696 | 1696 | */ |
1697 | - public function findObjectOrFail($mainTable, $filterString=null, array $parameters = array(), array $additionalTablesFetch = array(), $className = null) { |
|
1697 | + public function findObjectOrFail($mainTable, $filterString = null, array $parameters = array(), array $additionalTablesFetch = array(), $className = null) { |
|
1698 | 1698 | $bean = $this->findObject($mainTable, $filterString, $parameters, $additionalTablesFetch, $className); |
1699 | 1699 | if ($bean === null) { |
1700 | 1700 | throw new NoBeanFoundException("No result found for query on table '".$mainTable."'"); |
@@ -2,8 +2,6 @@ |
||
2 | 2 | namespace Mouf\Database\TDBM\Utils; |
3 | 3 | |
4 | 4 | use Doctrine\DBAL\Driver\Connection; |
5 | -use Doctrine\DBAL\Schema\Column; |
|
6 | -use Doctrine\DBAL\Schema\ForeignKeyConstraint; |
|
7 | 5 | use Doctrine\DBAL\Schema\Schema; |
8 | 6 | use Doctrine\DBAL\Schema\Table; |
9 | 7 | use Doctrine\DBAL\Types\Type; |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | |
207 | 207 | }"; |
208 | 208 | $this->ensureDirectoryExist($possibleFileName); |
209 | - file_put_contents($possibleFileName ,$str); |
|
209 | + file_put_contents($possibleFileName, $str); |
|
210 | 210 | @chmod($possibleFileName, 0664); |
211 | 211 | } |
212 | 212 | } |
@@ -226,11 +226,11 @@ discard block |
||
226 | 226 | foreach ($table->getColumns() as $column) { |
227 | 227 | $comments = $column->getComment(); |
228 | 228 | $matches = array(); |
229 | - if (preg_match('/@defaultSort(\((desc|asc)\))*/', $comments, $matches) != 0){ |
|
229 | + if (preg_match('/@defaultSort(\((desc|asc)\))*/', $comments, $matches) != 0) { |
|
230 | 230 | $defaultSort = $data['column_name']; |
231 | - if (count($matches == 3)){ |
|
231 | + if (count($matches == 3)) { |
|
232 | 232 | $defaultSortDirection = $matches[2]; |
233 | - }else{ |
|
233 | + } else { |
|
234 | 234 | $defaultSortDirection = 'ASC'; |
235 | 235 | } |
236 | 236 | } |
@@ -416,7 +416,7 @@ discard block |
||
416 | 416 | $possibleBaseFileName = $this->rootPath.$possibleBaseFileNames[0]; |
417 | 417 | |
418 | 418 | $this->ensureDirectoryExist($possibleBaseFileName); |
419 | - file_put_contents($possibleBaseFileName ,$str); |
|
419 | + file_put_contents($possibleBaseFileName, $str); |
|
420 | 420 | @chmod($possibleBaseFileName, 0664); |
421 | 421 | |
422 | 422 | $possibleFileNames = $classNameMapper->getPossibleFileNames($daonamespace."\\".$className); |
@@ -447,7 +447,7 @@ discard block |
||
447 | 447 | } |
448 | 448 | "; |
449 | 449 | $this->ensureDirectoryExist($possibleFileName); |
450 | - file_put_contents($possibleFileName ,$str); |
|
450 | + file_put_contents($possibleFileName, $str); |
|
451 | 451 | @chmod($possibleFileName, 0664); |
452 | 452 | } |
453 | 453 | } |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | $possibleFileName = $this->rootPath.$possibleFileNames[0]; |
524 | 524 | |
525 | 525 | $this->ensureDirectoryExist($possibleFileName); |
526 | - file_put_contents($possibleFileName ,$str); |
|
526 | + file_put_contents($possibleFileName, $str); |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | /** |
@@ -534,7 +534,7 @@ discard block |
||
534 | 534 | * @return string |
535 | 535 | */ |
536 | 536 | public static function toCamelCase($str) { |
537 | - $str = strtoupper(substr($str,0,1)).substr($str,1); |
|
537 | + $str = strtoupper(substr($str, 0, 1)).substr($str, 1); |
|
538 | 538 | while (true) { |
539 | 539 | if (strpos($str, "_") === false && strpos($str, " ") === false) { |
540 | 540 | break; |
@@ -544,9 +544,9 @@ discard block |
||
544 | 544 | if ($pos === false) { |
545 | 545 | $pos = strpos($str, " "); |
546 | 546 | } |
547 | - $before = substr($str,0,$pos); |
|
548 | - $after = substr($str,$pos+1); |
|
549 | - $str = $before.strtoupper(substr($after,0,1)).substr($after,1); |
|
547 | + $before = substr($str, 0, $pos); |
|
548 | + $after = substr($str, $pos+1); |
|
549 | + $str = $before.strtoupper(substr($after, 0, 1)).substr($after, 1); |
|
550 | 550 | } |
551 | 551 | return $str; |
552 | 552 | } |
@@ -627,7 +627,7 @@ discard block |
||
627 | 627 | Type::GUID => 'string' |
628 | 628 | ]; |
629 | 629 | |
630 | - return isset($map[$type->getName()])?$map[$type->getName()]:$type->getName(); |
|
630 | + return isset($map[$type->getName()]) ? $map[$type->getName()] : $type->getName(); |
|
631 | 631 | } |
632 | 632 | |
633 | 633 | /** |
@@ -642,7 +642,7 @@ discard block |
||
642 | 642 | |
643 | 643 | foreach ($tables as $table) { |
644 | 644 | $tableName = $table->getName(); |
645 | - $tableToBeanMap[$tableName] = $beanNamespace . "\\" . self::getBeanNameFromTableName($tableName); |
|
645 | + $tableToBeanMap[$tableName] = $beanNamespace."\\".self::getBeanNameFromTableName($tableName); |
|
646 | 646 | } |
647 | 647 | return $tableToBeanMap; |
648 | 648 | } |
@@ -45,7 +45,7 @@ |
||
45 | 45 | <div class="control-group"> |
46 | 46 | <label class="control-label">Store dates / timestamps in UTC:</label> |
47 | 47 | <div class="controls"> |
48 | - <input type="checkbox" name="storeInUtc" value="1" <?php echo $this->storeInUtc?'checked="checked"':"" ?>></input> |
|
48 | + <input type="checkbox" name="storeInUtc" value="1" <?php echo $this->storeInUtc ? 'checked="checked"' : "" ?>></input> |
|
49 | 49 | <span class="help-block">Select this option if you want timestamps to be stored in UTC. |
50 | 50 | If your application supports several time zones, you should select this option to store all dates in |
51 | 51 | the same time zone.</span> |