如何将“目标列表”添加到我的自定义模块

时间:2016-08-22 10:24:49

标签: sugarcrm

我已经创建了一个模块,并通过开发人员工具命名为:Custom_module - >模块构建器 我试图将“目标列表”添加到Custom_module,就像模块Campaign一样,但我找不到这样做的方式 每个人都可以帮助您找到将“目标列表”添加到我的模块的最佳方法。 感谢

1 个答案:

答案 0 :(得分:0)

您只需在custom sub panel中创建custom module即可。 target listProspectLists模块。

点击此链接创建自定义模块。

http://shanedowling.com/sugarcrm-7-custom-subpanels

https://developer.sugarcrm.com/2015/05/18/creating-subpanels-with-custom-results-in-sugar-7-5/

<强> 1。创建新的链接类

这应该进入自定义/模块// YourNewLink.php ,这个类将充当自定义功能,将在两个记录之间建立链接。

<?php

/**
 * Custom filtered link
 */
class YourNewLink extends Link2
{
    /**
     * DB
     *
     * @var DBManager
     */
    protected $db;

    public function __construct($linkName, $bean, $linkDef = false)
    {
        $this->focus = $bean;
        $this->name = $linkName;
        $this->db = DBManagerFactory::getInstance();
        if (empty($linkDef)) {
            $this->def = $bean->field_defs[$linkName];
        } else {
            $this->def = $linkDef;
        }
    }

    /**
     * Returns false if no relationship was found for this link
     *
     * @return bool
     */
    public function loadedSuccesfully()
    {
        // this link always loads successfully
        return true;
    }

    /**
     * @see Link2::getRelatedModuleName()
     */
    public function getRelatedModuleName()
    {
        return '<Your_Module>';
    }

    /**
     *
     * @see Link2::buildJoinSugarQuery()
     */
    public function buildJoinSugarQuery($sugar_query, $options = array())
    {
        $joinParams = array('joinType' => isset($options['joinType']) ? $options['joinType'] : 'INNER');
        $jta = 'active_other_invites';
        if (!empty($options['joinTableAlias'])) {
            $jta = $joinParams['alias'] = $options['joinTableAlias'];
        }

        $sugar_query->joinRaw($this->getCustomJoin($options), $joinParams);
        return $sugar_query->join[$jta];
    }

    /**
     * Builds main join subpanel
     * @param string $params
     * @return string JOIN clause
     */
    protected function getCustomJoin($params = array())
    {
        $bean_id = $this->db->quoted($this->focus->id);
        $sql = " INNER JOIN(";
        $sql .= "SELECT id FROM accounts WHERE id={$bean_id}"; // This is essentially a select statement that will return a set of ids that you can match with the existing sugar_query
        $sql .= ") accounts_result ON accounts_result.id = sugar_query_table.id";
        return $sql;
    }

<强> 2。为链接字段添加新的vardef条目。

对于此示例,我将在联系人模块上创建自定义链接。因此,此代码位于 custom / Extension / modules / Contacts / Ext / Vardefs / your_field_name.php

<?php
$dictionary["Contact"]["fields"]["your_field_name"] = array(
    'name' => 'active_other_invites',
    'type' => 'link',
    'link_file' => 'custom/modules/<YourModule>/YourNewLink.php',
    'link_class' => 'YourNewLink',
    'source' => 'non-db',
    'vname' => 'LBL_NEW_LINK',
    'module' => '<YourModule>',
    'link_type' => 'many',
    'relationship' => '',
);

第3。将新链接添加为子面板

这取决于自定义/扩展/模块/联系人/外部/客户端/基础/布局/子面板/ your_subpanel_name.php

<?php
$viewdefs['Contacts']['base']['layout']['subpanels']['components'][] = array (
  'layout' => 'subpanel',
  'label' => 'LBL_NEW_LINK',
  'context' =>
  array (
    'link' => 'your_field_name',
  ),
);

<强> 4。添加标签

自定义/扩展/模块/联系人/外部/语言/ en_us.new_link.php

<?php
$mod_strings['LBL_ACTIVE_OTHER_INVITES'] = 'Your New Link';

<强> 5。快速修复和重建