Example #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;
 }
Example #2
0
 public function actionApproveGraduate($id, $status)
 {
     $model = \common\models\Work::findOne($id);
     if (Yii::$app->user->can('chief') && $model->approve_status == 1) {
         $model->approve_status = $status;
         $model->save();
     }
 }
 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);
     }
 }
Example #7
0
 /**
  * @get works
  */
 public function getTerms()
 {
     return $this->hasMany(Work::className(), ['teacher_id' => 'id'])->where(['work_type_id' => Work::TYPE_TERM]);
 }
Example #8
0
//= $form->field($model, 'name')->textInput()
?>

    <?php 
//= $form->field($model, 'student_id')->textInput()
?>

    <?php 
//= $form->field($model, 'teacher_id')->textInput()
?>

    <?php 
//= $form->field($model, 'date')->textInput()
?>

    <?php 
echo $form->field($model, 'approve_status')->dropDownList(ArrayHelper::map(Work::getStatusList(), 'id', 'name'))->label('Статус');
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Добавить' : 'Сохранить', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php 
ActiveForm::end();
?>

</div>
Example #9
0
 /**
  * @get works
  */
 public function getWorks()
 {
     return $this->hasMany(Work::className(), ['student_id' => 'id']);
 }
Example #10
0
 /**
  * Finds the Work model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Work the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Work::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #11
0
 public function getReserved()
 {
     return $this->hasOne(Work::className(), ['reserved_id' => 'id']);
 }
Example #12
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;
     }
 }