/** * Looks up notification criteria in x2_criteria relevant to this model * and field and performs the specified operation. * Soon to be eliminated in wake of x2flow automation system. * * @param string $fieldName the name of the current field * @param string $old the old value * @param string $new the new value */ public function checkNotificationCriteria($fieldName, $old, $new) { $model = $this->getOwner(); $modelClass = get_class($model); $allCriteria = Criteria::model()->findAllByAttributes(array('modelType' => $modelClass, 'modelField' => $fieldName)); foreach ($allCriteria as $criteria) { if ($criteria->comparisonOperator == "=" && $new == $criteria->modelValue || $criteria->comparisonOperator == ">" && $new >= $criteria->modelValue || $criteria->comparisonOperator == "<" && $new <= $criteria->modelValue || $criteria->comparisonOperator == "change" && $new != $old) { $users = preg_split('/[\\s,]+/', $criteria->users, null, PREG_SPLIT_NO_EMPTY); if ($criteria->type == 'notification') { foreach ($users as $user) { $event = new Events(); $event->user = $user; $event->associationType = 'Notification'; $event->type = 'notif'; $notif = new Notification(); $notif->type = 'change'; $notif->fieldName = $fieldName; $notif->modelType = get_class($model); $notif->modelId = $model->id; if ($criteria->comparisonOperator == 'change') { $notif->comparison = 'change'; // if the criteria is just 'changed' $notif->value = $new; // record the new value } else { $notif->comparison = $criteria->comparisonOperator; // otherwise record the operator type $notif->value = mb_substr($criteria->modelValue, 0, 250, 'UTF-8'); // and the comparison value } $notif->user = $user; $notif->createdBy = $this->editingUsername; $notif->createDate = time(); if ($notif->save()) { $event->associationId = $notif->id; $event->save(); } } } elseif ($criteria->type == 'action') { foreach ($users as $user) { $action = new Actions(); $action->assignedTo = $user; if ($criteria->comparisonOperator == "=") { $action->actionDescription = "A record of type " . $modelClass . " has been modified to meet {$criteria->modelField} {$criteria->comparisonOperator} {$criteria->modelValue}" . " by " . $this->editingUsername; } else { if ($criteria->comparisonOperator == ">") { $action->actionDescription = "A record of type " . $modelClass . " has been modified to meet {$criteria->modelField} {$criteria->comparisonOperator} {$criteria->modelValue}" . " by " . $this->editingUsername; } else { if ($criteria->comparisonOperator == "<") { $action->actionDescription = "A record of type " . $modelClass . " has been modified to meet {$criteria->modelField} {$criteria->comparisonOperator} {$criteria->modelValue}" . " by " . $this->editingUsername; } else { if ($criteria->comparisonOperator == "change") { $action->actionDescription = "A record of type " . $modelClass . " has had its {$criteria->modelField} field changed from " . $old . ' to ' . $new . ' by ' . $this->editingUsername; } } } } $action->dueDate = mktime('23', '59', '59'); $action->createDate = time(); $action->lastUpdated = time(); $action->updatedBy = 'admin'; $action->visibility = 1; $action->associationType = lcfirst($modelClass); $action->associationId = $model->id; $action->associationName = $model->name; $action->save(); } } elseif ($criteria->type == 'assignment') { $model->assignedTo = $criteria->users; if ($model->save()) { $event = new Events(); $event->type = 'notif'; $event->user = $model->assignedTo; $event->associationType = 'Notification'; $notif = new Notification(); $notif->user = $model->assignedTo; $notif->createDate = time(); $notif->type = 'assignment'; $notif->modelType = $modelClass; $notif->modelId = $model->id; if ($notif->save()) { $event->associationId = $notif->id; if ($this->createEvent) { $event->save(); } } } } } } }
/** * Delete a notification criteria. * * This function is called to delete a user created notification critera. * Some criteria are built in to the app and cannot be deleted this way. * * @param int $id The ID of the criteria to be deleted. */ public function actionDeleteCriteria($id) { Criteria::model()->deleteByPk($id); $this->redirect(array('addCriteria')); }
<?php echo TbHtml::button('<i class="fa fa-times fa-lg"></i> Cancel', array('onclick' => 'js:document.location.href="/mtcontrool"', 'color' => TbHtml::BUTTON_COLOR_DANGER, 'size' => TbHtml::BUTTON_SIZE_SMALL, 'title' => 'Cancel', 'class' => 'btn pull-right', 'style' => 'color: white;')); ?> </div> <div class="well"> <p class="help-block">Fields with <span class="required">*</span> are required.</p> <?php echo $form->errorSummary($model); ?> <?php echo $form->textFieldControlGroup($model, 'name', array('span' => 5, 'maxlength' => 400)); ?> <?php echo $form->dropDownListControlGroup($model, 'id_criteria', CHtml::listData(Criteria::model()->findAll(), 'id', 'name'), array('prompt' => 'Selected')); ?> </div> <?php $this->endWidget(); ?> </div><!-- form -->
href="<?php echo Yii::app()->request->baseUrl; ?> /css/users.css" /> <div class="infoblock shadow"><h1 style="color:#20B2AA;">Manage Test Cases</h1></div> <HR WIDTH=1180 ALIGN=LEFT > <?php $this->widget('bootstrap.widgets.TbBreadcrumb', array('links' => array('Test Cases' => array('index'), 'Manage'))); ?> <div class="jumbotron"> <br/> <div class="well-button"> <?php echo TbHtml::Button('<i class="fa fa-arrow-left"></i> Back', array('onclick' => 'js:document.location.href="/mtcontrool"', 'id' => 'b1', 'title' => 'Back', 'color' => TbHtml::BUTTON_COLOR_DEFAULT, 'size' => TbHtml::BUTTON_SIZE_SMALL, 'style' => 'color: green;')); ?> </div> <?php $this->widget('bootstrap.widgets.TbGridView', array('id' => 'test-case-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array('num', 'name', 'description', 'required', 'notes', 'steps', 'result', array('name' => 'id_criteria', 'value' => 'Criteria::Model()->FindByPk($data->id_criteria)->name', 'filter' => CHtml::listData(Criteria::model()->findAll(), 'id', 'name')), array('class' => 'bootstrap.widgets.TbButtonColumn')))); ?> </div> <br/>
protected function calculateChanges($old, $new, &$model = null) { $arr = array(); $keys = array_keys($new); for ($i = 0; $i < count($keys); $i++) { if ($old[$keys[$i]] != $new[$keys[$i]]) { $arr[$keys[$i]] = $new[$keys[$i]]; $allCriteria = Criteria::model()->findAllByAttributes(array('modelType' => $this->modelClass, 'modelField' => $keys[$i])); foreach ($allCriteria as $criteria) { if ($criteria->comparisonOperator == "=" && $new[$keys[$i]] == $criteria->modelValue || $criteria->comparisonOperator == ">" && $new[$keys[$i]] >= $criteria->modelValue || $criteria->comparisonOperator == "<" && $new[$keys[$i]] <= $criteria->modelValue || $criteria->comparisonOperator == "change" && $new[$keys[$i]] != $old[$keys[$i]]) { if ($criteria->type == 'notification') { $pieces = explode(", ", $criteria->users); foreach ($pieces as $piece) { $notif = new Notifications(); $profile = CActiveRecord::model('ProfileChild')->findByAttributes(array('username' => Yii::app()->user->getName())); if ($criteria->comparisonOperator == "=") { $notif->text = "A record of type " . $this->modelClass . " has been modified to meet {$criteria->modelField} {$criteria->comparisonOperator} {$criteria->modelValue}" . " by " . Yii::app()->user->getName(); } else { if ($criteria->comparisonOperator == ">") { $notif->text = "A record of type " . $this->modelClass . " has been modified to meet {$criteria->modelField} {$criteria->comparisonOperator} {$criteria->modelValue}" . " by " . Yii::app()->user->getName(); } else { if ($criteria->comparisonOperator == "<") { $notif->text = "A record of type " . $this->modelClass . " has been modified to meet {$criteria->modelField} {$criteria->comparisonOperator} {$criteria->modelValue}" . " by " . Yii::app()->user->getName(); } else { if ($criteria->comparisonOperator == "change") { $notif->text = "A record of type " . $this->modelClass . " has had its {$criteria->modelField} field changed from " . $old[$keys[$i]] . " to " . $new[$keys[$i]] . " by " . Yii::app()->user->getName(); } } } } $notif->user = $piece; $notif->createDate = time(); $notif->viewed = 0; $notif->record = $this->modelClass . ":" . $new['id']; $notif->save(); } } else { if ($criteria->type == 'action') { $pieces = explode(", ", $criteria->users); foreach ($pieces as $piece) { $action = new Actions(); $action->assignedTo = $piece; if ($criteria->comparisonOperator == "=") { $action->actionDescription = "A record of type " . $this->modelClass . " has been modified to meet {$criteria->modelField} {$criteria->comparisonOperator} {$criteria->modelValue}" . " by " . Yii::app()->user->getName(); } else { if ($criteria->comparisonOperator == ">") { $action->actionDescription = "A record of type " . $this->modelClass . " has been modified to meet {$criteria->modelField} {$criteria->comparisonOperator} {$criteria->modelValue}" . " by " . Yii::app()->user->getName(); } else { if ($criteria->comparisonOperator == "<") { $action->actionDescription = "A record of type " . $this->modelClass . " has been modified to meet {$criteria->modelField} {$criteria->comparisonOperator} {$criteria->modelValue}" . " by " . Yii::app()->user->getName(); } else { if ($criteria->comparisonOperator == "change") { $action->actionDescription = "A record of type " . $this->modelClass . " has had its {$criteria->modelField} field changed from " . $old[$keys[$i]] . " to " . $new[$keys[$i]] . " by " . Yii::app()->user->getName(); } } } } $action->dueDate = mktime('23', '59', '59'); $action->createDate = time(); $action->lastUpdated = time(); $action->updatedBy = 'admin'; $action->visibility = 1; $action->associationType = strtolower($this->modelClass); $action->associationId = $new['id']; $model = CActiveRecord::model($this->modelClass)->findByPk($new['id']); $action->associationName = $model->name; $action->save(); } } else { if ($criteria->type == 'assignment') { $model->assignedTo = $criteria->users; $model->save(); $notif = new Notifications(); $notif->text = "A record of type " . $this->modelClass . " has been re-assigned to you."; $notif->user = $model->assignedTo; $notif->createDate = time(); $notif->viewed = 0; $notif->record = $this->modelClass . ":" . $new['id']; $notif->save(); } } } } } } } $str = ''; foreach ($arr as $key => $item) { $str .= "<b>{$key}</b> <u>FROM:</u> {$old[$key]} <u>TO:</u> {$item} <br />"; } return $str; }
<div class="infoblock shadow"><h1 style="color:#20B2AA;">Manage Characteristics</h1></div> <HR WIDTH=1180 ALIGN=LEFT > <?php $this->widget('bootstrap.widgets.TbBreadcrumb', array('links' => array('Characteristics' => array('index'), 'Manage Characteristics'))); ?> <div class="search-form" style="display:none"> <?php $this->renderPartial('_search', array('model' => $model)); ?> </div><!-- search-form --> </br> <div class="well-button"> <?php echo TbHtml::Button('<i class="fa fa-arrow-left"></i> Back', array('onclick' => 'js:document.location.href="/mtcontrool"', 'id' => 'b1', 'title' => 'Back', 'color' => TbHtml::BUTTON_COLOR_DEFAULT, 'size' => TbHtml::BUTTON_SIZE_SMALL, 'style' => 'color: green;')); ?> </div> <div class="group-div"> <?php $this->widget('bootstrap.widgets.TbGridView', array('id' => 'characteristic-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array(array('name' => 'name'), array('name' => 'id_criteria', 'value' => 'Criteria::Model()->FindByPk($data->id_criteria)->name', 'filter' => CHtml::listData(Criteria::model()->findAll(), 'id', 'name')), array('class' => 'bootstrap.widgets.TbButtonColumn', 'template' => '{update} {delete}')))); ?> </div> </br>
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Criteria the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Criteria::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
<?php echo TbHtml::button('<i class="fa fa-times fa-lg"></i> Cancel', array('onclick' => 'js:document.location.href="/mtcontrool"', 'color' => TbHtml::BUTTON_COLOR_DANGER, 'size' => TbHtml::BUTTON_SIZE_SMALL, 'title' => 'Cancel', 'class' => 'btn pull-right', 'style' => 'color: white;')); ?> </div> <div class="well"> <p class="help-block">Fields with <span class="required">*</span> are required.</p> <?php echo $form->errorSummary($model); ?> <?php echo $form->dropDownListControlGroup($model, 'id_criteria', CHtml::listData(Criteria::model()->findAll(), 'id', 'name'), array('ajax' => array('type' => 'POST', 'url' => CController::createUrl('TestCase/Selectdos'), 'update' => '#' . CHtml::activeId($model, 'id_characteristic')), 'prompt' => 'Select')); ?> </br> <div class="littlehelp"> <p class="soc-block"> <span class=" icon-arrow-right" aria-hidden="true"></span> If you wouldn't choose a characteristic, the test case'll be considered default (obrigatory).</p> </div> </br> <!-- echo $form->dropDownListControlGroup($model,'id_characteristic',CHtml::listData(Characteristic::model()->findAll(), 'id', 'name'), array( 'prompt'=>'Selected', ));-->
public function actionDeleteCriteria($id) { $model = Criteria::model()->findByPk($id); $model->delete(); $this->redirect(array('addCriteria')); }