当前位置: 首页>>代码示例>>PHP>>正文


PHP CRM_Utils_Array::first方法代码示例

本文整理汇总了PHP中CRM_Utils_Array::first方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_Array::first方法的具体用法?PHP CRM_Utils_Array::first怎么用?PHP CRM_Utils_Array::first使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CRM_Utils_Array的用法示例。


在下文中一共展示了CRM_Utils_Array::first方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: preProcess

 /**
  * Set variables up before form is built.
  *
  * @return void
  */
 public function preProcess()
 {
     parent::preProcess();
     $setTab = CRM_Utils_Request::retrieve('setTab', 'Int', $this, FALSE, 0);
     $mapping = CRM_Utils_Array::first(CRM_Core_BAO_ActionSchedule::getMappings(array('id' => $this->_isTemplate ? CRM_Event_ActionMapping::EVENT_TPL_MAPPING_ID : CRM_Event_ActionMapping::EVENT_NAME_MAPPING_ID)));
     $reminderList = CRM_Core_BAO_ActionSchedule::getList(FALSE, $mapping, $this->_id);
     if ($reminderList && is_array($reminderList)) {
         // Add action links to each of the reminders
         foreach ($reminderList as &$format) {
             $action = CRM_Core_Action::UPDATE + CRM_Core_Action::DELETE;
             if ($format['is_active']) {
                 $action += CRM_Core_Action::DISABLE;
             } else {
                 $action += CRM_Core_Action::ENABLE;
             }
             $scheduleReminder = new CRM_Admin_Page_ScheduleReminders();
             $links = $scheduleReminder->links();
             $links[CRM_Core_Action::DELETE]['qs'] .= "&context=event&compId={$this->_id}";
             $links[CRM_Core_Action::UPDATE]['qs'] .= "&context=event&compId={$this->_id}";
             $format['action'] = CRM_Core_Action::formLink($links, $action, array('id' => $format['id']), ts('more'), FALSE, 'actionSchedule.manage.action', 'ActionSchedule', $this->_id);
         }
     }
     $this->assign('rows', $reminderList);
     $this->assign('setTab', $setTab);
     $this->assign('component', 'event');
     // Update tab "disabled" css class
     $this->ajaxResponse['tabValid'] = is_array($reminderList) && count($reminderList) > 0;
     $this->setPageTitle(ts('Scheduled Reminder'));
 }
开发者ID:nielosz,项目名称:civicrm-core,代码行数:34,代码来源:ScheduleReminders.php

示例2: civicrm_api3_h_r_job_contract_get

/**
 * HRJobContract.get API
 *
 * @param array $params
 * @return array API result descriptor
 * @throws API_Exception
 */
function civicrm_api3_h_r_job_contract_get($params)
{
    $returnFields = array();
    if (!empty($params['return'])) {
        if (is_array($params['return'])) {
            $returnFields = $params['return'];
        } else {
            $returnFields = explode(',', $params['return']);
        }
    }
    $contracts = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
    foreach ($contracts['values'] as $key => $contract) {
        $isCurrent = true;
        $contractDetails = civicrm_api3('HRJobDetails', 'get', array('sequential' => 1, 'jobcontract_id' => $contract['id']));
        $details = CRM_Utils_Array::first($contractDetails['values']);
        if (!empty($details['period_end_date'])) {
            if ($details['period_end_date'] < date('Y-m-d')) {
                $isCurrent = false;
            }
        }
        $contracts['values'][$key]['is_current'] = (int) $isCurrent;
        foreach ($returnFields as $returnField) {
            if (!empty($details[$returnField])) {
                $contracts['values'][$key][$returnField] = $details[$returnField];
            }
        }
    }
    return $contracts;
}
开发者ID:JoeMurray,项目名称:civihr,代码行数:36,代码来源:HRJobContract.php

