コード例 #1
0
ファイル: Resource.php プロジェクト: sgabison/website
 public function getTags()
 {
     $result = array();
     if ($this->model->getId() > 0) {
         $sql = sprintf(" SELECT distinct r.src_id FROM `object_relations_15` r join object_query_15 o on o.oo_id=r.src_id WHERE r.`dest_id` = '%d' AND r.`fieldname` = 'societe' ", $this->model->getId());
         $data = $this->db->FetchAll($sql);
     }
     foreach ($data as $key => $row) {
         $tags = \Object\Tags::getById($row["src_id"]);
         if ($tags instanceof \Object\Tags) {
             $result[] = $tags;
         }
     }
     return $result;
 }
コード例 #2
0
ファイル: Resource.php プロジェクト: sgabison/resaExpress
 public function replace($data = array())
 {
     try {
         if ($this->model->getId() > 0) {
             $object = $this->model;
         } elseif ($data['id'] > 0 and $data['id'] != "") {
             $object = \Object\Tags::getById($data['id']);
         } elseif ($data['o_id'] > 0 and $data['o_id'] != "") {
             $object = \Object\Tags::getById($data['o_id']);
         } else {
             $object = $this->model;
             $date = new \Zend_Date();
             $object->setCreationDate($date->get());
             //todo
             $object->setUserOwner(1);
             $object->setUserModification(1);
             if (method_exists($object, "setDateRegister")) {
                 $object->setDateRegister($date->get());
             }
             $object->setPublished(1);
         }
         if ($object instanceof \Object\Tags) {
             $object->setValues($data);
             $object->setTag($data['name_fr'], 'fr_FR');
             $object->setTag($data['name_en'], 'en');
             $date = new \Zend_Date();
             $object->setModificationDate($date);
             if (!$object->getO_key()) {
                 $folder = $this->getFolderRoot();
                 $object->setParent($folder);
                 $key1 = $this->model->getClassName();
                 $numero = $date->get(\Zend_Date::TIMESTAMP);
                 $object_key = $this->correctClassname($key1) . '-' . $numero;
                 $object->setO_key(strtolower($object_key));
             }
             return $object;
         } else {
             \Logger::warning("Erreur :  Classe de l'objet erronnée");
             return false;
         }
     } catch (\Exception $e) {
         \Logger::warning($e->getMessage());
         return false;
     }
 }
コード例 #3
0
 public function tagsListAction()
 {
     $reponse = new Reponse();
     $societe = $this->societe;
     $tags = $societe->getTags();
     //we check if we are in the Editor
     if ($_POST['action']) {
         //if REMOVE
         if ($_POST['action'] == "remove") {
             foreach ($_POST['id'] as $id) {
                 $tag = Object_Tags::getById($id, 1);
                 if ($tag instanceof \Object\Tags) {
                     $tag->delete();
                 }
             }
             $reponse->message = 'TXT_TAGS_LIST';
             $reponse->success = true;
             $reponse->data = '';
         }
         //if EDIT
         if ($_POST['action'] == "edit") {
             $tag = \Object\Tags::getById($_POST['id'], 1);
             if ($tag instanceof Object\Tags) {
                 $tag->setCode($_POST['data']['code']);
                 $tag->setTag($_POST['data']['name_en'], "en");
                 $tag->setTag($_POST['data']['name_fr'], "fr_FR");
                 $tag->setIcon($_POST['data']['icon']);
                 $tag->save();
             }
             $data = $_POST['data'];
             $data['DT_RowId'] = "row_" . $_POST['data']['id'];
             $reponse->message = 'TXT_TAGS_LIST';
             $reponse->success = true;
             $reponse->row = $data;
         }
         //if CREATE
         if ($_POST['action'] == "create") {
             $row['code'] = $_POST['data']['code'];
             $row['name_fr'] = $_POST['data']['name_fr'];
             $row['name_en'] = $_POST['data']['name_en'];
             $row['icon'] = $_POST['data']['icon'];
             $current = Object\Tags::getByCode($row['code'], 1);
             if ($current instanceof Object\Tags) {
                 $error['code'] = "code";
                 $error['status'] = "Tag already exists";
                 $reponse->fieldErrors = array($error);
             } else {
                 $result = $societe->createTag($row);
                 if ($result instanceof \Object\Tags) {
                     $row['DT_RowId'] = $result->getId();
                     $row['id'] = $result->getId();
                     $reponse->success = true;
                     $reponse->message = "TXT_CREATE_OK";
                     $reponse->row = $row;
                     $reponse->debug = $data;
                 } else {
                     $reponse->success = false;
                     $reponse->message = "TXT_CREATE_ERROR";
                     $reponse->row = $result;
                     $reponse->debug = $result;
                 }
             }
         }
     } else {
         $data = array();
         foreach ($tags as $key => $tag) {
             $i++;
             $array = array();
             $array = $tag->toArray();
             $array['id'] = $tag->getId();
             $array['DT_RowId'] = $tag->getId();
             array_push($data, $array);
         }
         $reponse->message = 'TXT_TAGS_LIST';
         $reponse->success = true;
         $reponse->data = $data;
     }
     $this->render($reponse);
 }