Пример #1
0
 /**
  * @param int|string $ids
  * @param int        $user_id
  */
 public function delete($ids, $user_id)
 {
     $user_id = intval($user_id);
     if (is_numeric($ids)) {
         $id = [intval($ids)];
     } else {
         $id = array_flip(array_flip(array_map('intval', explode(",", $ids))));
     }
     $db = $this->db->getWriter();
     $db->pdo->beginTransaction();
     $rt = hook()->apply("Gallery_delete", true, $id, $db);
     if ($rt !== true) {
         $db->pdo->rollBack();
         $this->throwMsg(-4);
     }
     $rt = $db->delete("gallery", ['AND' => ['id' => $id, 'users_id' => $user_id]]);
     if ($rt === false) {
         $db->pdo->rollBack();
         $this->throwMsg(-4);
     }
     if ($rt < 1) {
         $db->pdo->rollBack();
         $this->throwMsg(-5);
     }
     $db->pdo->commit();
 }
Пример #2
0
 /**
  * 删除一条评论,
  * @param int    $id
  * @param string $type
  * @param int    $user_id
  */
 public function delete($id, $type, $user_id)
 {
     $id = intval($id);
     $type = trim($type);
     if (!isset($this->type_list[$type])) {
         $this->throwMsg(-4);
     }
     $user_id = intval($user_id);
     $comment = $this->db->get("comments", ['comment_parent', 'comment_parent_top'], ['AND' => ['id' => $id, 'users_id' => $user_id]]);
     if (empty($comment)) {
         $this->throwMsg(-3);
     }
     $writer = $this->db->getWriter();
     $writer->pdo->beginTransaction();
     $parent = intval($comment['comment_parent']);
     $parent_top = intval($comment['comment_parent_top']);
     if ($parent !== 0) {
         //存在上级回复,即非顶级评论,将所有指向它的评论指向它的上级
         if ($writer->update("comments", ['comment_parent' => $parent], ['comment_parent' => $id]) === false) {
             $writer->pdo->rollBack();
             $this->throwMsg(-1);
         }
     } elseif ($parent_top === 0) {
         //不存在上级回复,且自身为顶级回复
         //取第一条回复
         $top = $this->db->select('comments', ['id'], ['comment_parent_top' => $id, 'LIMIT' => 1]);
         if (isset($top[0])) {
             $top = $top[0];
             if ($writer->update('comments', ['comment_parent_top' => NULL, 'comment_parent' => NULL], ['id' => $top['id']]) === false) {
                 $writer->pdo->rollBack();
                 $this->throwMsg(-1);
             }
             if ($writer->update('comments', ['comment_parent' => $top['id']], ['comment_parent' => $id]) === false) {
                 $writer->pdo->rollBack();
                 $this->throwMsg(-1);
             }
             if ($writer->update('comments', ['comment_parent_top' => $top['id']], ['comment_parent_top' => $id]) === false) {
                 $writer->pdo->rollBack();
                 $this->throwMsg(-1);
             }
         } elseif ($top === false) {
             $writer->pdo->rollBack();
             $this->throwMsg(-1);
         }
     }
     //针对无法触发DELETE触发器的计数器添加和删除操作
     $this->deleteRelationTable($id, $this->type_list[$type], $writer);
     $rt = $this->db->delete("comments", ['AND' => ['id' => $id, 'users_id' => $user_id]]);
     if ($rt === false) {
         $writer->pdo->rollBack();
         $this->throwMsg(-1);
     } else {
         if ($rt < 1) {
             $writer->pdo->rollBack();
             $this->throwMsg(-2);
         }
     }
     $writer->pdo->commit();
 }
Пример #3
0
 /**
  * 为对应专业和课程插入数据
  * @param $id_id
  * @param $mc_id
  * @param $icl_id
  * @return bool|int
  */
 public function insert_mc_id_class_list($id_id, $mc_id, $icl_id)
 {
     $stmt = $this->driver->getWriter()->prepare("INSERT INTO scores (mc_id, is_id)(\n\tSELECT\n\t\tmg_curriculum.mc_id,\n\t\tinfo_student.is_id\n\tFROM\n\t\tinfo_class\n\tINNER JOIN info_student ON info_class.icl_id = info_student.icl_id\n\tINNER JOIN mg_curriculum ON info_class.id_id =mg_curriculum.id_id\n\tWHERE\n\t\tmg_curriculum.id_id = :id_id\n\tAND mg_curriculum.mc_id = :mc_id\n\tAND info_class.icl_id = :icl_id\n)");
     if ($stmt->execute([':id_id' => $id_id, ':mc_id' => $mc_id, ':icl_id' => $icl_id])) {
         $r = $stmt->rowCount();
     } else {
         $r = false;
     }
     $stmt->closeCursor();
     return $r;
 }