Skip to content

Commit

Permalink
Merge pull request #968 from civicrm/integration
Browse files Browse the repository at this point in the history
Sync master with integration
  • Loading branch information
davialexandre committed Jun 7, 2016
2 parents 7486e53 + 7faf2cd commit 9a4060c
Show file tree
Hide file tree
Showing 386 changed files with 39,611 additions and 5,582 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
87 changes: 87 additions & 0 deletions bin/build-dao.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/env bash
#####################################################################################
# This script uses GenCode.php to generate the files and since GenCode has some
# problems dealing with extensions entities, the script does some tricks to get
# thing done. It works by adding the extension entities schema xml files to the
# CiviCRM own schema files, making it look like your entities are part of CiviCRM
# schema. Next it runs GenCode.php, which will generate DAOs for all the given
# entities (Civi's and your extension), and finally it copies your extension's
# DAOs to your extension CRM/NAMESPACE/DAO directory.

CIVIROOT="$1"
EXTROOT="$2"
NAMESPACE="$3"
EXTSRCDIR="$EXTROOT/CRM/$NAMESPACE"
EXTDAODIR="$EXTSRCDIR/DAO"
XMLBUILD="$EXTROOT/build/xml/schema"

function validateOptions() {
if [ -z "$CIVIROOT" -o ! -d "$CIVIROOT" ]; then
echo "ERROR: invalid civicrm-dir: [$CIVIROOT]"
printUsage
fi

if [ -z "$EXTROOT" -o ! -d "$EXTROOT" ]; then
echo "ERROR: invalid extension-dir: [$EXTROOT]"
printUsage
fi

if [ -z "$NAMESPACE" -o ! -d "$EXTSRCDIR" ]; then
echo "ERROR: invalid namespace: [$NAMESPACE]"
printUsage
fi
}

function printUsage() {
echo ""
echo "usage: $0 <civicrm-dir> <extension-dir> <namespace>"
echo "example: $0 /var/www/drupal/sites/all/modules/civicrm /var/www/drupal/sites/all/modules/civicrm/tools/extensions/civihr/your-extension YourNamespace"
exit
}

## Make a tempdir, $ext/build/xml/schema; compile full XML tree
function buildXmlSchema() {
mkdir -p "$XMLBUILD"

## Mix together main xml files
cp -fr "$CIVIROOT"/xml/schema/* "$XMLBUILD/"
cp -fr "$EXTROOT"/xml/schema/* "$XMLBUILD/"

## Build root xml file
## We build on the core Schema.xml so that we don't have to do as much work to
## manage inter-table dependencies
grep -v '</database>' "$CIVIROOT"/xml/schema/Schema.xml > "$XMLBUILD"/Schema.xml
cat "$XMLBUILD"/Schema.xml.inc >> "$XMLBUILD"/Schema.xml
echo '</database>' >> "$XMLBUILD"/Schema.xml
}

## Run GenCode; copy out the DAOs
function buildDAO() {
pushd $CIVIROOT/xml > /dev/null
php GenCode.php $XMLBUILD/Schema.xml
popd > /dev/null

[ ! -d "$EXTDAODIR" ] && mkdir -p "$EXTDAODIR"
cp -f "$CIVIROOT/CRM/$NAMESPACE/DAO"/* "$EXTDAODIR/"
}

function cleanup() {
for DIR in "$EXTROOT/build" "$CIVIROOT/CRM/$NAMESPACE" ; do
if [ -e "$DIR" ]; then
echo "Cleanup: removing $DIR"
rm -rf "$DIR"
fi
done
}


##############################
## Main
set -e
validateOptions
cleanup
buildXmlSchema
buildDAO
cleanup
echo
echo "If there have been XML schema changes, then be sure to manually update the .sql files!"
66 changes: 64 additions & 2 deletions com.civicrm.hrjobroles/CRM/Hrjobroles/BAO/HrJobRoles.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

class CRM_Hrjobroles_BAO_HrJobRoles extends CRM_Hrjobroles_DAO_HrJobRoles {


/**
* Create a new HrJobRoles based on array-data
*
* @param array $params key-value pairs
* @return CRM_Hrjobroles_DAO_HrJobRoles|NULL
* @return CRM_Activity_DAO_HrJobRoles|NULL
*/
public static function create($params) {
$entityName = 'HrJobRoles';
Expand All @@ -21,7 +22,68 @@ public static function create($params) {
return $instance;
}

/**
* Return an associative array with Roles for specific contact.
* @param int $cuid
* @return array
*/
public static function getContactRoles($cuid) {
$queryParam = array(1 => array($cuid, 'String'));
$query = "SELECT cjr.id as role_id, cjr.job_contract_id as contract_id, cjr.title
FROM civicrm_hrjobroles cjr
left join civicrm_hrjobcontract cjc on cjr.job_contract_id=cjc.id
where cjc.contact_id=%1 and cjc.deleted = 0;";
$counter = 0;
$roles = CRM_Core_DAO::executeQuery($query, $queryParam);
$rolesList = array();
while ($roles->fetch()) {
$roleDetails['role_id'] = $roles->role_id;
$roleDetails['contract_id'] = $roles->contract_id;
$roleDetails['title'] = $roles->title;
$rolesList[$counter++] = $roleDetails;
}

return $rolesList;
}

/**
* Get options for a given job roles field along with their database IDs.
*
* @param String $fieldName
*
* @return Array
*/
public static function buildDbOptions($fieldName) {
$queryParam = array(1 => array($fieldName, 'String'));
$query = "SELECT cpv.id, cpv.label from civicrm_option_value cpv
LEFT JOIN civicrm_option_group cpg on cpv.option_group_id = cpg.id
WHERE cpg.name = %1";
$options = array();
$result = CRM_Core_DAO::executeQuery($query, $queryParam);
while ($result->fetch()) {
$options[] = array( 'id'=>$result->id, 'label'=>strtolower($result->label) );
}
return $options;
}

/**
* Check Contact if exist .
*
* @param String $searchValue
* @param String $searchField
* @return Integer ( Contact ID or 0 if not exist)
*/
public static function checkContact($searchValue, $searchField) {
$queryParam = array(1 => array($searchValue, 'String'));
$query = "SELECT id from civicrm_contact where ".$searchField." = %1";
$result = CRM_Core_DAO::executeQuery($query, $queryParam);
return $result->fetch() ? $result->id : 0;
}

public static function importableFields() {
return static::import();
$fields = array('' => array('title' => ts('- do not import -')));
return array_merge($fields, static::import());
}


}
Loading

0 comments on commit 9a4060c

Please sign in to comment.