示例3: preProcess

 /**
  * @param CRM_Core_Form $form
  */
 public static function preProcess(&$form)
 {
     //get multi client case configuration
     $xmlProcessorProcess = new CRM_Case_XMLProcessor_Process();
     $form->_allowMultiClient = (bool) $xmlProcessorProcess->getAllowMultipleCaseClients();
     if ($form->_context == 'caseActivity') {
         $contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $form);
         $atype = CRM_Core_OptionGroup::getValue('activity_type', 'Change Case Start Date', 'name');
         $caseId = CRM_Utils_Array::first($form->_caseId);
         $form->assign('changeStartURL', CRM_Utils_System::url('civicrm/case/activity', "action=add&reset=1&cid={$contactID}&caseid={$caseId}&atype={$atype}"));
         return;
     }
     $form->_context = CRM_Utils_Request::retrieve('context', 'String', $form);
     $form->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $form);
     $form->assign('context', $form->_context);
     // check if the case type id passed in url is a valid one
     $caseTypeId = CRM_Utils_Request::retrieve('ctype', 'Positive', $form);
     $caseTypes = CRM_Case_PseudoConstant::caseType();
     $form->_caseTypeId = array_key_exists($caseTypeId, $caseTypes) ? $caseTypeId : NULL;
     // check if the case status id passed in url is a valid one
     $caseStatusId = CRM_Utils_Request::retrieve('case_status_id', 'Positive', $form);
     $caseStatus = CRM_Case_PseudoConstant::caseStatus();
     $form->_caseStatusId = array_key_exists($caseStatusId, $caseStatus) ? $caseStatusId : NULL;
     // Add attachments
     CRM_Core_BAO_File::buildAttachment($form, 'civicrm_activity', $form->_activityId);
     $session = CRM_Core_Session::singleton();
     $session->pushUserContext(CRM_Utils_System::url('civicrm/case', 'reset=1'));
 }
开发者ID:kidaa30,项目名称:yes,代码行数:31,代码来源:OpenCase.php

示例4: create

 /**
  * Create a new HRJobDetails based on array-data
  *
  * @param array $params key-value pairs
  * @return CRM_HRJob_DAO_HRJobDetails|NULL
  *
  */
 public static function create($params)
 {
     $hook = empty($params['id']) ? 'create' : 'edit';
     $previousDetailsRevisionId = null;
     if ($hook == 'create') {
         $previousRevisionResult = civicrm_api3('HRJobContractRevision', 'getcurrentrevision', array('sequential' => 1, 'jobcontract_id' => $params['jobcontract_id']));
         if (!empty($previousRevisionResult['values']['details_revision_id'])) {
             $previousDetailsRevisionId = $previousRevisionResult['values']['details_revision_id'];
         }
     }
     $instance = parent::create($params);
     // setting 'effective_date' if it's not set:
     $revision = civicrm_api3('HRJobContractRevision', 'get', array('sequential' => 1, 'jobcontract_id' => $params['jobcontract_id'], 'id' => $instance->jobcontract_revision_id));
     if (!empty($revision['values'][0])) {
         $revisionData = array_shift($revision['values']);
         if (!$revisionData['effective_date']) {
             civicrm_api3('HRJobContractRevision', 'create', array('id' => $revisionData['id'], 'effective_date' => $instance->period_start_date));
         }
     }
     $revisionResult = civicrm_api3('HRJobContractRevision', 'get', array('sequential' => 1, 'id' => $instance->jobcontract_revision_id));
     $revision = CRM_Utils_Array::first($revisionResult['values']);
     $duplicate = CRM_Utils_Array::value('action', $params, $hook);
     if ($hook == 'create' && empty($revision['role_revision_id']) && $duplicate != 'duplicate' && empty($params['import'])) {
         //civicrm_api3('HRJobRole', 'create', array('jobcontract_id' => $revision['jobcontract_id'],'title' => $instance->title, 'location'=> $instance->location, 'percent_pay_role' => 100, 'jobcontract_revision_id' => $instance->jobcontract_revision_id));
         CRM_Hrjobcontract_BAO_HRJobRole::create(array('jobcontract_id' => $revision['jobcontract_id'], 'title' => $instance->title, 'location' => $instance->location, 'percent_pay_role' => 100, 'jobcontract_revision_id' => $instance->jobcontract_revision_id));
     }
     if ($previousDetailsRevisionId) {
         CRM_Core_BAO_File::copyEntityFile('civicrm_hrjobcontract_details', $previousDetailsRevisionId, 'civicrm_hrjobcontract_details', $revision['details_revision_id']);
     }
     $contract = new CRM_Hrjobcontract_DAO_HRJobContract();
     $contract->id = $revision['jobcontract_id'];
     $contract->find(true);
     CRM_Hrjobcontract_JobContractDates::setDates($contract->contact_id, $revision['jobcontract_id'], $instance->period_start_date, $instance->period_end_date);
     return $instance;
 }
开发者ID:JoeMurray,项目名称:civihr,代码行数:42,代码来源:HRJobDetails.php

