Skip to content

Commit

Permalink
Merge pull request #392 from magento/models-generation
Browse files Browse the repository at this point in the history
Added generate models action
  • Loading branch information
coderimus authored Nov 23, 2020
2 parents 274caf2 + 8ff6339 commit 42e4954
Show file tree
Hide file tree
Showing 29 changed files with 1,787 additions and 38 deletions.
4 changes: 4 additions & 0 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<action id="MagentoCreateCLICommand" class="com.magento.idea.magento2plugin.actions.generation.NewCLICommandAction" />
<action id="MagentoCreateUiComponentGrid" class="com.magento.idea.magento2plugin.actions.generation.NewUiComponentGridAction" />
<action id="MagentoCreateUiComponentForm" class="com.magento.idea.magento2plugin.actions.generation.NewUiComponentFormAction" />
<action id="NewModelsAction" class="com.magento.idea.magento2plugin.actions.generation.NewModelsAction" />
<add-to-group group-id="NewGroup" anchor="last"/>
</group>

Expand Down Expand Up @@ -210,6 +211,9 @@
<internalFileTemplate name="Magento Routes XML"/>
<internalFileTemplate name="Magento Layout XML"/>
<internalFileTemplate name="Magento ACL XML"/>
<internalFileTemplate name="Magento Collection Class"/>
<internalFileTemplate name="Magento Model Class"/>
<internalFileTemplate name="Magento Resource Model Class"/>

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

Expand Down
26 changes: 26 additions & 0 deletions resources/fileTemplates/internal/Magento Collection Class.php.ft
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 resources/fileTemplates/internal/Magento Model Class.php.ft
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.
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.
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;
}
}
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;
}
}
Loading

0 comments on commit 42e4954

Please sign in to comment.