Commit d9ac3542 authored by Pradeep Nayak's avatar Pradeep Nayak

--worked on RG-49

parent b56b5b0f
<?php
// This file declares a managed database record of type "Job".
// The record will be automatically inserted, updated, or deleted from the
// database as appropriate. For more details, see "hook_civicrm_managed" at:
// http://wiki.civicrm.org/confluence/display/CRMDOC42/Hook+Reference
return array (
0 =>
array (
'name' => 'Cron:Grant.ChangeStatus',
'entity' => 'Job',
'params' =>
array (
'version' => 3,
'name' => 'Call Grant.ChangeStatus API',
'description' => 'Call Grant.ChangeStatus API',
'run_frequency' => 'Daily',
'api_entity' => 'Grant',
'api_action' => 'ChangeStatus',
'parameters' => '',
),
),
);
\ No newline at end of file
<?php
/**
* Grant.ChangeStatus API specification (optional)
* This is used for documentation and validation.
*
* @param array $spec description of fields supported by this API call
* @return void
* @see http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
*/
function _civicrm_api3_grant_changestatus_spec(&$spec) {
$spec['magicword']['api.required'] = 1;
}
/**
* Grant.ChangeStatus API
*
* @param array $params
* @return array API result descriptor
* @see civicrm_api3_create_success
* @see civicrm_api3_create_error
* @throws API_Exception
*/
function civicrm_api3_grant_changestatus($params) {
if (array_key_exists('magicword', $params) && $params['magicword'] == 'sesame') {
$returnValues = array( // OK, return several data rows
12 => array('id' => 12, 'name' => 'Twelve'),
34 => array('id' => 34, 'name' => 'Thirty four'),
56 => array('id' => 56, 'name' => 'Fifty six'),
);
// ALTERNATIVE: $returnValues = array(); // OK, success
// ALTERNATIVE: $returnValues = array("Some value"); // OK, return a single value
// Spec: civicrm_api3_create_success($values = 1, $params = array(), $entity = NULL, $action = NULL)
return civicrm_api3_create_success($returnValues, $params, 'grant', 'changestatus');
} else {
throw new API_Exception(/*errorMessage*/ 'Everyone knows that the magicword is "sesame"', /*errorCode*/ 1234);
}
}
...@@ -106,11 +106,18 @@ function _grantprograms_civix_upgrader() { ...@@ -106,11 +106,18 @@ function _grantprograms_civix_upgrader() {
/** /**
* Search directory tree for files which match a glob pattern * Search directory tree for files which match a glob pattern
* *
* Note: Dot-directories (like "..", ".git", or ".svn") will be ignored.
* Note: In Civi 4.3+, delegate to CRM_Utils_File::findFiles()
*
* @param $dir string, base dir * @param $dir string, base dir
* @param $pattern string, glob pattern, eg "*.txt" * @param $pattern string, glob pattern, eg "*.txt"
* @return array(string) * @return array(string)
*/ */
function _grantprograms_civix_find_files($dir, $pattern) { function _grantprograms_civix_find_files($dir, $pattern) {
if (is_callable(array('CRM_Utils_File', 'findFiles'))) {
return CRM_Utils_File::findFiles($dir, $pattern);
}
$todos = array($dir); $todos = array($dir);
$result = array(); $result = array();
while (!empty($todos)) { while (!empty($todos)) {
...@@ -123,7 +130,7 @@ function _grantprograms_civix_find_files($dir, $pattern) { ...@@ -123,7 +130,7 @@ function _grantprograms_civix_find_files($dir, $pattern) {
if ($dh = opendir($subdir)) { if ($dh = opendir($subdir)) {
while (FALSE !== ($entry = readdir($dh))) { while (FALSE !== ($entry = readdir($dh))) {
$path = $subdir . DIRECTORY_SEPARATOR . $entry; $path = $subdir . DIRECTORY_SEPARATOR . $entry;
if ($entry == '.' || $entry == '..') { if ($entry{0} == '.') {
} elseif (is_dir($path)) { } elseif (is_dir($path)) {
$todos[] = $path; $todos[] = $path;
} }
...@@ -167,3 +174,42 @@ function _grantprograms_civix_glob($pattern) { ...@@ -167,3 +174,42 @@ function _grantprograms_civix_glob($pattern) {
$result = glob($pattern); $result = glob($pattern);
return is_array($result) ? $result : array(); return is_array($result) ? $result : array();
} }
/**
* Inserts a navigation menu item at a given place in the hierarchy
*
* $menu - menu hierarchy
* $path - path where insertion should happen (ie. Administer/System Settings)
* $item - menu you need to insert (parent/child attributes will be filled for you)
* $parentId - used internally to recurse in the menu structure
*/
function _grantprograms_civix_insert_navigation_menu(&$menu, $path, $item, $parentId = NULL) {
static $navId;
// If we are done going down the path, insert menu
if (empty($path)) {
if (!$navId) $navId = CRM_Core_DAO::singleValueQuery("SELECT max(id) FROM civicrm_navigation");
$navId ++;
$menu[$navId] = array (
'attributes' => array_merge($item, array(
'label' => CRM_Utils_Array::value('name', $item),
'active' => 1,
'parentID' => $parentId,
'navID' => $navId,
))
);
return true;
} else {
// Find an recurse into the next level down
$found = false;
$path = explode('/', $path);
$first = array_shift($path);
foreach ($menu as $key => &$entry) {
if ($entry['attributes']['name'] == $first) {
if (!$entry['child']) $entry['child'] = array();
$found = _grantprograms_civix_insert_navigation_menu($entry['child'], implode('/', $path), $item, $key);
}
}
return $found;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment