コード例 #1
0
 /**
  * Upgrade 1001 - add civicrm_segment_tree
  *
  * @return TRUE on success
  * @throws Exception
  */
 public function upgrade_1001()
 {
     $this->ctx->log->info('Applying update 1001');
     CRM_Core_DAO::executeQuery("CREATE TABLE IF NOT EXISTS civicrm_segment_tree (id INT UNSIGNED NOT NULL)");
     CRM_Contactsegment_BAO_Segment::buildSegmentTree();
     return TRUE;
 }
コード例 #2
0
/**
 * Segment.Delete 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_segment_delete($params)
{
    if (array_key_exists('id', $params)) {
        return civicrm_api3_create_success(CRM_Contactsegment_BAO_Segment::deleteById($params['id']), $params, 'Segment', 'Delete');
    } else {
        throw new API_Exception('Id is a mandatory param when deleting a segment', 'mandatory_id_missing', 010);
    }
}
コード例 #3
0
 /**
  * Function to add or update segment
  * 
  * @param array $params
  * @return array $result
  * @throws Exception when params empty
  * @access public
  * @static
  */
 public static function add($params)
 {
     $result = array();
     $preSegment = array();
     if (empty($params)) {
         throw new Exception('Params can not be empty when adding or updating a segment', 9003);
     }
     $segment = new CRM_Contactsegment_BAO_Segment();
     if (isset($params['id'])) {
         $segment->id = $params['id'];
         // pre hook if edit
         $op = "edit";
         self::storeValues($segment, $preSegment);
         CRM_Utils_Hook::pre($op, 'Segment', $segment->id, $preSegment);
         $segment->find(true);
     } else {
         $op = "create";
     }
     $fields = self::fields();
     foreach ($params as $paramKey => $paramValue) {
         if (isset($fields[$paramKey])) {
             $segment->{$paramKey} = $paramValue;
         }
     }
     if (!$segment->name && $segment->label) {
         $segment->name = CRM_Contactsegment_Utils::generateNameFromLabel($segment->label);
     }
     $segment->save();
     if (!$segment->is_active) {
         CRM_Contactsegment_BAO_Segment::setInactive($segment->id);
     }
     // post hook
     CRM_Utils_Hook::post($op, 'Segment', $segment->id, $segment);
     self::storeValues($segment, $result);
     return $result;
 }
コード例 #4
0
/**
 * Segment.Get 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_segment_get($params)
{
    return civicrm_api3_create_success(CRM_Contactsegment_BAO_Segment::getValues($params), $params, 'Segment', 'Get');
}
コード例 #5
0
/**
 * Segment.Create 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_segment_create($params)
{
    return civicrm_api3_create_success(CRM_Contactsegment_BAO_Segment::add($params), $params, 'Segment', 'Create');
}
コード例 #6
0
/**
 * Implementation of hook civicrm_pre
 * to rebuild segment tree when segment is deleted
 *
 * @param string $op
 * @param string $objectName
 * @param int $objectId
 * @param array $params
 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_pre
 */
function contactsegment_civicrm_pre($op, $objectName, $objectId, &$params)
{
    if ($objectName == "Segment" && $op == "delete") {
        CRM_Contactsegment_BAO_Segment::buildSegmentTree();
    }
}