Example #1
0
/**
 * Get a list of applications available for connections.
 *
 * @param array $params
 * @return array
 * @throws API_Exception
 * @throws CRM_Core_Exception
 * @throws \Civi\Cxn\Rpc\Exception\InvalidMessageException
 */
function civicrm_api3_cxn_app_get($params)
{
    // You should not change CIVICRM_CXN_APPS_URL in production; this is for local development.
    $url = defined('CIVICRM_CXN_APPS_URL') ? CIVICRM_CXN_APPS_URL : \Civi\Cxn\Rpc\Constants::OFFICIAL_APPMETAS_URL;
    list($headers, $blob, $code) = CRM_Cxn_CiviCxnHttp::singleton()->send('GET', $url, '');
    if ($code != 200) {
        throw new API_Exception("Failed to download application list.");
    }
    $agent = new \Civi\Cxn\Rpc\Agent(NULL, NULL);
    $agent->setCertValidator(CRM_Cxn_BAO_Cxn::createCertificateValidator());
    $message = $agent->decode(array(AppMetasMessage::NAME, GarbledMessage::NAME), $blob);
    if ($message instanceof AppMetasMessage) {
        return _civicrm_api3_basic_array_get('CxnApp', $params, $message->getData(), 'appId', array('appId', 'appUrl', 'desc', 'appCert', 'perm'));
    } elseif ($message instanceof GarbledMessage) {
        return civicrm_api3_create_error('Received garbled response', array('garbled_message' => $message->getData()));
    } else {
        return civicrm_api3_create_error("Unrecognized message");
    }
}
Example #2
0
/**
 * System Check API.
 *
 * @param array $params
 *
 * @return array
 *   API result descriptor; return items are alert codes/messages
 * @see civicrm_api3_create_success
 * @see civicrm_api3_create_error
 * @throws API_Exception
 */
function civicrm_api3_system_check($params)
{
    // array(array('name'=> $, 'severity'=>$, ...))
    $id = 1;
    $returnValues = $fields = array();
    _civicrm_api3_system_check_spec($fields);
    // array(CRM_Utils_Check_Message)
    $messages = CRM_Utils_Check::checkAll();
    foreach ($messages as $msg) {
        $returnValues[] = $msg->toArray() + array('id' => $id++);
    }
    return _civicrm_api3_basic_array_get('systemCheck', $params, $returnValues, "id", array_keys($fields));
}
Example #3
0
 public function testBasicArrayGetReturn()
 {
     $records = array(array('snack_id' => 'a', 'fruit' => 'apple', 'cheese' => 'swiss'), array('snack_id' => 'b', 'fruit' => 'grape', 'cheese' => 'cheddar'), array('snack_id' => 'c', 'fruit' => 'apple', 'cheese' => 'cheddar'));
     $kernel = new \Civi\API\Kernel(new \Symfony\Component\EventDispatcher\EventDispatcher());
     $provider = new \Civi\API\Provider\AdhocProvider(3, 'Widget');
     $provider->addAction('get', 'access CiviCRM', function ($apiRequest) use($records) {
         return _civicrm_api3_basic_array_get('Widget', $apiRequest['params'], $records, 'snack_id', array('snack_id', 'fruit', 'cheese'));
     });
     $kernel->registerApiProvider($provider);
     $r1 = $kernel->run('Widget', 'get', array('version' => 3, 'snack_id' => 'b', 'return' => 'fruit'));
     $this->assertAPISuccess($r1);
     $this->assertEquals(array('b' => array('id' => 'b', 'fruit' => 'grape')), $r1['values']);
     $r2 = $kernel->run('Widget', 'get', array('version' => 3, 'snack_id' => 'b', 'return' => array('fruit', 'cheese')));
     $this->assertAPISuccess($r2);
     $this->assertEquals(array('b' => array('id' => 'b', 'fruit' => 'grape', 'cheese' => 'cheddar')), $r2['values']);
     $r3 = $kernel->run('Widget', 'get', array('version' => 3, 'cheese' => 'cheddar', 'return' => array('fruit')));
     $this->assertAPISuccess($r3);
     $this->assertEquals(array('b' => array('id' => 'b', 'fruit' => 'grape'), 'c' => array('id' => 'c', 'fruit' => 'apple')), $r3['values']);
 }
Example #4
0
/**
 * Get a list of available extensions.
 *
 * @param array $params
 *
 * @return array
 *   API result
 */
function civicrm_api3_extension_get($params)
{
    $statuses = CRM_Extension_System::singleton()->getManager()->getStatuses();
    $mapper = CRM_Extension_System::singleton()->getMapper();
    $result = array();
    $id = 0;
    foreach ($statuses as $key => $status) {
        //try {
        //  $info = (array) $mapper->keyToInfo($key);
        //} catch (CRM_Extension_Exception $e) {
        $info = array();
        $info['id'] = $id++;
        // backward compatibility with indexing scheme
        $info['key'] = $key;
        //}
        $info['status'] = $status;
        $result[] = $info;
    }
    return _civicrm_api3_basic_array_get('Extension', $params, $result, 'id', array('id', 'key', 'status'));
}
Example #5
0
 /**
  * @param array $apiRequest
  *   The full description of the API request.
  * @return array
  *    Formatted API result
  * @throws \API_Exception
  */
 public function doGet($apiRequest)
 {
     return _civicrm_api3_basic_array_get($apiRequest['entity'], $apiRequest['params'], $this->records, 'id', $this->fields);
 }
Example #6
0
/**
 * System Check API.
 *
 * @param array $params
 *
 * @return array
 *   API result descriptor; return items are alert codes/messages
 * @see civicrm_api3_create_success
 * @see civicrm_api3_create_error
 * @throws API_Exception
 */
function civicrm_api3_system_check($params)
{
    // array(array('name'=> $, 'severity'=>$, ...))
    $id = 1;
    $returnValues = array();
    // array(CRM_Utils_Check_Message)
    $messages = CRM_Utils_Check::singleton()->checkAll();
    foreach ($messages as $msg) {
        $returnValues[] = $msg->toArray() + array('id' => $id++);
    }
    return _civicrm_api3_basic_array_get('systemCheck', $params, $returnValues, "id", array('id', 'name', 'message', 'title', 'severity', 'is_visible'));
}
Example #7
0
/**
 * Get a list of remotely available extensions.
 *
 * @param array $params
 *
 * @return array
 *   API result
 */
function civicrm_api3_extension_getremote($params)
{
    $extensions = CRM_Extension_System::singleton()->getBrowser()->getExtensions();
    $result = array();
    $id = 0;
    foreach ($extensions as $key => $obj) {
        $info = array();
        $info['id'] = $id++;
        // backward compatibility with indexing scheme
        $info = array_merge($info, (array) $obj);
        $result[] = $info;
    }
    return _civicrm_api3_basic_array_get('Extension', $params, $result, 'id', CRM_Utils_Array::value('return', $params, array()));
}