コード例 #1
0
 /**
  * Function to add or update condition
  * 
  * @param array $params 
  * @return array $result
  * @access public
  * @throws Exception when params is empty
  * @static
  */
 public static function add($params)
 {
     $result = array();
     if (empty($params)) {
         throw new Exception('Params can not be empty when adding or updating a civirule condition');
     }
     $condition = new CRM_Civirules_BAO_Condition();
     $fields = self::fields();
     foreach ($params as $key => $value) {
         if (isset($fields[$key])) {
             $condition->{$key} = $value;
         }
     }
     if (!isset($condition->name) || empty($condition->name)) {
         $condition->name = CRM_Civirules_Utils::buildNameFromLabel($condition->label);
     }
     $condition->save();
     self::storeValues($condition, $result);
     return $result;
 }