Mercurial > hg > extraction-interface
comparison develop/models/extractapp.php @ 21:c805470cefee
Remove bootstrap.TaggingText UI layout modification
| author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
|---|---|
| date | Tue, 24 Feb 2015 16:09:59 +0100 |
| parents | 04db1dd9d10d |
| children | a8ae5cbc3364 |
comparison
equal
deleted
inserted
replaced
| 20:04db1dd9d10d | 21:c805470cefee |
|---|---|
| 6 | 6 |
| 7 public function Index() { | 7 public function Index() { |
| 8 return array("Index Value 1", "Value 2", "Value 3"); | 8 return array("Index Value 1", "Value 2", "Value 3"); |
| 9 } | 9 } |
| 10 | 10 |
| 11 protected $section_id = 0, $data_path, $file_id = 0, $branch_id = 0, $user_id = 0, $lg_text = ""; | 11 protected $section_id = 0, $data_path, $file_id = 0, $branch_id = 0, $user_id = 0, $lg_text = "", $topic = 0; |
| 12 public $messages = ""; | 12 public $messages = ""; |
| 13 | 13 |
| 14 private function Initialize($_urlvalues) { | 14 private function Initialize($_urlvalues) { |
| 15 $this->SetSectionId($_urlvalues); | 15 $this->SetSectionId($_urlvalues); |
| 16 | 16 |
| 82 $this->branch_id = $_postdata['branchId']; | 82 $this->branch_id = $_postdata['branchId']; |
| 83 } | 83 } |
| 84 if ($_postdata['userId']) { | 84 if ($_postdata['userId']) { |
| 85 $this->user_id = $_postdata['userId']; | 85 $this->user_id = $_postdata['userId']; |
| 86 } | 86 } |
| 87 | 87 if ($_postdata['topic_id']) { |
| 88 $this->topic = $_postdata['topic_id']; | |
| 89 } | |
| 90 | |
| 91 $this->messages .= "Info: "; | |
| 92 $this->messages .= "file_id=".$this->file_id.", section_id=".$this->section_id; | |
| 93 $this->messages .= ", user_id=".$this->user_id.", branch_id=".$this->branch_id.", topic_id=".$this->topic."<br>"; | |
| 88 | 94 |
| 89 } | 95 } |
| 90 public function InitData($_postdata) { | 96 public function InitData($_postdata) { |
| 91 $file_id = $_postdata['fileId']; | 97 $file_id = $_postdata['fileId']; |
| 92 $branch_id = $_postdata['branchId']; | 98 $branch_id = $_postdata['branchId']; |
| 363 public function ExportTable($postdata) { | 369 public function ExportTable($postdata) { |
| 364 // $this->Initialize($urlvalues); | 370 // $this->Initialize($urlvalues); |
| 365 | 371 |
| 366 $content = $postdata['content']; | 372 $content = $postdata['content']; |
| 367 $topic = $postdata['topic']; | 373 $topic = $postdata['topic']; |
| 368 $section_id = $this->section_id; | 374 $section_id = $postdata['sectionId']; |
| 375 | |
| 376 //$section_id = $this->section_id; | |
| 369 | 377 |
| 370 | 378 |
| 371 // TODO: this should be get from LGServic: sectionName, bookId, bookName | 379 // TODO: this should be get from LGServic: sectionName, bookId, bookName |
| 372 $section_info = $this->GetSectionInfo(); | 380 $section_info = $this->GetSectionInfo(); |
| 373 | 381 |
| 485 } | 493 } |
| 486 | 494 |
| 487 // === for manage tag list === | 495 // === for manage tag list === |
| 488 public function EditTaglist($_postdata) { | 496 public function EditTaglist($_postdata) { |
| 489 | 497 |
| 498 $query = "SELECT `AUTO_INCREMENT` FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'taglist'"; | |
| 499 $largest_id = mysql_query($query); | |
| 500 | |
| 490 $topic_id = $_postdata['topic_id']; | 501 $topic_id = $_postdata['topic_id']; |
| 491 $result = $this->GetTaglistByTopicID($topic_id); | 502 $result = $this->GetTaglistByTopicID($topic_id); |
| 492 | 503 |
| 493 $taglistArray = array(); | 504 $taglistArray = array(); |
| 494 foreach ($result as $row) { | 505 foreach ($result as $row) { |
| 506 */ | 517 */ |
| 507 | 518 |
| 508 $data = array(); | 519 $data = array(); |
| 509 $data['taglistArray'] = $taglistArray; | 520 $data['taglistArray'] = $taglistArray; |
| 510 $data['topic_id'] = $topic_id; | 521 $data['topic_id'] = $topic_id; |
| 522 $data['largest_id'] = $largest_id; | |
| 523 | |
| 524 | |
| 511 return $data; | 525 return $data; |
| 512 | 526 |
| 513 } | 527 } |
| 514 | 528 |
| 515 private function _GetTag($_postdata) { | 529 private function _GetTag($_postdata) { |
| 597 $data = array(); | 611 $data = array(); |
| 598 $data['taglistArray'] = $taglistArray; | 612 $data['taglistArray'] = $taglistArray; |
| 599 $data['topic'] = $topic; | 613 $data['topic'] = $topic; |
| 600 $data['topic_name'] = $topic_name; | 614 $data['topic_name'] = $topic_name; |
| 601 | 615 |
| 616 | |
| 617 | |
| 618 | |
| 619 // ------ | |
| 620 $query = "SELECT taglist.*, topic_tag_relation.topic_id FROM taglist LEFT JOIN topic_tag_relation ON taglist.id = topic_tag_relation.tag_id ORDER BY `topic_id`"; | |
| 621 $result = mysql_query($query); | |
| 622 if (!$result) { | |
| 623 return json_encode("Failed during selecting/joining taglist and topic_tag_relation table."); | |
| 624 } | |
| 625 | |
| 626 $tag_intopic = array(); | |
| 627 $tag_others = array(); | |
| 628 $tag_tmp_others = array(); | |
| 629 while ($row = mysql_fetch_assoc($result)) { | |
| 630 if ($row['topic_id'] == $topic) { | |
| 631 array_push($tag_intopic, array('id=>'=>$row['id'],'name'=>$row['name'], 'tag'=>$row['tag'], 'color'=>$row['color'], 'topic_id'=>$row['topic_id'])); | |
| 632 } else { | |
| 633 array_push($tag_tmp_others, array('id=>'=>$row['id'],'name'=>$row['name'], 'tag'=>$row['tag'], 'color'=>$row['color'], 'topic_id'=>$row['topic_id'])); | |
| 634 } | |
| 635 } | |
| 636 | |
| 637 | |
| 638 foreach ($tag_tmp_others as $tmp) { | |
| 639 $cnt = 0; | |
| 640 foreach ($tag_intopic as $intopic) { | |
| 641 if ($tmp['tag'] == $intopic['tag']) { | |
| 642 break; | |
| 643 } else { | |
| 644 $cnt ++; | |
| 645 } | |
| 646 } | |
| 647 if ($cnt == count($tag_intopic)) { | |
| 648 array_push($tag_others, $tmp); | |
| 649 } | |
| 650 } | |
| 651 | |
| 652 | |
| 653 $data['tag_intopic'] = $tag_intopic; | |
| 654 $data['tag_others'] = $tag_others; | |
| 655 | |
| 602 return $data; | 656 return $data; |
| 603 } | 657 } |
| 658 | |
| 659 | |
| 604 public function UpdateTagsInTopic($_postdata) { | 660 public function UpdateTagsInTopic($_postdata) { |
| 605 $topic_id = $_postdata['topic_id']; | 661 $topic_id = $_postdata['topic_id']; |
| 606 $tag_ids = json_decode(str_replace('\\', '', $_postdata['ids'])); | 662 $tag_ids = json_decode(str_replace('\\', '', $_postdata['ids'])); |
| 607 | 663 |
| 608 // update topic_tag_relation by tags_ids array as `tag_id` and topic_id as `topic_id` | 664 // update topic_tag_relation by tags_ids array as `tag_id` and topic_id as `topic_id` |
| 609 $query = "SELECT * FROM topic_tag_relation"; | 665 // --- add new topic_tag_relation --- |
| 666 foreach ($tag_ids as $tag_id) { | |
| 667 $query = "SELECT * FROM topic_tag_relation WHERE tag_id=".$tag_id; | |
| 668 $result = mysql_query($query); | |
| 669 if (!$result) { | |
| 670 echo json_encode("error when select from topic_tag_relation"); | |
| 671 } | |
| 672 $topic_tag = array(); | |
| 673 $flag = false; | |
| 674 while ($row = mysql_fetch_assoc($result)) { | |
| 675 if ($row['topic_id'] == $topic_id) { | |
| 676 $flag = true; | |
| 677 break; | |
| 678 } | |
| 679 } | |
| 680 if (!$flag) { | |
| 681 // insert a row into topic_tag_relation table | |
| 682 $queryUpdate = "INSERT INTO topic_tag_relation (topic_id, tag_id) VALUES (".$topic_id.",".$tag_id.")"; | |
| 683 $resultUpdate = mysql_query($queryUpdate); | |
| 684 if (!$resultUpdate) { | |
| 685 return json_encode("error when insert topic_tag_relation table"); | |
| 686 } | |
| 687 } | |
| 688 | |
| 689 } | |
| 690 | |
| 691 // --- remove tags from this topic --- | |
| 692 $query = "SELECT * FROM topic_tag_relation WHERE topic_id=".$topic_id; | |
| 610 $result = mysql_query($query); | 693 $result = mysql_query($query); |
| 611 if (!$result) { | 694 if (!$result) { |
| 612 echo json_encode("error when select from topic_tag_relation"); | 695 echo json_encode("error when select from topic_tag_relation"); |
| 613 } | 696 } |
| 697 | |
| 698 while ($row = mysql_fetch_assoc($result)) { | |
| 699 $cnt = 0; | |
| 700 foreach ($tag_ids as $tag_id) { | |
| 701 if ($row['tag_id'] == $tag_id) { | |
| 702 break; | |
| 703 } else { | |
| 704 $cnt ++; | |
| 705 } | |
| 706 } | |
| 707 $_id = $row['id']; | |
| 708 if ($cnt == count($tag_ids)) { | |
| 709 // delete row with (topic_id, tag_ids) | |
| 710 $queryDelete = "DELETE FROM topic_tag_relation WHERE id=".$_id; | |
| 711 $resultDelete = mysql_query($queryDelete); | |
| 712 if (!$resultDelete) { | |
| 713 echo json_encode("error when delete from topic_tag_relation"); | |
| 714 } | |
| 715 } | |
| 716 } | |
| 717 | |
| 718 | |
| 719 | |
| 720 /* | |
| 721 ยง $query = "SELECT * FROM topic_tag_relation"; | |
| 722 $result = mysql_query($query); | |
| 723 if (!$result) { | |
| 724 echo json_encode("error when select from topic_tag_relation"); | |
| 725 } | |
| 614 $topic_tag = array(); | 726 $topic_tag = array(); |
| 615 while ($row = mysql_fetch_assoc($result)) { | 727 while ($row = mysql_fetch_assoc($result)) { |
| 616 array_push($topic_tag, array('tag_id'=>$row['tag_id'], 'topic_id'=>$row['topic_id'])); | 728 array_push($topic_tag, array('tag_id'=>$row['tag_id'], 'topic_id'=>$row['topic_id'])); |
| 617 } | 729 } |
| 730 | |
| 618 | 731 |
| 619 foreach ($topic_tag as $value) { | 732 foreach ($topic_tag as $value) { |
| 620 $flag = false; | 733 $flag = false; |
| 621 foreach ($tag_ids as $tag_id) { | 734 foreach ($tag_ids as $tag_id) { |
| 622 if ($value['tag_id'] == $tag_id) { | 735 if ($value['tag_id'] == $tag_id) { |
| 637 if (!$resultUpdate) { | 750 if (!$resultUpdate) { |
| 638 return json_encode("error when update topic_tag_relation table"); | 751 return json_encode("error when update topic_tag_relation table"); |
| 639 } | 752 } |
| 640 } | 753 } |
| 641 } | 754 } |
| 755 */ | |
| 642 | 756 |
| 643 } | 757 } |
| 644 | 758 |
| 645 | 759 |
| 646 private function GetTaglistByTopicID($topic_id) { | 760 private function GetTaglistByTopicID($topic_id) { |
