+ // Format oop params
+ function formatOOP(entity, action, params, indent) {
+ var code = '',
+ newLine = "\n" + _.repeat(' ', indent);
+ if (entity.substr(0, 7) !== 'Custom_') {
+ code = "\\Civi\\Api4\\" + entity + '::' + action + '()';
+ } else {
+ code = "\\Civi\\Api4\\CustomValue::" + action + "('" + entity.substr(7) + "')";
+ }
+ _.each(params, function(param, key) {
+ var val = '';
+ if (typeof objectParams[key] !== 'undefined' && key !== 'chain') {
+ _.each(param, function(item, index) {
+ val = phpFormat(index) + ', ' + phpFormat(item, 2 + indent);
+ code += newLine + "->add" + ucfirst(key).replace(/s$/, '') + '(' + val + ')';
+ });
+ } else if (key === 'where') {
+ _.each(param, function (clause) {
+ if (clause[0] === 'AND' || clause[0] === 'OR' || clause[0] === 'NOT') {
+ code += newLine + "->addClause(" + phpFormat(clause[0]) + ", " + phpFormat(clause[1]).slice(1, -1) + ')';
+ } else {
+ code += newLine + "->addWhere(" + phpFormat(clause).slice(1, -1) + ")";
+ }
+ });
+ } else if (key === 'select') {
+ code += newLine;
+ // addSelect() is a variadic function & can take multiple arguments; selectRowCount() is a shortcut for addSelect('row_count')
+ code += isSelectRowCount(params) ? '->selectRowCount()' : '->addSelect(' + phpFormat(param).slice(1, -1) + ')';
+ } else if (key === 'chain') {
+ _.each(param, function(chain, name) {
+ code += newLine + "->addChain('" + name + "', " + formatOOP(chain[0], chain[1], chain[2], 2 + indent);
+ code += (chain.length > 3 ? ',' : '') + (!_.isEmpty(chain[2]) ? newLine : ' ') + (chain.length > 3 ? phpFormat(chain[3]) : '') + ')';
+ });
+ }
+ else {
+ code += newLine + "->set" + ucfirst(key) + '(' + phpFormat(param, 2 + indent) + ')';
+ }
+ });
+ return code;
+ }
+