1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
<?php
class TagsController extends ModulesController {
var $helpers = array('BeTree', 'BeToolbar');
var $components = array('BeTree', 'BeSecurity');
var $uses = array('Category') ;
protected $moduleName = 'tags';
public function index($order = "label", $dir = 1) {
$data = $this->Category->getTags(array(
"cloud" => true,
"order" => $order,
"dir" => $dir
));
$this->set("numTags", count($data));
$this->set('tags', $data);
$this->set("order", $order);
$this->set("dir", (($dir)? 0 : 1) );
}
public function view($id = null) {
$tag = array();
$referenced = array();
if(isset($id)) {
$tag = $this->Category->findById($id);
if($tag == null || $tag === false) {
throw new BeditaException(__("Error loading tag: ", true).$id);
}
$referenced = $this->Category->getContentsByTag($tag["name"]);
$tag["weight"] = count($referenced);
}
$this->set('tag', $tag);
$this->set("referenced", $referenced);
}
public function save() {
$this->checkWriteModulePermission();
if(empty($this->data))
throw new BeditaException( __("No data", true));
$new = (empty($this->data['id'])) ? true : false ;
$exclude_id = (empty($this->data['id']))? null : $this->data['id'];
if($this->Category->tagLabelPresent($this->data["label"],$exclude_id)) {
throw new BeditaException(__("Tag already present", true)." - ".$this->data["label"]);
}
$this->Transaction->begin() ;
if(!$this->Category->save($this->data)) {
throw new BeditaException(__("Error saving tag", true), $this->Category->validationErrors);
}
$this->Transaction->commit();
$this->userInfoMessage(__("Tag saved", true)." - ".$this->data["label"]);
$this->eventInfo("tag [". $this->data["label"]."] saved");
}
public function delete() {
$this->checkWriteModulePermission();
if(empty($this->params["form"]["tags_selected"]))
throw new BeditaException( __("No tag selected", true));
$this->Transaction->begin();
foreach ($this->params["form"]["tags_selected"] as $id) {
$this->Category->delete($id);
}
$this->Transaction->commit();
$tagsListDeleted = implode(",", $this->params["form"]["tags_selected"]);
$this->userInfoMessage(__("Tag deleted", true) . " - " . $tagsListDeleted);
$this->eventInfo("Tag $tagsListDeleted deleted");
}
public function deleteSelected() {
$this->checkWriteModulePermission();
if(empty($this->params["form"]["tags_selected"]))
throw new BeditaException( __("No tag selected", true));
$this->Transaction->begin();
foreach ($this->params["form"]["tags_selected"] as $id) {
$this->Category->delete($id);
}
$this->Transaction->commit();
$tagsListDeleted = implode(",", $this->params["form"]["tags_selected"]);
$this->userInfoMessage(__("Tag deleted", true) . " - " . $tagsListDeleted);
$this->eventInfo("Tag $tagsListDeleted deleted");
}
public function listAllTags($href=false) {
$this->layout = "ajax";
$this->set("listTags",$this->Category->getTags(array("cloud" => true)));
if ($href)
$this->set("href", true);
}
public function addMultipleTags() {
$this->checkWriteModulePermission();
if(empty($this->params["form"]["addtaglist"]))
throw new BeditaException( __("No tag in text area", true));
$this->Transaction->begin();
$tag_ids = $this->Category->saveTagList($this->params["form"]["addtaglist"]);
$this->Transaction->commit();
$listTagIds = implode(",", $tag_ids);
$this->userInfoMessage(__("Tags saved", true)." - " . $listTagIds);
$this->eventInfo("tags [". $listTagIds ."] saved");
}
public function changeStatus() {
$this->checkWriteModulePermission();
if(empty($this->params["form"]["tags_selected"]))
throw new BeditaException( __("No tag selected", true));
$this->Transaction->begin();
foreach ($this->params["form"]["tags_selected"] as $id) {
$this->Category->id = $id;
$this->Category->saveField("status", $this->params["form"]["newStatus"]);
}
$this->Transaction->commit();
}
protected function forward($action, $result) {
$moduleRedirect = array(
'addMultipleTags' => array(
'OK' => $this->referer(),
'ERROR' => $this->referer()
)
);
return $this->moduleForward($action, $result, $moduleRedirect);
}
}