Skip to content

Commit

Permalink
#22 [Hook] add: use tags instead of note for get actioncomm
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Mar 21, 2023
1 parent c97b71f commit 1945e64
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
31 changes: 25 additions & 6 deletions class/actions_easycrm.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,22 +241,27 @@ public function addMoreActionsButtons(array $parameters, CommonObject $object, s
*/
public function printCommonFooter(array $parameters): int
{
global $db, $langs, $user;
global $conf, $db, $langs, $user;

// Do something only for the current context
if (in_array($parameters['currentcontext'], ['thirdpartycomm', 'projectcard'])) {
if (isModEnabled('agenda')) {
require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';

$pictopath = dol_buildpath('/easycrm/img/easycrm_color.png', 1);
$picto = img_picto('', $pictopath, '', 1, 0, 0, '', 'pictoModule');

$actiomcomm = new ActionComm($db);
$category = new Categorie($db);

$category->fetch('', $langs->trans('CommercialRelaunching'));

$actiomcomms = $actiomcomm->getActions(GETPOST('socid'), ($parameters['currentcontext'] != 'thirdpartycomm' ? GETPOST('id') : ''), ($parameters['currentcontext'] != 'thirdpartycomm' ? 'project' : ''), ' AND a.note = "' . $langs->trans('CommercialRelaunching') . '"');
$filter = ' AND a.id IN (SELECT c.fk_actioncomm FROM ' . MAIN_DB_PREFIX . 'categorie_actioncomm as c WHERE c.fk_categorie = ' . $category->id . ')';
$actiomcomms = $actiomcomm->getActions(GETPOST('socid'), ($parameters['currentcontext'] != 'thirdpartycomm' ? GETPOST('id') : ''), ($parameters['currentcontext'] != 'thirdpartycomm' ? 'project' : ''), $filter, 'a.datec');
if (is_array($actiomcomms) && !empty($actiomcomms)) {
$nbActiomcomms = count($actiomcomms);
$lastActiomcomm = array_pop($actiomcomms);
$lastActiomcomm = array_shift($actiomcomms);
} else {
$nbActiomcomms = 0;
}
Expand All @@ -281,22 +286,36 @@ public function printCommonFooter(array $parameters): int
if (isModEnabled('agenda') && isModEnabled('project') && $user->hasRight('projet', 'lire') && isModEnabled('saturne')) {
require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';

require_once __DIR__ . '/../../saturne/lib/object.lib.php';

$pictopath = dol_buildpath('/easycrm/img/easycrm_color.png', 1);
$picto = img_picto('', $pictopath, '', 1, 0, 0, '', 'pictoModule');

$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
// If $page is not defined, or '' or -1 or if we click on clear filters
$page = 0;
}

$offset = $limit * $page;

$actiomcomm = new ActionComm($db);
$category = new Categorie($db);

$category->fetch('', $langs->trans('CommercialRelaunching'));

$projects = saturne_fetch_all_object_type('Project');
$filter = ' AND a.id IN (SELECT c.fk_actioncomm FROM ' . MAIN_DB_PREFIX . 'categorie_actioncomm as c WHERE c.fk_categorie = ' . $category->id . ')';
$projects = saturne_fetch_all_object_type('Project', '', '', $limit, $offset);
if (is_array($projects) && !empty($projects)) {
foreach ($projects as $project) {
if (!empty($project->id)) {
$actiomcomms = $actiomcomm->getActions($project->fk_soc, $project->id, 'project', ' AND a.note = "' . $langs->trans('CommercialRelaunching') . '"');
$actiomcomms = $actiomcomm->getActions($project->fk_soc, $project->id, 'project', $filter, 'a.datec');
if (is_array($actiomcomms) && !empty($actiomcomms)) {
$nbActiomcomms = count($actiomcomms);
$lastActiomcomm = array_pop($actiomcomms);
$lastActiomcomm = array_shift($actiomcomms);
} else {
$nbActiomcomms = 0;
}
Expand Down
18 changes: 13 additions & 5 deletions core/modules/modEasyCRM.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function __construct($db)
// A condition to hide module
$this->hidden = false;
// List of module class names as string that must be enabled if this module is enabled. Example: array('always1'=>'modModuleToEnable1','always2'=>'modModuleToEnable2', 'FR1'=>'modModuleToEnableFR'...)
$this->depends = ['modSaturne', 'modFckeditor'];
$this->depends = ['modSaturne', 'modFckeditor', 'modAgenda', 'modSociete', 'modProjet', 'modCategorie'];
$this->requiredby = []; // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...)
$this->conflictwith = []; // List of module class names as string this module is in conflict with. Example: array('modModuleToDisable1', ...)

Expand Down Expand Up @@ -353,7 +353,7 @@ public function __construct($db)
*/
public function init($options = ''): int
{
global $conf, $langs;
global $conf, $langs, $user;

if ($this->error > 0) {
setEventMessages('', $this->errors, 'errors');
Expand All @@ -367,10 +367,18 @@ public function init($options = ''): int

// Create extrafields during init
include_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
$extra_fields = new ExtraFields($this->db);
$extrafields = new ExtraFields($this->db);

$extra_fields->addExtraField('commrelaunch', $langs->transnoentities('CommercialsRelaunching'), 'text', 100, 2000, 'projet', 0, 0, '', '', '', '', 2);
$extra_fields->addExtraField('commtask', $langs->transnoentities('CommercialTask'), 'sellist', 100, 2000, 'projet', 0, 0, '', 'a:1:{s:7:"options";a:1:{s:39:"projet_task:ref:rowid::fk_projet = $ID$";N;}}', 1, '', 1);
$extrafields->addExtraField('commrelaunch', $langs->transnoentities('CommercialsRelaunching'), 'text', 100, 2000, 'projet', 0, 0, '', '', '', '', 2);
$extrafields->addExtraField('commtask', $langs->transnoentities('CommercialTask'), 'sellist', 100, 2000, 'projet', 0, 0, '', 'a:1:{s:7:"options";a:1:{s:39:"projet_task:ref:rowid::fk_projet = $ID$";N;}}', 1, '', 1);

require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';

$category = new Categorie($this->db);

$category->label = $langs->trans('CommercialRelaunching');
$category->type = 'actioncomm';
$category->create($user);

// Permissions
$this->remove($options);
Expand Down
5 changes: 3 additions & 2 deletions view/quickevent.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@
$actioncomm->label = GETPOST('label');
$actioncomm->datep = $dateStart;
$actioncomm->datef = $dateEnd;
$actioncomm->note_private = $langs->transnoentities('CommercialRelaunching');
$actioncomm->socid = $socid;
$actioncomm->userownerid = $user->id;
$actioncomm->percentage = -1;
Expand Down Expand Up @@ -263,7 +262,9 @@
if (isModEnabled('categorie') && $conf->global->EASYCRM_EVENT_CATEGORIES_VISIBLE > 0) {
print '<tr><td>' . $langs->trans('Categories') . '</td><td>';
$cate_arbo = $form->select_all_categories(Categorie::TYPE_ACTIONCOMM, '', 'parent', 64, 0, 1);
print img_picto('', 'category', 'class="pictofixedwidth"') . $form->multiselectarray('categories', $cate_arbo, GETPOST('categories', 'array'), '', 0, 'quatrevingtpercent widthcentpercentminusx');
$category->fetch('', $langs->trans('CommercialRelaunching'));
$categoriesArray = [$category->id, $category->label];
print img_picto('', 'category', 'class="pictofixedwidth"') . $form->multiselectarray('categories', $cate_arbo, GETPOSTISSET('categories') ? GETPOST('categories', 'array') : $categoriesArray, '', 0, 'quatrevingtpercent widthcentpercentminusx');
print '</td></tr>';
}

Expand Down

0 comments on commit 1945e64

Please sign in to comment.