/** * Render/save the Custom Lead Routing Rules * * This method renders a grid of Custom Round Robin Rules and allows for new * rules to be created and saved. These rules are used in conjunction with * {@link AdminController::actionGetRoutingType} when the "Custom Round Robin" * lead distribution method is chosen. */ public function actionRoundRobinRules() { $model = new LeadRouting(); $users = User::getNames(); unset($users['Anyone']); unset($users['admin']); $priorityArray = array(); for ($i = 1; $i <= LeadRouting::model()->count() + 1; $i++) { $priorityArray[$i] = $i; } $dataProvider = new CActiveDataProvider('LeadRouting', array('criteria' => array('order' => 'priority ASC'))); if (isset($_POST['LeadRouting'])) { $values = $_POST['Values']; $criteria = array(); for ($i = 0; $i < count($values['field']); $i++) { $tempArr = array($values['field'][$i], $values['comparison'][$i], $values['value'][$i]); $criteria[] = implode(',', $tempArr); } $model->criteria = json_encode($criteria); $model->attributes = $_POST['LeadRouting']; $model->priority = $_POST['LeadRouting']['priority']; if (isset($_POST['group'])) { $group = true; $model->groupType = $_POST['groupType']; } else { $model->groupType = null; } $model->users = Fields::parseUsers($model->users); $check = LeadRouting::model()->findByAttributes(array('priority' => $model->priority)); if (isset($check)) { $query = "UPDATE x2_lead_routing " . "SET priority=priority+1 " . "WHERE priority>='{$model->priority}'"; $command = Yii::app()->db->createCommand($query); $command->execute(); } if ($model->save()) { $this->redirect('roundRobinRules'); } } $this->render('customRules', array('model' => $model, 'users' => $users, 'dataProvider' => $dataProvider, 'priorityArray' => $priorityArray)); }