Skip to content

Commit 0b2f495

Browse files
author
Vitaliy Boyko
committed
Added generate models action
1 parent 553e14e commit 0b2f495

29 files changed

+1786
-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

@@ -212,6 +213,9 @@
212213
<internalFileTemplate name="Magento Routes Xml"/>
213214
<internalFileTemplate name="Magento Module Layout Xml"/>
214215
<internalFileTemplate name="Magento Module ACL XML"/>
216+
<internalFileTemplate name="Magento Module Collection Class"/>
217+
<internalFileTemplate name="Magento Module Model Class"/>
218+
<internalFileTemplate name="Magento Module Resource Model Class"/>
215219

216220
<postStartupActivity implementation="com.magento.idea.magento2plugin.project.startup.CheckIfMagentoPathIsValidActivity"/>
217221
</extensions>
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 Module 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 Module 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 Module 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: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
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+
public class CollectionData {
9+
private final String moduleName;
10+
private final String dbTableName;
11+
private final String modelName;
12+
private final String collectionName;
13+
private final String collectionFqn;
14+
private final String collectionDirectory;
15+
private final String collectionNamespace;
16+
private final String resourceModelName;
17+
private final String resourceModelFqn;
18+
private final String modelFqn;
19+
20+
/**
21+
* Models Data.
22+
*
23+
* @param moduleName String
24+
* @param dbTableName String
25+
* @param modelName String
26+
* @param collectionName String
27+
* @param collectionFqn String
28+
* @param collectionDirectory String
29+
* @param resourceModelName String
30+
* @param resourceModelFqn String
31+
* @param modelFqn String
32+
*/
33+
public CollectionData(
34+
final String moduleName,
35+
final String dbTableName,
36+
final String modelName,
37+
final String collectionName,
38+
final String collectionFqn,
39+
final String collectionDirectory,
40+
final String collectionNamespace,
41+
final String resourceModelName,
42+
final String resourceModelFqn,
43+
final String modelFqn
44+
) {
45+
this.moduleName = moduleName;
46+
this.dbTableName = dbTableName;
47+
this.modelName = modelName;
48+
this.collectionName = collectionName;
49+
this.collectionFqn = collectionFqn;
50+
this.collectionDirectory = collectionDirectory;
51+
this.collectionNamespace = collectionNamespace;
52+
this.resourceModelName = resourceModelName;
53+
this.resourceModelFqn = resourceModelFqn;
54+
this.modelFqn = modelFqn;
55+
}
56+
57+
/**
58+
* Module Name.
59+
*
60+
* @return String
61+
*/
62+
public String getModuleName() {
63+
return moduleName;
64+
}
65+
66+
/**
67+
* DB table Name.
68+
*
69+
* @return String
70+
*/
71+
public String getDbTableName() {
72+
return dbTableName;
73+
}
74+
75+
/**
76+
* Model Name.
77+
*
78+
* @return String
79+
*/
80+
public String getModelName() {
81+
return modelName;
82+
}
83+
84+
/**
85+
* Collection Name.
86+
*
87+
* @return String
88+
*/
89+
public String getCollectionName() {
90+
return collectionName;
91+
}
92+
93+
/**
94+
* Collection FQN.
95+
*
96+
* @return String
97+
*/
98+
public String getCollectionFqn() {
99+
return collectionFqn;
100+
}
101+
102+
/**
103+
* Collection Directory.
104+
*
105+
* @return String
106+
*/
107+
public String getCollectionDirectory() {
108+
return collectionDirectory;
109+
}
110+
111+
/**
112+
* Collection Namespace.
113+
*
114+
* @return String
115+
*/
116+
public String getCollectionNamespace() {
117+
return collectionNamespace;
118+
}
119+
120+
/**
121+
* Resource Model Name.
122+
*
123+
* @return String
124+
*/
125+
public String getResourceModelName() {
126+
return resourceModelName;
127+
}
128+
129+
/**
130+
* Resource Model FQN.
131+
*
132+
* @return String
133+
*/
134+
public String getResourceModelFqn() {
135+
return resourceModelFqn;
136+
}
137+
138+
/**
139+
* Model FQN.
140+
*
141+
* @return String
142+
*/
143+
public String getModelFqn() {
144+
return modelFqn;
145+
}
146+
}

0 commit comments

Comments
 (0)