public function actionSaveSort()
 {
     $objTypeId = Yii::app()->request->getParam('id', NULL);
     $sort = Yii::app()->request->getParam('sort');
     if (count($sort) >= param('searchMaxField', 15)) {
         HAjax::jsonError(tt('Search max field ') . param('searchMaxField', 3));
     }
     if ($objTypeId !== NULL && $sort && is_array($sort)) {
         $elements = SearchForm::getSearchFields();
         $sql = "DELETE FROM {{search_form}} WHERE obj_type_id=:id AND status!=:status";
         Yii::app()->db->createCommand($sql)->execute(array(':id' => $objTypeId, ':status' => SearchFormModel::STATUS_NOT_REMOVE));
         $i = 3;
         foreach ($sort as $field) {
             if (!isset($elements[$field])) {
                 continue;
             }
             $search = new SearchFormModel();
             $search->attributes = array('obj_type_id' => $objTypeId, 'field' => $field, 'status' => $elements[$field]['status'], 'sorter' => $i, 'formdesigner_id' => isset($elements[$field]['formdesigner_id']) ? $elements[$field]['formdesigner_id'] : 0);
             $search->save();
             $i++;
         }
         // delete assets js cache
         ConfigurationModel::clearGenerateJSAssets();
         HAjax::jsonOk();
     }
     HAjax::jsonError();
 }
 public function afterSave()
 {
     if ($this->isNewRecord) {
         if (issetModule('formdesigner')) {
             Yii::import('application.modules.formdesigner.models.*');
             $forms = FormDesigner::model()->findAll();
             foreach ($forms as $form) {
                 $formType = new FormDesignerObjType();
                 $formType->formdesigner_id = $form->id;
                 $formType->obj_type_id = $this->id;
                 $formType->save();
             }
         }
         $searchFields = SearchFormModel::model()->sort()->findAllByAttributes(array('obj_type_id' => SearchFormModel::OBJ_TYPE_ID_DEFAULT));
         foreach ($searchFields as $field) {
             $newSearch = new SearchFormModel();
             $newSearch->attributes = $field->attributes;
             $newSearch->obj_type_id = $this->id;
             $newSearch->save();
         }
     }
     return parent::afterSave();
 }
Exemple #3
0
<?php

$compact = isset($compact) ? $compact : 0;
$isInner = isset($isInner) ? $isInner : 0;
if (isset($this->objType) && $this->objType) {
    $searchFields = SearchFormModel::model()->sort()->findAllByAttributes(array('obj_type_id' => $this->objType), array('group' => 'field'));
    if (!$searchFields) {
        $searchFields = SearchFormModel::model()->sort()->findAllByAttributes(array('obj_type_id' => SearchFormModel::OBJ_TYPE_ID_DEFAULT), array('group' => 'field'));
    }
} else {
    $searchFields = SearchFormModel::model()->sort()->findAllByAttributes(array('obj_type_id' => SearchFormModel::OBJ_TYPE_ID_DEFAULT), array('group' => 'field'));
}
$i = 1;
foreach ($searchFields as $search) {
    if ($isInner) {
        $divClass = 'search_inner_row';
    } else {
        $divClass = 'header-form-line';
    }
    if ($search->status <= SearchFormModel::STATUS_NOT_REMOVE) {
        $this->renderPartial('//site/_search_field_' . $search->field, array('divClass' => $divClass, 'textClass' => 'formalabel', 'controlClass' => 'formacontrol', 'fieldClass' => 'width290 search-input-new', 'minWidth' => '290', 'isInner' => $isInner));
    } else {
        $this->renderPartial('//site/_search_new_field', array('divClass' => $divClass, 'textClass' => 'formalabel', 'controlClass' => 'formacontrol', 'fieldClass' => 'width290 search-input-new', 'minWidth' => '290', 'search' => $search, 'isInner' => $isInner));
    }
    $i++;
    if (!$isInner) {
        echo '<div class="clear"></div>';
    }
    SearchForm::increaseJsCounter();
}