1. Go to this page and download the library: Download remp/crm-application-module library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
remp / crm-application-module example snippets
use Crm\ApplicationModule\DataProvider\DataProviderManager;
class DemoModule
{
public function registerDataProviders(DataProviderManager $dataProviderManager)
{
$dataProviderManager->registerDataProvider(
'frontend_menu',
$this->getInstance(DemoFrontendMenuDataProvider::class)
);
}
}
use Crm\ApplicationModule\DataProvider\DataProviderException;
use Crm\ApplicationModule\DataProvider\FrontendMenuDataProviderInterface;
use Crm\ApplicationModule\Menu\MenuContainerInterface;
class DemoFrontendMenuDataProvider implements FrontendMenuDataProviderInterface
{
public function provide(array $params): void
{
if (!isset($params['menuContainer'])) {
throw new DataProviderException('missing [menuContainer] within data provider params');
}
/** @var MenuContainerInterface $menuContainer */
$menuContainer = $params['menuContainer'];
$menuContainer->removeMenuItemByLink(':Invoices:Invoices:invoiceDetails');
}
}
namespace Crm\DemoModule\Presenters;
class DemoPresenter extends \Crm\AdminModule\Presenters\AdminPresenter
{
// ...
public function renderDefault()
{
}
public function createComponentGoogleUserSubscribersRegistrationSourceStatsGraph()
{
$control = $this->factory->create();
$results = $this->database->table('subscriptions')
->where('subscriptions.start_time < ?', $this->database::literal('NOW()'))
->where('subscriptions.end_time > ?', $this->database::literal('NOW()'))
->group('user.source')
->select('user.source, count(*) AS count')
->order('count DESC')
->fetchAll();
$data = [];
foreach ($results as $row) {
$data[$row['source']] = $row['count'];
}
$control->addSerie($this->translator->translate('dashboard.users.active_sub_registrations.serie'), $data);
return $control;
}
// ...
}
namespace Crm\DemoModule\Presenters;
class DemoPresenter extends \Crm\AdminModule\Presenters\AdminPresenter
{
// ...
public function renderDefault()
{
}
public function createComponentGoogleUserActiveSubscribersRegistrationsSourceStatsGraph(GoogleBarGraphGroupControlFactoryInterface $factory)
{
$graphDataItem = new GraphDataItem();
$graphDataItem->setCriteria(
(new Criteria)->setTableName('payments')
->setTimeField('created_at')
->setJoin('JOIN users ON payments.user_id = users.id')
->setWhere("AND payments.status = '" . PaymentsRepository::STATUS_PAID . "'")
->setGroupBy('users.source') // <-- THIS LINE DEFINES THE GROUPPING
->setSeries('users.source') // <-- THIS LINE DEFINES CHART SERIES
->setValueField('count(*)')
->setStart(DateTime::from($this->dateFrom))
->setEnd(DateTime::from($this->dateTo))
);
$control = $factory->create();
$control->setGraphTitle($this->translator->translate('dashboard.payments.registration.title'))
->setGraphHelp($this->translator->translate('dashboard.payments.registration.tooltip'))
->addGraphDataItem($graphDataItem);
return $control;
}
namespace Crm\DemoModule\Presenters;
class DemoPresenter extends \Crm\AdminModule\Presenters\AdminPresenter
{
// ...
public function renderDefault()
{
}
public function createComponentGoogleSubscriptionsEndGraph(GoogleLineGraphGroupControlFactoryInterface $factory)
{
$items = [];
$graphDataItem = new GraphDataItem();
$graphDataItem->setCriteria((new Criteria())
->setTableName('subscriptions')
->setTimeField('end_time')
->setValueField('count(*)')
->setStart($this->dateFrom)
->setEnd($this->dateTo));
$graphDataItem->setName($this->translator->translate('dashboard.subscriptions.ending.now.title'));
$items[] = $graphDataItem;
$graphDataItem = new GraphDataItem();
$graphDataItem->setCriteria((new Criteria())
->setTableName('subscriptions')
->setWhere('AND next_subscription_id IS NOT NULL')
->setTimeField('end_time')
->setValueField('count(*)')
->setStart($this->dateFrom)
->setEnd($this->dateTo));
$graphDataItem->setName($this->translator->translate('dashboard.subscriptions.ending.withnext.title'));
$items[] = $graphDataItem;
$control = $factory->create()
->setGraphTitle($this->translator->translate('dashboard.subscriptions.ending.title'))
->setGraphHelp($this->translator->translate('dashboard.subscriptions.ending.tooltip'));
foreach ($items as $graphDataItem) {
$control->addGraphDataItem($graphDataItem);
}
return $control;
}
// ...
}
namespace Crm\DemoModule\Presenters;
class DemoPresenter extends \Crm\AdminModule\Presenters\AdminPresenter
{
/** @var \Crm\ApplicationModule\Graphs\GraphData\GraphData @inject */
public $graphData;
// ...
public function renderDefault()
{
}
public function createComponentSmallGraph()
{
return new Multiplier(function ($id) {
$control = new InlineBarGraph;
$graphDataItem = new GraphDataItem();
$graphDataItem
->setCriteria(
(new Criteria())
->setTableName('payments')
->setWhere('AND payment_gateway_id = ' . $id)
->setGroupBy('payment_gateway_id')
->setStart('-3 months')
);
$this->graphData->clear();
$this->graphData->addGraphDataItem($graphDataItem);
$this->graphData->setScaleRange('day');
$data = $this->graphData->getData();
if (!empty($data)) {
$data = array_pop($data);
}
$control->setGraphTitle($this->translator->translate('payments.admin.payment_gateways.small_graph.title'))
->addSerie($data);
return $control;
});
}
// ...
}
namespace Crm\DemoModule\Presenters;
class DemoPresenter extends \Crm\AdminModule\Presenters\AdminPresenter
{
// ...
public function renderDefault()
{
}
public function createComponentPaidPaymentsSmallBarGraph(SmallBarGraphControlFactoryInterface $factory)
{
return $this->generateSmallBarGraphComponent(PaymentsRepository::STATUS_PAID, 'Paid', $factory);
}
private function generateSmallBarGraphComponent($status, $title, SmallBarGraphControlFactoryInterface $factory)
{
$data = $this->paymentsHistogramFactory->paymentsLastMonthDailyHistogram($status);
$control = $factory->create();
$control->setGraphTitle($title)->addSerie($data);
return $control;
}
// ...
}