示例5: testAppraisalsApiFlow

 /**
  * Test Appraisals API flow including
  * - create Appraisal Cycle
  * - create Appraisals for Appraisal Cycle
  * - modify Appraisals and populate Appraisal Cycle Due Dates into Appraisal Due Dates.
  * - delete Appraisal Cycle and Appraisal
  */
 function testAppraisalsApiFlow()
 {
     $time = time();
     $expected = array();
     $this->quickCleanup(array('civicrm_contact', 'civicrm_appraisal_cycle', 'civicrm_appraisal'));
     ////////// Create Test Contacts ////////////////////////////////////////
     foreach ($this->_contacts as $key => $contact) {
         $result = civicrm_api3('Contact', 'create', array('sequential' => 1, 'contact_type' => "Individual", 'first_name' => $contact['first_name'], 'last_name' => "Appraisal Test Contact", 'email' => $contact['email']));
         $this->_contacts[$key]['id'] = $result['id'];
     }
     $cycleStartDate = $time;
     $cycleEndDate = $time + 30 * self::DAY;
     $selfAppraisalDue = $time + 5 * self::DAY;
     $managerAppraisalDue = $time + 15 * self::DAY;
     $gradeDue = $time + 25 * self::DAY;
     ////////// Create Test Appraisal Cycle 1: //////////////////////////////
     civicrm_api3('AppraisalCycle', 'create', array('sequential' => 1, 'name' => "Test Appraisal Cycle 1", 'cycle_start_date' => date('Y-m-d', $cycleStartDate), 'cycle_end_date' => date('Y-m-d', $cycleEndDate), 'self_appraisal_due' => date('Y-m-d', $selfAppraisalDue), 'manager_appraisal_due' => date('Y-m-d', $managerAppraisalDue), 'grade_due' => date('Y-m-d', $gradeDue), 'type_id' => 1));
     $expected['AppraisalCycle1'] = array('id' => 1, 'name' => "Test Appraisal Cycle 1", 'cycle_start_date' => date('Y-m-d', $cycleStartDate), 'cycle_end_date' => date('Y-m-d', $cycleEndDate), 'self_appraisal_due' => date('Y-m-d', $selfAppraisalDue), 'manager_appraisal_due' => date('Y-m-d', $managerAppraisalDue), 'grade_due' => date('Y-m-d', $gradeDue), 'type_id' => 1);
     $appraisalCycle1 = civicrm_api3('AppraisalCycle', 'get', array('sequential' => 1, 'id' => 1));
     $this->assertAPIArrayComparison(CRM_Utils_Array::first($appraisalCycle1['values']), $expected['AppraisalCycle1']);
     ////////// Create Test Appraisal Cycle 2: //////////////////////////////
     civicrm_api3('AppraisalCycle', 'create', array('sequential' => 1, 'name' => "Test Appraisal Cycle 2", 'cycle_start_date' => date('Y-m-d', $cycleStartDate + 30 * self::DAY), 'cycle_end_date' => date('Y-m-d', $cycleEndDate + 30 * self::DAY), 'self_appraisal_due' => date('Y-m-d', $selfAppraisalDue + 30 * self::DAY), 'manager_appraisal_due' => date('Y-m-d', $managerAppraisalDue + 30 * self::DAY), 'grade_due' => date('Y-m-d', $gradeDue + 30 * self::DAY), 'type_id' => 2));
     $expected['AppraisalCycle2'] = array('id' => 2, 'name' => "Test Appraisal Cycle 2", 'cycle_start_date' => date('Y-m-d', $cycleStartDate + 30 * self::DAY), 'cycle_end_date' => date('Y-m-d', $cycleEndDate + 30 * self::DAY), 'self_appraisal_due' => date('Y-m-d', $selfAppraisalDue + 30 * self::DAY), 'manager_appraisal_due' => date('Y-m-d', $managerAppraisalDue + 30 * self::DAY), 'grade_due' => date('Y-m-d', $gradeDue + 30 * self::DAY), 'type_id' => 2);
     $appraisalCycle2 = civicrm_api3('AppraisalCycle', 'get', array('sequential' => 1, 'id' => 2));
     $this->assertAPIArrayComparison(CRM_Utils_Array::first($appraisalCycle2['values']), $expected['AppraisalCycle2']);
     ////////// Create Test Appraisal 1 for Appraisal Cycle 1: //////////////
     civicrm_api3('Appraisal', 'create', array('sequential' => 1, 'appraisal_cycle_id' => 1, 'contact_id' => $this->_contacts[0]['id'], 'manager_id' => $this->_contacts[2]['id'], 'self_appraisal_file_id' => "", 'manager_appraisal_file_id' => "", 'self_appraisal_due' => "", 'manager_appraisal_due' => "", 'grade_due' => "", 'due_changed' => "0", 'meeting_date' => date('Y-m-d', $cycleEndDate - 2 * self::DAY), 'meeting_completed' => "0", 'approved_by_employee' => "0", 'grade' => "", 'notes' => "Test Notes of Test Appraisal 1", 'status_id' => 1));
     $expected['Appraisal1'] = array("id" => "1", "appraisal_cycle_id" => "1", "contact_id" => "{$this->_contacts[0]['id']}", "manager_id" => "{$this->_contacts[2]['id']}", "self_appraisal_due" => date('Y-m-d', $selfAppraisalDue), "manager_appraisal_due" => date('Y-m-d', $managerAppraisalDue), "grade_due" => date('Y-m-d', $gradeDue), "due_changed" => "0", "meeting_date" => date('Y-m-d', $cycleEndDate - 2 * self::DAY), "meeting_completed" => "0", "approved_by_employee" => "0", "notes" => "Test Notes of Test Appraisal 1", "status_id" => "1");
     $appraisal1 = civicrm_api3('Appraisal', 'get', array('sequential' => 1, 'id' => 1));
     $this->assertAPIArrayComparison(CRM_Utils_Array::first($appraisal1['values']), $expected['Appraisal1']);
     ////////// Create Test Appraisal 2 for Appraisal Cycle 1: //////////////
     civicrm_api3('Appraisal', 'create', array('sequential' => 1, 'appraisal_cycle_id' => 1, 'contact_id' => $this->_contacts[1]['id'], 'manager_id' => $this->_contacts[2]['id'], 'meeting_date' => date('Y-m-d', $cycleEndDate - 2 * self::DAY), 'notes' => "Test Notes of Test Appraisal 2"));
     $expected['Appraisal2'] = array("id" => "2", "appraisal_cycle_id" => "1", "contact_id" => $this->_contacts[1]['id'], "manager_id" => $this->_contacts[2]['id'], "self_appraisal_due" => date('Y-m-d', $selfAppraisalDue), "manager_appraisal_due" => date('Y-m-d', $managerAppraisalDue), "grade_due" => date('Y-m-d', $gradeDue), "due_changed" => "0", "meeting_date" => date('Y-m-d', $cycleEndDate - 2 * self::DAY), "meeting_completed" => "0", "approved_by_employee" => "0", "notes" => "Test Notes of Test Appraisal 2", "status_id" => "1");
     $appraisal2 = civicrm_api3('Appraisal', 'get', array('sequential' => 1, 'id' => 2));
     $this->assertAPIArrayComparison(CRM_Utils_Array::first($appraisal2['values']), $expected['Appraisal2']);
     ////////// Change 'grade_due' for Appraisal 2: /////////////////////////
     civicrm_api3('Appraisal', 'create', array('sequential' => 1, 'id' => 2, 'grade_due' => date('Y-m-d', $gradeDue + 1 * self::DAY)));
     ////////// Change Due Dates for Appraisal Cycle 1: /////////////////////
     civicrm_api3('AppraisalCycle', 'create', array('sequential' => 1, 'id' => 1, "self_appraisal_due" => date('Y-m-d', $selfAppraisalDue + 2 * self::DAY), "manager_appraisal_due" => date('Y-m-d', $managerAppraisalDue + 2 * self::DAY), 'grade_due' => date('Y-m-d', $gradeDue + 2 * self::DAY)));
     // Checking Due Dates for Appraisal 1.
     // They should be changed according to the AppraisalCycle create call above.
     $expected['Appraisal1DueDates'] = array('id' => "1", 'self_appraisal_due' => date('Y-m-d', $selfAppraisalDue + 2 * self::DAY), 'manager_appraisal_due' => date('Y-m-d', $managerAppraisalDue + 2 * self::DAY), 'grade_due' => date('Y-m-d', $gradeDue + 2 * self::DAY));
     $appraisal1DueDates = civicrm_api3('Appraisal', 'get', array('sequential' => 1, 'id' => 1, 'return' => "id,self_appraisal_due,manager_appraisal_due,grade_due"));
     $this->assertAPIArrayComparison(CRM_Utils_Array::first($appraisal1DueDates['values']), $expected['Appraisal1DueDates']);
     // Checking Due Dates for Appraisal 2.
     // They should be unchanged as we've modified individual 'grade_due' date.
     $expected['Appraisal2DueDates'] = array('id' => "2", 'self_appraisal_due' => date('Y-m-d', $selfAppraisalDue), 'manager_appraisal_due' => date('Y-m-d', $managerAppraisalDue), 'grade_due' => date('Y-m-d', $gradeDue + 1 * self::DAY));
     $appraisal2DueDates = civicrm_api3('Appraisal', 'get', array('sequential' => 1, 'id' => 2, 'return' => "id,self_appraisal_due,manager_appraisal_due,grade_due"));
     $this->assertAPIArrayComparison(CRM_Utils_Array::first($appraisal2DueDates['values']), $expected['Appraisal2DueDates']);
     ////////// Delete Appraisal 1: /////////////////////////////////////////
     civicrm_api3('Appraisal', 'delete', array('sequential' => 1, 'id' => 1));
     $this->assertAPIDeleted('Appraisal', 1);
     ////////// Delete Appraisal Cycle 2: /////////////////////////////////////////
     civicrm_api3('AppraisalCycle', 'delete', array('sequential' => 1, 'id' => 2));
     $this->assertAPIDeleted('AppraisalCycle', 2);
 }
