Пример #1
0
 public function showLangModal()
 {
     $language = Yii::app()->params['language'];
     $this->beginWidget('bootstrap.widgets.TbModal', array('id' => $this->modalId, 'htmlOptions' => array('style' => 'margin-top:-200px;', 'backdrop' => 'static')));
     echo "<div class=\"modal-header\">\n                <h4 style=\"width:30%;display: inline-block;\">翻译</h4> \n                <span id='" . $this->modalId . "message' style=\"margin-left:30px;color:red;\"></span>\n            </div>";
     echo "<div id='" . $this->modalId . "ModalBody' class=\"modal-body\" style=\"text-align:center\">";
     $tableName = $this->model->tableName();
     $attribute = $this->attribute;
     echo CHtml::hiddenField('tableName', $tableName);
     echo CHtml::hiddenField('attribute', $attribute);
     $pk = $this->model->primaryKey;
     echo CHtml::activeHiddenField($this->model, $this->model->pk, array('name' => 'pk'));
     $result = Translation::model()->find('model=:tableName and pk=:pk and attribute=:attribute', array(':tableName' => $tableName, ':pk' => $pk, ':attribute' => $attribute));
     $data = json_decode($result->data);
     foreach ($language as $key => $value) {
         if (strtolower($key) == 'zh_cn') {
             continue;
         }
         echo "<div><span style='width:80px !important;display: inline-block;'>" . $value . '</span>' . CHtml::textField($key, $data->{$key}) . "</div>";
     }
     echo "</div>";
     echo "<div class=\"modal-footer\" style=\"text-align: center;\">";
     $this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'button', 'type' => 'info', 'label' => '保存', 'htmlOptions' => array('id' => $this->modalId . 'save')));
     echo "&nbsp;";
     $this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'button', 'label' => '取消', 'htmlOptions' => array("data-dismiss" => "modal", 'id' => $this->modalId . 'back')));
     echo "</div>";
     $this->endWidget();
 }
 public function run()
 {
     if (Yii::app()->request->getPost('table')) {
         $table = Yii::app()->request->getPost('table');
     } else {
         $table = 'location';
     }
     if (Yii::app()->request->getPost('lan_id')) {
         $lan_id = Yii::app()->request->getPost('lan_id');
     } else {
         $lan_id = 2;
         //en
     }
     $dbmodel = ucfirst($table);
     $row = $dbmodel::model()->selectAll();
     $translateRow = Translation::model()->select($table, $row['subject'][0], $lan_id);
     foreach ($row as $k => $r) {
         $row[$k]['translate'] = isset($translateRow[$k]) ? $translateRow[$k]['translate'] : '';
         $row[$k]['translate_id'] = isset($translateRow[$k]) ? $translateRow[$k]['id'] : '';
     }
     echo CJSON::encode($this->controller->renderPartial('translationUser', array('row' => $row, 'table' => $table, 'column' => $row['subject'][0], 'lan_id' => $lan_id), true, true));
     Yii::app()->end();
 }
Пример #3
0
 public function actionTranslations($id, $book_id)
 {
     $user = $this->loadUser($id);
     $book = Book::model()->with("membership")->findByPk((int) $book_id);
     if (!$book) {
         throw new CHttpException(404, "Перевода не существует. Вероятно, он удалён.");
     }
     if (!$book->can("read")) {
         throw new CHttpException(403, "Вы не можете просматривать версии перевода в этом проекте. " . $book->getWhoCanDoIt("read", false));
     }
     if (!$book->can("trread")) {
         throw new CHttpException(403, "Вы не можете просматривать версии перевода в этом проекте. " . $book->getWhoCanDoIt("trread", false));
     }
     $translations = new CActiveDataProvider(Translation::model()->userbook($user->id, $book->id)->with("orig.chap"), array("criteria" => array("order" => "t.cdate desc"), "pagination" => array("pageSize" => 20)));
     $this->side_view = array("profile_side" => array("user" => $user, "userinfo" => $user->userinfo));
     $this->render("translations", array("user" => $user, "book" => $book, "translations" => $translations));
 }
Пример #4
0
 public static function getTranslationFromWordOnSomeLng($str, $toLng)
 {
     /* @var $lng TranslationLng */
     /* @var $word Translation */
     /* @var $neededWord Translation */
     $ret = "";
     $neededWord = null;
     $allWords = Translation::model()->findAll();
     foreach ($allWords as $word) {
         foreach (Constants::GetLngArray() as $lngIndex => $lng) {
             $strWord = $word->getWordByLng($lng);
             if ($str == $strWord) {
                 $neededWord = $word;
             }
         }
     }
     if ($neededWord != null) {
         $ret = $neededWord->getWordByLng($toLng);
     } else {
         $ret = $str;
     }
     return $ret;
 }
Пример #5
0
 public function actionTr_rm($book_id, $chap_id, $orig_id)
 {
     $chap = $this->loadChapter($book_id, $chap_id);
     $user = Yii::app()->user;
     /** @var Translation $tr  */
     $tr = Translation::model()->findByPk((int) $_POST["tr_id"], array("condition" => "chap_id = :chap_id AND book_id = :book_id", "params" => array(":chap_id" => $chap->id, ":book_id" => $chap->book_id)));
     if (!$tr) {
         throw new CHttpException(404, "Этот вариант перевода уже удалили.");
     }
     $tr->chap = $chap;
     if ($tr->user_id != $user->id && $chap->book->membership->status != GroupMember::MODERATOR) {
         throw new CHttpException(403, "Только модераторы могут удалять чужие переводы.");
     }
     if ($tr->delete()) {
         $chap->setModified();
     }
     echo json_encode(array("status" => "ok", "tr_id" => $tr->id, "n_vars" => $chap->n_vars, "d_vars" => $chap->d_vars, "n_verses" => $chap->n_verses));
 }
Пример #6
0
 /**
  * Отдаёт список проголосовавших за вариант перевода $_GET["id"] в JSON
  * @param $book_id
  * @param $chap_id
  * @throws CHttpException
  */
 public function actionRating_explain($book_id, $chap_id)
 {
     $chap = $this->loadChapter($book_id, $chap_id);
     /** @var Translation $tr */
     $tr = Translation::model()->with("marks.user")->findByPk((int) $_GET["id"]);
     if (!$tr) {
         throw new CHttpException(404, "Версия перевода удалена.");
     }
     // Проверяем, верны ли показания в translate.rating и translate.n_votes, раз уж мы всё равно загрузили все оценки
     $n_votes = count($tr->marks);
     $rating = 0;
     foreach ($tr->marks as $mark) {
         $rating += $mark->mark;
     }
     // Autofix: translate.rating, translate.n_votes
     if ($n_votes != $tr->n_votes || $rating != $tr->rating) {
         $tr->n_votes = $n_votes;
         $tr->rating = $rating;
         $tr->save(false, array("rating", "n_votes"));
     }
     $json = array();
     foreach (array_reverse($tr->marks) as $mark) {
         $json[] = array("id" => $mark->user->id, "login" => $mark->user->login, "mark" => $mark->mark);
     }
     echo json_encode($json);
 }
Пример #7
0
 public function actionTransdel()
 {
     /* @var $word Translation */
     //get id from request
     $id = Yii::app()->request->getParam('id', null);
     //get word by id
     $word = Translation::model()->findByPk($id);
     //if not found - redirect to index
     if ($word == null) {
         $this->redirect($this->createUrl('/admin/panel/index'));
     }
     //delete
     $word->deleteLng();
     $word->delete();
     //redirect to list
     $this->redirect($this->createUrl('/admin/panel/translations'));
 }