/**      
  * @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
  * @ firmanın danısman bilgisini döndürür !!
  * @version v 1.0  09.02.2016
  * @param array | null $args
  * @return array
  * @throws \PDOException
  */
 public function getFirmProfileConsultant($params = array())
 {
     try {
         $pdo = $this->slimApp->getServiceManager()->get('pgConnectFactory');
         $getFirmIdValue = -1;
         $getFirm = InfoFirmProfile::getFirmIdsForNetworkKey(array('network_key' => $params['network_key']));
         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.id AS firm_id,\n                    a.consultant_id,\n                    iud.name, \n                    iud.surname,\n                    iud.auth_email,\n                    \n\t\t    \n                    \n                    ifk.network_key,\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                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.id = a.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                INNER JOIN info_users_communications iuc ON iuc.user_id = u.id AND iuc.cons_allow_id = 2\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) . "\n                ORDER BY  iud.name, iud.surname \n                ";
             $statement = $pdo->prepare($sql);
             //  echo debugPDO($sql, $parameters);
             $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  user_id not_null_violation
             $errorInfoColumn = 'network_key';
             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());
     }
 }