开发者ID:JoeMurray,项目名称:civihr,代码行数:63,代码来源:AppraisalsApiTest.php

示例6: civicrm_api3_h_r_job_hour_create

/**
 * HRJobHour.create API
 *
 * @param array $params
 * @return array API result descriptor
 * @throws API_Exception
 */
function civicrm_api3_h_r_job_hour_create($params)
{
    $result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
    if (empty($result['is_error'])) {
        $row = CRM_Utils_Array::first($result['values']);
        $revision_id = $row['jobcontract_revision_id'];
        $revision = civicrm_api3('HRJobContractRevision', 'get', array('sequential' => 1, 'id' => $revision_id, 'options' => array('limit' => 1)));
        //CRM_Hrjobcontract_Estimator::updateEstimatesByRevision($revision);
    }
    return $result;
}
开发者ID:JoeMurray,项目名称:civihr,代码行数:18,代码来源:HRJobHour.php

示例7: create

 /**
  * Create a new HRJobHour based on array-data
  *
  * @param array $params key-value pairs
  * @return CRM_HRJob_DAO_HRJobHour|NULL
  *
  */
 public static function create($params)
 {
     $hook = empty($params['id']) ? 'create' : 'edit';
     $instance = parent::create($params);
     $currentInstanceResult = civicrm_api3('HRJobHour', 'get', array('sequential' => 1, 'id' => $instance->id));
     $currentInstance = CRM_Utils_Array::first($currentInstanceResult['values']);
     $revisionResult = civicrm_api3('HRJobContractRevision', 'get', array('sequential' => 1, 'id' => $currentInstance['jobcontract_revision_id']));
     $revision = CRM_Utils_Array::first($revisionResult['values']);
     if ($hook == 'create' && empty($params['import'])) {
         $result = civicrm_api3('HRJobRole', 'get', array('sequential' => 1, 'jobcontract_revision_id' => $revision['role_revision_id'], 'options' => array('limit' => 1)));
         if (!empty($result['values'])) {
             $role = CRM_Utils_Array::first($result['values']);
             CRM_Hrjobcontract_BAO_HRJobRole::create(array('id' => $role['id'], 'hours' => $instance->hours_amount, 'role_hours_unit' => $instance->hours_unit));
         }
     }
     return $instance;
 }
