Esempio n. 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Work::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->setSort(['attributes' => ['id', 'studentFullname' => ['asc' => ['user.last_name' => SORT_ASC], 'desc' => ['user.last_name' => SORT_DESC], 'label' => 'studentFullname'], 'groupName' => ['asc' => ['student.group.name' => SORT_ASC], 'desc' => ['student.group.name' => SORT_DESC], 'label' => 'groupName'], 'disciplineName' => ['asc' => ['groupHasDiscipline.discipline.name' => SORT_ASC], 'desc' => ['groupHasDiscipline.discipline.name' => SORT_DESC]]]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'work_type_id' => $this->work_type_id, 'name' => $this->name, 'student_id' => $this->student_id, 'teacher_id' => $this->teacher_id, 'date' => $this->date, 'approve_status' => $this->approve_status]);
     $query->joinWith('student')->joinWith(['student.user' => function ($q) {
         $q->where('user.first_name LIKE "%' . $this->studentFullname . '%" ' . 'OR user.last_name LIKE "%' . $this->studentFullname . '%"' . 'OR user.middle_name LIKE "%' . $this->studentFullname . '%"');
     }]);
     $query->joinWith('student')->joinWith(['student.group' => function ($q) {
         $q->where('group.name LIKE "%' . $this->groupName . '%" ');
     }]);
     if ($this->work_type_id == Work::TYPE_TERM) {
         $query->joinWith('groupHasDiscipline')->joinWith(['groupHasDiscipline.discipline' => function ($q) {
             $q->where('discipline.name LIKE "%' . $this->disciplineName . '%" ');
         }]);
     }
     return $dataProvider;
 }
Esempio n. 2
0
 public function getisReserved()
 {
     if (Work::find()->where(['reserved_id' => $this->id, 'approve_status' => 3])->count()) {
         return true;
     } else {
         return false;
     }
 }
 public function up()
 {
     $users = User::find()->where(['is_deleted' => 0])->all();
     foreach ($users as $user) {
         $employer_work_count = Work::find()->where(['is_deleted' => 0, 'user_id' => $user['id']])->count();
         $sqls = "update user set employer_work_count = '{$employer_work_count}' where id = '{$user['id']}'";
         $this->execSqls($sqls);
     }
     return 1;
 }
 public function up()
 {
     $works = Work::find()->all();
     foreach ($works as $work) {
         $work->released_at += 1;
         $work->save(false);
         echo "重建 work: {$work->id} , {$work->title} \n ";
     }
     echo "完成\n";
 }
 public function up()
 {
     $works = Work::find()->all();
     foreach ($works as $work) {
         if ($work->description && strpos('<p>', $work->description) === false) {
             echo "Convert  {$work->id} 's description...\n";
             $work->description = Markdown::process($work->description, 'gfm');
             $work->save(false);
         }
     }
     echo "DOne\n";
 }
 public function up()
 {
     $uids = User::find()->select('id')->where(['is_deleted' => 0])->asArray()->all();
     foreach ($uids as $uid) {
         $uid = $uid['id'];
         $complete = Work::find()->select('id')->where(['user_id' => $uid, 'status' => 30])->indexBy('id')->asArray()->all();
         $complete = array_keys($complete);
         if (empty($complete)) {
             continue;
         }
         $money = WorkContract::find()->select('final_money')->where(['work_id' => $complete])->sum('final_money');
         $u = User::findOne(['id' => $uid]);
         $u->employer_transaction_amount = $money;
         $u->save(false);
     }
 }
Esempio n. 7
0
 /**     
  * @delete graduate
  */
 public function actionDeleteGraduate($id)
 {
     if (Work::find()->where(['id' => $id, 'student_id' => Yii::$app->user->identity->student->id])->count()) {
         $this->findModel($id)->delete();
     }
     return $this->redirect(['graduate']);
 }
Esempio n. 8
0
 public static function changeStatus($student, $status, $type)
 {
     $work = Work::find()->where(['student_id' => $student, 'work_type_id' => $type])->one();
     $work->approve_status = $status;
     if ($work->save()) {
         return true;
     } else {
         return false;
     }
 }