@@ -31,16 +31,16 @@ discard block |
||
| 31 | 31 | return $this->config; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - public function setModels($models, $csv,$is_save=true) |
|
| 34 | + public function setModels($models, $csv, $is_save = true) |
|
| 35 | 35 | { |
| 36 | 36 | foreach ($models as $table => $model) { |
| 37 | - if (is_array($model) == false ) { |
|
| 37 | + if (is_array($model) == false) { |
|
| 38 | 38 | continue; |
| 39 | 39 | } |
| 40 | 40 | $total = count($model); |
| 41 | 41 | for ($i = 0; $i < $total; $i++) { |
| 42 | 42 | if (isset($this->config[$table][$i])) { |
| 43 | - $this->setModel($model[$i], $this->config[$table][$i], $csv, $table,$is_save); |
|
| 43 | + $this->setModel($model[$i], $this->config[$table][$i], $csv, $table, $is_save); |
|
| 44 | 44 | } else { |
| 45 | 45 | throw new \Exception('設定ファイルが正しくないか、構成が異なっています。table=' . $table); |
| 46 | 46 | } |
@@ -49,14 +49,14 @@ discard block |
||
| 49 | 49 | return true; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - public function setModel($model, $config, $csv, $table,$is_save=true) |
|
| 52 | + public function setModel($model, $config, $csv, $table, $is_save = true) |
|
| 53 | 53 | { |
| 54 | 54 | foreach ($config as $key => $rec) { |
| 55 | 55 | $col = $this->getCsvCol($rec); |
| 56 | - $func = ( isset($rec['func']) === true && $rec['func'] ) ? $rec['func'] : null; |
|
| 56 | + $func = (isset($rec['func']) === true && $rec['func']) ? $rec['func'] : null; |
|
| 57 | 57 | if (method_exists($this, $func) === true) { |
| 58 | 58 | $this->$func($model, $key, $csv, $col); |
| 59 | - } elseif ( $func && method_exists($this, $func) === false) { |
|
| 59 | + } elseif ($func && method_exists($this, $func) === false) { |
|
| 60 | 60 | throw new \Exception(get_class($this) . 'に関数=' . $func . 'が実装されていません。(table=' . $table . ')'); |
| 61 | 61 | } elseif (isset($rec['csv']) === true && isset($csv[$col]) === true) { |
| 62 | 62 | $model->$key = $csv[$col]; |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | $model->$key = null; |
| 65 | 65 | } |
| 66 | 66 | } |
| 67 | - if ( $is_save ) { |
|
| 67 | + if ($is_save) { |
|
| 68 | 68 | $model->save(); |
| 69 | 69 | } |
| 70 | 70 | } |
@@ -74,8 +74,8 @@ discard block |
||
| 74 | 74 | $col = isset($rec['csv']) ? $rec['csv'] : null; |
| 75 | 75 | if (strpos($col, ",") !== false) { |
| 76 | 76 | $col = explode(",", $col); |
| 77 | - } elseif ( is_numeric($col) === true ) { |
|
| 78 | - $col = ($col + 0 ) -1; |
|
| 77 | + } elseif (is_numeric($col) === true) { |
|
| 78 | + $col = ($col+0)-1; |
|
| 79 | 79 | } |
| 80 | 80 | return $col; |
| 81 | 81 | } |
@@ -47,35 +47,35 @@ |
||
| 47 | 47 | unset($rec); |
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | - public function mergeCount($count_data,$is_merge=false) |
|
| 50 | + public function mergeCount($count_data, $is_merge = false) |
|
| 51 | 51 | {
|
| 52 | 52 | $tree = isset($this->tree) ? $this->tree : []; |
| 53 | - foreach ( $count_data as $count ) {
|
|
| 53 | + foreach ($count_data as $count) {
|
|
| 54 | 54 | if (isset($count->id) === false) {
|
| 55 | 55 | throw new Exception('count data record object does not have property => "id".');
|
| 56 | 56 | } |
| 57 | 57 | if (isset($count->count) === false) {
|
| 58 | 58 | throw new Exception('count data record object does not have property => "count".');
|
| 59 | 59 | } |
| 60 | - $this->addCount($this->tree,$count->id,$count->count,$is_merge); |
|
| 60 | + $this->addCount($this->tree, $count->id, $count->count, $is_merge); |
|
| 61 | 61 | |
| 62 | 62 | } |
| 63 | 63 | $this->tree = $tree; |
| 64 | 64 | } |
| 65 | - protected function addCount(&$tree,$id,$count,$is_merge) |
|
| 65 | + protected function addCount(&$tree, $id, $count, $is_merge) |
|
| 66 | 66 | {
|
| 67 | - foreach ( $tree as $rec ) {
|
|
| 68 | - if ( $rec->id == $id ) {
|
|
| 69 | - if( isset($rec->count) ) {
|
|
| 67 | + foreach ($tree as $rec) {
|
|
| 68 | + if ($rec->id == $id) {
|
|
| 69 | + if (isset($rec->count)) {
|
|
| 70 | 70 | $rec->count += $count; |
| 71 | 71 | } else {
|
| 72 | 72 | $rec->count = $count; |
| 73 | 73 | } |
| 74 | - if ( isset($rec->parent_id) && $rec->parent_id && $is_merge ) {
|
|
| 75 | - $this->addCount($this->tree,$rec->parent_id,$count,$is_merge); |
|
| 74 | + if (isset($rec->parent_id) && $rec->parent_id && $is_merge) {
|
|
| 75 | + $this->addCount($this->tree, $rec->parent_id, $count, $is_merge); |
|
| 76 | 76 | } |
| 77 | - } elseif ( count($rec->children) ) {
|
|
| 78 | - $this->addCount($rec->children,$id,$count,$is_merge); |
|
| 77 | + } elseif (count($rec->children)) {
|
|
| 78 | + $this->addCount($rec->children, $id, $count, $is_merge); |
|
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | } |