/**
  * Провека параметров и подготовка настроек 
  * для обновлении или добавления
  * 
  * @param type $data
  * @return type
  */
 public function isValid($data)
 {
     require_once ABS_PATH . '/freelancers/widgets/FreelancersPreviewWidget.php';
     require_once ABS_PATH . '/classes/freelancer.php';
     $this->is_valid = false;
     $max_pos = FreelancersPreviewWidget::MAX_ITEMS;
     $this->group_id = isset($data['group']) ? intval($data['group']) : 0;
     $this->prof_id = isset($data['prof']) ? intval($data['prof']) : 0;
     $hash = isset($data['hash']) ? $data['hash'] : null;
     //Проверка группы/раздела именно тех на странице которых был открыт попап
     if ($hash !== paramsHash(array($this->group_id, $this->prof_id))) {
         return $this->is_valid;
     }
     $value = isset($data['value']) ? $data['value'] : '';
     $this->uid = isset($data['uid']) && $data['uid'] > 0 ? $data['uid'] : null;
     $this->pos = isset($data['pos']) && $data['pos'] > 0 && $data['pos'] <= $max_pos ? intval($data['pos']) : null;
     if (!$this->uid || !$this->pos || empty($value)) {
         return $this->is_valid;
     }
     $user = new freelancer();
     $user->GetUserByUID($this->uid);
     if ($user->uid <= 0) {
         return $this->is_valid;
     }
     $pattern = implode('|', FreelancersPreviewEditorPopup::$types);
     $matches = array();
     if (preg_match("/^({$pattern})_([0-9]+)\$/", $value, $matches)) {
         $this->type = self::$type_from_string[$matches[1]];
         $this->src_id = $matches[2];
         switch ($this->type) {
             case self::TYPE_PF:
                 require_once ABS_PATH . '/classes/portfolio.php';
                 $portfolio = new portfolio();
                 $this->is_valid = (bool) $portfolio->isExistActive($this->uid, $this->src_id);
                 break;
             case self::TYPE_TU:
                 require_once ABS_PATH . '/classes/tservices/tservices.php';
                 $tservices = new tservices($this->uid);
                 $this->is_valid = (bool) $tservices->isExistActive($this->src_id);
                 break;
         }
         if ($this->is_valid) {
             $res = $this->getRowByUidAndPos($this->uid, $this->pos, $this->group_id, $this->prof_id);
             $this->id = $res ? $res['id'] : 0;
             //Уже есть данная позиция
             //то готовим данные для обновления
             if ($this->id > 0) {
                 $this->data = array('src_id' => $this->src_id, 'type' => $this->type, 'is_default' => false);
                 $this->is_default = $res['is_default'] == 't';
                 //Первое добавление позиции
                 //то готовим новые данные для добавления
             } else {
                 $exist_data = isset($_SESSION[self::SESS_EXIST_PREVIEW_DATA]) ? $_SESSION[self::SESS_EXIST_PREVIEW_DATA] : null;
                 for ($idx = 1; $idx <= $max_pos; $idx++) {
                     if ($idx == $this->pos) {
                         $this->data[$idx] = array('src_id' => $this->src_id, 'type' => $this->type, 'user_id' => $this->uid, 'pos' => $idx, 'group_id' => $this->group_id, 'prof_id' => $this->prof_id, 'is_default' => false);
                     } elseif (isset($exist_data['ids'][$idx - 1])) {
                         $this->data[$idx] = array('src_id' => $exist_data['ids'][$idx - 1], 'type' => $exist_data['type'], 'user_id' => $this->uid, 'pos' => $idx, 'group_id' => $this->group_id, 'prof_id' => $this->prof_id, 'is_default' => false);
                     }
                 }
             }
             //Устанавливаем по возможности
             //текущии настройки для общего каталога / раздела
             /*
               - общий каталог поумолчанию из основного подраздела (специализации), но может и настраиваться по своему
               - раздел каталога поумолчанию из последнего отредактированного подраздела, но может настраиваться по своему
               - подраздел (специализация) настраивается по своему 
             */
             if ($this->prof_id > 0 && $this->group_id == 0 && count($this->data)) {
                 $is_exist_setting_for_catalog = false;
                 $is_exist_setting_for_group = false;
                 require_once ABS_PATH . '/classes/professions.php';
                 $group_id = professions::GetGroupIdByProf($this->prof_id);
                 $exist_data = $this->getExistData($group_id);
                 $current_settings = array();
                 if ($exist_data) {
                     foreach ($exist_data as $el) {
                         //Существующие текущие настройки раздела
                         if ($el['prof_id'] == $this->prof_id && $el['group_id'] == 0) {
                             unset($el['id']);
                             if ($el['pos'] == $this->pos) {
                                 $el['src_id'] = $this->src_id;
                                 $el['type'] = $this->type;
                             }
                             $current_settings[$el['pos']] = $el;
                             //Существующие настройки для общего каталога
                         } elseif ($el['prof_id'] == 0 && $el['group_id'] == 0 && $el['is_default'] == 'f') {
                             $is_exist_setting_for_catalog = true;
                             //Существующие настройки для группы
                         } elseif ($el['prof_id'] == 0 && $el['group_id'] == $group_id && $el['is_default'] == 'f') {
                             $is_exist_setting_for_group = true;
                         }
                     }
                 }
                 //Если настройки для каталога нет и эта основная
                 //специализация то ее добавляем в общий каталог
                 $data_extended = array();
                 $current_settings = $this->id > 0 ? $current_settings : $current_settings + $this->data;
                 if (!$is_exist_setting_for_catalog) {
                     $is_main_prof = (bool) $this->db()->val('SELECT 1 FROM freelancer 
                              WHERE uid = ?i AND spec = ?i LIMIT 1', $this->uid, $this->prof_id);
                     if ($is_main_prof) {
                         foreach ($current_settings as $el) {
                             $el['prof_id'] = 0;
                             $el['group_id'] = 0;
                             $el['is_default'] = true;
                             $data_extended[] = $el;
                         }
                     }
                 }
                 //Если нет настроек для группы раздела то добавляем текущии
                 //настройки как поумолчанию для группы
                 if (!$is_exist_setting_for_group) {
                     foreach ($current_settings as $el) {
                         $el['prof_id'] = 0;
                         $el['group_id'] = $group_id;
                         $el['is_default'] = true;
                         $data_extended[] = $el;
                     }
                 }
                 if ($data_extended) {
                     $this->data_extra_update = $data_extended;
                 }
             }
         }
     }
     return $this->is_valid;
 }