开发者ID:JoeMurray,项目名称:civihr,代码行数:24,代码来源:HRJobHour.php

示例8: create

 /**
  * Create a new HRJobPension based on array-data
  *
  * @param array $params key-value pairs
  * @return CRM_HRJob_DAO_HRJobPension|NULL
  * 
  */
 public static function create($params)
 {
     $hook = empty($params['id']) ? 'create' : 'edit';
     $previousPensionRevisionId = null;
     if ($hook == 'create') {
         $previousRevisionResult = civicrm_api3('HRJobContractRevision', 'getcurrentrevision', array('sequential' => 1, 'jobcontract_id' => $params['jobcontract_id']));
         if (!empty($previousRevisionResult['values']['pension_revision_id'])) {
             $previousPensionRevisionId = $previousRevisionResult['values']['pension_revision_id'];
         }
     }
     $instance = parent::create($params);
     $revisionResult = civicrm_api3('HRJobContractRevision', 'get', array('sequential' => 1, 'id' => $instance->jobcontract_revision_id));
     $revision = CRM_Utils_Array::first($revisionResult['values']);
     if ($previousPensionRevisionId) {
         CRM_Core_BAO_File::copyEntityFile('civicrm_hrjobcontract_pension', $previousPensionRevisionId, 'civicrm_hrjobcontract_pension', $revision['pension_revision_id']);
     }
     return $instance;
 }
