Skip to content

Instantly share code, notes, and snippets.

@d3v2a
Last active May 12, 2026 18:21
Show Gist options
  • Select an option

  • Save d3v2a/c624a84234a2c7377959d83cc0cace87 to your computer and use it in GitHub Desktop.

Select an option

Save d3v2a/c624a84234a2c7377959d83cc0cace87 to your computer and use it in GitHub Desktop.
exemple skill compression

from: https://github.com/jeffsenso/dolibarr-skills/blob/dbe7f77e488e1f1bd9f4fb7dfc66656837d774cb/skills/dolibarr-development/references/coding-rules.md

DLB:code_rules_ref

SRC:wiki.dolibarr.org/lang_dev_rules

PHP:

COMPAT: php>=7.1 db:mysql>=5.7|maria|pgsql os:win|linux|mac

FILE: ext:.php fmt:lf tag:<?php_only hdr:copyright_req

STYLE: psr:12 exc:

  • tabs_ok
  • long_decl_ok
  • max_line=1000

STR: concat:"txt ".$var cmt://|/**/ ret:ok>=0|err<0

INC: include_once:.class.php|.lib.php include:.inc.php|.tpl.php

FORBID: dead_code select* short_tags

INPUT: never:$_GET|$_POST use:GETPOST

EX: id=GETPOST('id','int') ref=GETPOST('ref','alpha') txt=GETPOST('txt','alphanohtml')

GLOBALS: db user conf langs mysoc hookmanager extrafields

REQ: core:require_once(DOL_DOCUMENT_ROOT...) mod:dol_include_once(...)

LOG: dol_syslog(msg,LOG_INFO|DEBUG|WARNING|ERR)

DATE: now:dol_now() mk:dol_mktime() fmt:dol_print_date() str2ts:dol_stringtotime() add:dol_time_plus_duree()

SQL_DATE: ts2db:$db->idate() db2ts:$db->jdate()

NOTE: db_dates=php_tz tms=gmt

FLOAT: amount:price2num(v,'MT') other:round()

DIR: base:DOL_DATA_ROOT mk:dol_mkdir()

VER: if:(float)DOL_VERSION>=17 or:versioncompare()

SQL:

TABLE: prefix:llx_ engine:innodb pk:rowid auto_inc

STD_FIELDS: rowid ref entity ref_ext date_creation tms fk_user_creat fk_user_modif import_key status note_private note_public

TYPE: pk|fk:int|bigint bool:smallint amount:double(24,8) vat:double(6,3) qty:real str:varchar(N) ts:timestamp dt:datetime date:date txt:text|mediumtext

FORBID: enum char(1)

KEYS: pk:rowid uk:uk_table_field fk:fk_table_field idx:idx_table_field

FK: soft_only no_db_constraint

SQL_CODE: txn: begin() query() commit|rollback()

SELECT: never:select* never:sql_date_fn use:explicit_fields

FLOW: query num_rows fetch_object free

DATE_SQL: use:dol_now()+idate() never:NOW|SYSDATE|DATEDIFF|DATE

PORT: ifsql:$db->ifsql()

FORBID_SQL: GROUP_CONCAT WITH_ROLLUP DELETE_CASCADE UPDATE_CASCADE triggers stored_proc quoted_numeric

HTML:

RULES: html:not_xhtml attr:lowercase+dq

URL: dol_buildpath()

IMG: img_picto()

LAYOUT: no_forced_width

JS: if($conf->use_javascript_ajax)

POPUP: forbid_except_tooltip

TPL: no_smarty|twig use:tpl.php

CSS: liste_titre=table_hdr pair|impair=alt_rows flat=input button=submit

MVC: ACT: /* Actions */

VIEW: /* View */ llxHeader() llxFooter()

PATTERNS: table_module active_record mvc no_composer libs:embedded

ROLE:llm_knowledge_compressor

GOAL: min_tok|max_info|llm_readable|human_opt

RULES:

STRUCT: tree>phrase use: key: sub:key flow: cfg: rule:

LANG: rm: articles filler prose repetition

keep: tech_terms api code selectors ids constraints

FMT: key:value a>b x|y|z 1->2->3

ABBR: cfg=config req=request res=result desc=description auth=authentication compat=compatibility func=function db=database env=environment

avoid:ambiguous_abbr

PRIO: keep: rules flow relations exceptions forbid api signatures formats business_logic

reduce: explanation pedagogy human_text

CODE: keep:useful rm:long_comments

SHORT: ok fail forbid req opt def ex

LIST: prefer:a|b|c

OUT: raw_only no_intro stable compact multi_llm

TARGET: semantic_rebuild token_reduction llm_native

IN: {{TEXT}}

OUT:

from: https://github.com/jeffsenso/dolibarr-skills/blob/dbe7f77e488e1f1bd9f4fb7dfc66656837d774cb/skills/dolibarr-development/references/hooks-triggers.md Dolibarr:hooks|triggers

