diff --git a/application/modules/default/controllers/SettingsController.php b/application/modules/default/controllers/SettingsController.php index 1d1e6641d..1fb99dc14 100644 --- a/application/modules/default/controllers/SettingsController.php +++ b/application/modules/default/controllers/SettingsController.php @@ -1,1516 +1,1519 @@ . **/ class SettingsController extends Local_Controller_Action_DomainSwitch { protected $_auth; protected $_memberId; /** @var Zend_Db_Table */ protected $_memberTable; /** @var Zend_Db_Table_Row */ protected $_memberSettings; protected $_projectTable; /** @var Zend_Db_Table_Row */ protected $_mainproject; private $htmlVerifier = '<meta name="ocs-site-verification" content="?" />'; public function init() { parent::init(); $this->getResponse()->clearHeaders(array('Expires', 'Pragma', 'Cache-Control'))->setHeader('Pragma', 'no-cache', true) ->setHeader('Cache-Control', 'private, no-cache, must-revalidate', true) ; $this->_auth = Zend_Auth::getInstance(); $this->_memberId = $this->_auth->getStorage()->read()->member_id; $this->_memberTable = new Default_Model_DbTable_Member(); $showMember = $this->_memberTable->find($this->_memberId)->current(); $this->view->member = $showMember; $this->_memberSettings = $showMember; $this->_projectTable = new Default_Model_DbTable_Project(); // init default main project $main_project_id = $showMember->main_project_id; $mainproject_rowset = $this->_projectTable->find($main_project_id); $this->_mainproject = $this->view->mainproject = $mainproject_rowset->current(); } public function indexAction() { $this->view->member = $this->_memberSettings; $memberSettings = $this->_memberSettings->toArray(); $paypalValidStatusTable = new Default_Model_DbTable_PaypalValidStatus(); $paypalValidStatus = $paypalValidStatusTable->find($this->_memberSettings->paypal_valid_status)->current(); $this->view->paypal_valid_status = $paypalValidStatus; $this->view->profileform = $this->formProfile(); $this->view->profileform->populate($memberSettings); $this->view->profileform->aboutme->setValue($this->_mainproject->description); $this->view->accounts = $this->formConnectedAccounts(); $this->view->accounts->populate($memberSettings); $this->view->github = $this->formGithub(); $this->view->github->populate($memberSettings); $this->view->pictureform = $this->formProfilePicture(); $this->view->pictureform->populate($memberSettings); $this->view->pictureformbg = $this->formProfilePictureBackground(); $this->view->pictureformbg->populate($memberSettings); $this->view->passwordform = $this->formPassword(); $websiteOwner = new Local_Verification_WebsiteOwner(); $linkWebsite = stripslashes($this->_memberSettings->link_website); $this->view->homepageform = $this->formHomepage($linkWebsite, $websiteOwner->generateAuthCode($linkWebsite), $this->_memberSettings->validated); $this->view->newsletterform = $this->formNewsletter(stripslashes($this->_memberSettings->newsletter)); $this->view->paymentform = $this->formPayment(); $this->view->paymentform->populate($memberSettings); } public function profileAction() { $this->view->member = $this->_memberSettings; $memberSettings = $this->_memberSettings->toArray(); $this->view->profileform = $this->formProfile(); $this->view->profileform->populate($memberSettings); $this->view->profileform->aboutme->setValue($this->_mainproject->description); $this->view->accounts = $this->formConnectedAccounts(); $this->view->accounts->populate($memberSettings); $this->view->pictureform = $this->formProfilePicture(); $this->view->pictureform->populate($memberSettings); $this->view->pictureformbg = $this->formProfilePictureBackground(); $this->view->pictureformbg->populate($memberSettings); $websiteOwner = new Local_Verification_WebsiteOwner(); $linkWebsite = stripslashes($this->_memberSettings->link_website); $this->view->homepageform = $this->formHomepage($linkWebsite, $websiteOwner->generateAuthCode($linkWebsite), $this->_memberSettings->validated); } /** * Forms */ /** * @return Default_Form_Settings * @throws Zend_Form_Exception */ private function formProfile() { $form = new Default_Form_Settings(); $form->setMethod("POST")->setAttrib("id", "settingsProfileForm")->setAction('/settings/saveprofile'); $userNameLength = new Zend_Validate_StringLength(array('min' => 4, 'max' => 35)); $username = $form->createElement('text', 'username')->setLabel("Username:")->setRequired(false)->setFilters(array('StringTrim')) ->addValidator($userNameLength)->setAttrib('readonly', 'true')->setDecorators(array( 'ViewHelper', 'Label', 'Errors', array( 'ViewScript', array( 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 'placement' => false ) ) )) ; $form->addElement($username); $firstname = $form->createElement('text', 'firstname')->setLabel("First Name:")->setRequired(false)->removeDecorator('HtmlTag') ->setFilters(array('StringTrim'))->setDecorators(array( 'ViewHelper', 'Label', 'Errors', array( 'ViewScript', array( 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 'placement' => false ) ) )) ; $form->addElement($firstname); $lastname = $form->createElement('text', 'lastname')->setLabel("Last Name:")->setRequired(false)->removeDecorator('HtmlTag') ->setFilters(array('StringTrim'))->setDecorators(array( 'ViewHelper', 'Label', 'Errors', array( 'ViewScript', array( 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 'placement' => false ) ) )) ; $form->addElement($lastname); $city = $form->createElement('text', 'city')->setLabel("City:")->setRequired(false)->setFilters(array('StringTrim')) ->removeDecorator('HtmlTag')->setDecorators(array( 'ViewHelper', 'Label', 'Errors', array( 'ViewScript', array( 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 'placement' => false ) ) )) ; $form->addElement($city); $country = $form->createElement('text', 'country')->setLabel("Country:")->setRequired(false)->setFilters(array('StringTrim')) ->removeDecorator('HtmlTag')->setDecorators(array( 'ViewHelper', 'Label', 'Errors', array( 'ViewScript', array( 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 'placement' => false ) ) )) ; $form->addElement($country); $about = $form->createElement('textarea', 'aboutme')->setLabel('About me:')->setRequired(false)->setAttrib('class', 'about') ->setDecorators(array( 'ViewHelper', 'Label', 'Errors', array( 'ViewScript', array( 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 'placement' => false ) ) )) ; $form->addElement($about); return $form; } /** * @return Default_Form_Settings * @throws Zend_Form_Exception */ private function formConnectedAccounts() { $form = new Default_Form_Settings(); $form->setMethod("POST")->setAttrib("id", "settingsConnectedAccounts")->setAction('/settings/accounts'); $facebook = $form->createElement('text', 'link_facebook')->setLabel("Facebook Profile:")->setRequired(false) ->removeDecorator('HtmlTag')->setDecorators(array( 'ViewHelper', 'Label', 'Errors', array( 'ViewScript', array( 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 'placement' => false ) ) )) ; $facebook->addValidator(new Local_Validate_PartialUrl()); $form->addElement($facebook); $twitter = $form->createElement('text', 'link_twitter')->setLabel("Twitter Profile:")->setRequired(false)->removeDecorator('HtmlTag') ->setDecorators(array( 'ViewHelper', 'Label', 'Errors', array( 'ViewScript', array( 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 'placement' => false ) ) )) ; $twitter->addValidator(new Local_Validate_PartialUrl); $form->addElement($twitter); $github = $form->createElement('text', 'link_github')->setLabel("GitHub Profile:")->setRequired(false)->removeDecorator('HtmlTag') ->setDecorators(array( 'ViewHelper', 'Label', 'Errors', array( 'ViewScript', array( 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 'placement' => false ) ) )) ; $github->addValidator(new Local_Validate_PartialUrl); $form->addElement($github); return $form; } /** * @return Default_Form_Settings * @throws Zend_Form_Exception */ private function formGithub() { $form = new Default_Form_Settings(); $form->setMethod("POST")->setAttrib("id", "settingsGithub")->setAction('/settings/github'); $github = new Default_Form_Element_UsernameGithub('link_github'); $github->setLabel("GitHub Profile:")->setRequired(false)->removeDecorator('HtmlTag')->setDecorators(array( 'ViewHelper', 'Label', 'Errors', array( 'ViewScript', array( 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 'placement' => false ) ) )) ; $form->addElement($github); $token = new Default_Form_Element_TokenGithub('token_github'); $token->setLabel("GitHub Access Token:")->setRequired(false)->removeDecorator('HtmlTag')->setDecorators(array( 'ViewHelper', 'Label', 'Errors', array( 'ViewScript', array( 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 'placement' => false ) ) )) ; $form->addElement($token); return $form; } /** * @return Default_Form_Settings * @throws Zend_File_Transfer_Exception * @throws Zend_Form_Exception */ private function formProfilePicture() { $form = new Default_Form_Settings(); $form->setMethod("POST")->setAttrib("id", "settingsPictureForm")->setAction('/settings/picture') ->setAttrib('enctype', 'multipart/form-data') ; $hiddenProfilePicture = $form->createElement('hidden', 'profile_image_url')->setDecorators(array( 'ViewHelper', array( 'ViewScript', array( 'viewScript' => 'settings/viewscripts/flatui_hidden_image.phtml', 'placement' => false ) ) ))->setAttrib('data-target', '#profile-picture-preview') ; $form->addElement($hiddenProfilePicture); $imageTable = new Default_Model_DbTable_Image(); $productPicture = $form->createElement('file', 'profile_picture_upload')->setDisableLoadDefaultDecorators(true)->setLabel('Profile Picture') ->setRequired(false)->setDecorators(array( 'File', array( 'ViewScript', array( 'viewScript' => 'settings/viewscripts/flatui_profile_image.phtml', 'placement' => false ) ) ))->setAttrib('class', 'product-picture') ->setAttrib('onchange', 'ImagePreview.previewImage(this, \'profile-picture-preview\');') ->setTransferAdapter(new Local_File_Transfer_Adapter_Http())->setMaxFileSize(2097152)->addValidator('Count', false, 1) ->addValidator('Size', false, array('min' => '5kB', 'max' => '2MB')) ->addValidator('Extension', false, $imageTable->getAllowedFileExtension())->addValidator('ImageSize', false, array( 'minwidth' => 20, 'maxwidth' => 1024, 'minheight' => 20, 'maxheight' => 1024 ))->addValidator('MimeType', false, $imageTable->getAllowedMimeTypes()) ; $form->addElement($productPicture); $facebook_username = $form->createElement('text', 'facebook_username')->setLabel("From Facebook Profile:")->setRequired(false) ->removeDecorator('HtmlTag') ->setAttrib('data-href', 'https://graph.facebook.com/{username}/picture?type=large') ->setAttrib('data-target', '#profile-picture-preview')->setAttrib('data-src', 'facebook') ->setAttrib('class', 'avatar')->setDecorators(array( 'ViewHelper', 'Label', 'Errors' )) ; $form->addElement($facebook_username); $twitter_username = $form->createElement('text', 'twitter_username')->setLabel("From Twitter Profile:")->setRequired(false) ->removeDecorator('HtmlTag') ->setAttrib('data-href', 'http://twitter.com/api/users/profile_image/{username}') ->setAttrib('data-target', '#profile-picture-preview')->setAttrib('data-src', 'twitter') ->setAttrib('class', 'avatar')->setDecorators(array( 'ViewHelper', 'Label', 'Errors' )) ; $form->addElement($twitter_username); $gravatar_email = $form->createElement('text', 'gravatar_email')->setLabel("From Gravatar Profile:")->setRequired(false) ->setAttrib('data-href', 'http://www.gravatar.com/avatar/{username}.jpg') ->setAttrib('data-target', '#profile-picture-preview')->setAttrib('data-func', 'MD5') ->setAttrib('data-src', 'gravatar')->setAttrib('class', 'avatar')->setDecorators(array( 'ViewHelper', 'Label', 'Errors' )) ; $form->addElement($gravatar_email); $hiddenProfilePictureSrc = $form->createElement('hidden', 'profile_img_src')->setDecorators(array( 'ViewHelper' )) ; $form->addElement($hiddenProfilePictureSrc); return $form; } /** * @return Default_Form_Settings * @throws Zend_File_Transfer_Exception * @throws Zend_Form_Exception */ private function formProfilePictureBackground() { $form = new Default_Form_Settings(); $form->setMethod("POST")->setAttrib("id", "settingsPictureBackgroundForm")->setAction('/settings/picturebackground') ->setAttrib('enctype', 'multipart/form-data') ; $hiddenProfilePicture = $form->createElement('hidden', 'profile_image_url_bg')->setDecorators(array( 'ViewHelper', array( 'ViewScript', array( 'viewScript' => 'settings/viewscripts/flatui_hidden_image.phtml', 'placement' => false ) ) ))->setAttrib('data-target', '#profile-picture-bg-preview') ; $form->addElement($hiddenProfilePicture); $imageTable = new Default_Model_DbTable_Image(); $productPicture = $form->createElement('file', 'profile_picture_background_upload')->setDisableLoadDefaultDecorators(true) ->setLabel('Background Picture')->setRequired(false)->setDecorators(array( 'File', array( 'ViewScript', array( 'viewScript' => 'settings/viewscripts/flatui_profile_image_background.phtml', 'placement' => false ) ) ))->setAttrib('class', 'product-picture')->setAttrib('onchange', 'ImagePreview.previewImageMember(this, \'profile-picture-background-preview\');') ->setTransferAdapter(new Local_File_Transfer_Adapter_Http())//->setMaxFileSize(2097152) ->addValidator('Count', false, 1)//->addValidator('Size', false, array('min' => '5kB', 'max' => '2MB')) ->addValidator('Extension', false, $imageTable->getAllowedFileExtension()) ->addValidator('MimeType', false, $imageTable->getAllowedMimeTypes()) ; $form->addElement($productPicture); return $form; } /** * @return Default_Form_Settings * @throws Zend_Form_Exception */ private function formPassword() { $form = new Default_Form_Settings(); $form->setMethod("POST")->setAttrib("id", "settingsPasswordForm")->setAction('/settings/password'); $passOld = $form->createElement('password', 'passwordOld')->setLabel('Enter old Password:')->setRequired(true) ->removeDecorator('HtmlTag')->addValidator(new Local_Validate_OldPasswordConfirm())->setDecorators(array( 'ViewHelper', 'Label', 'Errors', array( 'ViewScript', array( 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 'placement' => false ) ) )) ; $pass1 = $form->createElement('password', 'password1')->setLabel('Enter new Password:')->setRequired(true) ->addValidator(new Zend_Validate_NotEmpty(Zend_Validate_NotEmpty::STRING))->removeDecorator('HtmlTag') ->setDecorators(array( 'ViewHelper', 'Label', 'Errors', array( 'ViewScript', array( 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 'placement' => false ) ) )) ; $pass2 = $form->createElement('password', 'password2')->setLabel('Re-enter new Password:')->setRequired(true) ->addValidator(new Zend_Validate_NotEmpty(Zend_Validate_NotEmpty::STRING))->removeDecorator('HtmlTag') ->setDecorators(array( 'ViewHelper', 'Label', 'Errors', array( 'ViewScript', array( 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 'placement' => false ) ) )) ; $passValid = new Local_Validate_PasswordConfirm($pass2->getValue()); $pass1->addValidator($passValid); $form->addElement($passOld)->addElement($pass1)->addElement($pass2); return $form; } /** * @param string $valHomepage * @param string $valVerifyKey * @param bool $isVerified * * @return Local_Form * @throws Zend_Form_Exception */ private function formHomepage($valHomepage = '', $valVerifyKey = '', $isVerified = false) { $form = new Local_Form(); $form->setMethod("POST")->setAttrib("id", "settingsHomepageForm")->setAction('/settings/homepage') ->addPrefixPath('Local_Form_Element_', 'Local/Form/Element/', 'element') ; $homepage = $form->createElement('text', 'link_website')->setLabel("Website:")->setRequired(false)->setValue($valHomepage) ->addValidator(new Local_Validate_PartialUrl)->setDecorators(array( 'ViewHelper', 'Label', 'Errors', array( 'ViewScript', array( 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 'placement' => false ) ) )) ; if ($isVerified) { $homepage->setDescription('
'); } else { $homepage->setDescription('
'); } $homepage->addDecorators(array( array('Description', array('tag' => '', 'escape' => false)) )); $form->addElement($homepage); $hash = $form->createElement('hash', 'csrf', array('salt' => 'RumbaSpiess')); $hash->setDecorators(array('ViewHelper', 'Errors')); $hash->getValidator('Identical')->setMessage('Your session is outdated. Please reload the page an try again.'); $form->addElement($hash); if ('' != $valVerifyKey) { $value = str_replace('?', $valVerifyKey, $this->htmlVerifier); $verifyCode = $form->createElement('note', 'html_verifier')->setValue($value)->removeDecorator('HtmlTag')->removeDecorator('Label'); $form->addElement($verifyCode); } return $form; } /** * @param string $valNewsletter * * @return Default_Form_Settings * @throws Zend_Form_Exception * @throws Zend_Validate_Exception */ private function formNewsletter($valNewsletter = '') { $form = new Default_Form_Settings(); $form->setMethod("POST")->setAttrib("id", "settingsNewsletterForm")->setAction('/settings/newsletter'); $questionValid = new Zend_Validate_InArray(array('1', '0')); $questionValid->setMessage('Yes is required!'); $question = $form->createElement('checkbox', 'newsletter')// ->addValidator($questionValid, true) ->setRequired(true)->removeDecorator('HtmlTag')->removeDecorator('Label') ; $question->setValue($valNewsletter); $form->addElement($question); return $form; } /** * @param string $valPaypalEmail * @param string $valWalletAddress * @param string $valDwollaId * * @return Default_Form_Settings * @throws Zend_Form_Exception * @throws Zend_Validate_Exception */ private function formPayment($valPaypalEmail = '', $valWalletAddress = '', $valDwollaId = '') { $form = new Default_Form_Settings(); $form->setMethod("POST")->setAttrib("id", "settingsPaymentForm")->setAction('/settings/payment'); $mailValidCheck = new Zend_Validate_EmailAddress(); $mailValidCheck->setMessage('RegisterFormEmailErrNotValid', Zend_Validate_EmailAddress::INVALID) ->setMessage('RegisterFormEmailErrNotValid', Zend_Validate_EmailAddress::INVALID_FORMAT) ->setMessage('RegisterFormEmailErrNotValid', Zend_Validate_EmailAddress::INVALID_LOCAL_PART) ->setMessage("RegisterFormEmailErrWrongHost", Zend_Validate_EmailAddress::INVALID_HOSTNAME) ->setMessage("RegisterFormEmailErrWrongHost2", Zend_Validate_Hostname::INVALID_HOSTNAME) ->setMessage("RegisterFormEmailErrHostLocal", Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED) ->setOptions(array('domain' => true)) ; $mailEmpty = new Zend_Validate_NotEmpty(); $mailEmpty->setMessage('RegisterFormEmailErrEmpty', Zend_Validate_NotEmpty::IS_EMPTY); $mailValidatorChain = new Zend_Validate(); $mailValidatorChain->addValidator($mailValidCheck, true); $mail = $form->createElement('text', 'paypal_mail')->setLabel('Paypal: Email Adress')->setRequired(false) ->addValidator($mailValidCheck, true)->setDecorators(array( 'ViewHelper', 'Label', 'Errors', array( 'ViewScript', array( 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 'placement' => false ) ) )) ; $mail->setValue($valPaypalEmail); $form->addElement($mail); $bitcoinAddress = $form->createElement('text', 'wallet_address')->setLabel('Bitcoin: Your Public Wallet Address')->setRequired(false) ->setDecorators(array( 'ViewHelper', 'Label', 'Errors', array( 'ViewScript', array( 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 'placement' => false ) ) ))->addValidators(array( array( 'regex', false, array( 'pattern' => '/^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$/', 'messages' => 'The Bitcoin Address is not valid.' ) ) )) ; $bitcoinAddress->setValue($valWalletAddress); $form->addElement($bitcoinAddress); $dwolla = $form->createElement('text', 'dwolla_id')->setLabel('Dwolla: User ID (xxx-xxx-xxxx)')->setRequired(false) ->setDecorators(array( 'ViewHelper', 'Label', 'Errors', array( 'ViewScript', array( 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 'placement' => false ) ) )) ; $dwolla->setValue($valDwollaId); $form->addElement($dwolla); return $form; } public function savetagsAction() { $this->_helper->layout->disableLayout(); $error_text = ''; - $tag_id = $_POST['tag_id']; + $tag_id = null; + if(!empty($_POST['tag_id'])) { + $tag_id = $_POST['tag_id']; + } $tag_group_id = $_POST['tag_group_id']; $tag_type_id = Zend_Registry::get('config')->settings->client->default->tag_type_osuser; $tag_object_id = $this->_memberId; $model = new Default_Model_Tags(); $model->saveOSTagForUser($tag_id,$tag_type_id,$tag_group_id,$tag_object_id); $this->_helper->json(array('status' => 'ok')); } public function saveprofileAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer('partials/profile'); if ($this->_request->isPost()) { $form = $this->formProfile(); if ($form->isValid($_POST)) { $values = $form->getValues(); //remove email and username unset($values['username']); unset($values['mail']); $values['firstname'] = Default_Model_HtmlPurify::purify($values['firstname']); $values['lastname'] = Default_Model_HtmlPurify::purify($values['lastname']); $values['city'] = Default_Model_HtmlPurify::purify($values['city']); $values['country'] = Default_Model_HtmlPurify::purify($values['country']); $values['aboutme'] = Default_Model_HtmlPurify::purify($values['aboutme']); $this->_memberSettings->setFromArray($values); $this->_memberSettings->save(); $this->_mainproject->description = $values['aboutme']; $this->_mainproject->save(); $this->view->profileform = $form; $this->view->save = 1; // ppload // Update profile information $this->_updatePploadProfile(); } else { $this->view->profileform = $form; $this->view->error = 1; } } else { $form = $this->formProfile(); $form->populate($this->_memberSettings->toArray()); $this->view->profileform = $form; } } /** * ppload */ protected function _updatePploadProfile() { $pploadApi = new Ppload_Api(array( 'apiUri' => PPLOAD_API_URI, 'clientId' => PPLOAD_CLIENT_ID, 'secret' => PPLOAD_SECRET )); $profileName = ''; if ($this->_memberSettings->firstname || $this->_memberSettings->lastname) { $profileName = trim($this->_memberSettings->firstname . ' ' . $this->_memberSettings->lastname); } else { if ($this->_memberSettings->username) { $profileName = $this->_memberSettings->username; } } $profileRequest = array( 'owner_id' => $this->_memberId, 'name' => $profileName, 'email' => $this->_memberSettings->mail, 'homepage' => $this->_memberSettings->link_website, 'image' => $this->_memberSettings->profile_image_url, 'description' => $this->_mainproject->description ); $profileResponse = $pploadApi->postProfile($profileRequest); } public function accountsAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer('partials/accounts'); if ($this->_request->isPost()) { $form = $this->formConnectedAccounts(); if ($form->isValid($_POST)) { $this->_memberSettings->setFromArray($form->getValues()); $this->_memberSettings->save(); $this->view->accounts = $form; $this->view->save = 1; } else { $this->view->accounts = $form; $this->view->error = 1; } } else { $form = $this->formProfile(); $form->populate($this->_memberSettings->toArray()); $this->view->accounts = $form; } } public function githubAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer('partials/github'); if ($this->_request->isPost()) { $form = $this->formGithub(); if ($form->isValid($_POST)) { $this->_memberSettings->setFromArray($form->getValues()); $this->_memberSettings->save(); $memberToken = new Default_Model_DbTable_MemberToken(); $memberToken->save(array( 'token_member_id' => $this->_memberId, 'token_provider_name' => 'github_personal', 'token_value' => $form->getValue('token_github'), 'token_provider_username' => $form->getValue('link_github') )); $this->view->github = $form; $this->view->save = 1; } else { $this->view->github = $form; $this->view->error = 1; } } else { $form = $this->formProfile(); $form->populate($this->_memberSettings->toArray()); $this->view->github = $form; } } public function pictureAction() { ini_set('memory_limit', '128M'); $this->_helper->layout->disableLayout(); if ($this->_request->isPost()) { $form = $this->formProfilePicture(); $formFilename = $form->getElement('profile_picture_upload')->getFileName(); if (is_array($formFilename)) { Zend_Registry::get('logger')->info(__METHOD__ . ' :: form input:' . print_r($formFilename, true)); $filename = $formFilename['profile_picture_upload']; } else { Zend_Registry::get('logger')->info(__METHOD__ . ' :: form input:' . print_r($formFilename, true)); $filename = $formFilename; } $profilePictureTitleFilename = pathinfo($filename); if (!isset($profilePictureTitleFilename)) { $form->populate($this->_memberSettings->toArray()); $form->addErrorMessage('Please select a new picture'); $form->markAsError(); $this->view->pictureform = $form; $this->view->error = 1; $this->renderScript('settings/partials/picture.phtml'); return; } if ($form->isValid($_POST)) { $tmpProfilePictureTitle = IMAGES_UPLOAD_PATH . 'tmp/' . Local_Tools_UUID::generateUUID() . '_' . $profilePictureTitleFilename['basename']; $form->getElement('profile_picture_upload') ->addFilter('Rename', array('target' => $tmpProfilePictureTitle, 'overwrite' => true)) ; $values = $form->getValues(); if (array_key_exists('profile_picture_upload', $values) && $values['profile_picture_upload'] != "") { $imageService = new Default_Model_DbTable_Image(); $newImageName = $imageService->saveImageOnMediaServer($tmpProfilePictureTitle); } if ($form->getElement('facebook_username')->getValue() !== null) { $this->_memberSettings->facebook_username = $values['facebook_username']; } if ($form->getElement('twitter_username')->getValue() !== null) { $this->_memberSettings->twitter_username = $values['twitter_username']; } if ($form->getElement('gravatar_email')->getValue() !== null) { $this->_memberSettings->gravatar_email = $values['gravatar_email']; } if ($values['profile_img_src'] == 'local' && isset($newImageName)) { $this->_auth->getIdentity()->avatar = $newImageName; $this->_auth->getIdentity()->profile_image_url = IMAGES_MEDIA_SERVER . '/cache/200x200-2/img/' . $newImageName; $this->_memberSettings->avatar = $newImageName; $this->_memberSettings->profile_image_url = IMAGES_MEDIA_SERVER . '/cache/200x200-2/img/' . $newImageName; $this->_memberSettings->avatar_type_id = Default_Model_DbTable_Member::MEMBER_AVATAR_TYPE_USERUPDATED; } $this->_memberSettings->profile_img_src = $values['profile_img_src']; $this->_memberSettings->save(); $this->view->member = $this->_memberSettings; $form->populate($this->_memberSettings->toArray()); try { $id_server = new Default_Model_Ocs_OAuth(); $id_server->updateAvatarForUser($this->_memberSettings->member_id); } catch (Exception $e) { Zend_Registry::get('logger')->err($e->getMessage() . PHP_EOL . $e->getTraceAsString()); } try { $ldap_server = new Default_Model_Ocs_Ldap(); $ldap_server->updateAvatar($this->_memberSettings->member_id); Zend_Registry::get('logger')->debug(__METHOD__ . ' - ldap : ' . implode(PHP_EOL." - ", $ldap_server->getMessages())); } catch (Exception $e) { Zend_Registry::get('logger')->err($e->getMessage() . PHP_EOL . $e->getTraceAsString()); } $this->view->save = 1; $this->view->pictureform = $form; // ppload // Update profile information $this->_updatePploadProfile(); $this->renderScript('settings/partials/picture.phtml'); } else { $this->view->pictureform = $form; $this->view->error = 1; $this->renderScript('settings/partials/picture.phtml'); } } else { $form = $this->formProfilePicture(); $form->populate($this->_memberSettings->toArray()); $this->view->pictureform = $form; $this->renderScript('settings/partials/picture.phtml'); } } public function deletepicturebackgroundAction() { $this->_helper->layout->disableLayout(); $this->_memberSettings->profile_image_url_bg = null; $this->_memberSettings->save(); $this->_helper->json(array( 'status' => 'ok' )); } public function picturebackgroundAction() { ini_set('memory_limit', '128M'); $this->_helper->layout->disableLayout(); if ($this->_request->isPost()) { $form = $this->formProfilePictureBackground(); $profilePictureElement = $form->getElement('profile_picture_background_upload'); if (!isset($profilePictureElement)) { $form->populate($this->_memberSettings->toArray()); $form->addErrorMessage('Please select a new picture'); $form->markAsError(); $this->view->pictureformbg = $form; $this->view->error = 1; $this->renderScript('settings/partials/picture-bg.phtml'); return; } $profilePictureTitleFilename = pathinfo($form->getElement('profile_picture_background_upload')->getFileName()); if ($form->isValid($_POST)) { $tmpProfilePictureTitle = IMAGES_UPLOAD_PATH . 'tmp/' . Local_Tools_UUID::generateUUID() . '_' . $profilePictureTitleFilename['basename']; $form->getElement('profile_picture_background_upload') ->addFilter('Rename', array('target' => $tmpProfilePictureTitle, 'overwrite' => true)) ; $values = $form->getValues(); if (array_key_exists('profile_picture_background_upload', $values) && $values['profile_picture_background_upload'] != "") { $imageService = new Default_Model_DbTable_Image(); $newImageName = $imageService->saveImageOnMediaServer($tmpProfilePictureTitle); } if (isset($newImageName)) { $this->_memberSettings->profile_image_url_bg = IMAGES_MEDIA_SERVER . '/cache/1920x450-2/img/' . $newImageName; } $this->_memberSettings->save(); $this->view->member = $this->_memberSettings; $form->populate($this->_memberSettings->toArray()); $this->view->save = 1; $this->view->pictureformbg = $form; $this->renderScript('settings/partials/picture-bg.phtml'); } else { $this->view->pictureformbg = $form; $this->view->error = 1; $this->renderScript('settings/partials/picture-bg.phtml'); } } else { $form = $this->formProfilePictureBackground(); $form->populate($this->_memberSettings->toArray()); $this->view->pictureformbg = $form; $this->renderScript('settings/partials/picture-bg.phtml'); } } public function passwordAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer('partials/password'); if ($this->_request->isPost()) { $form = $this->formPassword(); if ($form->isValid($_POST)) { $values = $form->getValues(); if ($this->_memberSettings->password != Local_Auth_Adapter_Ocs::getEncryptedPassword($values['passwordOld'], $this->_memberSettings->password_type)) { $form->addErrorMessage('Your old Password is wrong!'); $this->view->passwordform = $form; $this->view->error = 1; } else { //20180801 ronald: If a Hive User changes his password, we change the password type to our Default if($this->_memberSettings->password_type == Default_Model_Member::PASSWORD_TYPE_HIVE) { //Save old data $this->_memberSettings->password_old = $this->_memberSettings->password; $this->_memberSettings->password_type_old = Default_Model_Member::PASSWORD_TYPE_HIVE; //Change type and password $this->_memberSettings->password_type = Default_Model_Member::PASSWORD_TYPE_OCS; } $this->_memberSettings->password = Local_Auth_Adapter_Ocs::getEncryptedPassword($values['password1'], $this->_memberSettings->password_type); $this->_memberSettings->save(); $this->view->passwordform = $this->formPassword(); $this->view->save = 1; //Update Auth-Services try { $id_server = new Default_Model_Ocs_OAuth(); $id_server->updatePasswordForUser($this->_memberSettings->member_id); } catch (Exception $e) { Zend_Registry::get('logger')->err($e->getMessage() . PHP_EOL . $e->getTraceAsString()); } try { $ldap_server = new Default_Model_Ocs_Ldap(); $ldap_server->updatePassword($this->_memberSettings->member_id); Zend_Registry::get('logger')->debug(__METHOD__ . ' - ldap : ' . implode(PHP_EOL." - ", $ldap_server->getMessages())); } catch (Exception $e) { Zend_Registry::get('logger')->err($e->getMessage() . PHP_EOL . $e->getTraceAsString()); } } } else { $this->view->passwordform = $form; $this->view->error = 1; } } else { $form = $this->formPassword(); $this->view->passwordform = $form; } } public function homepageAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer('partials/website'); if ($this->_request->isGet()) { $websiteVerifier = new Local_Verification_WebsiteOwner(); $authCode = $websiteVerifier->generateAuthCode($this->_memberSettings->link_website); $form = $this->formHomepage($this->_memberSettings->link_website, $authCode, $this->_memberSettings->validated); $this->view->homepageform = $form; return; } $form = $this->formHomepage($_POST['link_website']); if ($form->isNotValid($_POST)) { $this->view->homepageform = $form; $this->view->error = 1; return; } $values = $form->getValues(); if ($this->_memberSettings->link_website == $values['link_website']) { $websiteVerifier = new Local_Verification_WebsiteOwner(); $authCode = $websiteVerifier->generateAuthCode($this->_memberSettings->link_website); $form = $this->formHomepage($this->_memberSettings->link_website, $authCode); $this->view->homepageform = $form; $this->view->save = 0; return; } $websiteVerifier = new Local_Verification_WebsiteOwner(); $authCode = $websiteVerifier->generateAuthCode($values['link_website']); //$queue = Local_Queue_Factory::getQueue(); //$command = new Backend_Commands_CheckMemberWebsite($this->_memberId, $values['link_website'], $authCode); //$queue->send(serialize($command)); $this->_memberSettings->link_website = $values['link_website']; $this->_memberSettings->validated = 0; $this->_memberSettings->save(); $this->view->save = 1; $this->view->homepageform = $this->formHomepage($values['link_website'], $authCode); // ppload // Update profile information $this->_updatePploadProfile(); } public function newsletterAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer('partials/newsletter'); if ($this->_request->isPost()) { $form = $this->formNewsletter(); if ($form->isValid($_POST)) { $values = $form->getValues(); $this->_memberSettings->newsletter = $values['newsletter']; $this->_memberSettings->save(); $this->view->newsletterform = $this->formNewsletter($this->_memberSettings->newsletter); $this->view->save = 1; } else { $this->view->newsletterform = $form; $this->view->error = 1; } } else { $form = $this->formNewsletter($this->_memberSettings->newsletter); $this->view->newsletterform = $form; } } public function paymentAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer('partials/payment'); if ($this->_request->isPost()) { $form = $this->formPayment(); if ($form->isValid($_POST)) { $values = $form->getValues(); //If the user changes the paypal address, we set the valid staus back to null if ($this->_memberSettings->paypal_mail != $values['paypal_mail']) { //$showMember = $this->_memberTable->find($this->_memberId)->current(); //$showMember->paypal_valid_status = null; //$this->_memberTable->save($showMember); //$this->view->member = $showMember; $this->_memberTable->update(array('paypal_valid_status' => null), 'member_id = ' . $this->_memberId); //Log if paypal changes $desc = 'Paypal-Address changed from '; if (isset($this->_memberSettings->paypal_mail)) { $desc .= $this->_memberSettings->paypal_mail; } $desc .= ' to ' . $values['paypal_mail']; Default_Model_ActivityLog::logActivity($this->_memberSettings->member_id, null, $this->_memberId, Default_Model_ActivityLog::MEMBER_PAYPAL_CHANGED, array('title' => '', 'description' => $desc)); } $this->_memberSettings->paypal_mail = $values['paypal_mail']; $this->_memberSettings->wallet_address = $values['wallet_address']; $this->_memberSettings->dwolla_id = $values['dwolla_id']; $this->_memberSettings->save(); $this->view->paymentform = $this->formPayment(); $this->view->paymentform->populate($this->_memberSettings->toArray()); $this->view->save = 1; } else { $this->view->paymentform = $form; $this->view->error = 1; } } else { $form = $this->formPayment(); $form->populate($this->_memberSettings->toArray()); $this->view->paymentform = $form; } } public function deleteAction() { $this->_memberSettings->is_deleted = 1; $this->_memberSettings->is_active = 0; $this->_memberSettings->save(); $tableProject = new Default_Model_Project(); $tableProject->setAllProjectsForMemberDeleted($this->_memberId); $auth = Zend_Auth::getInstance(); $auth->clearIdentity(); $session = new Zend_Session_Namespace(); $session->unsetAll(); Zend_Session::forgetMe(); Zend_Session::destroy(); $config = Zend_Registry::get('config'); $cookieName = $config->settings->session->remember_me->name; $cookieData = $this->_request->getCookie($cookieName, null); if ($cookieData) { $cookieData = unserialize($cookieData); $remember_me_seconds = $config->settings->session->remember_me->cookie_lifetime; $domain = Local_Tools_ParseDomain::get_domain($this->getRequest()->getHttpHost()); $cookieExpire = time() - $remember_me_seconds; setcookie($cookieName, null, $cookieExpire, '/', $domain, null, true); //TODO: Remove Cookie from database $modelAuthorization = new Default_Model_Authorization(); $modelAuthorization->removeAllCookieInformation('member_id', $cookieData['mi']); } // ppload // Delete owner and related data $pploadApi = new Ppload_Api(array( 'apiUri' => PPLOAD_API_URI, 'clientId' => PPLOAD_CLIENT_ID, 'secret' => PPLOAD_SECRET )); $ownerResponse = $pploadApi->deleteOwner($this->_memberId); } public function githubtokenAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer('partials/github'); $modelGithubOauth = new Default_Model_Oauth_Github( Zend_Registry::get('db'), 'member', Zend_Registry::get('config')->third_party->github); $modelGithubOauth->authStart('/settings'); } public function addemailAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer('partials/email'); $filterInput = $this->createFilter(); if ($filterInput->hasInvalid()) { $this->view->messages = $filterInput->getMessages(); return; } $resultSet = $this->saveEmail($filterInput); $this->sendConfirmationMail($resultSet->toArray()); $this->view->messages = array('user_email' => array('success' => 'Your email was saved. Please check your email account for verification email.')); } /** * @return Zend_Filter_Input * @throws Zend_Validate_Exception */ protected function createFilter() { $mailValidCheck = new Zend_Validate_EmailAddress(); $mailValidCheck->setOptions(array('domain' => true)); $mailExistCheck = new Zend_Validate_Db_NoRecordExists(array( 'table' => 'member_email', 'field' => 'email_address', 'exclude' => array('field' => 'email_deleted', 'value' => 1) )); $mailExistCheck->setMessage('RegisterFormEmailErrAlreadyRegistered', Zend_Validate_Db_NoRecordExists::ERROR_RECORD_FOUND); // Filter-Parameter $filterInput = new Zend_Filter_Input(array('*' => 'StringTrim', 'user_email' => 'StripTags'), array( 'user_email' => array( $mailValidCheck, $mailExistCheck, 'presence' => 'required' ) ), $this->getAllParams()); return $filterInput; } /** * @param Zend_Filter_Input $filterInput * * @return Zend_Db_Table_Row_Abstract * @throws Exception */ protected function saveEmail($filterInput) { $data = array(); $data['email_member_id'] = $this->_authMember->member_id; $data['email_address'] = $filterInput->getEscaped('user_email'); $data['email_hash'] = md5($filterInput->getEscaped('user_email')); $data['email_verification_value'] = Default_Model_MemberEmail::getVerificationValue($this->_authMember->username, $filterInput->getEscaped('user_email')); $modelMemberEmail = new Default_Model_DbTable_MemberEmail(); return $modelMemberEmail->save($data); } /** * @param array $data */ protected function sendConfirmationMail($data) { $config = Zend_Registry::get('config'); $defaultFrom = $config->resources->mail->defaultFrom->email; $confirmMail = new Default_Plugin_SendMail('tpl_verify_email'); $confirmMail->setTemplateVar('servername', $this->getServerName()); $confirmMail->setTemplateVar('username', $this->_authMember->username); $confirmMail->setTemplateVar('email_address', $data['email_address']); $confirmMail->setTemplateVar('verificationlinktext', 'Click here to verify your email address'); $confirmMail->setTemplateVar('verificationlink', 'https://' . $this->getServerName() . '/settings/verification/v/' . $data['email_verification_value'] . ''); $confirmMail->setTemplateVar('verificationurl', 'https://' . $this->getServerName() . '/settings/verification/v/' . $data['email_verification_value']); $confirmMail->setReceiverMail($data['email_address']); $confirmMail->setFromMail($defaultFrom); $confirmMail->send(); } /** * @return mixed */ protected function getServerName() { /** @var Zend_Controller_Request_Http $request */ $request = $this->getRequest(); return $request->getHttpHost(); } public function removeemailAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer('partials/email'); $emailId = (int)$this->getParam('i'); $modelEmail = new Default_Model_DbTable_MemberEmail(); $result = $modelEmail->delete($emailId); $this->view->messages = array('user_email' => array('success' => 'Your email was removed.')); } public function setdefaultemailAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer('partials/email'); $emailId = (int)$this->getParam('i'); $modelEmail = new Default_Model_MemberEmail(); $result = $modelEmail->setDefaultEmail($emailId, $this->_authMember->member_id); if (true === $result) { try { $id_server = new Default_Model_Ocs_OAuth(); $id_server->updateMailForUser($this->_authMember->member_id); } catch (Exception $e) { Zend_Registry::get('logger')->err($e->getMessage() . PHP_EOL . $e->getTraceAsString()); } try { $ldap_server = new Default_Model_Ocs_Ldap(); $ldap_server->updateMail($this->_authMember->member_id); Zend_Registry::get('logger')->debug(__METHOD__ . ' - ldap : ' . implode(PHP_EOL." - ", $ldap_server->getMessages())); } catch (Exception $e) { Zend_Registry::get('logger')->err($e->getMessage() . PHP_EOL . $e->getTraceAsString()); } try { $openCode = new Default_Model_Ocs_Gitlab(); $openCode->updateMail($this->_authMember->member_id); Zend_Registry::get('logger')->debug(__METHOD__ . ' - opencode : ' . implode(PHP_EOL." - ", $openCode->getMessages())); } catch (Exception $e) { Zend_Registry::get('logger')->err($e->getMessage() . PHP_EOL . $e->getTraceAsString()); } } } public function resendverificationAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer('partials/email'); $emailId = (int)$this->getParam('i'); $modelEmail = new Default_Model_DbTable_MemberEmail(); $data = $modelEmail->find($emailId)->current(); $data->email_verification_value = md5($data->email_address . $this->_authMember->username . time()); $data->save(); $this->sendConfirmationMail($data); $this->view->messages = array('user_email' => array('success' => 'New verification mail was send. Please check your email account.')); } public function verificationAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); // Filter-Parameter $filterInput = new Zend_Filter_Input(array('*' => 'StringTrim', 'v' => 'StripTags'), array( 'v' => array( 'presence' => 'required' ) ), $this->getAllParams()); if ($filterInput->hasInvalid()) { $this->_helper->flashMessenger->addMessage('

There was an error verifying your email.

'); $this->forward('index'); return; } $modelEmail = new Default_Model_MemberEmail(); $result = $modelEmail->verificationEmail($filterInput->getEscaped('v')); if ($result == 1) { $this->_helper->flashMessenger->addMessage('

Your email was successfully verified.

'); } else { $this->_helper->flashMessenger->addMessage('

There was an error verifying your email.

'); } $this->forward('index'); } } diff --git a/application/modules/default/models/Tags.php b/application/modules/default/models/Tags.php index 4facd5951..aba6b2eca 100644 --- a/application/modules/default/models/Tags.php +++ b/application/modules/default/models/Tags.php @@ -1,1201 +1,1206 @@ . * * Created: 11.09.2017 */ class Default_Model_Tags { const TAG_TYPE_PROJECT = 1; const TAG_TYPE_MEMBER = 2; const TAG_TYPE_FILE = 3; const TAG_TYPE_OSUSER = 9; const TAG_USER_GROUPID = 5; const TAG_CATEGORY_GROUPID = 6; const TAG_LICENSE_GROUPID = 7; const TAG_PACKAGETYPE_GROUPID = 8; const TAG_ARCHITECTURE_GROUPID = 9; const TAG_GHNS_EXCLUDED_GROUPID = 10; const TAG_PRODUCT_ORIGINAL_GROUPID = 11; const TAG_PRODUCT_ORIGINAL_ID = 2451; const TAG_PRODUCT_EBOOK_GROUPID = 14; const TAG_PRODUCT_EBOOK_AUTHOR_GROUPID = 15; const TAG_PRODUCT_EBOOK_EDITOR_GROUPID = 16; const TAG_PRODUCT_EBOOK_ILLUSTRATOR_GROUPID = 17; const TAG_PRODUCT_EBOOK_TRANSLATOR_GROUPID = 18; const TAG_PRODUCT_EBOOK_SUBJECT_GROUPID = 19; const TAG_PRODUCT_EBOOK_SHELF_GROUPID = 20; const TAG_PRODUCT_EBOOK_LANGUAGE_GROUPID = 21; const TAG_PRODUCT_EBOOK_TYPE_GROUPID = 22; const TAG_PRODUCT_EBOOK_ID = 2532; const TAG_PROJECT_GROUP_IDS = '6,7,10';//type product : category-tags, license-tags,ghns_excluded const TAG_FILE_GROUP_IDS = '8,9';//file-packagetype-tags,file-architecture-tags // $tag_project_group_ids ='6,7,10'; // $tag_file_group_ids ='8,9'; /** * Default_Model_Tags constructor. */ public function __construct() { } /** * @param int $object_id * @param string $tags * @param int $tag_type */ public function processTags($object_id, $tags, $tag_type) { $this->assignTags($object_id, $tags, $tag_type); $this->deassignTags($object_id, $tags, $tag_type); } /** * @param int $object_id * @param string $tags * @param int $tag_type */ public function assignTags($object_id, $tags, $tag_type) { $new_tags = array_diff(explode(',', $tags), explode(',', $this->getTags($object_id, $tag_type))); $tableTags = new Default_Model_DbTable_Tags(); $listIds = $tableTags->storeTags(implode(',', $new_tags)); $prepared_insert = array_map(function ($id) use ($object_id, $tag_type) { return "({$id}, {$tag_type}, {$object_id})"; }, $listIds); $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id) VALUES " . implode(',', $prepared_insert); $this->getAdapter()->query($sql); } /** * @param int $object_id * @param int $tag_type * * @return string|null */ public function getTags($object_id, $tag_type) { $sql = " SELECT GROUP_CONCAT(tag.tag_name) AS tag_names FROM tag_object JOIN tag ON tag.tag_id = tag_object.tag_id join tag_group_item on tag_object.tag_id = tag_group_item.tag_id WHERE tag_type_id = :type AND tag_object_id = :object_id and tag_group_item.tag_group_id <> :tag_user_groupid and tag_object.is_deleted = 0 GROUP BY tag_object.tag_object_id "; $result = $this->getAdapter()->fetchRow($sql, array('type' => $tag_type, 'object_id' => $object_id, 'tag_user_groupid' =>Default_Model_Tags::TAG_USER_GROUPID )); if (isset($result['tag_names'])) { return $result['tag_names']; } return null; } /** * @param int $object_id * @param int $tag_type * @param String $tag_group_ids * * @return string|null */ public function getTagsArray($object_id, $tag_type,$tag_group_ids) { $sql = " SELECT tag.tag_id,tag.tag_name,tag_group_item.tag_group_id,tag.tag_fullname, tag.tag_description FROM tag_object JOIN tag ON tag.tag_id = tag_object.tag_id join tag_group_item on tag_object.tag_id = tag_group_item.tag_id and tag_object.tag_group_id = tag_group_item.tag_group_id WHERE tag_type_id = :type AND tag_object_id = :object_id and tag_object.tag_group_id in ({$tag_group_ids} ) and tag_object.is_deleted = 0 order by tag_group_item.tag_group_id desc , tag.tag_name asc "; $result = $this->getAdapter()->fetchAll($sql, array('type' => $tag_type, 'object_id' => $object_id)); return $result; } /** * @param int $object_id * @param int $tag_type * * @return string|null */ public function getTagsUser($object_id, $tag_type) { $tag_group_ids =$this::TAG_USER_GROUPID; $tags = $this->getTagsArray($object_id, $tag_type,$tag_group_ids); $tag_names = ''; foreach ($tags as $tag) { $tag_names=$tag_names.$tag['tag_name'].','; } $len = strlen($tag_names); if ($len>0) { return substr($tag_names,0,($len-1)); } return null; } /** * @param int $projectid * @param int $tag * * @return string|null */ public function isTagsUserExisting($project_id, $tagname) { $sql_object= "select count(1) as cnt from tag_object JOIN tag ON tag.tag_id = tag_object.tag_id WHERE tag.tag_name = :tagname and tag_object.tag_group_id=:tag_group_id and tag_object.is_deleted=0 and tag_object.tag_object_id=:project_id and tag_object.tag_type_id=:tag_type_id"; $r = $this->getAdapter()->fetchRow($sql_object, array( 'tagname' => $tagname ,'tag_group_id'=>Default_Model_Tags::TAG_USER_GROUPID , 'project_id'=>$project_id , 'tag_type_id'=>Default_Model_Tags::TAG_TYPE_PROJECT )); if($r['cnt'] ==0){ return false; }else{ return true; } } /** * @param int $object_id * @param int $tag_type * * @return string|null */ public function getTagsCategory($object_id, $tag_type) { $tag_group_ids = $this::TAG_CATEGORY_GROUPID; $tags = $this->getTagsArray($object_id, $tag_type,$tag_group_ids); $tag_names = ''; foreach ($tags as $tag) { $tag_names=$tag_names.$tag['tag_name'].','; } $len = strlen($tag_names); if ($len>0) { return substr($tag_names,0,($len-1)); } return null; } /** * @param int $object_id * @param int $tag_type * * @return string|null */ public function getTagsSystem($object_id, $tag_type) { $tag_group_ids ='6,7,10'; $tags = $this->getTagsArray($object_id, $tag_type,$tag_group_ids); $tag_names = ''; foreach ($tags as $tag) { $tag_names=$tag_names.$tag['tag_name'].','; } $len = strlen($tag_names); if ($len>0) { return substr($tag_names,0,($len-1)); } return null; } /** * @param int $object_id * @param int $tag_type * * @return string|null */ public function getTagsSystemList($project_id) { $tag_project_group_ids = SELF::TAG_PROJECT_GROUP_IDS; $tag_file_group_ids = SELF::TAG_FILE_GROUP_IDS; $sql =" SELECT tag.tag_id,tag.tag_name,tag_object.tag_group_id FROM tag_object JOIN tag ON tag.tag_id = tag_object.tag_id WHERE tag_type_id = :type_project AND tag_object_id = :project_id and tag_object.tag_group_id in ({$tag_project_group_ids} ) and tag_object.is_deleted = 0 union all SELECT distinct t.tag_id,t.tag_name,o.tag_group_id FROM tag_object o JOIN tag t ON t.tag_id = o.tag_id inner join project p on o.tag_parent_object_id = p.project_id inner join ppload.ppload_files f on p.ppload_collection_id = f.collection_id and o.tag_object_id=f.id and f.active = 1 WHERE o.tag_type_id = :type_file AND p.project_id = :project_id and o.tag_group_id in ({$tag_file_group_ids} ) and o.is_deleted = 0 order by tag_group_id , tag_name "; $result = $this->getAdapter()->fetchAll($sql, array('type_project' => Default_Model_Tags::TAG_TYPE_PROJECT , 'project_id' => $project_id , 'type_file' => Default_Model_Tags::TAG_TYPE_FILE )); return $result; } /** * @param int $object_id * @param int $tag_type * * @return string|null */ public function getTagsUserCount($object_id, $tag_type) { $sql = " SELECT count(*) as cnt FROM tag_object JOIN tag ON tag.tag_id = tag_object.tag_id join tag_group_item on tag_object.tag_id = tag_group_item.tag_id and tag_object.tag_group_id = tag_group_item.tag_group_id WHERE tag_type_id = :type AND tag_object_id = :object_id and tag_object.is_deleted = 0 and tag_group_item.tag_group_id = :tag_user_groupid "; $result = $this->getAdapter()->fetchRow($sql, array('type' => $tag_type, 'object_id' => $object_id, 'tag_user_groupid' =>Default_Model_Tags::TAG_USER_GROUPID )); if (isset($result['cnt'])) { return $result['cnt']; } return 0; } public function filterTagsUser($filter, $limit) { $sql = " select tag.tag_id ,tag.tag_name from tag join tag_group_item on tag.tag_id = tag_group_item.tag_id and tag_group_item.tag_group_id = :tag_user_groupid where tag.tag_name like '%".$filter."%' "; if (isset($limit)) { $sql.= ' limit ' . $limit; } $result = $this->getAdapter()->fetchAll($sql, array('tag_user_groupid' =>Default_Model_Tags::TAG_USER_GROUPID )); return $result; } /** * @return Zend_Db_Adapter_Abstract */ private function getAdapter() { return Zend_Db_Table::getDefaultAdapter(); } /** * @param int $object_id * @param string $tags * @param int $tag_type */ public function deassignTags($object_id, $tags, $tag_type) { $removable_tags = array_diff(explode(',', $this->getTags($object_id, $tag_type)), explode(',', $tags)); //$sql = "DELETE tag_object FROM tag_object JOIN tag ON tag.tag_id = tag_object.tag_id WHERE tag.tag_name = :name and tag_object.tag_object_id=:object_id"; $sql = "UPDATE tag_object inner join tag ON tag.tag_id = tag_object.tag_id SET tag_changed = NOW() , is_deleted = 1 WHERE tag.tag_name = :name and tag_object.tag_object_id=:object_id"; $this->getAdapter()->query($sql, array('tagObjectId' => $object_id, 'tagType' => $tag_type)); foreach ($removable_tags as $removable_tag) { $this->getAdapter()->query($sql, array('name' => $removable_tag,'object_id' => $object_id)); } $this->updateChanged($object_id, $tag_type); } /** * @param int $object_id * @param string $tags * @param int $tag_type */ public function processTagsUser($object_id, $tags, $tag_type) { if($tags) { $this->assignTagsUser($object_id, $tags, $tag_type); } $this->deassignTagsUser($object_id, $tags, $tag_type); } public function isProuductOriginal($project_id) { $sql_object= "select tag_item_id from tag_object WHERE tag_id = :tag_id and tag_object_id=:tag_object_id and tag_group_id=:tag_group_id and tag_type_id = :tag_type_id and is_deleted = 0"; $r = $this->getAdapter()->fetchRow($sql_object, array('tag_id' => self::TAG_PRODUCT_ORIGINAL_ID, 'tag_object_id' =>$project_id, 'tag_group_id' => self::TAG_PRODUCT_ORIGINAL_GROUPID, 'tag_type_id' => self::TAG_TYPE_PROJECT )); if($r){ return true; }else { return false; } } public function isProuductEbook($project_id) { $ebookTagGroupId = Zend_Registry::get('config')->settings->client->default->tag_group_ebook; $ebookTagId = Zend_Registry::get('config')->settings->client->default->tag_is_ebook; $sql_object= "select tag_item_id from tag_object WHERE tag_id = :tag_id and tag_object_id=:tag_object_id and tag_group_id=:tag_group_id and tag_type_id = :tag_type_id and is_deleted = 0"; $r = $this->getAdapter()->fetchRow($sql_object, array('tag_id' => $ebookTagId, 'tag_object_id' =>$project_id, 'tag_group_id' => $ebookTagGroupId, 'tag_type_id' => self::TAG_TYPE_PROJECT )); if($r){ return true; }else { return false; } } /** * @param int $object_id * @param string $value */ public function processTagProductOriginal($object_id, $is_original) { $sql_object= "select tag_item_id from tag_object WHERE tag_id = :tag_id and tag_object_id=:tag_object_id and tag_group_id=:tag_group_id and tag_type_id = :tag_type_id and is_deleted = 0"; $r = $this->getAdapter()->fetchRow($sql_object, array('tag_id' => self::TAG_PRODUCT_ORIGINAL_ID, 'tag_object_id' =>$object_id, 'tag_group_id' => self::TAG_PRODUCT_ORIGINAL_GROUPID, 'tag_type_id' => self::TAG_TYPE_PROJECT )); if($is_original=='1') { if(!$r){ $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id, tag_group_id) VALUES (:tag_id, :tag_type_id, :tag_object_id, :tag_group_id)"; $this->getAdapter()->query($sql, array('tag_id' => self::TAG_PRODUCT_ORIGINAL_ID, 'tag_type_id' => self::TAG_TYPE_PROJECT , 'tag_object_id' => $object_id, 'tag_group_id' => self::TAG_PRODUCT_ORIGINAL_GROUPID)); } }else{ if($r){ $sql = "UPDATE tag_object set tag_changed = NOW() , is_deleted = 1 WHERE tag_item_id = :tagItemId"; $this->getAdapter()->query($sql, array('tagItemId' => $r['tag_item_id'])); } } } /** * @param int $object_id * @param string $value */ public function processTagCollection($object_id) { $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id, tag_group_id) VALUES (:tag_id, :tag_type_id, :tag_object_id, :tag_group_id)"; $this->getAdapter()->query($sql, array('tag_id' => self::TAG_COLLECTION_ID_ID, 'tag_type_id' => self::TAG_TYPE_PROJECT , 'tag_object_id' => $object_id, 'tag_group_id' => self::TAG_COLLECTION_GROUPID)); } /** * @param int $object_id * @param string $tags * @param int $tag_type */ public function assignTagsUser($object_id, $tags, $tag_type) { $tags = strtolower($tags); $tag_group_id = 5; $new_tags = array_diff(explode(',', $tags), explode(',', $this->getTagsUser($object_id, $tag_type))); if(sizeof($new_tags)>0) { $tableTags = new Default_Model_DbTable_Tags(); $listIds = $tableTags->storeTagsUser(implode(',', $new_tags)); $prepared_insert = array_map(function ($id) use ($object_id, $tag_type,$tag_group_id) { return "({$id}, {$tag_type}, {$object_id},{$tag_group_id})"; }, $listIds); $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id,tag_group_id) VALUES " . implode(',', $prepared_insert); $this->getAdapter()->query($sql); } } /** * @param int $object_id * @param string $tags * @param int $tag_type */ public function addTagUser($object_id, $tag, $tag_type) { $tableTags = new Default_Model_DbTable_Tags(); $listIds = $tableTags->storeTagsUser($tag); $tag_group_id = $this::TAG_USER_GROUPID; $prepared_insert = array_map(function ($id) use ($object_id, $tag_type,$tag_group_id) { return "({$id}, {$tag_type}, {$object_id},{$tag_group_id})"; }, $listIds); $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id,tag_group_id) VALUES " . implode(',', $prepared_insert); $this->getAdapter()->query($sql); } public function deassignTagsUser($object_id, $tags, $tag_type) { if($tags) { $tags = strtolower($tags); $removable_tags = array_diff(explode(',', $this->getTagsUser($object_id, $tag_type)), explode(',', $tags)); } else { $removable_tags = explode(',', $this->getTagsUser($object_id, $tag_type)); } //$sql = "DELETE tag_object FROM tag_object JOIN tag ON tag.tag_id = tag_object.tag_id WHERE tag_group_id = ".Default_Model_Tags::TAG_USER_GROUPID." and tag.tag_name = :name and tag_object.tag_object_id=:object_id"; $sql = "UPDATE tag_object inner join tag ON tag.tag_id = tag_object.tag_id set tag_changed = NOW() , is_deleted = 1 WHERE tag_group_id = ".Default_Model_Tags::TAG_USER_GROUPID." and tag.tag_name = :name and tag_object.tag_object_id=:object_id"; foreach ($removable_tags as $removable_tag) { $this->getAdapter()->query($sql, array('name' => $removable_tag,'object_id' => $object_id)); // if Tag is the only one in Tag_object table then delete this tag for user_groupid = 5 $sql_object= "select count(1) as cnt from tag_object JOIN tag ON tag.tag_id = tag_object.tag_id WHERE tag.tag_name = :name"; $r = $this->getAdapter()->fetchRow($sql_object, array('name' => $removable_tag)); if($r['cnt'] ==0){ // then remove tag if not existing in Tag_object $sql_delete_tag = "delete from tag where tag_name=:name"; $this->getAdapter()->query($sql_delete_tag, array('name' => $removable_tag)); } } $this->updateChanged($object_id, $tag_type); } public function deleteTagUser($object_id, $tag, $tag_type) { $removable_tag =$tag; // $sql = "DELETE tag_object FROM tag_object JOIN tag ON tag.tag_id = tag_object.tag_id WHERE tag_group_id = ".Default_Model_Tags::TAG_USER_GROUPID." and tag.tag_name = :name and tag_object.tag_object_id=:object_id // and tag_group_id =".Default_Model_Tags::TAG_USER_GROUPID; $sql = "UPDATE tag_object inner join tag ON tag.tag_id = tag_object.tag_id set tag_changed = NOW() , is_deleted = 1 WHERE tag_group_id = ".Default_Model_Tags::TAG_USER_GROUPID." and tag.tag_name = :name and tag_object.tag_object_id=:object_id"; $this->getAdapter()->query($sql, array('name' => $removable_tag,'object_id' => $object_id)); // if Tag is the only one in Tag_object table then delete this tag for user_groupid = 5 $sql_object= "select count(1) as cnt from tag_object JOIN tag ON tag.tag_id = tag_object.tag_id WHERE tag.tag_name = :name "; $r = $this->getAdapter()->fetchRow($sql_object, array('name' => $removable_tag)); if($r['cnt'] ==0){ // then remove tag if not existing in Tag_object $sql_delete_tag = "delete from tag where tag_name=:name"; $this->getAdapter()->query($sql_delete_tag, array('name' => $removable_tag)); } $this->updateChanged($object_id, $tag_type); } private function updateChanged($object_id, $tag_type) { $sql = "UPDATE tag_object SET tag_changed = NOW() WHERE tag_object_id = :tagObjectId AND tag_type_id = :tagType"; $this->getAdapter()->query($sql, array('tagObjectId' => $object_id, 'tagType' => $tag_type)); } public function getTagsPerCategory($cat_id) { $sql = "select t.* from category_tag as c ,tag as t where c.tag_id = t.tag_id and c.category_id = :cat_id"; $r = $this->getAdapter()->fetchAll($sql, array('cat_id' => $cat_id)); return $r; } public function validateCategoryTags($cat_id,$tags) { if($tags == null) return true; //check if $cat_id children has tag already $sql = ' select * from category_tag where tag_id in ('.$tags.') and category_id in ( select c.project_category_id from project_category c join project_category d where d.project_category_id = '.$cat_id.' and c.lft> d.lft and c.rgtgetAdapter()->fetchAll($sql); if(sizeof($r)>0) return false; // check parent $sql = ' select ancestor_id_path from stat_cat_tree where project_category_id = '.$cat_id; $r = $this->getAdapter()->fetchRow($sql); $sql = ' select * from category_tag where category_id in ('.$r['ancestor_id_path'].') and category_id <> '.$cat_id.' and tag_id in ('.$tags.')'; $r = $this->getAdapter()->fetchAll($sql); if(sizeof($r)>0) return false; return true; } public function updateTagsPerCategory($cat_id,$tags) { $sql = "delete from category_tag where category_id=:cat_id"; $this->getAdapter()->query($sql, array('cat_id' => $cat_id)); if($tags){ $tags_id =explode(',', $tags); $prepared_insert = array_map(function ($id) use ($cat_id) { return "({$cat_id},{$id})"; }, $tags_id); $sql = "INSERT IGNORE INTO category_tag (category_id, tag_id) VALUES " . implode(',', $prepared_insert); $this->getAdapter()->query($sql); } } public function updateTagsPerStore($store_id,$tags) { $sql = "delete from config_store_tag where store_id=:store_id"; $this->getAdapter()->query($sql, array('store_id' => $store_id)); if($tags){ $tags_id =explode(',', $tags); $prepared_insert = array_map(function ($id) use ($store_id) { return "({$store_id},{$id})"; }, $tags_id); $sql = "INSERT IGNORE INTO config_store_tag (store_id, tag_id) VALUES " . implode(',', $prepared_insert); $this->getAdapter()->query($sql); } } public function getTagsPerGroup($groupid) { $sql = " select tag.tag_id ,tag.tag_name ,tag_fullname ,tag_description from tag join tag_group_item on tag.tag_id = tag_group_item.tag_id and tag_group_item.tag_group_id = :groupid order by tag_name "; $result = $this->getAdapter()->fetchAll($sql, array('groupid' => $groupid)); return $result; } public function getAllTagsForStoreFilter() { $sql = " select tag.tag_id, CASE WHEN tag.tag_fullname IS NULL THEN tag_name ELSE tag.tag_fullname END as tag_name from tag where tag.is_active = 1 order by tag_name "; $result = $this->getAdapter()->fetchAll($sql); return $result; } public function getAllTagGroupsForStoreFilter() { $sql = " select tag_group.group_id, tag_group.group_name as group_name from tag_group order by tag_group.group_name "; $result = $this->getAdapter()->fetchAll($sql); return $result; } public function saveLicenseTagForProject($object_id, $tag_id) { $tableTags = new Default_Model_DbTable_Tags(); $tags = $tableTags->fetchLicenseTagsForProject($object_id); if(count($tags) ==0){ //insert new tag if($tag_id) { $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id, tag_group_id) VALUES (:tag_id, :tag_type_id, :tag_object_id, :tag_group_id)"; $this->getAdapter()->query($sql, array('tag_id' => $tag_id, 'tag_type_id' => $this::TAG_TYPE_PROJECT, 'tag_object_id' => $object_id, 'tag_group_id' => $this::TAG_LICENSE_GROUPID)); } }else { $tag = $tags[0]; //remove tag license if(!$tag_id) { //$sql = "DELETE FROM tag_object WHERE tag_item_id = :tagItemId"; $sql = "UPDATE tag_object set tag_changed = NOW() , is_deleted = 1 WHERE tag_item_id = :tagItemId"; $this->getAdapter()->query($sql, array('tagItemId' => $tag['tag_item_id'])); } else { //Update old tag if($tag_id <> $tag['tag_id']) { $sql = "UPDATE tag_object SET tag_changed = NOW(),tag_id = :tag_id WHERE tag_item_id = :tagItemId"; $this->getAdapter()->query($sql, array('tagItemId' => $tag['tag_item_id'], 'tag_id' => $tag_id)); } } } // if(count($tags) >= 1) { // $tag = $tags[0]; // //remove tag license // if(!$tag_id) { // //$sql = "DELETE FROM tag_object WHERE tag_item_id = :tagItemId"; // $sql = "UPDATE tag_object set tag_changed = NOW() , is_deleted = 1 WHERE tag_item_id = :tagItemId"; // $this->getAdapter()->query($sql, array('tagItemId' => $tag['tag_item_id'])); // } else { // //Update old tag // if($tag_id <> $tag['tag_id']) { // $sql = "UPDATE tag_object SET tag_changed = NOW(),tag_id = :tag_id WHERE tag_item_id = :tagItemId"; // $this->getAdapter()->query($sql, array('tagItemId' => $tag['tag_item_id'], 'tag_id' => $tag_id)); // } // } // } else { // //insert new tag // if($tag_id) { // $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id, tag_group_id) VALUES (:tag_id, :tag_type_id, :tag_object_id, :tag_group_id)"; // $this->getAdapter()->query($sql, array('tag_id' => $tag_id, 'tag_type_id' => $this::TAG_TYPE_PROJECT, 'tag_object_id' => $object_id, 'tag_group_id' => $this::TAG_LICENSE_GROUPID)); // } // } } public function saveGhnsExcludedTagForProject($object_id, $tag_value) { $tableTags = new Default_Model_DbTable_Tags(); $ghnsExcludedTagId = $tableTags->fetchGhnsExcludedTagId(); $sql = "UPDATE tag_object SET tag_changed = NOW() , is_deleted = 1 WHERE tag_group_id = :tag_group_id AND tag_type_id = :tag_type_id AND tag_object_id = :tag_object_id"; $this->getAdapter()->query($sql, array('tag_group_id' => $this::TAG_GHNS_EXCLUDED_GROUPID, 'tag_type_id' => $this::TAG_TYPE_PROJECT, 'tag_object_id' => $object_id)); if($tag_value == 1) { $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id, tag_group_id) VALUES (:tag_id, :tag_type_id, :tag_object_id, :tag_group_id)"; $this->getAdapter()->query($sql, array('tag_id' => $ghnsExcludedTagId, 'tag_type_id' => $this::TAG_TYPE_PROJECT, 'tag_object_id' => $object_id, 'tag_group_id' => $this::TAG_GHNS_EXCLUDED_GROUPID)); } } public function saveArchitectureTagForProject($project_id, $file_id, $tag_id) { //first delte old //$sql = "DELETE FROM tag_object WHERE tag_group_id = :tag_group_id AND tag_type_id = :tag_type_id AND tag_object_id = :tag_object_id AND tag_parent_object_id = :tag_parent_object_id"; $sql = "UPDATE tag_object SET tag_changed = NOW() , is_deleted = 1 WHERE tag_group_id = :tag_group_id AND tag_type_id = :tag_type_id AND tag_object_id = :tag_object_id AND tag_parent_object_id = :tag_parent_object_id"; $this->getAdapter()->query($sql, array('tag_group_id' => $this::TAG_ARCHITECTURE_GROUPID, 'tag_type_id' => $this::TAG_TYPE_FILE, 'tag_object_id' => $file_id, 'tag_parent_object_id' => $project_id)); if($tag_id) { $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id, tag_parent_object_id, tag_group_id) VALUES (:tag_id, :tag_type_id, :tag_object_id, :tag_parent_object_id, :tag_group_id)"; $this->getAdapter()->query($sql, array('tag_id' => $tag_id, 'tag_type_id' => $this::TAG_TYPE_FILE, 'tag_object_id' => $file_id, 'tag_parent_object_id' => $project_id, 'tag_group_id' => $this::TAG_ARCHITECTURE_GROUPID)); } /** $tableTags = new Default_Model_DbTable_Tags(); $tags = $tableTags->fetchArchitectureTagsForProject($object_id); if(count($tags) == 1) { $tag = $tags[0]; //remove tag license if(!$tag_id) { $sql = "DELETE FROM tag_object WHERE tag_item_id = :tagItemId"; $this->getAdapter()->query($sql, array('tagItemId' => $tag['tag_item_id'])); } else { //Update old tag if($tag_id <> $tag['tag_id']) { $sql = "UPDATE tag_object SET tag_changed = NOW(),tag_id = :tag_id WHERE tag_item_id = :tagItemId"; $this->getAdapter()->query($sql, array('tagItemId' => $tag['tag_item_id'], 'tag_id' => $tag_id)); } } } else { //insert new tag if($tag_id) { $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id, tag_group_id) VALUES (:tag_id, :tag_type_id, :tag_object_id, :tag_group_id)"; $this->getAdapter()->query($sql, array('tag_id' => $tag_id, 'tag_type_id' => $this::TAG_TYPE_PROJECT, 'tag_object_id' => $object_id, 'tag_group_id' => $this::TAG_ARCHITECTURE_GROUPID)); } } * */ } public function saveFileTagForProjectAndTagGroup($project_id, $file_id, $tag_id, $tag_group_id) { //first delte old $sql = "UPDATE tag_object SET tag_changed = NOW() , is_deleted = 1 WHERE tag_group_id = :tag_group_id AND tag_type_id = :tag_type_id AND tag_object_id = :tag_object_id AND tag_parent_object_id = :tag_parent_object_id"; $this->getAdapter()->query($sql, array('tag_group_id' => $tag_group_id, 'tag_type_id' => $this::TAG_TYPE_FILE, 'tag_object_id' => $file_id, 'tag_parent_object_id' => $project_id)); if(!empty($tag_id)) { if(is_array($tag_id)) { foreach ($tag_id as $tag) { $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id, tag_parent_object_id, tag_group_id) VALUES (:tag_id, :tag_type_id, :tag_object_id, :tag_parent_object_id, :tag_group_id)"; $this->getAdapter()->query($sql, array('tag_id' => $tag, 'tag_type_id' => $this::TAG_TYPE_FILE, 'tag_object_id' => $file_id, 'tag_parent_object_id' => $project_id, 'tag_group_id' => $tag_group_id)); } } else { $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id, tag_parent_object_id, tag_group_id) VALUES (:tag_id, :tag_type_id, :tag_object_id, :tag_parent_object_id, :tag_group_id)"; $this->getAdapter()->query($sql, array('tag_id' => $tag_id, 'tag_type_id' => $this::TAG_TYPE_FILE, 'tag_object_id' => $file_id, 'tag_parent_object_id' => $project_id, 'tag_group_id' => $tag_group_id)); } } } public function deleteFileTagForProject($project_id, $file_id, $tag_id) { //first delte old $sql = "UPDATE tag_object SET tag_changed = NOW() , is_deleted = 1 WHERE tag_id= :tag_id AND tag_type_id = :tag_type_id AND tag_object_id = :tag_object_id AND tag_parent_object_id = :tag_parent_object_id"; $this->getAdapter()->query($sql, array('tag_id' => $tag_id, 'tag_type_id' => $this::TAG_TYPE_FILE, 'tag_object_id' => $file_id, 'tag_parent_object_id' => $project_id)); } public function savePackagetypeTagForProject($project_id, $file_id, $tag_id) { //first delte old $sql = "UPDATE tag_object SET tag_changed = NOW() , is_deleted = 1 WHERE tag_group_id = :tag_group_id AND tag_type_id = :tag_type_id AND tag_object_id = :tag_object_id AND tag_parent_object_id = :tag_parent_object_id"; $this->getAdapter()->query($sql, array('tag_group_id' => $this::TAG_PACKAGETYPE_GROUPID, 'tag_type_id' => $this::TAG_TYPE_FILE, 'tag_object_id' => $file_id, 'tag_parent_object_id' => $project_id)); if($tag_id) { $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id, tag_parent_object_id, tag_group_id) VALUES (:tag_id, :tag_type_id, :tag_object_id, :tag_parent_object_id, :tag_group_id)"; $this->getAdapter()->query($sql, array('tag_id' => $tag_id, 'tag_type_id' => $this::TAG_TYPE_FILE, 'tag_object_id' => $file_id, 'tag_parent_object_id' => $project_id, 'tag_group_id' => $this::TAG_PACKAGETYPE_GROUPID)); } } public function getProjectPackageTypesString($projectId) { $sql = 'SELECT DISTINCT ta.tag_fullname as name FROM tag_object t INNER JOIN tag ta on ta.tag_id = t.tag_id WHERE t.tag_group_id = :tag_group_id AND t.tag_parent_object_id = :project_id AND t.is_deleted = 0'; $resultSet = $this->getAdapter()->fetchAll($sql, array('tag_group_id' => $this::TAG_PACKAGETYPE_GROUPID,'project_id' => $projectId)); $resultString = ''; if (count($resultSet) > 0) { foreach ($resultSet as $item) { $resultString = $resultString . ' ' . stripslashes($item['name']) . ''; } return $resultString; } return ''; } public function getProjectPackageTypesPureStrings($projectId) { $sql = 'SELECT DISTINCT ta.tag_fullname as name FROM tag_object t INNER JOIN tag ta on ta.tag_id = t.tag_id WHERE t.tag_group_id = :tag_group_id AND t.tag_parent_object_id = :project_id AND t.is_deleted = 0'; $resultSet = $this->getAdapter()->fetchAll($sql, array('tag_group_id' => $this::TAG_PACKAGETYPE_GROUPID,'project_id' => $projectId)); $resultString = ''; if (count($resultSet) > 0) { foreach ($resultSet as $item) { $resultString = $resultString .' '. stripslashes($item['name']) ; } return $resultString; } return ''; } public function deleteFileTagsOnProject($projectId, $fileId) { $sql = "UPDATE tag_object inner join tag ON tag.tag_id = tag_object.tag_id set tag_changed = NOW() , is_deleted = 1 WHERE tag_type_id = :tag_type_id and tag_object.tag_object_id=:object_id and tag_object.tag_parent_object_id=:parent_object_id"; $this->getAdapter()->query($sql, array('tag_type_id' => $this::TAG_TYPE_FILE, 'object_id' => $fileId, 'parent_object_id' => $projectId)); } public function deletePackageTypeOnProject($projectId, $fileId) { $sql = "UPDATE tag_object inner join tag ON tag.tag_id = tag_object.tag_id set tag_changed = NOW() , is_deleted = 1 WHERE tag_group_id = :tag_group_id and tag_object.tag_object_id=:object_id and tag_object.tag_parent_object_id=:parent_object_id"; $this->getAdapter()->query($sql, array('tag_group_id' => $this::TAG_PACKAGETYPE_GROUPID, 'object_id' => $fileId, 'parent_object_id' => $projectId)); } public function deleteArchitectureOnProject($projectId, $fileId) { $sql = "UPDATE tag_object inner join tag ON tag.tag_id = tag_object.tag_id set tag_changed = NOW() , is_deleted = 1 WHERE tag_group_id = :tag_group_id and tag_object.tag_object_id=:object_id and tag_object.tag_parent_object_id=:parent_object_id"; $this->getAdapter()->query($sql, array('tag_group_id' => $this::TAG_ARCHITECTURE_GROUPID, 'object_id' => $fileId, 'parent_object_id' => $projectId)); } /** * @param int $projectId * @param int $fileId * @return string */ public function getPackageType($projectId, $fileId) { $sql = 'SELECT ta.tag_fullname as name FROM tag_object t INNER JOIN tag ta on ta.tag_id = t.tag_id WHERE t.tag_group_id = :tag_group_id AND t.tag_parent_object_id = :project_id AND t.tag_object_id = :file_id AND t.is_deleted = 0'; $resultSet = $this->getAdapter()->fetchAll($sql, array('tag_group_id' => $this::TAG_PACKAGETYPE_GROUPID,'project_id' => $projectId, 'file_id' => $fileId)); if (count($resultSet) > 0) { return $resultSet[0]['name']; } else { return ''; } } /** * @param int $projectId * @param int $fileId * @return string */ public function getFileTags($fileId) { $sql = 'SELECT ta.tag_id, ta.tag_fullname as name FROM tag_object t INNER JOIN tag ta on ta.tag_id = t.tag_id WHERE t.tag_type_id = :tag_type_id AND t.tag_object_id = :file_id AND t.is_deleted = 0'; $resultSet = $this->getAdapter()->fetchAll($sql, array('tag_type_id' => $this::TAG_TYPE_FILE,'file_id' => $fileId)); return $resultSet; } /** * @param int $projectId * @param int $fileId * @return string */ public function getTagsForFileAndTagGroup($projectId, $fileId, $tagGroup) { $sql = 'SELECT ta.tag_fullname as name FROM tag_object t INNER JOIN tag ta on ta.tag_id = t.tag_id WHERE t.tag_group_id = :tag_group_id AND t.tag_parent_object_id = :project_id AND t.tag_object_id = :file_id AND t.is_deleted = 0'; $resultSet = $this->getAdapter()->fetchAll($sql, array('tag_group_id' => $tagGroup,'project_id' => $projectId, 'file_id' => $fileId)); return $resultSet; } /** * @param int $object_id * * @return string|null */ public function getTagsEbookSubject($object_id) { $tag_group_ids = Zend_Registry::get('config')->settings->client->default->tag_group_ebook_subject; $tags = $this->getTagsArray($object_id, $this::TAG_TYPE_PROJECT,$tag_group_ids); return $tags; } /** * @param int $object_id * * @return string|null */ public function getTagsEbookAuthor($object_id) { $tag_group_ids = Zend_Registry::get('config')->settings->client->default->tag_group_ebook_author; $tags = $this->getTagsArray($object_id, $this::TAG_TYPE_PROJECT,$tag_group_ids); return $tags; } /** * @param int $object_id * * @return string|null */ public function getTagsEbookEditor($object_id) { $tag_group_ids = Zend_Registry::get('config')->settings->client->default->tag_group_ebook_editor; $tags = $this->getTagsArray($object_id, $this::TAG_TYPE_PROJECT,$tag_group_ids); return $tags; } /** * @param int $object_id * * @return string|null */ public function getTagsEbookIllustrator($object_id) { $tag_group_ids = Zend_Registry::get('config')->settings->client->default->tag_group_ebook_illustrator; $tags = $this->getTagsArray($object_id, $this::TAG_TYPE_PROJECT,$tag_group_ids); return $tags; } /** * @param int $object_id * * @return string|null */ public function getTagsEbookTranslator($object_id) { $tag_group_ids = Zend_Registry::get('config')->settings->client->default->tag_group_ebook_translator; $tags = $this->getTagsArray($object_id, $this::TAG_TYPE_PROJECT,$tag_group_ids); return $tags; } /** * @param int $object_id * * @return string|null */ public function getTagsEbookShelf($object_id) { $tag_group_ids = Zend_Registry::get('config')->settings->client->default->tag_group_ebook_shelf; $tags = $this->getTagsArray($object_id, $this::TAG_TYPE_PROJECT,$tag_group_ids); return $tags; } /** * @param int $object_id * * @return string|null */ public function getTagsEbookLanguage($object_id) { $tag_group_ids = Zend_Registry::get('config')->settings->client->default->tag_group_ebook_language; $tags = $this->getTagsArray($object_id, $this::TAG_TYPE_PROJECT,$tag_group_ids); return $tags; } /** * @param int $object_id * * @return string|null */ public function getTagsEbookType($object_id) { $tag_group_ids = Zend_Registry::get('config')->settings->client->default->tag_group_ebook_type; $tags = $this->getTagsArray($object_id, $this::TAG_TYPE_PROJECT,$tag_group_ids); return $tags; } public function saveCollectionTypeTagForProject($object_id, $tag_id) { $tableTags = new Default_Model_DbTable_Tags(); $collectionTagGroup = Zend_Registry::get('config')->settings->client->default->tag_group_collection_type_id; $tags = $tableTags->fetchTagsForProject($object_id, $collectionTagGroup); if(count($tags) ==0){ //insert new tag if($tag_id) { $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id, tag_group_id) VALUES (:tag_id, :tag_type_id, :tag_object_id, :tag_group_id)"; $this->getAdapter()->query($sql, array('tag_id' => $tag_id, 'tag_type_id' => $this::TAG_TYPE_PROJECT, 'tag_object_id' => $object_id, 'tag_group_id' => $collectionTagGroup)); } }else { $tag = $tags[0]; //remove tag license if(!$tag_id) { //$sql = "DELETE FROM tag_object WHERE tag_item_id = :tagItemId"; $sql = "UPDATE tag_object set tag_changed = NOW() , is_deleted = 1 WHERE tag_item_id = :tagItemId"; $this->getAdapter()->query($sql, array('tagItemId' => $tag['tag_item_id'])); } else { //Update old tag if($tag_id <> $tag['tag_id']) { $sql = "UPDATE tag_object SET tag_changed = NOW(),tag_id = :tag_id WHERE tag_item_id = :tagItemId"; $this->getAdapter()->query($sql, array('tagItemId' => $tag['tag_item_id'], 'tag_id' => $tag_id)); } } } } //========================== generic methods ============================= public function getTagGroups($tag_group_ids) { $sql = 'select g.group_id ,g.group_name ,g.group_display_name ,g.is_multi_select ,i.tag_group_item_id ,i.tag_id ,t.tag_name ,t.tag_fullname ,t.tag_description from tag_group g, tag_group_item i, tag t where g.group_id=i.tag_group_id and i.tag_id = t.tag_id and g.group_id in ('.$tag_group_ids.')'; $resultSet = $this->getAdapter()->fetchAll($sql); return $resultSet; } /* * $tag_ids array tag ids */ public function insertTagObject($tag_ids, $tag_type_id, $tag_group_id, $tag_object_id,$tag_parent_object_id) { + if($tag_ids==null || sizeof($tag_ids)==0) + { + return; + } if(!is_array($tag_ids)) { $tag_ids=array($tag_ids); } if($tag_parent_object_id) { $prepared_insert = array_map(function ($id) use ($tag_type_id,$tag_group_id,$tag_object_id,$tag_parent_object_id) { return "({$id}, {$tag_type_id},{$tag_group_id},{$tag_object_id},{$tag_parent_object_id})"; }, $tag_ids); $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_group_id,tag_object_id,tag_parent_object_id) VALUES " . implode(',',$prepared_insert); $this->getAdapter()->query($sql); }else { $prepared_insert = array_map(function ($id) use ($tag_type_id,$tag_group_id,$tag_object_id) { return "({$id}, {$tag_type_id},{$tag_group_id},{$tag_object_id})"; }, $tag_ids); $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_group_id,tag_object_id) VALUES " . implode(',',$prepared_insert); $this->getAdapter()->query($sql); } } public function fetchTagObject($tag_id,$tag_object_id,$tag_group_id,$tag_type_id) { $sql = $sql_object= "select tag_item_id from tag_object WHERE tag_id = :tag_id and tag_object_id=:tag_object_id and tag_group_id=:tag_group_id and tag_type_id = :tag_type_id and is_deleted = 0"; $r = $this->getAdapter()->fetchRow($sql_object, array('tag_id' => $tag_id, 'tag_object_id' =>$tag_object_id, 'tag_group_id' => $tag_group_id, 'tag_type_id' => $tag_type_id )); return $r; } public function deleteTagForTabObject($tag_object_id,$tag_group_id,$tag_type_id) { $sql = "UPDATE tag_object SET tag_changed = NOW() , is_deleted = 1 WHERE tag_group_id = :tag_group_id AND tag_type_id = :tag_type_id AND tag_object_id = :tag_object_id"; $this->getAdapter()->query($sql, array('tag_group_id' => $tag_group_id, 'tag_type_id' =>$tag_type_id, 'tag_object_id' => $tag_object_id)); } //========================== generic methods end ============================= // ======================== settings profile user os ========================================== /** * @return array */ public function getTagGroupsOSUser() { $tag_group_ids = Zend_Registry::get('config')->settings->client->default->tag_group_osuser; return $this->getTagGroups($tag_group_ids); } public function saveOSTagForUser($tag_id,$tag_type_id,$tag_group_id,$member_id) - { - $this->deleteTagForTabObject($member_id,$tag_group_id,$tag_type_id); + { + $this->deleteTagForTabObject($member_id,$tag_group_id,$tag_type_id); + $this->insertTagObject($tag_id,$tag_type_id,$tag_group_id,$member_id,null); } public function getTagsOSUser($member_id) { $tag_group_ids = Zend_Registry::get('config')->settings->client->default->tag_group_osuser; $tag_type_id = Zend_Registry::get('config')->settings->client->default->tag_type_osuser; return $this->getTagsArray($member_id,$tag_type_id,$tag_group_ids); } } \ No newline at end of file