forked from civicrm/org.civicrm.civicase
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #262 from compucorp/develop
Release v1.0.0-alpha8
- Loading branch information
Showing
138 changed files
with
16,160 additions
and
1,500 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.