コード例 #1
0
 public static function add($params)
 {
     $result = array();
     if (empty($params)) {
         throw new Exception('Params can not be empty when adding or updating a twitter account');
     }
     if (!empty($params['id'])) {
         CRM_Utils_Hook::pre('edit', 'TwitterAccount', $params['id'], $params);
     } else {
         CRM_Utils_Hook::pre('create', 'TwitterAccount', NULL, $params);
     }
     $account = new CRM_CiviruleTwitter_BAO_TwitterAccount();
     $fields = self::fields();
     foreach ($params as $key => $value) {
         if (isset($fields[$key])) {
             $account->{$key} = $value;
         }
     }
     $account->save();
     self::storeValues($account, $result);
     if (!empty($params['id'])) {
         CRM_Utils_Hook::post('edit', 'TwitterAccount', $account->id, $account);
     } else {
         CRM_Utils_Hook::post('create', 'TwitterAccount', $account->id, $account);
     }
     return $result;
 }