开发者ID:JoeMurray,项目名称:civihr,代码行数:25,代码来源:HRJobPension.php

示例9: create

 /**
  * Create a new HRJobHour based on array-data
  *
  * @param array $params key-value pairs
  * @return CRM_HRJob_DAO_HRJobHour|NULL
  *
  */
 public static function create($params)
 {
     $className = 'CRM_HRJob_DAO_HRJobHour';
     $entityName = 'HRJobHour';
     $hook = empty($params['id']) ? 'create' : 'edit';
     CRM_Utils_Hook::pre($hook, $entityName, CRM_Utils_Array::value('id', $params), $params);
     $instance = new $className();
     $instance->copyValues($params);
     $instance->save();
     if ($hook == 'create') {
         $result = civicrm_api3('HRJobRole', 'get', array('sequential' => 1, 'job_id' => $instance->job_id, 'options' => array('limit' => 1)));
         if (!empty($result['values'])) {
             $role = CRM_Utils_Array::first($result['values']);
             civicrm_api3('HRJobRole', 'update', array('id' => $role['id'], 'job_id' => $role['job_id'], 'hours' => $instance->hours_amount, 'role_hours_unit' => $instance->hours_unit));
         }
     }
     CRM_Utils_Hook::post($hook, $entityName, $instance->id, $instance);
     return $instance;
 }
开发者ID:JoeMurray,项目名称:civihr,代码行数:26,代码来源:HRJobHour.php

示例10: testCreateDomainResult

 /**
  * Test whether Domain.create returns a correct value for domain_version.
  *
  * See CRM-17430.
  */
 public function testCreateDomainResult()
 {
     // First create a domain.
     $domain_result = $this->callAPISuccess('Domain', 'create', $this->params);
     $result_value = CRM_Utils_Array::first($domain_result['values']);
     // Check for domain_version in create result.
     $this->assertEquals($this->params['domain_version'], $result_value['domain_version']);
 }
开发者ID:kcristiano,项目名称:civicrm-core,代码行数:13,代码来源:DomainTest.php

示例11: formRule

 /**
  * Global validation rules for the form.
  *
  * @param array $values
  *   Posted values of the form.
  *
  * @param $files
  * @param CRM_Core_Form $form
  *
  * @return array
  *   list of errors to be posted back to the form
  */
 public static function formRule($values, $files, $form)
 {
     $errors = array();
     $linkCaseId = CRM_Utils_Array::value('link_to_case_id', $values);
     assert('is_numeric($linkCaseId)');
     if ($linkCaseId == CRM_Utils_Array::first($form->_caseId)) {
         $errors['link_to_case'] = ts('Please select some other case to link.');
     }
     // do check for existing related cases.
     $relatedCases = $form->get('relatedCases');
     if (is_array($relatedCases) && array_key_exists($linkCaseId, $relatedCases)) {
         $errors['link_to_case'] = ts('Selected case is already linked.');
     }
     return empty($errors) ? TRUE : $errors;
 }
开发者ID:nielosz,项目名称:civicrm-core,代码行数:27,代码来源:LinkCases.php

