YetiForceCompany/YetiForceCRM

View on GitHub
modules/OSSMailView/models/ListView.php

Summary

Maintainability
A
2 hrs
Test Coverage
A
93%
<?php

/**
 * OSSMailView ListView model class.
 *
 * @copyright YetiForce S.A.
 * @license YetiForce Public License 6.5 (licenses/LicenseEN.txt or yetiforce.com)
 */
class OSSMailView_ListView_Model extends Vtiger_ListView_Model
{
    /** {@inheritdoc} */
    public function getBasicLinks()
    {
        $basicLinks = [];
        $moduleModel = $this->getModule();
        if (\App\Mail::checkInternalMailClient() && \App\Privilege::isPermitted($moduleModel->getName(), 'CreateView')) {
            $basicLinks[] = [
                'linktype' => 'LISTVIEWBASIC',
                'linklabel' => 'LBL_CREATEMAIL',
                'linkurl' => "javascript:window.location='index.php?module=OSSMail&view=Compose'",
                'linkclass' => 'modCT_' . $moduleModel->getName(),
                'linkicon' => 'fas fa-plus',
                'showLabel' => 1,
            ];
        }
        return $basicLinks;
    }

    /** {@inheritdoc} */
    public function getListViewMassActions($linkParams)
    {
        $currentUserModel = Users_Privileges_Model::getCurrentUserPrivilegesModel();
        $moduleModel = $this->getModule();
        $massActionLinks = [];
        if ($currentUserModel->hasModuleActionPermission($moduleModel->getId(), 'EditView')) {
            $massActionLinks[] = [
                'linktype' => 'LISTVIEWMASSACTION',
                'linklabel' => 'LBL_BindMails',
                'linkurl' => 'javascript:OSSMailView_List_Js.bindMails("index.php?module=' . $moduleModel->get('name') . '&action=BindMails")',
                'linkicon' => 'fas fa-redo-alt',
            ];
            $massActionLinks[] = [
                'linktype' => 'LISTVIEWMASSACTION',
                'linklabel' => 'LBL_ChangeType',
                'linkurl' => 'javascript:OSSMailView_List_Js.triggerChangeType("index.php?module=' . $moduleModel->get('name') . '&view=ChangeType")',
                'linkicon' => 'yfi yfi-full-editing-view',
            ];
        }
        if ($moduleModel->isPermitted('MassActive')) {
            $massActionLinks[] = [
                'linktype' => 'LISTVIEWMASSACTION',
                'linklabel' => 'LBL_MASS_ACTIVATE',
                'linkurl' => 'javascript:',
                'dataUrl' => 'index.php?module=' . $moduleModel->getName() . '&action=MassState&state=Active&sourceView=List',
                'linkclass' => 'js-mass-record-event',
                'linkicon' => 'fas fa-undo-alt',
            ];
        }
        if ($moduleModel->isPermitted('MassArchived')) {
            $massActionLinks[] = [
                'linktype' => 'LISTVIEWMASSACTION',
                'linklabel' => 'LBL_MASS_ARCHIVE',
                'linkurl' => 'javascript:',
                'dataUrl' => 'index.php?module=' . $moduleModel->getName() . '&action=MassState&state=Archived&sourceView=List',
                'linkclass' => 'js-mass-record-event',
                'linkicon' => 'fas fa-archive',
            ];
        }
        if ($moduleModel->isPermitted('MassTrash')) {
            $massActionLinks[] = [
                'linktype' => 'LISTVIEWMASSACTION',
                'linklabel' => 'LBL_MASS_MOVE_TO_TRASH',
                'linkurl' => 'javascript:',
                'dataUrl' => 'index.php?module=' . $moduleModel->getName() . '&action=MassState&state=Trash&sourceView=List',
                'linkclass' => 'js-mass-record-event',
                'linkicon' => 'fas fa-trash-alt',
            ];
        }
        if ($moduleModel->isPermitted('MassDelete')) {
            $massActionLinks[] = [
                'linktype' => 'LISTVIEWMASSACTION',
                'linklabel' => 'LBL_MASS_DELETE',
                'linkurl' => 'javascript:',
                'dataUrl' => 'index.php?module=' . $moduleModel->getName() . '&action=MassDelete&sourceView=List',
                'linkclass' => 'js-mass-record-event',
                'linkicon' => 'fas fa-eraser',
            ];
        }
        foreach ($massActionLinks as $massActionLink) {
            $links['LISTVIEWMASSACTION'][] = Vtiger_Link_Model::getInstanceFromValues($massActionLink);
        }
        return $links;
    }
}