88 public function index($sortfield =
"dateadh", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'')
94 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'cotisation',
'lire')) {
95 throw new RestException(401);
98 $sql =
"SELECT rowid";
99 $sql .=
" FROM ".MAIN_DB_PREFIX.
"subscription as t";
100 $sql .=
' WHERE 1 = 1';
106 throw new RestException(503,
'Error when validating parameter sqlfilters -> '.$errormessage);
110 $sql .= $this->db->order($sortfield, $sortorder);
115 $offset = $limit * $page;
117 $sql .= $this->db->plimit($limit + 1, $offset);
120 $result = $this->db->query($sql);
123 $num = $this->db->num_rows($result);
124 while ($i < min($limit, $num)) {
125 $obj = $this->db->fetch_object($result);
127 if ($subscription->fetch($obj->rowid)) {
133 throw new RestException(503,
'Error when retrieve subscription list : '.$this->db->lasterror());
135 if (!count($obj_ret)) {
136 throw new RestException(404,
'No Subscription found');
148 public function post($request_data =
null)
150 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'cotisation',
'creer')) {
151 throw new RestException(401);
154 $result = $this->
_validate($request_data);
157 foreach ($request_data as $field => $value) {
158 $subscription->$field = $value;
160 if ($subscription->create(DolibarrApiAccess::$user) < 0) {
161 throw new RestException(500,
'Error when creating contribution', array_merge(array($subscription->error), $subscription->errors));
163 return $subscription->id;
173 public function put($id, $request_data =
null)
175 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'creer')) {
176 throw new RestException(401);
180 $result = $subscription->fetch($id);
182 throw new RestException(404,
'Subscription not found');
185 foreach ($request_data as $field => $value) {
186 if ($field ==
'id') {
189 $subscription->$field = $value;
192 if ($subscription->update(DolibarrApiAccess::$user) > 0) {
193 return $this->
get($id);
195 throw new RestException(500,
'Error when updating contribution: '.$subscription->error);