hooks: purpose:inject|replace_code when:render|action_handle find:executeHooks( file:class/actions_mymodule.class.php

triggers: purpose:business_event_react when:BILL_CREATE|ORDER_VALIDATE|delete|modify find:run_triggers( file:core/triggers/interface_99_modMyModule_*.class.php

hooks.flow: 1>cfg.module_parts 2>create.actions_class 3>impl.methods 4>return_code

cfg.module_parts:

$this->module_parts=array(
 'hooks'=>array(
  'thirdpartycard',
  'orderlist',
  'globalcard',
  'all'
 )
);

rule: ctx_change->disable+enable_module ctx_find:grep initHooks(

ctx.common: thirdpartycard:thirdparty_view_edit ordercard:customer_order_card invoicecard:customer_invoice_card productcard:product_card contactcard:contact_card contractcard:contract_card propalcard:proposal_card membercard:member_card orderlist:customer_order_list invoicelist:invoice_list globalcard:all_cards all:all_ctx main:all_web_pages cli:all_cli_scripts

hooks.file: path:htdocs/custom/mymodule/class/actions_mymodule.class.php

hooks.class:

class ActionsMyModule
{
 public $errors=array();
 public $results=array();
 public $resprints='';

 public function doActions($parameters,&$object,&$action,$hookmanager)
 {
  if(in_array('thirdpartycard',explode(':',$parameters['context']))) {
   // code
  }
  return 0;
 }

 public function formObjectOptions($parameters,&$object,&$action,$hookmanager)
 {
  if(in_array('productcard',explode(':',$parameters['context']))) {
   $this->resprints='<tr><td>My extra field</td><td>value</td></tr>';
  }
  return 0;
 }

 public function printFieldListSelect($parameters,&$object,&$action,&$hookmanager)
 {
  if(in_array('orderlist',explode(':',$parameters['context']))) {
   $this->resprints=", myfield AS myalias";
  }
  return 0;
 }

 public function printFieldListWhere($parameters,&$object,&$action,$hookmanager)
 {
  return 0;
 }
}

hooks.return: 0:continue_std_code 1:replace_std_code <0:error+$this->errors[]

hooks.props: $this->resprints:instant_print $this->results:merge->$hookmanager->resArray mod.$object:propagate mod.$action:propagate

hooks.methods: doActions:POST_action formObjectOptions:add_HTML_rows formCreateThirdpartyOptions:add_create_fields printFieldListSelect:add_SQL_SELECT printFieldListFrom:add_SQL_FROM_JOIN printFieldListWhere:add_SQL_WHERE printFieldListOrderby:add_SQL_ORDERBY printFieldListTitle:add_list_header printFieldListValue:add_list_value addMoreBoxStatsCustomer:add_stats_boxes formAddObjectLine:add_order_invoice_rows afterPDFCreation:after_pdf sendEmailsAfterSend:after_mail

hooks.custom_point:

$hookmanager=new HookManager($db);
$hookmanager->initHooks(array('mymodulepage'));

$parameters=array('mydata'=>$value);

$reshook=$hookmanager->executeHooks(
 'myHookName',
 $parameters,
 $object,
 $action
);

if(empty($reshook)) {
 echo 'default output';
}

echo $hookmanager->resprints;

triggers.file: path:htdocs/custom/mymodule/core/triggers/interface_99_modMyModule_MyTrigger.class.php priority:99 rule:lower_first

triggers.class:

require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';

class InterfaceMyTrigger extends DolibarrTriggers
{
 public function __construct($db)
 {
  parent::__construct($db);

  $this->name='MyTrigger';
  $this->description='Trigger for my module';
  $this->version='1.0';
  $this->picto='technic';
 }

 public function runTrigger(
  $action,
  $object,
  User $user,
  Translate $langs,
  Conf $conf
 ) {
  if($action=='BILL_CREATE') {
   dol_syslog(
    "Trigger BILL_CREATE fired",
    LOG_DEBUG
   );
  }

  if($action=='ORDER_VALIDATE') {
   // code
  }

  return 0;
 }
}

triggers.return: 0:ok <0:error

triggers.events: BILL_CREATE BILL_MODIFY BILL_VALIDATE BILL_DELETE BILL_SENTBYMAIL ORDER_CREATE ORDER_VALIDATE ORDER_DELETE ORDER_SENTBYMAIL PROPAL_CREATE PROPAL_VALIDATE PROPAL_SENTBYMAIL COMPANY_CREATE COMPANY_MODIFY COMPANY_DELETE USER_CREATE USER_MODIFY USER_DELETE CONTRACT_CREATE CONTRACT_ACTIVATE CONTRACT_CLOSE PRODUCT_CREATE PRODUCT_MODIFY PRODUCT_DELETE

find: hooks:

grep -r "executeHooks(" htdocs/ --include="*.php" | grep -o "'[^']*'" | sort -u

ctx:

grep -r "initHooks(" htdocs/ --include="*.php"

triggers:

grep -r "run_triggers(" htdocs/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment