예제 #1
0
 public function run()
 {
     $model = new Soft();
     if (isset($_POST['Soft'])) {
         $model->attributes = $_POST['Soft'];
         //封面、图标、 文件
         $model->cover_image = isset($_POST['cover_image']) ? $_POST['cover_image'] : '';
         $model->soft_icon = isset($_POST['soft_icon']) ? $_POST['soft_icon'] : '';
         $model->soft_file = isset($_POST['soft_file']) ? $_POST['soft_file'] : '';
         //摘要
         $model->introduce = trim($_POST['Soft']['introduce']) ? $_POST['Soft']['introduce'] : Helper::truncate_utf8_string(preg_replace('/\\s+/', ' ', $_POST['Soft']['content']), 200);
         //标签   (前5个标签有效)
         $tags = trim($_POST['Soft']['tags']);
         $unique_tags = array_unique(explode(',', str_replace(array(' ', ','), array('', ','), $tags)));
         $explodeTags = array_slice($unique_tags, 0, 5);
         $model->tags = implode(',', $explodeTags);
         $model->create_time = time();
         $model->update_time = $model->create_time;
         if ($model->save()) {
             $this->controller->message('success', Yii::t('admin', 'Add Success'), $this->controller->createUrl('index'));
         }
     }
     //判断有无栏目
     $article_cat = Catalog::model()->find('type=:type', array(':type' => $this->controller->_type));
     if (!$article_cat) {
         $this->controller->message('error', Yii::t('admin', 'No Catalog'), $this->controller->createUrl('index'));
     }
     $this->controller->render('create', array('model' => $model));
 }
예제 #2
0
 /**
  * 新增数据
  *
  */
 public function actionCreate()
 {
     $model = new Soft();
     if (isset($_POST['Soft'])) {
         $model->attributes = $_POST['Soft'];
         if ($model->os && is_array($model->os)) {
             $model->os = implode(',', $model->os);
         }
         //软件文件
         $fileids = is_array($_POST['fileid']) ? implode(',', $_POST['fileid']) : '';
         $model->fileid = $fileids;
         if ($_FILES['softicon']['error'] == UPLOAD_ERR_OK) {
             //软件图标
             $upload = new Uploader();
             $upload->uploadFile($_FILES['softicon']);
             if ($upload->_error) {
                 $upload->deleteFile($upload->_file_name);
                 $this->message('error', Yii::t('admin', $upload->_error));
                 return;
             }
             $model->soft_icon = $upload->_file_name;
         } else {
             //未改变前的软件图标
             $model->soft_icon = $_POST['old_icon'];
         }
         if ($_FILES['attach']['error'] == UPLOAD_ERR_OK) {
             //封面图片
             $upload = new Uploader();
             $upload->uploadFile($_FILES['attach']);
             if ($upload->_error) {
                 $upload->deleteFile($upload->_file_name);
                 $this->message('error', Yii::t('admin', $upload->_error));
                 return;
             }
             $model->cover_image = $upload->_file_name;
         } else {
             //未改变前的封面图片
             $model->cover_image = $_POST['old_cover'];
         }
         //关键字(即标签,只要前10个关键字作为标签)
         $tags = trim($_POST['Soft']['seo_keywords']);
         $explodeTags = array_unique(explode(',', str_replace(array(' ', ','), array('', ','), $tags)));
         $model->create_time = time();
         $model->update_time = $model->create_time;
         if ($model->save()) {
             //更新标签数据
             Tag::model()->updateTagData($explodeTags, array('content_id' => $model->id, 'status' => $model->status, 'type_id' => $this->_type_ids['soft']));
             $this->message('success', Yii::t('admin', 'Add Success'), $this->createUrl('index'));
         }
     }
     //判断有无软件栏目
     $soft_cat = Catalog::model()->find('type=:type', array(':type' => $this->_type));
     if (!$soft_cat) {
         $this->message('error', Yii::t('admin', 'No Catalog'), $this->createUrl('index'));
     }
     $this->render('update', array('model' => $model));
 }
예제 #3
0
 public function testSoftDelete()
 {
     $user = new Soft();
     $user->name = 'Softy';
     $user->save();
     $this->assertEquals(true, $user->exists);
     $user->delete();
     $check = Soft::find($user->_id);
     $this->assertEquals(null, $check);
     $all = Soft::get();
     $this->assertEquals(0, $all->count());
     $all = Soft::withTrashed()->get();
     $this->assertEquals(1, $all->count());
     $check = $all[0];
     $this->assertInstanceOf('Carbon\\Carbon', $check->deleted_at);
     $this->assertEquals(true, $check->trashed());
     $check->restore();
     $all = Soft::get();
     $this->assertEquals(1, $all->count());
 }