Do we need to update session data? $auth = \Utility\Registry::getAuthData(); if ($auth['company']['id'] == $record->id) { $companyData = $record->toArray(array( 'city', 'region', 'contact' )); \Utility\Registry::setAuthParam('company', $companyData); } } public function linkPublicCentreClubs($companyId) { set_time_limit(0); ini_set('memory_limit','1024M'); $record = $this->em->find('Company\\Entity\\Company', $companyId); $dealershipName = $record->name; $companyId = $record->id; $isPublicCentre = $record->publicCentre; $today = new \DateTime (); $em = \Utility\Registry::getEntityManager (); $dealershipName = $dealershipName . ' Traders Club'; //\Utility\Debug::errorLog ( 'New dealer updated $dealershipName', $dealershipName ); //\Utility\Debug::errorLog ( 'New dealer updated company id', $companyId ); //\Utility\Debug::errorLog ( 'New dealer updated is publicCentre', $isPublicCentre ); // create an new price guide club (dealership name Traders Club) // Do a check for club $club = $em->getRepository ( '\PriceGuide\Entity\Club' )->findOneBy ( array ( 'name' => $dealershipName ) ); // > Create entry. // Create if nothing is found if (is_null ( $club )) { //\Utility\Debug::errorLog ( 'New dealer wasnt found', $dealershipName ); $publicClub = new \PriceGuide\Entity\Club (); $publicClubData = array ( 'company' => $em->getRepository ( '\Company\Entity\Company' )->find ( $companyId ), 'name' => $dealershipName, 'status' => 'Active', 'created' => $today ) ; $publicClub->fromArray ( $publicClubData ); $em->persist ( $publicClub ); $em->flush (); // Get id back $publicClubId = $publicClub->id; //\Utility\Debug::errorLog ( 'New dealer created club id', $publicClubId ); } else { //\Utility\Debug::errorLog ( 'New dealer updated is $club', $club->id ); $publicClubId = $club->id; } // Select from company where where dealer_type = "Trader" $traderSearch = "Trader"; $result = $this->em->createQuery ( 'SELECT company ' . 'FROM \Company\Entity\Company company ' . 'WHERE company.dealerType = :trader ' ) ->setParameter ( 'trader', $traderSearch )->getArrayResult (); //\Utility\Debug::errorLog ( 'add this club', $publicClubId ); foreach ( $result as $companys ) { //\Utility\Debug::errorLog ( 'all the $companys', $companys ); // get all the profiles $override $overridePgSearch = '1'; $profileResult = $this->em->createQuery ( 'SELECT profile, override ' . 'FROM User\Entity\Profile profile ' . 'LEFT JOIN profile.override override ' . 'WHERE IDENTITY(profile.company) = :companyID ' . 'AND override.pgMakeOffer = :overridePG ' ) ->setParameter ( 'companyID', $companys ['id'] )->setParameter ( 'overridePG', $overridePgSearch )-> getArrayResult (); foreach ( $profileResult as $clubProfiles ) { //\Utility\Debug::errorLog ( 'all the profiles found', $clubProfiles ); $existingClubMember = $em->getRepository ( '\PriceGuide\Entity\Member' )->findOneBy ( array ( 'club' => $em->getRepository ( '\PriceGuide\Entity\Club' )->find ( $publicClubId ), 'company' => $em->getRepository ( '\Company\Entity\Company' )->find ( $companys ['id'] ), 'profile' => $em->getRepository ( '\User\Entity\Profile' )->find ( $clubProfiles ['id'] ) ) ); // Set all listed traders as active members with email notifications on and sms off if (is_null ( $existingClubMember )) { // add new member //\Utility\Debug::errorLog ( 'add this trader', $companys ); $publicClubMember = new \PriceGuide\Entity\Member (); $publicClubMemberData = array ( 'club' => $em->getRepository ( '\PriceGuide\Entity\Club' )->find ( $publicClubId ), 'company' => $em->getRepository ( '\Company\Entity\Company' )->find ( $companys ['id'] ), 'profile' => $em->getRepository ( '\User\Entity\Profile' )->find ( $clubProfiles ['id'] ), 'allMakes' => '1', 'emailNotification' => '1', 'smsNotification' => '0', 'status' => 'Active', 'created' => $today ) ; $publicClubMember->fromArray ( $publicClubMemberData ); $em->persist ( $publicClubMember ); $em->flush (); } } // ProfileClub } // For each company found } /** * ExecuteAfter: Update. * Link all the trade center clubs for this dealer that is a public centre. * @param array $meta * @param object|null $jobRecord * @param object|null $record * @param \Workspace\Utility\ServiceInputParams $contract * @return array */ public function PublicCentreClubs($meta, $jobRecord, $record, \Workspace\Utility\ServiceInputParams $contract) { if ($record->publicCentre == 'True' || $record->publicCentre == '1') { exec("php /var/www/B4C2/public/index.php publicclubs process " . $record->id . " >>/log/php.log &"); }// if is public centre } public function directRouteMoveToPending($jobRecord) { $profile = $this->em->getRepository('\User\Entity\Profile') ->findOneBy(array('company' => $jobRecord->id), array('id' => 'ASC')); $oNotify = new \Utility\Comms\Notification(); $oNotify->sendFromTemplate( null, null, $jobRecord->id, $profile->id, $profile->email, null, null, 'registration-pending', array( 'firstName' => $profile->firstName, 'familyName' => $profile->familyName, 'status_reason' => $jobRecord->statusReason ) ); } public function directRouteMoveToActive($jobRecord) { $profile = $this->em->getRepository('\User\Entity\Profile') ->findOneBy(array('company' => $jobRecord->id), array('id' => 'ASC')); $oNotify = new \Utility\Comms\Notification(); $oNotify->sendFromTemplate( null, null, $jobRecord->id, $profile->id, $profile->email, null, null, 'registration-success', array( 'firstName' => $profile->firstName, 'familyName' => $profile->familyName, 'email' => $profile->email ) ); } public function directRouteMoveToDeclined($jobRecord) { $profile = $this->em->getRepository('\User\Entity\Profile') ->findOneBy(array('company' => $jobRecord->id), array('id' => 'ASC')); $oNotify = new \Utility\Comms\Notification(); $oNotify->sendFromTemplate( null, null, $jobRecord->id, $profile->id, $profile->email, null, null, 'registration-declined', array( 'firstName' => $profile->firstName, 'familyName' => $profile->familyName, 'status_reason' => $jobRecord->statusReason ) ); } /** * List of companies that can be invited. * @param object|null $jobRecord * @param array $input * @return \Workspace\Contract\UseOnce */ public function contractInviteSelectList($jobRecord, array $input = array()) { $options = new \Workspace\UseCase\Options(); $requirement = new \Workspace\UseCase\Requirement(); $requirement->addRequiredInput(array( 'Filter' => array( 'club' => 'Id' ) )); return new \Workspace\Contract\Recurring($options, $requirement); } /** * Reset pin for user. * @param object|null $jobRecord * @param \Workspace\Utility\ServiceInputParams $contract * @return array */ public function executeInviteSelectList($jobRecord, \Workspace\Utility\ServiceInputParams $contract) { $em = \Utility\Registry::getEntityManager(); $authData = \Utility\Registry::getAuthData(); $companyId = $authData['company']['id']; $clubId = $contract->data->Filter['club']; $memberslistdrop = $em->createQuery(' SELECT c.id, c.name AS companyName FROM \Company\Entity\Company c WHERE c.id NOT IN ( SELECT IDENTITY(m.company) FROM PriceGuide\Entity\Member m WHERE IDENTITY(m.club) = :clubId ) AND c.priceGuide = :activeid AND c.id != :company ORDER BY c.name' ); $memberslistdrop->setParameter('clubId', $clubId); $memberslistdrop->setParameter('activeid', '1'); $memberslistdrop->setParameter('company', $companyId); $memberslistu = $memberslistdrop->getArrayResult(); $datax = array(); foreach ( $memberslistu as $data ) { $datax[] = array( 'value' => $data['id'], 'label' => $data['companyName'] ); } return $contract->success('List Retrieved.', $datax); } /** * Contract to remove a document from a company. * @param object|null $jobRecord * @param array $input * @return \Workspace\Contract\UseOnce */ public function contractRemoveDocument($jobRecord, array $input = array()) { $options = new \Workspace\UseCase\Options(); $requirement = new \Workspace\UseCase\Requirement(); $requirement->addOptionalInput(array( 'Company' => array( 'docStockCertificate' => 'Boolean', 'docAddressProof' => 'Boolean', 'docCopyOfId' => 'Boolean', 'docCopyOfDirectorId' => 'Boolean', 'docCompanyRegistration' => 'Boolean' ) )); return new \Workspace\Contract\Recurring($options, $requirement); } /** * Remove a document from a company. * @param object|null $jobRecord * @param \Workspace\Utility\ServiceInputParams $contract * @return array */ public function executeRemoveDocument($jobRecord, \Workspace\Utility\ServiceInputParams $contract) { $fields = array( 'docStockCertificate', 'docAddressProof', 'docCopyOfId', 'docCopyOfDirectorId', 'docCompanyRegistration' ); $folder = \Utility\Registry::getConfigParam('DocumentPath'); foreach ($fields as $field) { if (isset($contract->data->Company[$field]) && $contract->data->Company[$field]) { if (file_exists($folder . '/' . $jobRecord->$field->filename)) { unlink($folder . '/' . $jobRecord->$field->filename); } $this->em->remove($jobRecord->$field); $jobRecord->$field = null; } } $this->em->flush(); return $contract->success('Document removed.', array()); } /** * List of companies that can be invited. * @param object|null $jobRecord * @param array $input * @return \Workspace\Contract\UseOnce */ public function checkDocuments() { $result = $this->em->createQuery( 'SELECT company, docStockCertificate, docAddressProof, docCopyOfId, docCopyOfDirectorId, docCompanyRegistration ' . 'FROM \Company\Entity\Company company ' . 'LEFT JOIN company.docStockCertificate docStockCertificate ' . 'LEFT JOIN company.docAddressProof docAddressProof ' . 'LEFT JOIN company.docCopyOfId docCopyOfId ' . 'LEFT JOIN company.docCopyOfDirectorId docCopyOfDirectorId ' . 'LEFT JOIN company.docCompanyRegistration docCompanyRegistration ' . 'WHERE docStockCertificate != :null ' . 'OR docAddressProof != :null ' . 'OR docCopyOfId != :null ' . 'OR docCopyOfDirectorId != :null ' . 'OR docCompanyRegistration != :null ' ) ->setParameter('null', 'null') ->getArrayResult(); $folder = \Utility\Registry::getConfigParam('DocumentPath'); $missingDocs = array(); $docs = array( 'docStockCertificate', 'docAddressProof', 'docCopyOfId', 'docCopyOfDirectorId', 'docCompanyRegistration', ); foreach ($result as $companies) { $companyId = $companies['id']; $missingDocs[$companyId] = array( 'company' => $companies['name'] . ' / ' . $companies['businessName'], 'docStockCertificate' => false, 'docAddressProof' => false, 'docCopyOfId' => false, 'docCopyOfDirectorId' => false, 'docCompanyRegistration' => false ); $missing = 0; foreach ($docs as $doc) { if (is_array($companies[$doc]) && !is_null($companies[$doc]['id']) ) { if (!file_exists($folder . '/' . $companies[$doc]['filename'])) { $missing++; $missingDocs[$companyId][$doc] = $companies[$doc]['filename']; } } } if (0 == $missing) { unset($missingDocs[$companyId]); } } $fp = fopen($folder . '/missingDocsFilelist.csv', 'w'); fputcsv($fp, array( 'Company name', 'Stock Certificate', 'Document Address Proof', 'Document Copy Of Id', 'Document Copy Of DirectorId', 'Document Company Registration' )); foreach ($missingDocs as $companyId => $fields) { fputcsv($fp, $fields); } fclose($fp); } }