本文整理汇总了PHP中Criteria::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Criteria::model方法的具体用法?PHP Criteria::model怎么用?PHP Criteria::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Criteria
的用法示例。
在下文中一共展示了Criteria::model方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkNotificationCriteria
/**
* 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();
}
}
}
}
}
}
}
示例2: actionDeleteCriteria
/**
* 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'));
}
示例3: array
<?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 -->
示例4: array
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/>
示例5: calculateChanges
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;
}
示例6: loadModel
/**
* 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;
}
示例7: actionDeleteCriteria
public function actionDeleteCriteria($id)
{
$model = Criteria::model()->findByPk($id);
$model->delete();
$this->redirect(array('addCriteria'));
}