Skip to content

Commit 42e4954

Browse files
authored
Merge pull request #392 from magento/models-generation
Added generate models action
2 parents 274caf2 + 8ff6339 commit 42e4954

29 files changed

+1787
-38
lines changed

resources/META-INF/plugin.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
<action id="MagentoCreateCLICommand" class="com.magento.idea.magento2plugin.actions.generation.NewCLICommandAction" />
6868
<action id="MagentoCreateUiComponentGrid" class="com.magento.idea.magento2plugin.actions.generation.NewUiComponentGridAction" />
6969
<action id="MagentoCreateUiComponentForm" class="com.magento.idea.magento2plugin.actions.generation.NewUiComponentFormAction" />
70+
<action id="NewModelsAction" class="com.magento.idea.magento2plugin.actions.generation.NewModelsAction" />
7071
<add-to-group group-id="NewGroup" anchor="last"/>
7172
</group>
7273

@@ -210,6 +211,9 @@
210211
<internalFileTemplate name="Magento Routes XML"/>
211212
<internalFileTemplate name="Magento Layout XML"/>
212213
<internalFileTemplate name="Magento ACL XML"/>
214+
<internalFileTemplate name="Magento Collection Class"/>
215+
<internalFileTemplate name="Magento Model Class"/>
216+
<internalFileTemplate name="Magento Resource Model Class"/>
213217

214218
<defaultLiveTemplates file="/liveTemplates/MagentoPWA.xml"/>
215219

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
#parse("PHP File Header.php")
3+
#if (${NAMESPACE})
4+
5+
namespace ${NAMESPACE};
6+
#end
7+
8+
#set ($uses = ${USES})
9+
#foreach ($use in $uses.split(","))
10+
use $use;
11+
#end
12+
13+
class ${NAME}#if (${EXTENDS}) extends ${EXTENDS}#end#if (${IMPLEMENTS}) implements ${IMPLEMENTS}#end {
14+
/**
15+
* @var string
16+
*/
17+
protected $_eventPrefix = '${DB_NAME}_collection';
18+
19+
/**
20+
* @inheritdoc
21+
*/
22+
protected function _construct()
23+
{
24+
$this->_init(${MODEL}::class, ${RESOURCE_MODEL}::class);
25+
}
26+
}

resources/fileTemplates/internal/Magento Collection Class.php.html

Whitespace-only changes.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
#parse("PHP File Header.php")
3+
#if (${NAMESPACE})
4+
5+
namespace ${NAMESPACE};
6+
#end
7+
8+
#set ($uses = ${USES})
9+
#foreach ($use in $uses.split(","))
10+
use $use;
11+
#end
12+
13+
class ${NAME}#if (${EXTENDS}) extends ${EXTENDS}#end#if (${IMPLEMENTS}) implements ${IMPLEMENTS}#end {
14+
/**
15+
* @var string
16+
*/
17+
protected $_eventPrefix = '${DB_NAME}_model';
18+
19+
/**
20+
* @inheritdoc
21+
*/
22+
protected function _construct()
23+
{
24+
$this->_init(${RESOURCE_MODEL}::class);
25+
}
26+
}

resources/fileTemplates/internal/Magento Model Class.php.html

Whitespace-only changes.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
#parse("PHP File Header.php")
3+
#if (${NAMESPACE})
4+
5+
namespace ${NAMESPACE};
6+
#end
7+
8+
#set ($uses = ${USES})
9+
#foreach ($use in $uses.split(","))
10+
use $use;
11+
#end
12+
13+
class ${NAME}#if (${EXTENDS}) extends ${EXTENDS}#end#if (${IMPLEMENTS}) implements ${IMPLEMENTS}#end {
14+
/**
15+
* @var string
16+
*/
17+
protected $_eventPrefix = '${DB_NAME}_resource_model';
18+
19+
/**
20+
* @inheritdoc
21+
*/
22+
protected function _construct()
23+
{
24+
$this->_init('${DB_NAME}', '${ENTITY_ID_COLUMN}');
25+
}
26+
}

resources/fileTemplates/internal/Magento Resource Model Class.php.html