示例12: filter

 /**
  * Ensure that the return values comply with the whitelist's
  * "fields" policy.
  *
  * Most API's follow a convention where the result includes
  * a 'values' array (which in turn is a list of records). Unfortunately,
  * some don't. If the API result doesn't meet our expectation,
  * then we probably don't know what's going on, so we abort the
  * request.
  *
  * This will probably break some of the layered-sugar APIs (like
  * getsingle, getvalue). Just use the meat-and-potatoes API instead.
  * Or craft a suitably targeted patch.
  *
  * @param array $apiRequest
  *   API request.
  * @param array $apiResult
  *   API result.
  * @return array
  *   Modified API result.
  * @throws \API_Exception
  */
 public function filter($apiRequest, $apiResult)
 {
     if ($this->fields === '*') {
         return $apiResult;
     }
     if (isset($apiResult['values']) && empty($apiResult['values'])) {
         // No data; filtering doesn't matter.
         return $apiResult;
     }
     if (is_array($apiResult['values'])) {
         $firstRow = \CRM_Utils_Array::first($apiResult['values']);
         if (is_array($firstRow)) {
             $fields = $this->filterFields(array_keys($firstRow));
             $apiResult['values'] = \CRM_Utils_Array::filterColumns($apiResult['values'], $fields);
             return $apiResult;
         }
     }
     throw new \API_Exception(sprintf('Filtering failed for %s.%s. Unrecognized result format.', $apiRequest['entity'], $apiRequest['action']));
 }
开发者ID:nielosz,项目名称:civicrm-core,代码行数:41,代码来源:WhitelistRule.php

示例13: hrjobcontract_civicrm_uninstall

/**
 * Implementation of hook_civicrm_uninstall
 *
 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_uninstall
 */
function hrjobcontract_civicrm_uninstall()
{
    $subTypeInfo = CRM_Contact_BAO_ContactType::subTypeInfo('Organization');
    $sub_type_name = array('Health Insurance Provider', 'Life Insurance Provider');
    foreach ($sub_type_name as $sub_type_name) {
        $subTypeName = ucfirst(CRM_Utils_String::munge($sub_type_name));
        $orid = array_key_exists($subTypeName, $subTypeInfo);
        if ($orid) {
            $id = $subTypeInfo[$subTypeName]['id'];
            CRM_Contact_BAO_ContactType::del($id);
        }
    }
    $jobContractMenu = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'job_contracts', 'id', 'name');
    if (!empty($jobContractMenu)) {
        CRM_Core_BAO_Navigation::processDelete($jobContractMenu);
    }
    CRM_Core_DAO::executeQuery("DELETE FROM civicrm_navigation WHERE name IN ('job_contracts', 'import_export_job_contracts', 'jobImport', 'hoursType', 'pay_scale','hours_location', 'hrjc_contact_type', 'hrjc_location', 'hrjc_pay_cycle', 'hrjc_benefit_name', 'hrjc_benefit_type', 'hrjc_deduction_name', 'hrjc_deduction_type', 'hrjc_health_provider', 'hrjc_life_provider', 'hrjc_pension_type', 'hrjc_revision_change_reason')");
    CRM_Core_BAO_Navigation::resetNavigation();
    //delete custom groups and field
    $customGroup = civicrm_api3('CustomGroup', 'get', array('name' => "HRJobContract_Summary"));
    $customGroupData = CRM_Utils_Array::first($customGroup['values']);
    if (!empty($customGroupData['id'])) {
        civicrm_api3('CustomGroup', 'delete', array('id' => $customGroupData['id']));
    }
    $customGroup = civicrm_api3('CustomGroup', 'get', array('name' => "HRJobContract_Summary"));
    $customGroupData = CRM_Utils_Array::first($customGroup['values']);
    if (!empty($customGroupData['id'])) {
        civicrm_api3('CustomGroup', 'delete', array('id' => $customGroupData['id']));
    }
    //delete all option group and values
    CRM_Core_DAO::executeQuery("DELETE FROM civicrm_option_group WHERE name IN ('job_contracts', 'hoursType', 'pay_scale','hours_location', 'hrjc_contact_type', 'hrjc_location', 'hrjc_pay_cycle', 'hrjc_benefit_name', 'hrjc_benefit_type', 'hrjc_deduction_name', 'hrjc_deduction_type', 'hrjc_health_provider', 'hrjc_life_provider', 'hrjc_pension_type', 'hrjc_revision_change_reason', 'hrjc_contract_type', 'hrjc_level_type', 'hrjc_department', 'hrjc_hours_type', 'hrjc_pay_grade', 'hrjc_health_provider', 'hrjc_life_provider', 'hrjc_location', 'hrjc_pension_type', 'hrjc_region', 'hrjc_pay_scale')");
    //delete job contract files to entities relations
    CRM_Core_DAO::executeQuery("DELETE FROM civicrm_entity_file WHERE entity_table LIKE 'civicrm_hrjobcontract_%'");
    return _hrjobcontract_civix_civicrm_uninstall();
}
开发者ID:JoeMurray,项目名称:civihr,代码行数:40,代码来源:hrjobcontract.php

