function members() { list($params, $id, $slug) = $this->parse_params(func_get_args()); $cat = new Category(); if (isset($params['content'])) { $getter = new Content(); $model = $url_bit = 'content'; } else { if (isset($params['albums'])) { $getter = new Album(); $model = 'album'; $url_bit = 'albums'; } else { if (isset($params['essays'])) { $getter = new Text(); $model = $url_bit = 'text'; } } } if (is_null($id) && !$slug) { $this->error('403', 'Required parameter "id" not present.'); return; } else { if (is_array($id)) { list($id, $content_id) = $id; } } if ($this->method != 'get') { $id = explode(',', $id); if (!isset($content_id)) { $this->error('403', 'Required content id not present.'); return; } if (strpos($content_id, ',') !== FALSE) { $ids = explode(',', $content_id); } else { $ids = array($content_id); } if (isset($params['content'])) { $c = new Content(); } else { if (isset($params['albums'])) { $c = new Album(); } else { $c = new Text(); $c->where('page_type', 0); } } $categories = $cat->where_in('id', $id)->get_iterated(); $first_category_id = false; foreach ($categories as $category) { if (!$first_category_id) { $first_category_id = $category->id; } $members = $category->{$model . 's'}->select('id')->get_iterated(); $member_ids = array(); foreach ($members as $member) { $member_ids[] = $member->id; } $contents = $c->where_in('id', $ids)->order_by('id ASC')->get_iterated(); foreach ($contents as $content) { if ($content->exists()) { switch ($this->method) { case 'post': case 'put': $category->save($content); break; case 'delete': $category->delete($content); break; } } } $category->update_counts($c->model); } if (count($categories) > 1 || $this->method == 'delete') { exit; } else { $this->redirect("/categories/{$first_category_id}/{$url_bit}"); } } if (!is_null($id)) { $category = $cat->get_by_id($id); } else { if ($slug) { $category = $cat->get_by_slug($slug); } } if (!$category->exists()) { $this->error('404', 'Category not found.'); return; } $params['auth'] = $this->auth; if ($model === 'album') { $final = $getter->listing(array_merge($params, array('category' => $category->id))); } else { $params['category'] = $category->id; $final = $getter->listing($params); } $final['category'] = $category->to_array(); $this->set_response_data($final); }