Whitespace-only changes.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation;
7+
8+
import com.intellij.ide.IdeView;
9+
import com.intellij.openapi.actionSystem.AnAction;
10+
import com.intellij.openapi.actionSystem.AnActionEvent;
11+
import com.intellij.openapi.actionSystem.CommonDataKeys;
12+
import com.intellij.openapi.actionSystem.DataContext;
13+
import com.intellij.openapi.actionSystem.LangDataKeys;
14+
import com.intellij.openapi.project.Project;
15+
import com.intellij.psi.PsiDirectory;
16+
import com.magento.idea.magento2plugin.MagentoIcons;
17+
import com.magento.idea.magento2plugin.actions.generation.dialog.NewModelsDialog;
18+
19+
public class NewModelsAction extends AnAction {
20+
public static final String ACTION_NAME = "Magento 2 Models";
21+
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 models";
22+
23+
/**
24+
* New controller action constructor.
25+
*/
26+
public NewModelsAction() {
27+
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
28+
}
29+
30+
@Override
31+
public void actionPerformed(final AnActionEvent event) {
32+
final DataContext dataContext = event.getDataContext();
33+
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
34+
35+
if (view == null) {
36+
return;
37+
}
38+
39+
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
40+
if (project == null) {
41+
return;
42+
}
43+
44+
final PsiDirectory directory = view.getOrChooseDirectory();
45+
if (directory == null) {
46+
return;
47+
}
48+
49+
NewModelsDialog.open(project, directory);
50+
}
51+
52+
@Override
53+
public boolean isDumbAware() {
54+
return false;
55+
}
56+
}
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation.data;
7+
8+
@SuppressWarnings({"PMD.ExcessiveParameterList"})
9+
public class CollectionData {
10+
private final String moduleName;
11+
private final String dbTableName;
12+
private final String modelName;
13+
private final String collectionName;
14+
private final String collectionFqn;
15+
private final String collectionDirectory;
16+
private final String collectionNamespace;
17+
private final String resourceModelName;
18+
private final String resourceModelFqn;
19+
private final String modelFqn;
20+
21+
/**
22+
* Models Data.
23+
*
24+
* @param moduleName String
25+
* @param dbTableName String
26+
* @param modelName String
27+
* @param collectionName String
28+
* @param collectionFqn String
29+
* @param collectionDirectory String
30+
* @param resourceModelName String
31+
* @param resourceModelFqn String
32+
* @param modelFqn String
33+
*/
34+
public CollectionData(
35+
final String moduleName,
36+
final String dbTableName,
37+
final String modelName,
38+
final String collectionName,
39+
final String collectionFqn,
40+
final String collectionDirectory,
41+
final String collectionNamespace,
42+
final String resourceModelName,
43+
final String resourceModelFqn,
44+
final String modelFqn
45+
) {
46+
this.moduleName = moduleName;
47+
this.dbTableName = dbTableName;
48+
this.modelName = modelName;
49+
this.collectionName = collectionName;
50+
this.collectionFqn = collectionFqn;
51+
this.collectionDirectory = collectionDirectory;
52+
this.collectionNamespace = collectionNamespace;
53+
this.resourceModelName = resourceModelName;
54+
this.resourceModelFqn = resourceModelFqn;
55+
this.modelFqn = modelFqn;
56+
}
57+
58+
/**
59+
* Module Name.
60+
*
61+
* @return String
62+
*/
63+
public String getModuleName() {
64+
return moduleName;
65+
}
66+
67+
/**
68+
* DB table Name.
69+
*
70+
* @return String
71+
*/
72+
public String getDbTableName() {
73+
return dbTableName;
74+
}
75+
76+
/**
77+
* Model Name.
78+
*
79+
* @return String
80+
*/
81+
public String getModelName() {
82+
return modelName;
83+
}
84+
85+
/**
86+
* Collection Name.
87+
*
88+
* @return String
89+
*/
90+
public String getCollectionName() {
91+
return collectionName;
92+
}
93+
94+
/**
95+
* Collection FQN.
96+
*
97+
* @return String
98+
*/
99+
public String getCollectionFqn() {
100+
return collectionFqn;
101+
}
102+
103+
/**
104+
* Collection Directory.
105+
*
106+
* @return String
107+
*/
108+
public String getCollectionDirectory() {
109+
return collectionDirectory;
110+
}
111+
112+
/**
113+
* Collection Namespace.
114+
*
115+
* @return String
116+
*/
117+
public String getCollectionNamespace() {
118+
return collectionNamespace;
119+
}
120+
121+
/**
122+
* Resource Model Name.
123+
*
124+
* @return String
125+
*/
126+
public String getResourceModelName() {
127+
return resourceModelName;
128+
}
129+
130+
/**
131+
* Resource Model FQN.
132+
*
133+
* @return String
134+
*/
135+
public String getResourceModelFqn() {
136+
return resourceModelFqn;
137+
}
138+
139+
/**
140+
* Model FQN.
141+
*
142+
* @return String
143+
*/
144+
public String getModelFqn() {
145+
return modelFqn;
146+
}
147+
}

0 commit comments

Comments
 (0)