Пример #1
0
 /**
  * Creates the ConstructBuildingTask.
  */
 public function createTask()
 {
     $building = $this->buildingFinder->getById($this->buildingId);
     /* @var $user \common\models\User */
     $user = Yii::$app->user->identity;
     $base = $user->getBase($this->baseId);
     // TODO once the ConstructionQueueRule is implemented, use it to pass
     //      the currently appropriate factor.
     $base->payFor($building, 1.0);
     $now = $this->getTimeComponent()->getStartTime();
     $finished = clone $now;
     $finished->add($building->getCostTime());
     $taskModel = new Task();
     $taskModel->data = ['baseId' => $this->baseId, 'buildingId' => $this->buildingId];
     $taskModel->dateTimeFinished = $finished;
     $taskModel->type = ConstructBuildingTask::className();
     $taskModel->user_id = $user->id;
     if (!$taskModel->save()) {
         throw new Exception('Failed to create task: ' . print_r($taskModel->firstErrors, true));
     }
 }
Пример #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Task::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => false, 'sort' => ['defaultOrder' => ['name' => SORT_ASC]]]);
     $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([self::tableName() . '.category' => $this->category, self::tableName() . '.active' => $this->active]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['>=', 'min_hours', $this->min_hours])->andFilterWhere(['<=', 'max_hours', $this->max_hours]);
     return $dataProvider;
 }
Пример #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $way = null)
 {
     if ($way == null) {
         $query = Task::find();
     } else {
         $query = $way;
     }
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $query->joinWith('taskType');
     $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, 'teacher_id' => $this->teacher_id]);
     $query->andFilterWhere(['like', 'task.name', $this->name])->andFilterWhere(['like', 'task.text', $this->text])->andFilterWhere(['like', 'task_type.name', $this->type_id]);
     return $dataProvider;
 }
Пример #4
0
 /**
  * @get tasks
  */
 public function getTasks()
 {
     return $this->hasMany(Task::className(), ['teacher_id' => 'id']);
 }
Пример #5
0
 /**
  * @get task
  */
 public function getTask()
 {
     return $this->hasOne(Task::className(), ['id' => 'task_id']);
 }
Пример #6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTasks()
 {
     return $this->hasMany(Task::className(), ['available_task_id' => 'id']);
 }
Пример #7
0
 /**
  * @return TaskQuery
  */
 public function getTask()
 {
     return $this->hasOne(Task::className(), ['id' => 'task_id'])->inverseOf('tickets');
 }
Пример #8
0
echo Select2::widget(['name' => 'task_type', 'id' => 'task_type', 'value' => $model->task->taskType->id, 'data' => ArrayHelper::map(TaskType::find()->all(), 'id', 'name'), 'options' => ['placeholder' => 'Выберите тип заданий ...', 'onchange' => '                  
                $.post( "' . Url::to(['//task/listbytype', 'id' => '']) . '"+$(this).val(), function( data ) {
                  $( "select#task" ).html( data );
                }); '], 'pluginOptions' => ['tags' => true]]);
?>
    
    <?php 
echo Html::tag('br');
?>
    
    <?php 
echo Html::label('Задание');
?>
    
    <?php 
echo Select2::widget(['name' => 'task', 'id' => 'task', 'value' => $model->task->id, 'data' => ArrayHelper::map(Task::find()->where(['type_id' => $model->task->taskType->id])->all(), 'id', 'name'), 'options' => ['placeholder' => 'Выберите задание ...', 'onchange' => '
                $.post( "' . Url::to(['//task/givepreview', 'id' => '']) . '"+$(this).val(), function( data ) {
                  $( "#givepreview" ).html( data );
                }); '], 'pluginOptions' => ['tags' => true]]);
?>
    
    <?php 
echo Html::tag('br');
?>
    
    <div class="panel panel-default">
        <div class='panel-heading'>Текст задания</div>
        <div class='panel-body'  id="givepreview" ><?php 
echo Markdown::process($model->task->text);
?>
</div>
Пример #9
0
 /**
  * @todo count how often method is called. On exit, decrease counter. When
  *       counter reaches zero, save all modified models.
  *       --> this handles the case where execution of some tasks load new
  *       models, which in turn start to execute tasks recursively.
  * @param TaskProviderInterface $taskProvider
  */
 public function executeFinishedTasks(TaskProviderInterface $taskProvider)
 {
     $aTaskModelIds = [];
     /* @var $finishedTaskModel Task */
     foreach ($taskProvider->getFinishedTasks() as $finishedTaskModel) {
         $aTaskModelIds[] = $finishedTaskModel->id;
         $class = $finishedTaskModel->type;
         $taskConfig = array_merge($finishedTaskModel->data, ['class' => $class, 'time' => $finishedTaskModel->getDateTimeFinished(), 'userId' => $finishedTaskModel->user_id, 'baseFinder' => \Yii::$app->get('baseManager'), 'userFinder' => \Yii::$app->get('userManager')]);
         $task = \Yii::createObject($taskConfig);
         if (!$task instanceof TaskInterface) {
             \Yii::error("'{$finishedTaskModel->type}' does not implement TaskInterface!");
             continue;
         }
         // $user = $this->getUser( $this, $finishedTaskModel );
         $task->execute();
     }
     Task::deleteAll(['id' => $aTaskModelIds]);
 }
Пример #10
0
/*= $form->field($model, 'invoice_id')->dropDownList(\yii\helpers\ArrayHelper::map(\common\models\Location::find()->active()->all(), 'id', 'fullName'), ['prompt' => '', 'id' => 'location-select']) */
?>
            <?php 
echo $form->field($model, 'invoice_id')->widget(\kartik\select2\Select2::className(), ['data' => \yii\helpers\ArrayHelper::map(\common\models\Location::find()->active()->all(), 'id', 'fullName'), 'options' => ['prompt' => '', 'id' => 'location-select']]);
?>

            <?php 
echo $form->field($model, 'title')->textInput(['maxlength' => true]);
?>

            <?php 
echo $form->field($model, 'description')->textArea(['rows' => 5]);
?>

            <?php 
echo $form->field($model, 'task_id')->widget(\kartik\select2\Select2::className(), ['data' => \yii\helpers\ArrayHelper::map(\common\models\Task::find()->active()->all(), 'id', 'name'), 'options' => ['prompt' => '', 'id' => 'task-select'], 'pluginOptions' => ['allowClear' => true]]);
?>
            <?php 
//TODO: Allow this list to dynamically populate using keywords through ajax...
?>

            <?php 
echo $form->field($model, 'priority_id')->dropDownList($model::$PRIORITIES, ['prompt' => '']);
?>

            <?php 
echo $form->field($model, 'bill_type_id')->widget(\kartik\depdrop\DepDrop::className(), ['data' => $model::$BILL_TYPE_SELECT, 'options' => ['prompt' => '', 'options' => [$model::BILL_PROACTIVE => ['disabled' => !($model->invoice && $model->invoice->location->proactive)]]], 'pluginOptions' => ['depends' => ['location-select'], 'url' => Url::to(['ajax-bill-type']), 'placeholder' => '']]);
?>

        </p>
        <?php 
Пример #11
0
 /**
  * Finds the Task model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Task the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Task::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Пример #12
0
 /**
  * @return Task[]
  */
 public function getFinishedTasks()
 {
     return $this->hasMany(Task::className(), ['user_id' => 'id'])->finished()->all();
 }