Exemplo n.º 1
0
 /**
  * Выбор пользователя в предложении к проекту
  * 
  * @param  array $aParams массив входящих данных
  * @return array $aResult ответ
  */
 protected function x____projects_response_select($aParams = array())
 {
     $this->_validDevice($aParams);
     require_once ABS_PATH . '/classes/projects_offers.php';
     $nUid = get_uid(false);
     $oOffer = new projects_offers();
     $nId = intvalPgSql($aParams['id']);
     $aOffer = $oOffer->GetPrjOfferById($nId);
     if (is_array($aOffer) && $aOffer) {
         require_once ABS_PATH . '/classes/projects.php';
         $oPrj = new new_projects();
         $aProject = $oPrj->GetPrjCust($aOffer['project_id']);
         if (!empty($aProject) || $aProject['is_blocked'] == 'f') {
             // Не позволяем производить действия с заблокированным проектом
             if ($nUid == $aProject['user_id']) {
                 $nSelect = intvalPgSql($aParams['select']);
                 if ($nSelect > 0 && $nSelect < 4) {
                     $aOffer['emp_uid'] = $aProject['user_id'];
                     switch ($nSelect) {
                         case 1:
                             $error = false;
                             if ($aProject['exec_id'] == $aOffer['user_id']) {
                                 $error = $oPrj->ClearExecutor($aProject['id'], $nUid);
                             }
                             if (!$error) {
                                 $error = $oOffer->SetRefused($aOffer['id'], $aProject['id'], $aOffer['user_id'], '', true);
                             }
                             if ($error) {
                                 $this->error(EXTERNAL_ERR_SERVER_ERROR);
                             } else {
                                 $aOffer['refused'] = 't';
                             }
                             break;
                         case 2:
                             $error = false;
                             if ($aProject['exec_id'] == $aOffer['user_id']) {
                                 $error = $oPrj->ClearExecutor($aProject['id'], $nUid);
                             }
                             if (!$error) {
                                 $error = $oOffer->SetSelected($aOffer['id'], $aProject['id'], $aOffer['user_id'], true);
                             }
                             if ($error) {
                                 $this->error(EXTERNAL_ERR_SERVER_ERROR);
                             } else {
                                 $aOffer['selected'] = 't';
                             }
                             break;
                         case 3:
                             if ($oPrj->SetExecutor($aProject['id'], $aOffer['user_id'], $nUid)) {
                                 $this->error(EXTERNAL_ERR_SERVER_ERROR);
                             } else {
                                 $aOffer['exec_id'] = $aOffer['user_id'];
                             }
                             break;
                     }
                     $aResult = array('project_response' => $this->_getProjectOfferData($aOffer));
                 } else {
                     $this->error(EXTERNAL_ERR_PRJ_SELECTED);
                 }
             } else {
                 $this->error(EXTERNAL_ERR_OWNER);
             }
         } else {
             $this->error(EXTERNAL_ERR_PROJECT_NOT_FOUND);
         }
     } else {
         $this->error(EXTERNAL_ERR_OFFER_NOT_FOUND);
     }
     return $aResult;
 }