예제 #1
0
 /**
  * @author Okan CIRAN
  * @ firmanın sözel verilerinin danısman bilgisini döndürür !!
  * @version v 1.0  23.05.2016
  * @param array | null $args
  * @return array
  * @throws \PDOException
  */
 public function getFirmVerbalConsultant($params = array())
 {
     try {
         $pdo = $this->slimApp->getServiceManager()->get('pgConnectFactory');
         $opUserId = InfoUsers::getUserId(array('pk' => $params['pk']));
         if (\Utill\Dal\Helper::haveRecord($opUserId)) {
             $opUserIdValue = $opUserId['resultSet'][0]['user_id'];
             $getFirm = InfoFirmProfile::getCheckIsThisFirmRegisteredUser(array('cpk' => $params['cpk'], 'op_user_id' => $opUserIdValue));
             if (\Utill\Dal\Helper::haveRecord($getFirm)) {
                 $getFirmId = $getFirm['resultSet'][0]['firm_id'];
                 $languageId = NULL;
                 $languageIdValue = 647;
                 if (isset($params['language_code']) && $params['language_code'] != "") {
                     $languageId = SysLanguage::getLanguageId(array('language_code' => $params['language_code']));
                     if (\Utill\Dal\Helper::haveRecord($languageId)) {
                         $languageIdValue = $languageId['resultSet'][0]['id'];
                     }
                 }
                 $sql = "\n                SELECT DISTINCT \n                    a.id AS firm_id,                          \n                    ifv.consultant_id,                   \n                    iud.name, \n                    iud.surname,\n                    iud.auth_email, \n                    ifk.network_key,\n\t\t    CASE COALESCE(NULLIF(TRIM(iud.picture), ''),'-') \n                        WHEN '-' THEN CONCAT(COALESCE(NULLIF(concat(sps.folder_road,'/'), '/'),''),sps.members_folder,'/' ,'image_not_found.png')\n                        ELSE CONCAT(COALESCE(NULLIF(concat(sps.folder_road,'/'), '/'),''),sps.members_folder,'/' ,TRIM(iud.picture)) END AS cons_picture \n                FROM info_firm_profile a\n                INNER JOIN sys_project_settings sps ON sps.op_project_id = 1 AND sps.active =0 AND sps.deleted =0 \n                INNER JOIN info_firm_keys ifk ON ifk.firm_id =  a.act_parent_id \n                INNER JOIN sys_language l ON l.id = a.language_id AND l.deleted =0 AND l.active =0 \n                LEFT JOIN sys_language lx ON lx.id = " . intval($languageIdValue) . " AND l.deleted =0 AND l.active =0 \n\t\tLEFT JOIN info_firm_profile ax ON (ax.id = a.id OR ax.language_parent_id = a.id) AND ax.language_id = lx.id AND ax.active =0 AND ax.deleted =0\n\t\tINNER JOIN info_firm_verbal ifv ON ifv.firm_id = ifk.firm_id AND ifv.deleted = 0 AND ifv.active =0 AND ifv.language_parent_id=0  \n\t\tLEFT JOIN info_firm_verbal ifvx ON (ifvx.id = ifv.id OR ifvx.language_parent_id = ifv.id) AND ifvx.deleted = 0 AND ifvx.active =0 AND ifvx.language_id = lx.id\n                INNER JOIN info_users u ON u.id = ifv.consultant_id AND u.role_id in (1,2,6)\n                INNER JOIN info_users_detail iud ON iud.root_id = u.id AND iud.cons_allow_id = 2    \n                WHERE    \n                    a.act_parent_id = " . intval($getFirmId) . "  \n                ORDER BY  iud.name, iud.surname \n                ";
                 $statement = $pdo->prepare($sql);
                 //   echo debugPDO($sql, $params);
                 $statement->execute();
                 $result = $statement->fetchAll(\PDO::FETCH_ASSOC);
                 $errorInfo = $statement->errorInfo();
                 if ($errorInfo[0] != "00000" && $errorInfo[1] != NULL && $errorInfo[2] != NULL) {
                     throw new \PDOException($errorInfo[0]);
                 }
                 return array("found" => true, "errorInfo" => $errorInfo, "resultSet" => $result);
             } else {
                 $errorInfo = '23502';
                 // 23502  not_null_violation
                 $errorInfoColumn = 'cpk';
                 $pdo->rollback();
                 return array("found" => false, "errorInfo" => $errorInfo, "resultSet" => '', "errorInfoColumn" => $errorInfoColumn);
             }
         } else {
             $errorInfo = '23502';
             // 23502  not_null_violation
             $errorInfoColumn = 'pk';
             $pdo->rollback();
             return array("found" => false, "errorInfo" => $errorInfo, "resultSet" => '', "errorInfoColumn" => $errorInfoColumn);
         }
     } catch (\PDOException $e) {
         //$debugSQLParams = $statement->debugDumpParams();
         return array("found" => false, "errorInfo" => $e->getMessage());
     }
 }
 /**
  * @author Okan CIRAN
  * info_firm_address tablosuna parametre olarak gelen id deki kaydın bilgilerini günceller   !!
  * @version v 1.0  16.05.2016
  * @param array | null $args
  * @return array
  * @throws \PDOException
  */
 public function update($params = array())
 {
     try {
         $pdo = $this->slimApp->getServiceManager()->get('pgConnectFactory');
         $pdo->beginTransaction();
         $opUserId = InfoUsers::getUserId(array('pk' => $params['pk']));
         if (\Utill\Dal\Helper::haveRecord($opUserId)) {
             $opUserIdValue = $opUserId['resultSet'][0]['user_id'];
             $getFirm = InfoFirmProfile::getCheckIsThisFirmRegisteredUser(array('cpk' => $params['cpk'], 'op_user_id' => $opUserIdValue));
             if (\Utill\Dal\Helper::haveRecord($getFirm)) {
                 $getFirmId = $getFirm['resultSet'][0]['firm_id'];
                 $kontrol = $this->haveRecords(array('id' => $params['id'], 'firm_id' => $getFirmId, 'firm_building_type_id' => $params['firm_building_type_id']));
                 if (!\Utill\Dal\Helper::haveRecord($kontrol)) {
                     $this->makePassive(array('id' => $params['id']));
                     $operationIdValue = -2;
                     $operationId = SysOperationTypes::getTypeIdToGoOperationId(array('parent_id' => 3, 'main_group' => 3, 'sub_grup_id' => 2, 'type_id' => 2));
                     if (\Utill\Dal\Helper::haveRecord($operationId)) {
                         $operationIdValue = $operationId['resultSet'][0]['id'];
                     }
                     $languageId = NULL;
                     $languageIdValue = 647;
                     if (isset($params['language_code']) && $params['language_code'] != "") {
                         $languageId = SysLanguage::getLanguageId(array('language_code' => $params['language_code']));
                         if (\Utill\Dal\Helper::haveRecord($languageId)) {
                             $languageIdValue = $languageId['resultSet'][0]['id'];
                         }
                     }
                     $profilePublic = 0;
                     if (isset($params['profile_public']) && $params['profile_public'] != "") {
                         $profilePublic = $params['profile_public'];
                     }
                     $active = 0;
                     if (isset($params['active']) && $params['active'] != "") {
                         $active = $params['active'];
                     }
                     $osbId = 0;
                     if (isset($params['osb_id']) && $params['osb_id'] != "") {
                         $osbId = $params['osb_id'];
                     }
                     $sql = " \n                 INSERT INTO info_firm_address(\n                        firm_id, \n                        consultant_id,\n                        operation_type_id,\n                        language_id,\n                        op_user_id, \n                        profile_public,\n                        act_parent_id,  \n                        firm_building_type_id,\n                        firm_building_name, \n                        address, \n                        borough_id, \n                        city_id, \n                        country_id,\n                        description,\n                        description_eng,\n                        osb_id,\n                        tel,\n                        fax,\n                        email,\n                        active,\n                        language_parent_id\n                        )                      \n                        SELECT                              \n                            firm_id,\n                            consultant_id,\n                            " . intval($operationIdValue) . ",\n                            " . intval($languageIdValue) . ",\n                            " . intval($opUserIdValue) . ",\n                            " . intval($profilePublic) . " AS profile_public, \n                            act_parent_id,                                \n                            " . intval($params['firm_building_type_id']) . " AS firm_building_type_id,\n                            '" . $params['firm_building_name'] . "' AS firm_building_name,\n                            '" . $params['address'] . "' AS address,\n                            " . intval($params['borough_id']) . " AS borough_id,  \n                            " . intval($params['city_id']) . " AS city_id,  \n                            " . intval($params['country_id']) . " AS country_id, \n                            '" . $params['description'] . "' AS description,\n                            '" . $params['description_eng'] . "' AS description_eng,\n                            " . intval($params['osb_id']) . " AS osb_id, \n                            '" . $params['tel'] . "' AS tel,\n                            '" . $params['fax'] . "' AS fax,\n                            '" . $params['email'] . "' AS email,\n                            " . intval($active) . " AS active, \n                            language_parent_id\n                        FROM info_firm_address \n                        WHERE id =  " . intval($params['id']) . " \n                        ";
                     $statement_act_insert = $pdo->prepare($sql);
                     //  echo debugPDO($sql, $params);
                     $insert_act_insert = $statement_act_insert->execute();
                     $affectedRows = $statement_act_insert->rowCount();
                     $insertID = $pdo->lastInsertId('info_firm_address_id_seq');
                     $errorInfo = $statement_act_insert->errorInfo();
                     if ($errorInfo[0] != "00000" && $errorInfo[1] != NULL && $errorInfo[2] != NULL) {
                         throw new \PDOException($errorInfo[0]);
                     }
                     /*
                      * ufak bir trik var. 
                      * işlem update oldugunda update işlemini yapan kişinin dil bilgisini kullanıcaz. 
                      * ancak delete işlemi oldugunda delete işlemini yapan user in dil bilgisini değil 
                      * silinen kaydı yapan kişinin dil bilgisini alıcaz.
                      */
                     $consIdAndLanguageId = SysOperationTypes::getConsIdAndLanguageId(array('table_name' => 'info_firm_address', 'id' => $params['id']));
                     if (\Utill\Dal\Helper::haveRecord($consIdAndLanguageId)) {
                         $ConsultantId = $consIdAndLanguageId['resultSet'][0]['consultant_id'];
                         // $languageIdValue = $consIdAndLanguageId ['resultSet'][0]['language_id'];
                     }
                     $xjobs = ActProcessConfirm::insert(array('op_user_id' => intval($opUserIdValue), 'operation_type_id' => intval($operationIdValue), 'table_column_id' => intval($insertID), 'cons_id' => intval($ConsultantId), 'preferred_language_id' => intval($languageIdValue)));
                     if ($xjobs['errorInfo'][0] != "00000" && $xjobs['errorInfo'][1] != NULL && $xjobs['errorInfo'][2] != NULL) {
                         throw new \PDOException($xjobs['errorInfo']);
                     }
                     $pdo->commit();
                     return array("found" => true, "errorInfo" => $errorInfo, "affectedRowsCount" => $affectedRows);
                 } else {
                     // 23505  unique_violation
                     $errorInfo = '23505';
                     $errorInfoColumn = 'firm_building_type_id';
                     $pdo->rollback();
                     $result = $kontrol;
                     return array("found" => false, "errorInfo" => $errorInfo, "resultSet" => '', "errorInfoColumn" => $errorInfoColumn);
                 }
             } else {
                 $errorInfo = '23502';
                 // 23502  not_null_violation
                 $errorInfoColumn = 'cpk';
                 $pdo->rollback();
                 return array("found" => false, "errorInfo" => $errorInfo, "resultSet" => '', "errorInfoColumn" => $errorInfoColumn);
             }
         } else {
             $errorInfo = '23502';
             // 23502  not_null_violation
             $errorInfoColumn = 'pk';
             $pdo->rollback();
             return array("found" => false, "errorInfo" => $errorInfo, "resultSet" => '', "errorInfoColumn" => $errorInfoColumn);
         }
     } catch (\PDOException $e) {
         $pdo->rollback();
         return array("found" => false, "errorInfo" => $e->getMessage());
     }
 }
 /**      
  * @author Okan CIRAN
  * @ Quest için npk lı firmanın danısman tarafından onaylanmış kayıtların sayısını döndürür !!
  * @version v 1.0  30.05.2016
  * @param array | null $args
  * @return array
  * @throws \PDOException
  */
 public function fillFirmSectorNpkQuestRtc($params = array())
 {
     try {
         $pdo = $this->slimApp->getServiceManager()->get('pgConnectFactory');
         $firmIdValue = NULL;
         $getFirm = InfoFirmProfile::getFirmIdsForNetworkKey(array('network_key' => $params['network_key']));
         if (\Utill\Dal\Helper::haveRecord($getFirm)) {
             $firmIdValue = $getFirm['resultSet'][0]['firm_id'];
             $sql = " \n                    SELECT \n                        COUNT(a.id) AS count \n                    FROM info_firm_sectoral a\n                    INNER JOIN info_users u ON u.id = a.op_user_id\n                    INNER JOIN info_firm_profile fp ON fp.act_parent_id = a.firm_id AND fp.cons_allow_id=2 AND fp.language_parent_id =0\n                    INNER JOIN sys_language l ON l.id = fp.language_id AND l.deleted =0 AND l.active =0                    \n                    INNER JOIN info_firm_keys ifk ON fp.act_parent_id = ifk.firm_id  \n\t\t    INNER JOIN sys_sectors ss ON ss.id = a.sector_id AND ss.deleted =0 AND ss.active =0 AND ss.language_parent_id =0                    \n\t\t    WHERE \n                        a.firm_id =  " . intval($firmIdValue) . " AND\n                        a.cons_allow_id =2 AND\n\t\t\ta.profile_public=0                 \n                            ";
             $statement = $pdo->prepare($sql);
             //echo debugPDO($sql, $params);
             $statement->execute();
             $result = $statement->fetchAll(\PDO::FETCH_ASSOC);
             $errorInfo = $statement->errorInfo();
             if ($errorInfo[0] != "00000" && $errorInfo[1] != NULL && $errorInfo[2] != NULL) {
                 throw new \PDOException($errorInfo[0]);
             }
             return array("found" => true, "errorInfo" => $errorInfo, "resultSet" => $result);
         } else {
             $errorInfo = '23502';
             // 23502  not_null_violation
             $errorInfoColumn = 'npk';
             $pdo->rollback();
             return array("found" => false, "errorInfo" => $errorInfo, "resultSet" => '', "errorInfoColumn" => $errorInfoColumn);
         }
     } catch (\PDOException $e) {
         return array("found" => false, "errorInfo" => $e->getMessage());
     }
 }
 /**
  * @author Okan CIRAN
  * @ info_firm_socialmedia tablosuna yeni bir kayıt oluşturur.  !!
  * @version v 1.0  09.05.2016
  * @param type $params
  * @return array
  * @throws \PDOException
  */
 public function insert($params = array())
 {
     try {
         $pdo = $this->slimApp->getServiceManager()->get('pgConnectFactory');
         $pdo->beginTransaction();
         $opUserId = InfoUsers::getUserId(array('pk' => $params['pk']));
         if (\Utill\Dal\Helper::haveRecord($opUserId)) {
             $opUserIdValue = $opUserId['resultSet'][0]['user_id'];
             $userfirmIdValue = -22;
             $userfirmId = InfoFirmProfile::getUserFirmIds(array('user_id' => $opUserIdValue));
             if (\Utill\Dal\Helper::haveRecord($userfirmId)) {
                 $userfirmIdValue = $userfirmId['resultSet'][0]['firm_id'];
             }
             $firmIdValue = -11;
             $firmId = InfoFirmProfile::getFirmIdsForNetworkKey(array('network_key' => $params['network_key']));
             if (\Utill\Dal\Helper::haveRecord($firmId)) {
                 $firmIdValue = $firmId['resultSet'][0]['firm_id'];
             }
             if ($firmIdValue == $userfirmIdValue) {
                 $kontrol = $this->haveRecords(array('firm_link' => $params['firm_link']));
                 if (!\Utill\Dal\Helper::haveRecord($kontrol)) {
                     $operationIdValue = -1;
                     $operationId = SysOperationTypes::getTypeIdToGoOperationId(array('parent_id' => 3, 'main_group' => 3, 'sub_grup_id' => 29, 'type_id' => 1));
                     if (\Utill\Dal\Helper::haveRecord($operationId)) {
                         $operationIdValue = $operationId['resultSet'][0]['id'];
                     }
                     $languageId = NULL;
                     $languageIdValue = 647;
                     if (isset($params['language_code']) && $params['language_code'] != "") {
                         $languageId = SysLanguage::getLanguageId(array('language_code' => $params['language_code']));
                         if (\Utill\Dal\Helper::haveRecord($languageId)) {
                             $languageIdValue = $languageId['resultSet'][0]['id'];
                         }
                     }
                     $ConsultantId = 1001;
                     $getConsultant = SysOsbConsultants::getConsultantIdForTableName(array('table_name' => 'info_firm_socialmedia', 'operation_type_id' => $operationIdValue, 'language_id' => $languageIdValue));
                     if (\Utill\Dal\Helper::haveRecord($getConsultant)) {
                         $ConsultantId = $getConsultant['resultSet'][0]['consultant_id'];
                     }
                     $sql = "\n                INSERT INTO info_firm_socialmedia(                        \n                        firm_id, \n                        profile_public, \n                        op_user_id, \n                        operation_type_id, \n                        consultant_id, \n                        sys_socialmedia_id, \n                        act_parent_id, \n                        firm_link\n                         )\n                VALUES (\n                        :firm_id, \n                        :profile_public, \n                        :op_user_id, \n                        :operation_type_id, \n                        :consultant_id, \n                        :sys_socialmedia_id, \n                        (SELECT last_value FROM info_firm_socialmedia_id_seq), \n                        :firm_link\n                                             )   ";
                     $statement = $pdo->prepare($sql);
                     $statement->bindValue(':profile_public', $params['profile_public'], \PDO::PARAM_INT);
                     $statement->bindValue(':operation_type_id', $operationIdValue, \PDO::PARAM_INT);
                     $statement->bindValue(':consultant_id', $ConsultantId, \PDO::PARAM_INT);
                     $statement->bindValue(':sys_socialmedia_id', $params['sys_socialmedia_id'], \PDO::PARAM_INT);
                     $statement->bindValue(':firm_id', $firmIdValue, \PDO::PARAM_INT);
                     $statement->bindValue(':op_user_id', $opUserIdValue, \PDO::PARAM_INT);
                     $statement->bindValue(':firm_link', $params['firm_link'], \PDO::PARAM_STR);
                     //  echo debugPDO($sql, $params);
                     $result = $statement->execute();
                     $insertID = $pdo->lastInsertId('info_firm_socialmedia_id_seq');
                     $errorInfo = $statement->errorInfo();
                     if ($errorInfo[0] != "00000" && $errorInfo[1] != NULL && $errorInfo[2] != NULL) {
                         throw new \PDOException($errorInfo[0]);
                     }
                     $xjobs = ActProcessConfirm::insert(array('op_user_id' => intval($opUserIdValue), 'operation_type_id' => intval($operationIdValue), 'table_column_id' => intval($insertID), 'cons_id' => intval($ConsultantId), 'preferred_language_id' => intval($languageIdValue)));
                     if ($xjobs['errorInfo'][0] != "00000" && $xjobs['errorInfo'][1] != NULL && $xjobs['errorInfo'][2] != NULL) {
                         throw new \PDOException($xjobs['errorInfo']);
                     }
                     $pdo->commit();
                     return array("found" => true, "errorInfo" => $errorInfo, "lastInsertId" => $insertID);
                 } else {
                     $errorInfo = '23502';
                     $errorInfoColumn = 'firm_link';
                     $pdo->rollback();
                     return array("found" => false, "errorInfo" => $errorInfo, "resultSet" => '', "errorInfoColumn" => $errorInfoColumn);
                 }
             } else {
                 $errorInfo = '23505';
                 $errorInfoColumn = 'firm_id';
                 $pdo->rollback();
                 return array("found" => false, "errorInfo" => $errorInfo, "resultSet" => '', "errorInfoColumn" => $errorInfoColumn);
             }
         } else {
             $errorInfo = '23502';
             // 23502  not_null_violation
             $errorInfoColumn = 'pk';
             $pdo->rollback();
             return array("found" => false, "errorInfo" => $errorInfo, "resultSet" => '', "errorInfoColumn" => $errorInfoColumn);
         }
     } catch (\PDOException $e) {
         $pdo->rollback();
         return array("found" => false, "errorInfo" => $e->getMessage());
     }
 }
 /**
  * @author Okan CIRAN
  * @ Gridi doldurmak için consultant ların yaptığı operasyon kayıtlarını döndürür !!
  * @version v 1.0  08.02.2016
  * @param array | null $args
  * @return array
  * @throws \PDOException
  */
 public function getAllFirmCons($params = array())
 {
     try {
         $pdo = $this->slimApp->getServiceManager()->get('pgConnectFactory');
         $opUserId = InfoUsers::getUserId(array('pk' => $params['pk']));
         if (\Utill\Dal\Helper::haveRecord($opUserId)) {
             $opUserIdValue = $opUserId['resultSet'][0]['user_id'];
             $getFirm = InfoFirmProfile::getCheckIsThisFirmRegisteredUser(array('cpk' => $params['cpk'], 'op_user_id' => $opUserIdValue));
             if (\Utill\Dal\Helper::haveRecord($getFirm)) {
                 $getFirmIdValue = $getFirm['resultSet'][0]['firm_id'];
                 $languageId = NULL;
                 $languageIdValue = 647;
                 if (isset($params['language_code']) && $params['language_code'] != "") {
                     $languageId = SysLanguage::getLanguageId(array('language_code' => $params['language_code']));
                     if (\Utill\Dal\Helper::haveRecord($languageId)) {
                         $languageIdValue = $languageId['resultSet'][0]['id'];
                     }
                 }
                 $sql = "                \n                SELECT DISTINCT\n                    a.act_parent_id AS firm_id,\n                    u.id AS consultant_id,\n                    iud.name, \n                    iud.surname,\n                    iud.auth_email,                \n                    CASE COALESCE(NULLIF(TRIM(iud.picture), ''),'-') \n                        WHEN '-' THEN CONCAT(COALESCE(NULLIF(concat(sps.folder_road,'/'), '/'),''),sps.members_folder,'/' ,'image_not_found.png')\n                        ELSE CONCAT(COALESCE(NULLIF(concat(sps.folder_road,'/'), '/'),''),sps.members_folder,'/' ,TRIM(iud.picture)) END AS cons_picture,\n                    a.consultant_id  = u.id AS firm_consultant,\n                    COALESCE(NULLIF(ifux.title, ''), ifux.title_eng) AS title,\n                    ifu.title_eng,\n                    COALESCE(NULLIF(soc.title, ''), soc.title_eng) AS osb_title,\n                    soc.title_eng osb_title_eng,\n                    ifk.network_key\n                FROM info_firm_profile a   \n                INNER JOIN sys_project_settings sps ON sps.op_project_id = 1 AND sps.active =0 AND sps.deleted =0 \n                INNER JOIN info_firm_keys ifk ON ifk.firm_id = a.act_parent_id \n                INNER JOIN sys_language l ON l.id = a.language_id AND l.deleted =0 AND l.active =0 \n                LEFT JOIN sys_language lx ON lx.id = " . intval($languageIdValue) . " AND l.deleted =0 AND l.active =0 \n\t\tLEFT JOIN info_firm_profile ax ON (ax.id = a.id OR ax.language_parent_id = a.id) AND ax.language_id = lx.id AND ax.active =0 AND ax.deleted =0\n                INNER JOIN info_users u ON u.role_id in (1,2,6) AND u.deleted =0  \n                INNER JOIN sys_osb_consultants soc ON soc.active = 0 AND soc.deleted =0 AND soc.user_id = u.id\n                INNER JOIN info_users_detail iud ON iud.root_id = u.id AND iud.cons_allow_id = 2\n                INNER JOIN info_users_communications iuc ON iuc.user_id = u.id AND iuc.cons_allow_id = 2\n                INNER JOIN info_firm_users ifu ON ifu.user_id = u.id AND ifu.firm_id = 1 AND ifu.cons_allow_id = 2\n                LEFT JOIN info_firm_users ifux ON (ifux.id = ifu.id OR ifux.language_parent_id = ifu.id) AND ifu.cons_allow_id = 2 AND ifux.language_id = lx.id\n                INNER JOIN sys_specific_definitions sd5 ON sd5.main_group = 5 AND sd5.first_group = iuc.communications_type_id AND sd5.deleted =0 AND sd5.active =0 AND l.id = sd5.language_id\n\t\tLEFT JOIN sys_specific_definitions sd5x ON (sd5x.id =sd5.id OR sd5x.language_parent_id = sd5.id) AND sd5x.deleted =0 AND sd5x.active =0 AND lx.id = sd5x.language_id\n                WHERE\n                    a.act_parent_id = " . intval($getFirmIdValue) . " AND                          \n                        u.id IN (\n                            SELECT DISTINCT consultant_id FROM info_firm_profile WHERE act_parent_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_academics WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_socialmedia WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_address WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_arge WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_building WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_certificate WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_clusters where firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_building WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_commercial_activity WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_communications WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_customers WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_energy_efficiency WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_fair WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_financial WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_green_energy_plant WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_language_info WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_machine_tool WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_machine_tool_work_schedule WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_membership WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_other_devices WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_personnel_info WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_potential WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_process WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_process_allocation WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_products WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_products_services WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_raw_materials WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_quality WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_recycling_plant WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_references WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_sectoral WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_university WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_user_desc_for_company WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_users WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_verbal WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_waste WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_work_safety WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_workflow_definition WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_workflow_materials WHERE firm_id = " . intval($getFirmIdValue) . " \n                            UNION\n                            SELECT DISTINCT consultant_id FROM info_firm_workflow_process WHERE firm_id = " . intval($getFirmIdValue) . " \n                        )\n                        ORDER BY firm_consultant DESC,iud.name,iud.surname \n                        ";
                 $statement = $pdo->prepare($sql);
                 // echo debugPDO($sql, $params);
                 $statement->execute();
                 $result = $statement->fetchAll(\PDO::FETCH_ASSOC);
                 $errorInfo = $statement->errorInfo();
                 if ($errorInfo[0] != "00000" && $errorInfo[1] != NULL && $errorInfo[2] != NULL) {
                     throw new \PDOException($errorInfo[0]);
                 }
                 return array("found" => true, "errorInfo" => $errorInfo, "resultSet" => $result);
             } else {
                 $errorInfo = '23502';
                 // 23502  not_null_violation
                 $errorInfoColumn = 'npk';
                 $pdo->rollback();
                 return array("found" => false, "errorInfo" => $errorInfo, "resultSet" => '', "errorInfoColumn" => $errorInfoColumn);
             }
         } else {
             $errorInfo = '23502';
             // 23502  not_null_violation
             $errorInfoColumn = 'pk';
             return array("found" => false, "errorInfo" => $errorInfo, "resultSet" => '', "errorInfoColumn" => $errorInfoColumn);
         }
     } catch (\PDOException $e) {
         //$debugSQLParams = $statement->debugDumpParams();
         return array("found" => false, "errorInfo" => $e->getMessage());
     }
 }
 /**
  * @author Okan CIRAN
  * kullanıcı - info_firm_machine_tool tablosuna parametre olarak gelen id deki kaydın bilgilerini günceller   !!
  * @version v 1.0  18.02.2016
  * @param array | null $args
  * @return array
  * @throws \PDOException
  */
 public function update($params = array())
 {
     try {
         $pdo = $this->slimApp->getServiceManager()->get('pgConnectFactory');
         $pdo->beginTransaction();
         $opUserId = InfoUsers::getUserId(array('pk' => $params['pk']));
         if (\Utill\Dal\Helper::haveRecord($opUserId)) {
             $opUserIdValue = $opUserId['resultSet'][0]['user_id'];
             $getFirm = InfoFirmProfile::getFirmIdsForNetworkKey(array('network_key' => $params['network_key']));
             if (\Utill\Dal\Helper::haveRecord($getFirm)) {
                 $getFirmId = $getFirm['resultSet'][0]['firm_id'];
                 $kontrol = $this->haveRecords(array('id' => $params['id'], 'firm_id' => $getFirmId, 'machine_id' => $params['sys_machine_tool_id']));
                 if (!\Utill\Dal\Helper::haveRecord($kontrol)) {
                     $this->makePassive(array('id' => $params['id']));
                     $operationIdValue = -2;
                     $operationId = SysOperationTypes::getTypeIdToGoOperationId(array('parent_id' => 3, 'main_group' => 3, 'sub_grup_id' => 41, 'type_id' => 2));
                     if (\Utill\Dal\Helper::haveRecord($operationId)) {
                         $operationIdValue = $operationId['resultSet'][0]['id'];
                     }
                     $languageId = NULL;
                     $languageIdValue = 647;
                     if (isset($params['language_code']) && $params['language_code'] != "") {
                         $languageId = SysLanguage::getLanguageId(array('language_code' => $params['language_code']));
                         if (\Utill\Dal\Helper::haveRecord($languageId)) {
                             $languageIdValue = $languageId['resultSet'][0]['id'];
                         }
                     }
                     $availabilityId = NULL;
                     if (isset($params['availability_id']) && $params['availability_id'] != "") {
                         $availabilityId = intval($params['availability_id']);
                     }
                     $sysMachineToolId = NULL;
                     if (isset($params['sys_machine_tool_id']) && $params['sys_machine_tool_id'] != "") {
                         $sysMachineToolId = intval($params['sys_machine_tool_id']);
                     }
                     $statement_act_insert = $pdo->prepare(" \n                 INSERT INTO info_firm_machine_tool(\n                        profile_public, \n                        language_id,\n                        op_user_id,\n                        operation_type_id,\n                        act_parent_id,   \n                        firm_id, \n                        availability_id, \n                        sys_machine_tool_id, \n                        consultant_id, \n                        language_parent_id,\n                        total,\n                        picture\n                        )\n                        SELECT  \n                            " . intval($params['profile_public']) . " AS profile_public, \n                            " . intval($languageIdValue) . ",   \n                            " . intval($opUserIdValue) . ",\n                            " . intval($operationIdValue) . ",    \n                            act_parent_id,                       \n                            firm_id, \n                            " . intval($availabilityId) . " AS availability_id,\n                            " . intval($sysMachineToolId) . " AS sys_machine_tool_id,                            \n                            consultant_id,\n                            language_parent_id,\n                            " . intval($params['total']) . " AS total,\n                            '" . $params['picture'] . "' AS picture\n                        FROM info_firm_machine_tool \n                        WHERE id =  " . intval($params['id']) . " \n                        ");
                     $insert_act_insert = $statement_act_insert->execute();
                     $affectedRows = $statement_act_insert->rowCount();
                     $insertID = $pdo->lastInsertId('info_firm_machine_tool_id_seq');
                     $errorInfo = $statement_act_insert->errorInfo();
                     if ($errorInfo[0] != "00000" && $errorInfo[1] != NULL && $errorInfo[2] != NULL) {
                         throw new \PDOException($errorInfo[0]);
                     }
                     /*
                      * ufak bir trik var. 
                      * işlem update oldugunda update işlemini yapan kişinin dil bilgisini kullanıcaz. 
                      * ancak delete işlemi oldugunda delete işlemini yapan user in dil bilgisini değil 
                      * silinen kaydı yapan kişinin dil bilgisini alıcaz.
                      */
                     $consIdAndLanguageId = SysOperationTypes::getConsIdAndLanguageId(array('table_name' => 'info_firm_machine_tool', 'id' => $params['id']));
                     if (\Utill\Dal\Helper::haveRecord($consIdAndLanguageId)) {
                         $ConsultantId = $consIdAndLanguageId['resultSet'][0]['consultant_id'];
                         // $languageIdValue = $consIdAndLanguageId ['resultSet'][0]['language_id'];
                     }
                     $xjobs = ActProcessConfirm::insert(array('op_user_id' => intval($opUserIdValue), 'operation_type_id' => intval($operationIdValue), 'table_column_id' => intval($insertID), 'cons_id' => intval($ConsultantId), 'preferred_language_id' => intval($languageIdValue)));
                     if ($xjobs['errorInfo'][0] != "00000" && $xjobs['errorInfo'][1] != NULL && $xjobs['errorInfo'][2] != NULL) {
                         throw new \PDOException($xjobs['errorInfo']);
                     }
                     $pdo->commit();
                     return array("found" => true, "errorInfo" => $errorInfo, "affectedRowsCount" => $affectedRows);
                 } else {
                     // 23505  unique_violation
                     $errorInfo = '23505';
                     $pdo->rollback();
                     $result = $kontrol;
                     return array("found" => false, "errorInfo" => $errorInfo, "resultSet" => '');
                 }
             } else {
                 $errorInfo = '23502';
                 // 23502  not_null_violation
                 $errorInfoColumn = 'npk';
                 $pdo->rollback();
                 return array("found" => false, "errorInfo" => $errorInfo, "resultSet" => '', "errorInfoColumn" => $errorInfoColumn);
             }
         } else {
             $errorInfo = '23502';
             // 23502  not_null_violation
             $errorInfoColumn = 'pk';
             $pdo->rollback();
             return array("found" => false, "errorInfo" => $errorInfo, "resultSet" => '', "errorInfoColumn" => $errorInfoColumn);
         }
     } catch (\PDOException $e) {
         $pdo->rollback();
         return array("found" => false, "errorInfo" => $e->getMessage());
     }
 }