Skip to content

Commit

Permalink
Merge pull request #262 from compucorp/develop
Browse files Browse the repository at this point in the history
Release v1.0.0-alpha8
  • Loading branch information
deb1990 authored Sep 20, 2019
2 parents 90f5dba + 04e2541 commit eb5ebcf
Show file tree
Hide file tree
Showing 138 changed files with 16,160 additions and 1,500 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.DS_Store
node_modules/
bin/*
!bin/install-php-linter
*.css.map
tests/backstop_data/cookies
tests/backstop_data/screenshots
Expand Down
50 changes: 50 additions & 0 deletions CRM/Civicase/APIHelpers/ActivityQueryApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

use CRM_Civicase_APIHelpers_GenericApi as GenericApiHelper;

/**
* Class CRM_Civicase_APIHelpers_ActivityQueryApi.
*/
class CRM_Civicase_APIHelpers_ActivityQueryApi {

/**
* Validates the Case Query related API parameters.
*
* @param array $params
* API parameters.
*/
public function validateParameters(array $params) {
if (!empty($params['params']) && !empty($params['id'])) {
throw new API_Exception("Please send either the params or Id");
}

if (empty($params['params']) && empty($params['id'])) {
throw new API_Exception("Both params and Id cannot be empty");
}
}

/**
* Returns the parameters for making calls to Activity.get.
*
* @param array $params
* API parameters.
*
* @return array|string
* The parameters for making call to Activity.get.
*/
public function getActivityGetRequestApiParams(array $params) {
$genericApiHelper = new GenericApiHelper();
$apiParams = '';

if (!empty($params['id'])) {
$apiParams = ['id' => ['IN' => $genericApiHelper->getParameterValue($params, 'id')]];
}

if (!empty($params['params'])) {
$apiParams = $params['params'];
}

return $apiParams;
}

}
24 changes: 24 additions & 0 deletions CRM/Civicase/APIHelpers/CasesByContactInvolved.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

class CRM_Civicase_APIHelpers_CasesByContactInvolved {
/**
* Adds joins and conditions to the given query in order to filter cases by
* contact involvement.
*
* @param CRM_Utils_SQL_Select $query
* The SQL object reference.
* @param Int|Array $contactInvolved
* The ID of the contact related to the case.
*/
public static function filter($query, $contactInvolved) {
if (!is_array($contactInvolved)) {
$contactInvolved = ['=' => $contactInvolved];
}

$caseClient = CRM_Core_DAO::createSQLFilter('contact_id', $contactInvolved);
$nonCaseClient = CRM_Core_DAO::createSQLFilter('involved.id', $contactInvolved);

\Civi\CCase\Utils::joinOnRelationship($query, 'involved');
$query->where("a.id IN (SELECT case_id FROM civicrm_case_contact WHERE ($nonCaseClient OR $caseClient))");
}
}
21 changes: 21 additions & 0 deletions CRM/Civicase/APIHelpers/CasesByManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

class CRM_Civicase_APIHelpers_CasesByManager {
/**
* Adds joins and conditions to the given query in order to filter cases by
* manager.
*
* @param CRM_Utils_SQL_Select $query
* The SQL object reference.
* @param Int|Array $caseManager
* The ID of the case manager.
*/
public static function filter($query, $caseManager) {
if (!is_array($caseManager)) {
$caseManager = ['=' => $caseManager];
}

\Civi\CCase\Utils::joinOnRelationship($query, 'manager');
$query->where(CRM_Core_DAO::createSQLFilter('manager.id', $caseManager));
}
}
38 changes: 38 additions & 0 deletions CRM/Civicase/APIHelpers/EntityTagQueryApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/**
* Class CRM_Civicase_APIHelpers_EntityTagQueryApi.
*/
class CRM_Civicase_APIHelpers_EntityTagQueryApi {

/**
* Validates the Entity Tag Query related API parameters.
*
* @param array $params
* API parameters.
*/
public function validateParameters(array $params) {
if (!empty($params['params']) && !empty($params['entity_id'])) {
throw new API_Exception('Please send either the params or Entity ID');
}

if (empty($params['params']) && empty($params['entity_id'])) {
throw new API_Exception('Both params and Entity ID cannot be empty');
}
}

/**
* Returns the name of an entity given the database table name.
*
* @param string $tableName
* Table name.
*
* @return null|string
* Entity Name.
*/
public function getEntityNameFromTable($tableName) {
$className = CRM_Core_DAO_AllCoreTables::getClassForTable($tableName);
return CRM_Core_DAO_AllCoreTables::getBriefName($className);
}

}
71 changes: 71 additions & 0 deletions CRM/Civicase/APIHelpers/GenericApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

/**
* Class CRM_Civicase_APIHelpers_GenericApi.
*/
class CRM_Civicase_APIHelpers_GenericApi {

/**
* Return the entity values based on the parameters passed.
*
* @param string $entityName
* The entity name.
* @param array $params
* API parameters.
* @param array $returnFields
* The fields the API will return.
*
* @return array
* Array of activities.
*/
public function getEntityValues($entityName, array $params, array $returnFields = []) {
$entityValues = [];
if ($returnFields) {
$params['return'] = $returnFields;
}

$params['options'] = ['limit' => 0];

$results = civicrm_api3($entityName, 'get', $params);

if ($results['count'] > 0) {
$entityValues = $results['values'];
}

return $entityValues;
}

/**
* Gets the parameter value from $params array.
*
* This function is useful when we want the parameter to not support
* any SQL operator, i.e we expect a single value or an array of values to
* be passed in for the parameter.
*
* @param array $params
* API parameters.
* @param string $parameterName
* Parameter name.
*
* @return array
* The parameter value.
*/
public function getParameterValue(array $params, $parameterName) {
if (empty($params[$parameterName])) {
return [];
}

if (!is_array($params[$parameterName])) {
return [$params[$parameterName]];
}

$acceptedSQLOperators = CRM_Core_DAO::acceptedSQLOperators();
if (array_intersect($acceptedSQLOperators, array_keys($params[$parameterName]))) {
throw new InvalidArgumentException("No SQL operators allowed for {$parameterName}");
}

return $params[$parameterName];

}

}
Loading

0 comments on commit eb5ebcf

Please sign in to comment.