Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added generate models action #392

Merged
merged 8 commits into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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