示例14: civicrm_api3_message_template_send

/**
 * Sends a template.
 *
 * @param array $params
 */
function civicrm_api3_message_template_send($params)
{
    // Change external param names to internal ones
    $fieldSpec = array();
    _civicrm_api3_message_template_send_spec($fieldSpec);
    foreach ($fieldSpec as $field => $spec) {
        if (isset($spec['api.aliases']) && array_key_exists($field, $params)) {
            $params[CRM_Utils_Array::first($spec['api.aliases'])] = $params[$field];
            unset($params[$field]);
        }
    }
    if (empty($params['messageTemplateID'])) {
        if (empty($params['groupName']) || empty($params['valueName'])) {
            // Can't use civicrm_api3_verify_mandatory for this because it would give the wrong field names
            throw new API_Exception("Mandatory key(s) missing from params array: requires id or option_group_name + option_value_name", "mandatory_missing", array("fields" => array('id', 'option_group_name', 'option_value_name')));
        }
    }
    CRM_Core_BAO_MessageTemplate::sendTemplate($params);
}
开发者ID:kcristiano,项目名称:civicrm-core,代码行数:24,代码来源:MessageTemplate.php

示例15: _civicrm_hrjobcontract_api3_replace

/**
 * HRJobContract implementation of the "replace" action.
 *
 * Replace the old set of entities (matching some given keys) with a new set of
 * entities (matching the same keys).
 *
 * Note: This will verify that 'values' is present, but it does not directly verify
 * any other parameters.
 *
 * @param string $entity entity name
 * @param array $params params from civicrm_api, including:
 *   - 'values': an array of records to save
 *   - all other items: keys which identify new/pre-existing records
 * @return array|int
 */
function _civicrm_hrjobcontract_api3_replace($entity, $params, $forceRevisionId = null)
{
    $transaction = new CRM_Core_Transaction();
    try {
        if (!is_array($params['values'])) {
            throw new Exception("Mandatory key(s) missing from params array: values");
        }
        // Extract the keys -- somewhat scary, don't think too hard about it
        $baseParams = _civicrm_api3_generic_replace_base_params($params);
        // Lookup pre-existing records
        $preexisting = civicrm_api($entity, 'get', $baseParams, $params);
        if (civicrm_error($preexisting)) {
            $transaction->rollback();
            return $preexisting;
        }
        // Save the new/updated records
        $jobcontractRevisionId = null;
        $creates = array();
        foreach ($params['values'] as $replacement) {
            if (empty($replacement['id']) && empty($replacement['jobcontract_revision_id'])) {
                $replacement['jobcontract_revision_id'] = $jobcontractRevisionId;
            }
            if ($forceRevisionId) {
                $replacement['jobcontract_revision_id'] = $forceRevisionId;
            }
            // Sugar: Don't force clients to duplicate the 'key' data
            $replacement = array_merge($baseParams, $replacement);
            //$action      = (isset($replacement['id']) || isset($replacement[$entity . '_id'])) ? 'update' : 'create';
            $action = 'create';
            $create = civicrm_api($entity, $action, $replacement);
            if (civicrm_error($create)) {
                $transaction->rollback();
                return $create;
            }
            foreach ($create['values'] as $entity_id => $entity_value) {
                $creates[$entity_id] = $entity_value;
            }
            $entityData = CRM_Utils_Array::first($create['values']);
            $jobcontractRevisionId = $entityData['jobcontract_revision_id'];
        }
        // Remove stale records
        $staleIDs = array_diff(array_keys($preexisting['values']), array_keys($creates));
        foreach ($staleIDs as $staleID) {
            $delete = civicrm_api($entity, 'delete', array('version' => $params['version'], 'id' => $staleID));
            if (civicrm_error($delete)) {
                $transaction->rollback();
                return $delete;
            }
        }
        return civicrm_api3_create_success($creates, $params);
    } catch (PEAR_Exception $e) {
        $transaction->rollback();
        return civicrm_api3_create_error($e->getMessage());
    } catch (Exception $e) {
        $transaction->rollback();
        return civicrm_api3_create_error($e->getMessage());
    }
}
开发者ID:JoeMurray,项目名称:civihr,代码行数:73,代码来源:jobcontract_utils.php


注:本文中的CRM_Utils_Array::first方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。