public function orderTerms($id) { $this->vocabulary->find($id); $request = \Request::instance(); $json = $request->getContent(); $content = json_decode($json); foreach ($content as $parent_key => $parent) { $parent_term = Term::find($parent->id); $parent_term->parent = 0; $parent_term->weight = $parent_key; $parent_term->save(); if (empty($parent->children)) { continue; } foreach ($parent->children as $child_key => $child) { $child_term = Term::find($child->id); $child_term->parent = $parent_term->id; $child_term->weight = $child_key; $child_term->save(); } } }
/** * Add an existing term to the inheriting model * * @param $term_id int * The ID of the term to link * * @return object * The TermRelation object */ public function hasTerm($term_id) { $term = $term_id instanceof Term ? $term_id : Term::findOrFail($term_id); $term_relation = ['term_id' => $term->id, 'vocabulary_id' => $term->vocabulary_id]; return $this->related()->where('term_id', $term_id)->count() ? true : false; }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id) { $validation = Validator::make(Input::All(), Vocabulary::$rules); if ($validation->fails()) { return Redirect::route($this->route_prefix . 'taxonomy.edit', $id)->withInput()->withErrors($validation)->with('message', 'There were validation errors.'); } $vocabulary = $this->vocabulary->find($id); $vocabulary->name = Input::get('name'); $vocabulary->save(); Term::where('vocabulary_id', $id)->delete(); $terms = preg_split('/[;,]/', trim(Input::get('terms'))); foreach ($terms as $term) { if (trim($term) != "") { $term = Term::create(['name' => $term, 'vocabulary_id' => $vocabulary->id]); } } return Redirect::route($this->route_prefix . 'taxonomy.index'); }
/** * Add an existing term to the inheriting model * * @param $term_id int * The ID of the term to link * * @return object * The TermRelation object */ public function addTerm($term_id) { $term = Term::findOrFail($term_id); $term_relation = ['term_id' => $term->id, 'vocabulary_id' => $term->vocabulary_id]; $this->related()->save(new TermRelation($term_relation)); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { Term::destroy($id); return Response::make('OK', 200); }