function form($id = FALSE) { $categories = new Category(); $categories->where("module = 'galleries' and parents = 0")->get(); $data['parent'] = $categories->get_clone(); $categories->clear(); $data['category'] = $categories->get_by_id($id); $this->template->build('admin/category_form', $data); }
public function delete() { $this->output->set_content_type('application/json'); $url = $this->uri->ruri_to_assoc(3); $category_id = isset($url['category_id']) ? intval($url['category_id']) : 0; if ($category_id !== 0) { $this->_transaction_isolation(); $this->db->trans_begin(); $category = new Category(); $category->get_by_id($category_id); $category->delete(); if ($this->db->trans_status()) { $this->db->trans_commit(); $this->output->set_output(json_encode(TRUE)); } else { $this->db->trans_rollback(); $this->output->set_output(json_encode(FALSE)); } } else { $this->output->set_output(json_encode(FALSE)); } }
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); }
public function getVotedCategories() { $categoryVotes = array(); $tagVotes = array(); foreach ($this->Team()->Members() as $member) { for ($day = 0; $day < $this->getNumDays(); $day++) { foreach ($member->getTags('Sad', $this->ID, $day) as $tag) { // Record the number of times this tag has been mentioned. if (!array_key_exists($tag->ID, $tagVotes)) { $tagVotes[$tag->ID] = 0; } $tagVotes[$tag->ID]++; } } } $votes = VoteMemberRelation::get('VoteMemberRelation', '"SprintID"=' . $this->ID . ' AND ' . '"Committed"=1'); if (!$votes) { return; } foreach ($votes as $vote) { if (!array_key_exists($vote->CategoryID, $categoryVotes)) { $categoryVotes[$vote->CategoryID] = 0; } $categoryVotes[$vote->CategoryID] += $vote->Votes; } // Rank the categories and tags by votes. arsort($categoryVotes); arsort($tagVotes); // Build the return structure for categories. $categories = array(); foreach ($categoryVotes as $categoryID => $votes) { $category = Category::get_by_id('Category', $categoryID); $category->TrendingTags = new ArrayList(array()); $categories[] = $category; if (count($categories) >= 3) { break; } } // Add the tags foreach ($tagVotes as $tagID => $votes) { $tag = Tag::get_by_id('Tag', $tagID); foreach ($categories as $category) { if ($category->ID == $tag->CategoryID) { $category->TrendingTags->add($tag); break; } } } return new ArrayList($categories); }
function list_import_lamsfet_tasks_labels_relations($tasks, $labels, $tasks_labels) { echo 'Starting task_category_rel import (' . count($tasks_labels) . ') ['; if (count($tasks_labels)) { foreach ($tasks_labels as $relation) { $task_id = $tasks[$relation->task_id]->_list_id; $category_id = $labels[$relation->label_id]->_list_id; $task = new Task(); $task->get_by_id(intval($task_id)); $category = new Category(); $category->get_by_id(intval($category_id)); if ($task->exists() && $category->exists()) { $task->save($category); } else { echo ' ( CATEGORY OR TASK NOT FOUND ' . $task_id . '(' . $relation->task_id . ')/' . $category_id . '(' . $relation->label_id . ') ) '; } echo '.'; } } echo '] ... done' . "\n"; }
function index_put() { $models = json_decode($this->put('models')); $data["results"] = array(); $data["count"] = 0; foreach ($models as $value) { $obj = new Category(null, $this->entity); $obj->get_by_id($value->id); $obj->name = $value->name; $obj->sub_of = $value->sub_of; if ($obj->save()) { //Results $data["results"][] = array("id" => $obj->id, "name" => $obj->name, "sub_of" => $obj->sub_of); } } $data["count"] = count($data["results"]); $this->response($data, 200); }