Example #1
0
 public static function updateLastData($boardId, $threadId, $threadTitle, $isThread = True)
 {
     $attributes = [];
     $attributes['modify_time'] = TTimeHelper::getCurrentTime();
     if ($isThread) {
         $attributes['threads'] = new Expression("[[threads]]+:bp0", [":bp0" => 1]);
     } else {
         $attributes['posts'] = new Expression("[[posts]]+:bp0", [":bp0" => 1]);
     }
     $attributes['user_id'] = YiiForum::getIdentity()->id;
     $attributes['user_name'] = YiiForum::getIdentity()->username;
     $attributes['thread_id'] = $threadId;
     $attributes['thread_title'] = $threadTitle;
     YiiForum::info($attributes);
     Board::updateAll($attributes, ['id' => intval($boardId)]);
 }
Example #2
0
 private function updatePermissions($allItems, $selectedItems, $existedItems, $parent, $child)
 {
     if ($selectedItems == null) {
         $selectedItems = [];
     }
     foreach ($allItems as $item) {
         $itemName = $item['name'];
         $child->name = $itemName;
         // check if the $itenName is selected
         if (in_array($itemName, $selectedItems)) {
             // check if exists in db
             if (in_array($itemName, $existedItems)) {
                 YiiForum::info('exist:' . $itemName);
                 continue;
             } else {
                 // add new permission
                 YiiForum::info('add:' . $itemName);
                 $this->auth->addChild($parent, $child);
             }
         } else {
             // check if exists in db
             if (in_array($itemName, $existedItems)) {
                 // need to be deleted
                 YiiForum::info('delete:' . $itemName);
                 $this->auth->removeChild($parent, $child);
             }
         }
     }
 }
 public function updateAssignments($allItems, $selectedItems, $existedItems, $id)
 {
     $auth = \Yii::$app->authManager;
     if ($selectedItems == null) {
         $selectedItems = [];
     }
     $role = new Role();
     foreach ($allItems as $item) {
         $itemName = $item['name'];
         $role->name = $itemName;
         // the selected role
         if (in_array($itemName, $selectedItems)) {
             // check if exists in db
             if (isset($existedItems[$itemName])) {
                 YiiForum::info('exist:' . $itemName);
                 continue;
             } else {
                 // add new role
                 YiiForum::info('add:' . $itemName);
                 $auth->assign($role, $id);
             }
         } else {
             // check if exists in db
             if (isset($existedItems[$itemName])) {
                 // need to be deleted
                 YiiForum::info('delete:' . $itemName);
                 $auth->revoke($role, $id);
             }
         }
     }
 }
Example #4
0
 /**
  * Updates an existing Thread model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionEditThread($id)
 {
     if (!YiiForum::checkAuth('thread_edit')) {
         return $this->noPermission();
     }
     YiiForum::checkIsGuest();
     $model = $this->findModel($id);
     $boardId = $model['board_id'];
     $post = Post::findOne(['thread_id' => $model['id']], 'create_time asc');
     if ($model->load(Yii::$app->request->post())) {
         //$model->board_id=$boardId;
         //$model->user_id=0;
         //$model->user_name='admin';
         //$model->create_time=$this->getCurrentTime();
         $model->modify_time = TTimeHelper::getCurrentTime();
         if ($model->save()) {
             YiiForum::info($post);
             $this->savePostForThread($model, $post);
         }
         YiiForum::info($model, __METHOD__);
         return $this->redirect(['view', 'id' => $model->id, 'boardid' => $boardId]);
     } else {
         if ($post) {
             $model->body = $post['body'];
         }
         $locals = [];
         $locals['currentBoard'] = $this->getBoard($boardId);
         $locals['model'] = $model;
         return $this->render('edit-thread', $locals);
     }
 }