-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #392 from magento/models-generation
Added generate models action
- Loading branch information
Showing
29 changed files
with
1,787 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
resources/fileTemplates/internal/Magento Collection Class.php.ft
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
#parse("PHP File Header.php") | ||
#if (${NAMESPACE}) | ||
|
||
namespace ${NAMESPACE}; | ||
#end | ||
|
||
#set ($uses = ${USES}) | ||
#foreach ($use in $uses.split(",")) | ||
use $use; | ||
#end | ||
|
||
class ${NAME}#if (${EXTENDS}) extends ${EXTENDS}#end#if (${IMPLEMENTS}) implements ${IMPLEMENTS}#end { | ||
/** | ||
* @var string | ||
*/ | ||
protected $_eventPrefix = '${DB_NAME}_collection'; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function _construct() | ||
{ | ||
$this->_init(${MODEL}::class, ${RESOURCE_MODEL}::class); | ||
} | ||
} |
Empty file.
26 changes: 26 additions & 0 deletions
26
resources/fileTemplates/internal/Magento Model Class.php.ft
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
#parse("PHP File Header.php") | ||
#if (${NAMESPACE}) | ||
|
||
namespace ${NAMESPACE}; | ||
#end | ||
|
||
#set ($uses = ${USES}) | ||
#foreach ($use in $uses.split(",")) | ||
use $use; | ||
#end | ||
|
||
class ${NAME}#if (${EXTENDS}) extends ${EXTENDS}#end#if (${IMPLEMENTS}) implements ${IMPLEMENTS}#end { | ||
/** | ||
* @var string | ||
*/ | ||
protected $_eventPrefix = '${DB_NAME}_model'; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function _construct() | ||
{ | ||
$this->_init(${RESOURCE_MODEL}::class); | ||
} | ||
} |
Empty file.
26 changes: 26 additions & 0 deletions
26
resources/fileTemplates/internal/Magento Resource Model Class.php.ft
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
#parse("PHP File Header.php") | ||
#if (${NAMESPACE}) | ||
|
||
namespace ${NAMESPACE}; | ||
#end | ||
|
||
#set ($uses = ${USES}) | ||
#foreach ($use in $uses.split(",")) | ||
use $use; | ||
#end | ||
|
||
class ${NAME}#if (${EXTENDS}) extends ${EXTENDS}#end#if (${IMPLEMENTS}) implements ${IMPLEMENTS}#end { | ||
/** | ||
* @var string | ||
*/ | ||
protected $_eventPrefix = '${DB_NAME}_resource_model'; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function _construct() | ||
{ | ||
$this->_init('${DB_NAME}', '${ENTITY_ID_COLUMN}'); | ||
} | ||
} |
Empty file.
56 changes: 56 additions & 0 deletions
56
src/com/magento/idea/magento2plugin/actions/generation/NewModelsAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
package com.magento.idea.magento2plugin.actions.generation; | ||
|
||
import com.intellij.ide.IdeView; | ||
import com.intellij.openapi.actionSystem.AnAction; | ||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.actionSystem.CommonDataKeys; | ||
import com.intellij.openapi.actionSystem.DataContext; | ||
import com.intellij.openapi.actionSystem.LangDataKeys; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.psi.PsiDirectory; | ||
import com.magento.idea.magento2plugin.MagentoIcons; | ||
import com.magento.idea.magento2plugin.actions.generation.dialog.NewModelsDialog; | ||
|
||
public class NewModelsAction extends AnAction { | ||
public static final String ACTION_NAME = "Magento 2 Models"; | ||
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 models"; | ||
|
||
/** | ||
* New controller action constructor. | ||
*/ | ||
public NewModelsAction() { | ||
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE); | ||
} | ||
|
||
@Override | ||
public void actionPerformed(final AnActionEvent event) { | ||
final DataContext dataContext = event.getDataContext(); | ||
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext); | ||
|
||
if (view == null) { | ||
return; | ||
} | ||
|
||
final Project project = CommonDataKeys.PROJECT.getData(dataContext); | ||
if (project == null) { | ||
return; | ||
} | ||
|
||
final PsiDirectory directory = view.getOrChooseDirectory(); | ||
if (directory == null) { | ||
return; | ||
} | ||
|
||
NewModelsDialog.open(project, directory); | ||
} | ||
|
||
@Override | ||
public boolean isDumbAware() { | ||
return false; | ||
} | ||
} |
147 changes: 147 additions & 0 deletions
147
src/com/magento/idea/magento2plugin/actions/generation/data/CollectionData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
/* | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
package com.magento.idea.magento2plugin.actions.generation.data; | ||
|
||
@SuppressWarnings({"PMD.ExcessiveParameterList"}) | ||
public class CollectionData { | ||
private final String moduleName; | ||
private final String dbTableName; | ||
private final String modelName; | ||
private final String collectionName; | ||
private final String collectionFqn; | ||
private final String collectionDirectory; | ||
private final String collectionNamespace; | ||
private final String resourceModelName; | ||
private final String resourceModelFqn; | ||
private final String modelFqn; | ||
|
||
/** | ||
* Models Data. | ||
* | ||
* @param moduleName String | ||
* @param dbTableName String | ||
* @param modelName String | ||
* @param collectionName String | ||
* @param collectionFqn String | ||
* @param collectionDirectory String | ||
* @param resourceModelName String | ||
* @param resourceModelFqn String | ||
* @param modelFqn String | ||
*/ | ||
public CollectionData( | ||
final String moduleName, | ||
final String dbTableName, | ||
final String modelName, | ||
final String collectionName, | ||
final String collectionFqn, | ||
final String collectionDirectory, | ||
final String collectionNamespace, | ||
final String resourceModelName, | ||
final String resourceModelFqn, | ||
final String modelFqn | ||
) { | ||
this.moduleName = moduleName; | ||
this.dbTableName = dbTableName; | ||
this.modelName = modelName; | ||
this.collectionName = collectionName; | ||
this.collectionFqn = collectionFqn; | ||
this.collectionDirectory = collectionDirectory; | ||
this.collectionNamespace = collectionNamespace; | ||
this.resourceModelName = resourceModelName; | ||
this.resourceModelFqn = resourceModelFqn; | ||
this.modelFqn = modelFqn; | ||
} | ||
|
||
/** | ||
* Module Name. | ||
* | ||
* @return String | ||
*/ | ||
public String getModuleName() { | ||
return moduleName; | ||
} | ||
|
||
/** | ||
* DB table Name. | ||
* | ||
* @return String | ||
*/ | ||
public String getDbTableName() { | ||
return dbTableName; | ||
} | ||
|
||
/** | ||
* Model Name. | ||
* | ||
* @return String | ||
*/ | ||
public String getModelName() { | ||
return modelName; | ||
} | ||
|
||
/** | ||
* Collection Name. | ||
* | ||
* @return String | ||
*/ | ||
public String getCollectionName() { | ||
return collectionName; | ||
} | ||
|
||
/** | ||
* Collection FQN. | ||
* | ||
* @return String | ||
*/ | ||
public String getCollectionFqn() { | ||
return collectionFqn; | ||
} | ||
|
||
/** | ||
* Collection Directory. | ||
* | ||
* @return String | ||
*/ | ||
public String getCollectionDirectory() { | ||
return collectionDirectory; | ||
} | ||
|
||
/** | ||
* Collection Namespace. | ||
* | ||
* @return String | ||
*/ | ||
public String getCollectionNamespace() { | ||
return collectionNamespace; | ||
} | ||
|
||
/** | ||
* Resource Model Name. | ||
* | ||
* @return String | ||
*/ | ||
public String getResourceModelName() { | ||
return resourceModelName; | ||
} | ||
|
||
/** | ||
* Resource Model FQN. | ||
* | ||
* @return String | ||
*/ | ||
public String getResourceModelFqn() { | ||
return resourceModelFqn; | ||
} | ||
|
||
/** | ||
* Model FQN. | ||
* | ||
* @return String | ||
*/ | ||
public String getModelFqn() { | ||
return modelFqn; | ||
} | ||
} |
Oops, something went wrong.