public function getUsersWhoFollowContent($id_cnt) { $favouriteModel = new Default_Model_UserHasFavourites(); $userProfileModel = new Default_Model_UserProfiles(); $contentHasUserModel = new Default_Model_ContentHasUser(); $favouriteIds = $this->_simplifyArray($favouriteModel->getAllUserIdsFromFavouriteContent($id_cnt)); $ownerIds = $this->_simplifyArray($contentHasUserModel->getContentOwners($id_cnt)); $mergedIds = array_merge($favouriteIds, $ownerIds); $followingUsers = array_keys($userProfileModel->getUsersWhoFollowContents($mergedIds)); return $followingUsers; }
public function viewAction() { if (Zend_Controller_Action_HelperBroker::hasHelper('redirector')) { $redirector = Zend_Controller_Action_HelperBroker::getExistingHelper('redirector'); } $hometargeturl = $this->_urlHelper->url(array('controller' => 'index', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true); // Get user identity $auth = Zend_Auth::getInstance(); // Disable edit profile by default $userEdit = false; // Get params $params = $this->getRequest()->getParams(); if (isset($params['user'])) { // Get username from params $username = $params['user']; } else { $redirector->gotoUrl($hometargeturl); } // Get content types $contentTypes = new Default_Model_ContentTypes(); $this->view->content_types = $contentTypes->getAllNamesAndIds(); // Get user data from User Model $user = new Default_Model_User(); $data = $user->getUserByName($username); if ($data == null) { $redirector->gotoUrl($hometargeturl); } $this->view->user = $data; $id = $data['id_usr']; // Get public user data from UserProfiles Model $userProfile = new Default_Model_UserProfiles(); $dataa = $userProfile->getPublicData($id); // $dataa is an array with key=>val like firstname => "Joel Peeloten" // This was replaced with get public data and the foreach above // Kept here just in case for the future /* $dataa['gender'] = $userprofile->getUserProfileValue($id, 'gender'); $dataa['surname'] = $userprofile->getUserProfileValue($id, 'surname'); $dataa['firstname'] = $userprofile->getUserProfileValue($id, 'firstname'); $dataa['category'] = $userprofile->getUserProfileValue($id, 'user category'); $dataa['profession'] = $userprofile->getUserProfileValue($id, 'profession'); $dataa['company'] = $userprofile->getUserProfileValue($id, 'company'); $dataa['biography'] = $userprofile->getUserProfileValue($id, 'biography'); $dataa['city'] = $userprofile->getUserProfileValue($id, 'city'); $dataa['phone'] = $userprofile->getUserProfileValue($id, 'phone'); $dataa['birthday'] = $userprofile->getUserProfileValue($id, 'birthday'); */ // No countries in countries_ctr and not very good table at all? // This would be better: http://snipplr.com/view/6636/mysql-table--iso-country-list-with-abbreviations/ /* $dataa['country'] = $userProfile->getUserProfileValue($id, 'country'); $userCountry = new Default_Model_UserCountry(); $dataa['country'] = $userCountry->getCountryNameById( $dataa['country']['profile_value_usp'] ); */ // Get content user has released $type = isset($params['type']) ? $params['type'] : 0; $contentList = $user->getUserContent($data['id_usr']); $temp = array(); // Initialize content counts $dataa['contentCounts']['all'] = 0; $dataa['contentCounts']['user_edit'] = 0; $dataa['contentCounts']['problem'] = 0; $dataa['contentCounts']['finfo'] = 0; $dataa['contentCounts']['idea'] = 0; // Count amount of content user has published // and check unpublished so only owner can see it. foreach ($contentList as $k => $c) { // If user not logged in and content not published, // remove content from list if (!$auth->hasIdentity() && $c['published_cnt'] == 0) { unset($contentList[$k]); // Else if user logged in and not owner of unpublished content, // remove content from list } else { if ($auth->hasIdentity() && $c['id_usr'] != $auth->getIdentity()->user_id && $c['published_cnt'] == 0) { unset($contentList[$k]); // Else increase content counts and sort content by content type } else { if (isset($c['key_cty'])) { // Set content to array by its content type //$temp[$c['key_cty']][] = $c; //$temp[] = $c; // Increase total count $dataa['contentCounts']['all']++; // Set content type count to 0 if count is not set if (!isset($dataa['contentCounts'][$c['key_cty']])) { $dataa['contentCounts'][$c['key_cty']] = 0; } // Increase content type count $dataa['contentCounts'][$c['key_cty']]++; } } } if ($c['published_cnt'] == 0) { $dataa['contentCounts']['user_edit']++; } } // end foreach // If user is logged in, and viewing self; allow edit if ($auth->hasIdentity()) { $identity = $auth->getIdentity(); if ($data['id_usr'] == $identity->user_id) { $userEdit = true; } } if ($auth->hasIdentity() && $data['id_usr'] == $auth->getIdentity()->user_id) { $favouriteModel = new Default_Model_UserHasFavourites(); $favouriteType = isset($params['favourite']) ? $params['favourite'] : 0; $favouriteList = $user->getUserFavouriteContent($data['id_usr']); // Initialize Favourite counts $dataa['favouriteCounts']['totalCount'] = 0; $dataa['favouriteCounts']['problem'] = 0; $dataa['favouriteCounts']['finfo'] = 0; $dataa['favouriteCounts']['idea'] = 0; foreach ($favouriteList as $k => $favourite) { /* * If content Id doesn't exist anymore: * unset from Favouritelist and remove all lines from user_has_favourites table that * refers to this content id */ if ($favourite['id_cnt'] == '') { unset($favouriteList[$k]); $favouriteModel->removeAllContentFromFavouritesByContentId($favourite['id_cnt_fvr']); } if (isset($favourite['key_cty'])) { // Increase total count $dataa['favouriteCounts']['totalCount']++; // Set content type count to 0 if count is not set if (!isset($dataa['favouriteCounts'][$favourite['key_cty']])) { $dataa['favouriteCounts'][$favourite['key_cty']] = 0; } // Increase content type count $dataa['favouriteCounts'][$favourite['key_cty']]++; } } //print_r($dataa);print_r($favouriteList);die; } //Zend_Debug::dump("" === null); //Zend_Debug::dump($dataa['contentCounts']['idea']); //Zend_Debug::dump($dataa['contentCounts']['idea'] == ""); //die; // My Posts box data $box = new Oibs_Controller_Plugin_AccountViewBox(); $box->setHeader("My Posts")->setClass("right")->setName("my-posts")->addTab("All", "all", "all selected", $dataa['contentCounts']['all'])->addTab("Challenges", "problem", "challenges", $dataa['contentCounts']['problem'])->addTab("Ideas", "idea", "ideas", $dataa['contentCounts']['idea'])->addTab("Visions", "finfo", "visions", $dataa['contentCounts']['finfo']); if ($dataa['contentCounts']['user_edit'] && $userEdit) { $box->addTab("Saved", "user_edit", "saved", $dataa['contentCounts']['user_edit']); } $boxes[] = $box; $views = new Default_Model_ContentViews(); $myViews = $views->getUserViewedContents($data['id_usr']); $box = new Oibs_Controller_Plugin_AccountViewBox(); $box->setHeader("My Views")->setName("my-views")->setClass("right")->addTab("Views", "views", "all selected"); //$boxes[] = $box; $myReaders = $user->getUsersViewers($data['id_usr']); $box = new Oibs_Controller_Plugin_AccountViewBox(); $box->setHeader("My Reads")->setClass("right")->setName("my-reads")->addTab("Readers", "readers", "all selected"); //$boxes[] = $box; // Set to view $this->view->user_has_image = $user->userHasProfileImage($data['id_usr']); $this->view->userprofile = $dataa; $this->view->authorContents = $contentList; /*$temp*/ $this->view->boxes = $boxes; $this->view->myViews = $myViews; $this->view->myReaders = $myReaders; //$this->view->authorFavourites = $favouriteList; $this->view->user_edit = $userEdit; $this->view->type = $type; /* Waiting for layout that is maybe coming // MyViews $viewsModel = new Default_Model_ContentViews(); Zend_Debug::dump($viewsModel->getUserViewedContents($data['id_usr'])); // MyReaders Zend_Debug::dump($user->getUsersViewers($data['id_usr'])); die;*/ $group_model = new Default_Model_UserHasGroup(); $usergroups = $group_model->getGroupsByUserId($id); $this->view->usergroups = $usergroups; }
private function getFavouriteRows($id_usr) { $favouriteModel = new Default_Model_UserHasFavourites(); $contentHasTagModel = new Default_Model_ContentHasTag(); $user = new Default_Model_User(); $favouriteList = $user->getUserFavouriteContent($id_usr); // Initialize Favourite counts $dataa['favouriteCounts'] = null; $dataa['favouriteCounts']['totalCount'] = 0; $dataa['favouriteCounts']['updated'] = 0; $dataa['favouriteCounts']['problem'] = 0; $dataa['favouriteCounts']['finfo'] = 0; $dataa['favouriteCounts']['idea'] = 0; foreach ($favouriteList as $k => $favourite) { /* * If content Id doesn't exist anymore: * unset from Favouritelist and remove all lines from user_has_favourites table that * refers to this content id */ if (isset($favourite['id_cnt_fvr']) && $favourite['id_cnt'] == '') { unset($favouriteList[$k]); $favouriteModel->removeAllContentFromFavouritesByContentId($favourite['id_cnt_fvr']); continue; } if (isset($favourite['key_cty'])) { $dataa['favouriteCounts']['totalCount']++; // Increase total count $dataa['favouriteCounts'][$favourite['key_cty']]++; // Increase content type count } if (isset($favourite['last_checked']) && isset($favourite['modified_cnt'])) { if (strtotime($favourite['last_checked']) < strtotime($favourite['modified_cnt'])) { $dataa['favouriteCounts']['updated']++; $favouriteList[$k] = array_merge($favourite, array('updated' => '1')); } else { $favouriteList[$k] = array_merge($favourite, array('updated' => '0')); } } } $newList = array('counts' => array('total' => $dataa['favouriteCounts']['totalCount'], 'updated' => $dataa['favouriteCounts']['updated'], 'problem' => $dataa['favouriteCounts']['problem'], 'finfo' => $dataa['favouriteCounts']['finfo'], 'idea' => $dataa['favouriteCounts']['idea']), 'contents' => array()); $k = 0; foreach ($favouriteList as $key => $favourite) { //print_r($favourite);die; $tags = $contentHasTagModel->getContentTags($favourite['id_cnt']); // Action helper for define is tag running number divisible by two $tags = $this->_helper->tagsizes->isTagDivisibleByTwo($tags); $this->gtranslate->setLangFrom($favourite['language_cnt']); $translang = $this->gtranslate->getLangPair(); $newList['contents'][$k]['class'] = "fvr_" . $favourite['key_cty']; if ($favourite['updated'] === "1") { $newList['contents'][$k]['class'] = "fvr_updated " . $newList['contents'][$k]['class']; } $newList['contents'][$k]['original'] = $favourite; $newList['contents'][$k]['translated'] = $this->gtranslate->translateContent($favourite); $newList['contents'][$k]['original']['tags'] = $tags; $newList['contents'][$k]['translated']['tags'] = $tags; $newList['contents'][$k]['original']['translang'] = $translang; $newList['contents'][$k]['translated']['translang'] = $translang; $k++; } return $newList; }
public function init() { $this->setMethod('post'); $this->setEnctype('multipart/form-data'); $this->setName('edit_profile_form'); $this->setAttrib('id', 'edit-profile-form'); $this->addElementPrefixPath('Oibs_Form_Decorator', 'Oibs/Form/Decorator/', 'decorator'); $mailvalid = new Zend_Validate_EmailAddress(); $mailvalid->setMessage('email-invalid', Zend_Validate_EmailAddress::INVALID); $mailvalid->setMessage('email-invalid-hostname', Zend_Validate_EmailAddress::INVALID_HOSTNAME); $mailvalid->setMessage('email-invalid-mx-record', Zend_Validate_EmailAddress::INVALID_MX_RECORD); $mailvalid->setMessage('email-dot-atom', Zend_Validate_EmailAddress::DOT_ATOM); $mailvalid->setMessage('email-quoted-string', Zend_Validate_EmailAddress::QUOTED_STRING); $mailvalid->setMessage('email-invalid-local-part', Zend_Validate_EmailAddress::INVALID_LOCAL_PART); $mailvalid->setMessage('email-length-exceeded', Zend_Validate_EmailAddress::LENGTH_EXCEEDED); $mailvalid->hostnameValidator->setMessage('hostname-invalid-hostname', Zend_Validate_Hostname::INVALID_HOSTNAME); $mailvalid->hostnameValidator->setMessage('hostname-local-name-not-allowed', Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED); $mailvalid->hostnameValidator->setMessage('hostname-unknown-tld', Zend_Validate_Hostname::UNKNOWN_TLD); $mailvalid->hostnameValidator->setMessage('hostname-invalid-local-name', Zend_Validate_Hostname::INVALID_LOCAL_NAME); $mailvalid->hostnameValidator->setMessage('hostname-undecipherable-tld', Zend_Validate_Hostname::UNDECIPHERABLE_TLD); // Clear div $clear = '<div class="clear"></div>'; // Headers $accountInformation = new Oibs_Form_Element_Note('accountinformation'); $accountInformation->setValue($clear . '<h3>Account information</h3>' . $clear); $personalInformation = new Oibs_Form_Element_Note('personalinformation'); $personalInformation->setValue('<h3>Personal Information</h3>' . $clear); $locationInformation = new Oibs_Form_Element_Note('locationinformation'); $locationInformation->setValue('<h3>Location Information</h3>' . $clear); $employmentInformation = new Oibs_Form_Element_Note('employmentinformation'); $employmentInformation->setValue('<h3>Employment Information</h3>' . $clear); $subscribeInformation = new Oibs_Form_Element_Note('subscribeinformation'); $subscribeInformation->setValue('<h3>Subscribe settings</h3>' . $clear); // Public text $publictext = 'Public'; // Username for description $auth = Zend_Auth::getInstance(); $identity = $auth->getIdentity(); $usernametext = $identity->username; $username = new Zend_Form_Element_Hidden('username'); $username->setLabel('Username')->setDescription($usernametext); $usernamepublic = new Zend_Form_Element_Hidden('username_publicity'); $usernamepublic->setLabel($publictext); $openid = new Zend_Form_Element_Text('openid'); $openid->setLabel('Open-ID')->setAttrib('id', 'open-ID')->addValidators(array(new Oibs_Validators_OpenidExists())); $openidclear = new Oibs_Form_Element_Note('openidclear'); $openidclear->setValue($clear); $password = new Zend_Form_Element_Password('password'); $password->setLabel('New password')->setAttrib('id', 'password')->addValidators(array(new Oibs_Validators_RepeatValidator('confirm_password'), array('NotEmpty', true, array('messages' => array('isEmpty' => 'Empty'))), array('StringLength', false, array(4, 22, 'messages' => array('stringLengthTooShort' => 'Password too short (4-22 characters)', 'stringLengthTooLong' => 'Password too long (4-22 characters)'))))); $passwordclear = new Oibs_Form_Element_Note('passwordclear'); $passwordclear->setValue($clear); $confirmpassword = new Zend_Form_Element_Password('confirm_password'); $confirmpassword->setLabel('Confirm password')->setAttrib('id', 'confirm-password')->addValidators(array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Empty'))), array('StringLength', false, array(4, 22, 'messages' => array('stringLengthTooShort' => 'Password too short (4-22 characters)', 'stringLengthTooLong' => 'Password too long (4-22 characters)'))))); $confirmpasswordclear = new Oibs_Form_Element_Note('confirm_passwordclear'); $confirmpasswordclear->setValue($clear); $email = new Zend_Form_Element_Text('email'); $email->setLabel('Email')->setAttrib('id', 'email')->setRequired(true)->addFilter('StringtoLower')->addValidators(array($mailvalid, array('NotEmpty', true, array('messages' => array('isEmpty' => 'Email empty'))), array('StringLength', false, array(6, 50, 'messages' => array('stringLengthTooShort' => 'Email too short (6-50 characters)', 'stringLengthTooLong' => 'Email too long (6-50 characters)'))))); $emailclear = new Oibs_Form_Element_Note('emailclear'); $emailclear->setValue($clear); $gravatar = new Zend_Form_Element_Hidden('gravatartext'); $gravatar->setLabel('Gravatar')->setDescription('<div style="text-align: right;">Enable <a href="http://www.gravatar.com">gravatar</a></div>'); $gravatarcheck = new Zend_Form_Element_Checkbox('gravatar'); $phone = new Zend_Form_Element_Text('phone'); $phone->setLabel('Phone')->setAttrib('id', 'phone'); $phonepublic = new Zend_Form_Element_Checkbox('phone_publicity'); $phonepublic->setLabel($publictext); $firstname = new Zend_Form_Element_Text('firstname'); $firstname->setLabel('First name')->setAttrib('id', 'first-name'); $firstnamepublic = new Zend_Form_Element_Checkbox('firstname_publicity'); $firstnamepublic->setLabel($publictext); // DB: surname $lastname = new Zend_Form_Element_Text('surname'); $lastname->setLabel('Last name')->setAttrib('id', 'last-name'); $lastnamepublic = new Zend_Form_Element_Checkbox('surname_publicity'); $lastnamepublic->setLabel($publictext); $gender = new Zend_Form_Element_Select('gender'); $gender->setLabel('Gender')->setAttrib('id', 'gender')->addMultiOptions(array('Select', 'Male', 'Female')); $genderpublic = new Zend_Form_Element_Checkbox('gender_publicity'); $genderpublic->setLabel($publictext); $birthday = new Zend_Form_Element_Text('birthday'); $birthday->setLabel('Date of Birth')->setAttrib('id', 'birthday')->setValidators(array(new Zend_Validate_Date('birthday'))); $birthdaypublic = new Zend_Form_Element_Checkbox('birthday_publicity'); $birthdaypublic->setLabel($publictext); $biography = new Zend_Form_Element_Textarea('biography'); $biography->setLabel('Biography')->setAttrib('id', 'biography')->setAttrib('rows', 30)->setAttrib('cols', 45)->addValidators(array(array('StringLength', false, array(0, 4000, 'messages' => array('stringLengthTooLong' => 'Biography too long'))))); //->setDescription('<div id="progressbar_biography" class="progress_ok"></div>'); $biographypublic = new Zend_Form_Element_Checkbox('biography_publicity'); $biographypublic->setLabel($publictext); $intereststext = new Oibs_Form_Element_Note('intereststext'); $intereststext->setValue('<div class="input-column1"></div>' . '<div class="input-column2 help">(Use commas to separate tags)</div><div class="clear"></div>'); $interests = new Zend_Form_Element_Text('interests'); $interests->setLabel('My interest (tags)')->setAttrib('id', 'interests'); $interestsclear = new Oibs_Form_Element_Note('interestsclear'); $interestsclear->setValue($clear); $weblinks_websites = new Oibs_Form_Element_Note('weblinks_websites'); $weblinks_websites->setValue('<div class="input-column-website1"><label><strong>Links to my websites:</strong></label></div>'); $weblinks_name = new Oibs_Form_Element_Note('weblinks_name'); $weblinks_name->setValue('<div class="input-column-website2">Name</div>'); $weblinks_url = new Oibs_Form_Element_Note('weblinks_url'); $weblinks_url->setValue('<div class="input-column-website3">Url</div><div class="clear"></div>'); $nameTooLongText = 'Name too long (max 45)'; $urlTooLongText = 'URL too long (max 150)'; $weblinks_name_site1 = new Zend_Form_Element_Text('weblinks_name_site1'); $weblinks_name_site1->setLabel('Web site 1')->setAttrib('id', 'website1-name')->addValidators(array(array('StringLength', false, array(0, 45, 'messages' => array('stringLengthTooLong' => $nameTooLongText))))); $weblinks_url_site1 = new Zend_Form_Element_Text('weblinks_url_site1'); $weblinks_url_site1->setAttrib('id', 'website1-url')->addValidators(array(new Oibs_Validators_UrlValidator(), array('StringLength', false, array(0, 150, 'messages' => array('stringLengthTooLong' => $urlTooLongText))))); $weblinks_name_site2 = new Zend_Form_Element_Text('weblinks_name_site2'); $weblinks_name_site2->setLabel('Web site 2')->setAttrib('id', 'website2-name')->addValidators(array(array('StringLength', false, array(0, 45, 'messages' => array('stringLengthTooLong' => $nameTooLongText))))); $weblinks_url_site2 = new Zend_Form_Element_Text('weblinks_url_site2'); $weblinks_url_site2->setAttrib('id', 'website2-url')->addValidators(array(new Oibs_Validators_UrlValidator(), array('StringLength', false, array(0, 150, 'messages' => array('stringLengthTooLong' => $urlTooLongText))))); $weblinks_name_site3 = new Zend_Form_Element_Text('weblinks_name_site3'); $weblinks_name_site3->setLabel('Web site 3')->setAttrib('id', 'website3-name')->setAttrib('id', 'website2-name')->addValidators(array(array('StringLength', false, array(0, 45, 'messages' => array('stringLengthTooLong' => $nameTooLongText))))); $weblinks_url_site3 = new Zend_Form_Element_Text('weblinks_url_site3'); $weblinks_url_site3->setAttrib('id', 'website3-url')->addValidators(array(new Oibs_Validators_UrlValidator(), array('StringLength', false, array(0, 150, 'messages' => array('stringLengthTooLong' => $urlTooLongText))))); $weblinks_name_site4 = new Zend_Form_Element_Text('weblinks_name_site4'); $weblinks_name_site4->setLabel('Web site 4')->setAttrib('id', 'website4-name')->setAttrib('id', 'website2-name')->addValidators(array(array('StringLength', false, array(0, 45, 'messages' => array('stringLengthTooLong' => $nameTooLongText))))); $weblinks_url_site4 = new Zend_Form_Element_Text('weblinks_url_site4'); $weblinks_url_site4->setAttrib('id', 'website4-url')->addValidators(array(new Oibs_Validators_UrlValidator(), array('StringLength', false, array(0, 150, 'messages' => array('stringLengthTooLong' => $urlTooLongText))))); $weblinks_name_site5 = new Zend_Form_Element_Text('weblinks_name_site5'); $weblinks_name_site5->setLabel('Web site 5')->setAttrib('id', 'website5-name')->setAttrib('id', 'website2-name')->addValidators(array(array('StringLength', false, array(0, 45, 'messages' => array('stringLengthTooLong' => $nameTooLongText))))); $weblinks_url_site5 = new Zend_Form_Element_Text('weblinks_url_site5'); $weblinks_url_site5->setAttrib('id', 'website5-url')->addValidators(array(new Oibs_Validators_UrlValidator(), array('StringLength', false, array(0, 150, 'messages' => array('stringLengthTooLong' => $urlTooLongText))))); $languages = new Default_Model_Languages(); $allLanguages = $languages->getAllNamesAndIds(); $userlanguage = new Zend_Form_Element_Select('userlanguage'); $userlanguage->setLabel('User interface language')->setAttrib('id', 'user-interface-language')->addMultiOption('', 'Select'); foreach ($allLanguages as $language) { $userlanguage->addMultiOption($language['id_lng'], $language['name_lng']); } $userlanguageclear = new Oibs_Form_Element_Note('userlanguageclear'); $userlanguageclear->setValue($clear); /* $avatar = new Zend_Form_Element_File('avatar'); $avatar->setLabel('Avatar image'); */ // DB: city $hometown = new Zend_Form_Element_Text('city'); $hometown->setLabel('Hometown')->setAttrib('id', 'hometown')->setRequired(true)->addValidators(array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Hometown empty'))), array('Regex', true, array('/^[\\p{L}0-9.\\- ]*$/')))); $hometownpublic = new Zend_Form_Element_Checkbox('city_publicity'); $hometownpublic->setLabel($publictext); $hometownpublic->helper = 'FormHidden'; $address = new Zend_Form_Element_Text('address'); $address->setLabel('Address')->setAttrib('id', 'address'); $addresspublic = new Zend_Form_Element_Checkbox('address_publicity'); $addresspublic->setLabel($publictext)->setAttrib('checked', 'checked')->setValue(1); $addresspublic->helper = 'FormHidden'; $country_model = new Default_Model_Countries(); $allCountries = $country_model->getAllCountries(); $usercountry = new Zend_Form_Element_Select('country'); $usercountry->setLabel('Country of Residence')->setAttrib('id', 'country')->addMultiOption('', 'Select'); foreach ($allCountries as $country) { $usercountry->addMultiOption($country['iso_ctr'], $country['printable_name_ctr']); } $usercountrypublic = new Zend_Form_Element_Checkbox('country_publicity'); $usercountrypublic->setLabel($publictext); $timezone_model = new Default_Model_Timezones(); $allTimezones = $timezone_model->getAllTimezones(); $usertimezone = new Zend_Form_Element_Select('usertimezone'); $usertimezone->setLabel('Time Zone')->setAttrib('id', 'time-zone')->addMultiOption('', 'Select'); foreach ($allTimezones as $timezone) { $usertimezone->addMultiOption($timezone['id_tmz'], $timezone['gmt_tmz'] . ' ' . $timezone['timezone_location_tmz']); } $usertimezonepublic = new Zend_Form_Element_Checkbox('usertimezone_publicity'); $usertimezonepublic->setLabel($publictext); $userProfilesModel = new Default_Model_UserProfiles(); $employments = $userProfilesModel->getEmployments(); $employments = array_merge(array('' => 'Select'), $employments); $employment = new Zend_Form_Element_Select('employment'); $employment->setLabel('I am currently')->setAttrib('id', 'status')->setRequired(true)->addMultiOptions($employments)->setErrorMessages(array('Select status')); $employmentpublic = new Zend_Form_Element_Checkbox('employment_publicity'); $employmentpublic->setLabel($publictext); // DB: company $employer_organization = new Zend_Form_Element_Text('company'); $employer_organization->setLabel('Employer / Organization')->setAttrib('id', 'employer-organization'); $employer_organizationpublic = new Zend_Form_Element_Checkbox('company_publicity'); $employer_organizationpublic->setLabel($publictext); //Subscribe things $favouritesModel = new Default_Model_UserHasFavourites(); $subscribeOptions = $favouritesModel->getFollows(); unset($subscribeOptions['8']); //Unsetting the translation box till its in use. //print_r($subscribeOptions);die; $test = new Zend_Form_Element_MultiCheckbox('lol'); //$test->setV $subscribeClasses = array("own_follows" => "Own contents", "fvr_follows" => "Favourite contents"); foreach ($subscribeClasses as $key => $value) { $subscribe[$key] = new Zend_Form_Element_MultiCheckbox($key); $subscribe[$key]->setLabel('Activities you want to follow in your ' . $value); $subscribe[$key]->addMultiOptions($subscribeOptions); } $subscribeclear = new Oibs_Form_Element_Note('subscribeclear'); $subscribeclear->setValue($clear); $save = new Zend_Form_Element_Submit('save'); $save->setLabel('Save profile')->setAttrib('id', 'save-profile')->setAttrib('class', 'submit-button'); $cancel = new Zend_Form_Element_Submit('cancel'); $cancel->setLabel('Cancel')->setAttrib('id', 'cancel')->setAttrib('class', 'submit-button'); $this->addElements(array($accountInformation, $username, $usernamepublic, $openid, $openidclear, $password, $passwordclear, $confirmpassword, $confirmpasswordclear, $personalInformation, $email, $emailclear, $gravatar, $gravatarcheck, $phone, $phonepublic, $firstname, $firstnamepublic, $lastname, $lastnamepublic, $gender, $genderpublic, $birthday, $birthdaypublic, $biography, $biographypublic, $weblinks_websites, $weblinks_name, $weblinks_url, $weblinks_name_site1, $weblinks_url_site1, $weblinks_name_site2, $weblinks_url_site2, $weblinks_name_site3, $weblinks_url_site3, $weblinks_name_site4, $weblinks_url_site4, $weblinks_name_site5, $weblinks_url_site5, $userlanguage, $userlanguageclear, $locationInformation, $hometown, $hometownpublic, $address, $addresspublic, $usercountry, $usercountrypublic, $usertimezone, $usertimezonepublic, $employmentInformation, $employment, $employmentpublic, $employer_organization, $employer_organizationpublic, $save, $cancel)); $accountInformation->setDecorators(array('ViewHelper')); $personalInformation->setDecorators(array('ViewHelper')); $locationInformation->setDecorators(array('ViewHelper')); $employmentInformation->setDecorators(array('ViewHelper')); $subscribeInformation->setDecorators(array('ViewHelper')); $username->setDecorators(array('InputDecorator')); $usernamepublic->setDecorators(array('PublicDecorator')); $openid->setDecorators(array('InputDecorator')); $openidclear->setDecorators(array('ViewHelper')); $password->setDecorators(array('InputDecorator')); $passwordclear->setDecorators(array('ViewHelper')); $confirmpassword->setDecorators(array('InputDecorator')); $confirmpasswordclear->setDecorators(array('ViewHelper')); $email->setDecorators(array('InputDecorator')); $emailclear->setDecorators(array('ViewHelper')); $gravatar->setDecorators(array('InputDecorator')); $gravatarcheck->setDecorators(array('PublicDecorator')); $phone->setDecorators(array('InputDecorator')); $phonepublic->setDecorators(array('PublicDecorator')); $firstname->setDecorators(array('InputDecorator')); $firstnamepublic->setDecorators(array('PublicDecorator')); $lastname->setDecorators(array('InputDecorator')); $lastnamepublic->setDecorators(array('PublicDecorator')); $gender->setDecorators(array('InputDecorator')); $genderpublic->setDecorators(array('PublicDecorator')); $birthday->setDecorators(array('InputDecorator')); $birthdaypublic->setDecorators(array('PublicDecorator')); $biography->setDecorators(array('InputDecorator')); $biographypublic->setDecorators(array('PublicDecorator')); $intereststext->setDecorators(array('ViewHelper')); $interests->setDecorators(array('InputDecorator')); $interestsclear->setDecorators(array('ViewHelper')); $weblinks_websites->setDecorators(array('ViewHelper')); $weblinks_name->setDecorators(array('ViewHelper')); $weblinks_url->setDecorators(array('ViewHelper')); $weblinks_name_site1->setDecorators(array('InputWebsiteNameDecorator')); $weblinks_url_site1->setDecorators(array('InputWebsiteUrlDecorator')); $weblinks_name_site2->setDecorators(array('InputWebsiteNameDecorator')); $weblinks_url_site2->setDecorators(array('InputWebsiteUrlDecorator')); $weblinks_name_site3->setDecorators(array('InputWebsiteNameDecorator')); $weblinks_url_site3->setDecorators(array('InputWebsiteUrlDecorator')); $weblinks_name_site4->setDecorators(array('InputWebsiteNameDecorator')); $weblinks_url_site4->setDecorators(array('InputWebsiteUrlDecorator')); $weblinks_name_site5->setDecorators(array('InputWebsiteNameDecorator')); $weblinks_url_site5->setDecorators(array('InputWebsiteUrlDecorator')); $userlanguage->setDecorators(array('InputDecorator')); $userlanguageclear->setDecorators(array('ViewHelper')); $hometown->setDecorators(array('InputDecorator')); $hometownpublic->setDecorators(array('PublicDecorator')); $address->setDecorators(array('InputDecorator')); $addresspublic->setDecorators(array('PublicDecorator')); $usercountry->setDecorators(array('InputDecorator')); $usercountrypublic->setDecorators(array('PublicDecorator')); $usertimezone->setDecorators(array('InputDecorator')); $usertimezonepublic->setDecorators(array('PublicDecorator')); $employment->setDecorators(array('InputDecorator')); $employmentpublic->setDecorators(array('PublicDecorator')); $employer_organization->setDecorators(array('InputDecorator')); $employer_organizationpublic->setDecorators(array('PublicDecorator')); $subscribe['own_follows']->setDecorators(array('InputDecorator')); $subscribe['fvr_follows']->setDecorators(array('InputDecorator')); $subscribeclear->setDecorators(array('ViewHelper')); $save->setDecorators(array('ViewHelper', array('HtmlTag', array('tag' => 'div', 'openOnly' => true, 'id' => 'save_changes')))); $cancel->setDecorators(array('ViewHelper', array('HtmlTag', array('tag' => 'div', 'closeOnly' => true)))); $this->setDecorators(array('FormElements', 'Form')); }
/** * editAction * * Edit content * */ public function editAction() { // Get authentication $auth = Zend_Auth::getInstance(); // If user has identity if ($auth->hasIdentity()) { // Get requests $params = $this->getRequest()->getParams(); // Get session data $previewSession = new Zend_Session_Namespace('contentpreview'); // If preview $backFromPreview = isset($previewSession->backFromPreview) ? $previewSession->backFromPreview : 0; $preview = isset($params['preview']) ? 1 : 0; if ($preview) { $previewSession->unsetAll(); $previewSession->previewData = $params; $backToUrl = $this->getRequest()->getRequestUri(); $previewSession->backToUrl = $backToUrl; $url = $this->_urlHelper->url(array('controller' => 'content', 'action' => 'preview', 'language' => $this->view->language), 'lang_default', true); $this->_redirect($url); } // Get content type $contentId = isset($params['content_id']) ? $params['content_id'] : 0; $userId = $auth->getIdentity()->user_id; $cntHasUsr = new Default_Model_ContentHasUser(); $userIsOwner = $cntHasUsr->contentHasOwner($userId, $contentId); if ($userIsOwner) { if ($contentId != 0) { $content = new Default_Model_Content(); $data = $content->getDataAsSimpleArray($contentId); // Creating array for form data $formData = array(); // Adding content type to form $formData['content_type'] = $data['id_cty_cnt']; // Adding content id to form $formData['content_id'] = $contentId; $formData['content_header'] = stripslashes($data['title_cnt']); $modelCntHasTag = new Default_Model_ContentHasTag(); $keywords = $modelCntHasTag->getContentTags($data['id_cnt']); $tags = ""; $tagCount = count($keywords); for ($i = 0; $i < $tagCount; $i++) { $tags .= $keywords[$i]['name_tag']; if ($i != $tagCount - 1) { $tags .= ', '; } } $formData['content_keywords'] = stripslashes($tags); $formData['content_textlead'] = stripslashes($data['lead_cnt']); $formData['content_text'] = stripslashes($data['body_cnt']); $modelCntHasRec = new Default_Model_ContentHasRelatedCompany(); $relComps = $modelCntHasRec->getContentRelComps($data['id_cnt']); $recs = ""; $recCount = count($relComps); for ($i = 0; $i < $recCount; $i++) { $recs .= $relComps[$i]['name_rec']; if ($i != $recCount - 1) { $recs .= ', '; } } $formData['content_related_companies'] = stripslashes($recs); $formData['content_research'] = $data['research_question_cnt']; $formData['content_opportunity'] = $data['opportunity_cnt']; $formData['content_threat'] = $data['threat_cnt']; $formData['content_solution'] = $data['solution_cnt']; $formData['published_cnt'] = $data['published_cnt']; $formData['content_references'] = $data['references_cnt']; $languages = new Default_Model_Languages(); $idLngInd = $languages->getLangIdByLangName($this->view->language); $allLanguages = $languages->getAllNamesAndIds(); $formData['languages'] = array(); $formData['languages'][0] = $this->view->translate("content-add-select-language"); foreach ($allLanguages as $lng) { $formData['languages'][$lng['id_lng']] = $lng['name_lng']; } $finfoClasses = new Default_Model_FutureinfoClasses(); $allClasses = $finfoClasses->getAllNamesAndIds(); $formData['FutureinfoClasses'] = array(); $formData['FutureinfoClasses'][0] = $this->view->translate("content-add-select-finfo-classification"); foreach ($allClasses as $class) { $formData['FutureinfoClasses'][$class['id_fic']] = $class['name_fic']; } // Getting innovation types from the database $modelInnovationTypes = new Default_Model_InnovationTypes(); $innovationTypes = $modelInnovationTypes->getAllNamesAndIds(); // Getting the innovation type of the content $modelCntHasIvt = new Default_Model_ContentHasInnovationTypes(); $formData['selected_ivt'] = $modelCntHasIvt->getInnovationTypeIdOfContent($data['id_cnt']); // Adding all innovation types to form $formData['InnovationTypes'] = array(); $formData['InnovationTypes'][0] = $this->view->translate("content-add-select-innovation"); foreach ($innovationTypes as $ivt) { $formData['InnovationTypes'][$ivt['id_ivt']] = $ivt['name_ivt']; } // end foreach if (empty($formData['InnovationTypes'])) { $formData['InnovationTypes'] = array(0 => '----'); } $languages = new Default_Model_Languages(); $idLngInd = $languages->getLangIdByLangName($this->view->language); // Getting language of the content $formData['content_language'] = $languages->getLangIdByLangName($data['language_cnt']); // Getting the industry of the content $modelCntHasInd = new Default_Model_ContentHasIndustries(); $cntInd = $modelCntHasInd->getIndustryIdOfContent($data['id_cnt']); // Getting industries from the database $modelIndustries = new Default_Model_Industries(); $industries = $modelIndustries->getNamesAndIdsById(0, $idLngInd); // Getting all industries of the content $industryIds = $modelIndustries->getAllContentIndustryIds($cntInd); $formData['industryIds'] = $industryIds; // Adding all industries of the content to form $formData['selected_industry'] = $industryIds[0]; $formData['selected_division'] = $industryIds[1]; $formData['selected_group'] = $industryIds[2]; $formData['selected_class'] = $industryIds[3]; // Adding all industries to form $formData['Industries'] = array(); $formData['Industries'][0] = $this->view->translate("content-add-select-industry"); foreach ($industries as $ind) { $formData['Industries'][$ind['id_ind']] = $ind['name_ind']; } // end foreach if (empty($formData['Industries'])) { $formData['Industries'] = array(0 => '----'); } // Adding all divisions to form $formData['Divisions'] = array(); $formData['Divisions'][0] = $this->view->translate("content-add-select-division-no-industry"); if ($industryIds[0] != 0) { $divisions = $modelIndustries->getNamesAndIdsById($industryIds[0], $idLngInd); foreach ($divisions as $div) { $formData['Divisions'][$div['id_ind']] = $div['name_ind']; } // end foreach } // Adding all groups to form $formData['Groups'] = array(); $formData['Groups'][0] = $this->view->translate("content-add-select-group-no-division"); if ($industryIds[1] != 0) { $groups = $modelIndustries->getNamesAndIdsById($industryIds[1], $idLngInd); foreach ($groups as $grp) { $formData['Groups'][$grp['id_ind']] = $grp['name_ind']; } // end foreach } $formData['Classes'] = array(); $formData['Classes'][0] = $this->view->translate("content-add-select-class-no-group"); // If there's no group selected if ($industryIds[2] != 0) { $classes = $modelIndustries->getNamesAndIdsById($industryIds[2], $idLngInd); foreach ($classes as $class) { $formData['Classes'][$class['id_ind']] = $class['name_ind']; } // end foreach } $modelContentTypes = new Default_Model_ContentTypes(); $contentType = $modelContentTypes->getTypeById($data['id_cty_cnt']); $this->view->short_contenttype = $contentType; $title_cnt = $content->getContentHeaderByContentId($data['id_cnt']); $this->view->contentHeader = $title_cnt; // Get contents filenames from database $filesModel = new Default_Model_Files(); $filenames = $filesModel->getFilenamesByCntId($contentId); $formData['filenames'] = $filenames; // Form for content adding $form = new Default_Form_EditContentForm(null, $formData, $contentId, $contentType, $this->view->language); $form->populate($formData); $this->view->form = $form; $url = $this->_urlHelper->url(array('controller' => 'msg', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true); // populate form if ($backFromPreview) { // Get previewdata and populate it to form $previewData = $previewSession->previewData; $form->populate($previewData); // Delete session data $previewSession->unsetAll(); } // If posted if ($this->getRequest()->isPost()) { // Get content data $data = $this->getRequest()->getPost(); // Content id $data['content_id'] = $contentId; // If form data is valid, handle database insertions if ($form->isValid($data)) { // If form data is going to be published if (isset($data['content_publish'])) { $data['publish'] = 1; $message_error = 'content-publish-not-successful'; } elseif (isset($data['content_save'])) { $data['publish'] = 0; $message_error = 'content-save-not-successful'; } // Content keywords /* FIXED: split() is deprecated in PHP 5.3.0 -> and removed in * PHP 6.0, so changed to explode(). Also trim(array) doesn't * trim array values, so this is done with foreach now. */ $keywords = array(); foreach (explode(',', $data['content_keywords']) as $keyword) { if (trim($keyword) != "") { $keywords[] = strip_tags(trim($keyword)); } } $data['content_keywords'] = array_unique($keywords); // Related companies $relatedCompanies = array(); foreach (explode(',', $data['content_related_companies']) as $relatedCompany) { if (trim($relatedCompany) != "") { $relatedCompanies[] = strip_tags(trim($relatedCompany)); } } $data['content_related_companies'] = array_unique($relatedCompanies); // Get user id $data['User']['id_usr'] = $auth->getIdentity()->user_id; if ($data['content_division'] == 0) { $data['content_industry_id'] = $data['content_industry']; } elseif ($data['content_group'] == 0) { $data['content_industry_id'] = $data['content_division']; } elseif ($data['content_class'] == 0) { $data['content_industry_id'] = $data['content_group']; } elseif ($data['content_class'] != 0) { $data['content_industry_id'] = $data['content_class']; } if ($data['content_language'] == 0) { $data['content_language'] = $this->view->language; } else { $data['content_language'] = $languages->getLangNameByLangId($data['content_language']); } //echo "<pre>"; print_r($data); echo "</pre>"; die(); $data['files'] = $_FILES['content_file_upload']; // Edit content $content = new Default_Model_Content(); $edit = $content->editContent($data); $url = $this->_urlHelper->url(array('controller' => 'msg', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true); if ($edit) { $favourite = new Default_Model_UserHasFavourites(); $favouriteEdited = $favourite->setFavouriteModifiedTrue($edit); if ($data['publish'] == 1) { $url = $this->_urlHelper->url(array('content_id' => $edit, 'language' => $this->view->language), 'content_shortview', true); $this->_redirect($url); } else { $message_ok = $this->view->translate('content-save-successful'); $message_ok .= ' (' . $content->getContentHeaderByContentId($edit) . ')'; $message_ok .= '<br /><br />' . $this->view->translate('content-save-successful2'); $userpage = $this->_urlHelper->url(array('controller' => 'account', 'action' => 'view', 'user' => $auth->getIdentity()->username, 'language' => $this->view->language), 'lang_default', true); $message_ok .= ' <a href="' . $userpage . '">' . $this->view->translate('content-save-successful3') . '</a>'; $message_ok .= ' ' . $this->view->translate('content-save-successful4'); $this->flash($message_ok, $url); } } else { $this->flash($message_error, $url); } } else { // What is this? //Zend_Debug::dump($form); die; } /* // Content keywords $keywords = split(', ', trim($data['content_keywords'])); $data['content_keywords'] = array_unique($keywords); if($data['content_group'] == 0) { $data['content_industry_id'] = $data['content_division']; } elseif($data['content_class'] == 0) { $data['content_industry_id'] = $data['content_group']; } elseif($data['content_class'] != 0) { $data['content_industry_id'] = $data['content_class']; } // Update the edited content to database $content = new Default_Model_Content(); if($content->editContent($data)) { $message = 'content-edit-successful'; } else { $message = 'content-edit-not-successful'; } $this->flash($message, $url);*/ } } else { $message = 'content-edit-no-id'; $this->flash($message, $url); } } else { $message = 'content-edit-not-owner'; $this->flash($message, $url); } } else { // If not logged, redirecting to system message page $message = 'content-edit-not-logged'; $this->flash($message, $url); } // end else }
/** * removeContent * Removes specified content from the database and all related stuff * * @param int id_cnt The id of content to be removed * @return boolean array $contentRemoveChecker * @author Mikko Korpinen */ public function removeContentAndDepending($id_cnt = 0) { $contentRemoveChecker = array('removeContentFromCampaign' => true, 'removeContentFromContent' => true, 'removeContentFromFutureinfoClasses' => true, 'removeContentFromIndustries' => true, 'removeContentFromInnovationTypes' => true, 'removeContentFromRelatedCompanies' => true, 'removeContentRelatedCompanies' => true, 'removeContentFromTags' => true, 'removeContentTags' => true, 'removeContentFromUser' => true, 'removeContentViews' => true, 'removeContentFlags' => true, 'removeContentCommentFlags' => true, 'removeContentRatings' => true, 'removeContentFiles' => true, 'removeUserFromFavorites' => true, 'removeContent' => true, 'removeContentComments' => true); // cnt_has_cmp $cmpHasCnt = new Default_Model_CampaignHasContent(); if (!$cmpHasCnt->removeContentCampaignLinks($id_cnt)) { $contentRemoveChecker['removeContentFromCampaign'] = false; } // cnt_has_cnt $cntHasCnt = new Default_Model_ContentHasContent(); if (!$cntHasCnt->removeContentFromContents($id_cnt)) { $contentRemoveChecker['removeContentFromContent'] = false; } // cnt_has_fic /* not used $cntHasFic = new Default_Model_ContentHasFutureinfoClasses(); if (!$cntHasFic->removeFutureinfoClassesFromContent($id_cnt)) $contentRemoveChecker['removeContentFromFutureinfoClasses'] = false; */ // cnt_has_grp // Not used? // cnt_has_ind /* not used $cntHasInd = new Default_Model_ContentHasIndustries(); if (!$cntHasInd->removeIndustriesFromContent($id_cnt)) $contentRemoveChecker['removeContentFromIndustries'] = false; */ // cnt_has_ivt /* not used $cntHasIvt = new Default_Model_ContentHasInnovationTypes(); if (!$cntHasIvt->removeInnovationTypesFromContent($id_cnt)) $contentRemoveChecker['removeContentFromInnovationTypes'] = false; */ // related_companies_rec and cnt_has_rec $cntHasRec = new Default_Model_ContentHasRelatedCompany(); $recs = $cntHasRec->getContentRelComps($id_cnt); $rec = new Default_Model_RelatedCompanies(); foreach ($recs as $id_rec) { if (!$cntHasRec->checkIfOtherContentHasRelComp($id_rec['id_rec'], $id_cnt)) { if (!$rec->removeRelComp($id_rec['id_rec'])) { $contentRemoveChecker['removeRelatedCompanies'] = false; } } } if (!$cntHasRec->removeContentRelComps($id_cnt)) { $contentRemoveChecker['removeContentFromRelatedCompanies'] = false; } // tags_tag and cnt_has_tag $cntHasTag = new Default_Model_ContentHasTag(); $tags = $cntHasTag->getContentTags($id_cnt); $tag = new Default_Model_Tags(); foreach ($tags as $id_tag) { if (!$cntHasTag->checkIfOtherContentHasTag($id_tag['id_tag'], $id_cnt)) { if (!$tag->removeTag($id_tag['id_tag'])) { $contentRemoveChecker['removeTags'] = false; } } } if (!$cntHasTag->removeContentTags($id_cnt)) { $contentRemoveChecker['removeContentFromTags'] = false; } // cnt_has_usr $cntHasUsr = new Default_Model_ContentHasUser(); if (!$cntHasUsr->removeUserFromContent($id_cnt)) { $contentRemoveChecker['removeContentFromUser'] = false; } // cnt_publish_times_pbt // Not used? // cnt_views_vws $cntWiewsVws = new Default_Model_ContentViews(); if (!$cntWiewsVws->removeContentViews($id_cnt)) { $contentRemoveChecker['removeContentViews'] = false; } // Flags from content_flags_cfl $contentflagmodel = new Default_Model_ContentFlags(); $cnfl_ids = $contentflagmodel->getFlagsByContentId($id_cnt); if (is_array($cnfl_ids)) { foreach ($cnfl_ids as $cfl_id) { if (!$contentflagmodel->removeFlag($cfl_id)) { $contentRemoveChecker['removeContentFlags'] = false; } } } // Flags from comment_flags_cfl $commentflagmodel = new Default_Model_CommentFlags(); $cmfl_ids = $commentflagmodel->getFlagsByContentId($id_cnt); if (is_array($cmfl_ids)) { foreach ($cmfl_ids as $cfl_id) { if (!$commentflagmodel->removeFlag($cfl_id)) { $contentRemoveChecker['removeContentCommentFlags'] = false; } } } // content_ratings_crt $contentRatingRct = new Default_Model_ContentRatings(); if (!$contentRatingRct->removeContentRatings($id_cnt)) { $contentRemoveChecker['removeContentRatings'] = false; } // files_fil $files = new Default_Model_Files(); if (!$files->removeFiles($id_cnt, "content")) { $contentRemoveChecker['removeContentFiles'] = false; } // links_lnk // Not used? // usr_has_fvr $usrHasFvr = new Default_Model_UserHasFavourites(); if (!$usrHasFvr->removeAllContentFromFavouritesByContentId($id_cnt)) { $contentRemoveChecker['removeUserFromFavorites'] = false; } // contents_cnt $contentmodel = new Default_Model_Content(); if (!$contentmodel->removeContent($id_cnt)) { $contentRemoveChecker['removeContent'] = false; } // coments_cmt $commentmodel = new Default_Model_Comments(); if (!$commentmodel->removeAllContentComments($id_cnt)) { $contentRemoveChecker['removeContentComments'] = false; } return $contentRemoveChecker; }
/** * index page: Contains the content viewing functionality. * * @todo Implement group ownership user images and content links * @todo Include translation and content info for page title * @todo More from box should show ratings * @todo If not ajax "more from", at least separate to proper MVC * @todo Look over comment loading for data being fetched and not shown * @todo Comment rating, userpic (maybe not) * * @param id integer id of content to view * @param page integer (optional) Page number for paginator * @param count integer (optional) Count of content for paginator * @param rate integer (optional) Rating given by user */ function indexAction() { // get requests $request = $this->getRequest(); $params = $request->getParams(); $baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl(); $absoluteBaseUrl = strtolower(trim(array_shift(explode('/', $_SERVER['SERVER_PROTOCOL'])))) . '://' . $_SERVER['HTTP_HOST'] . Zend_Controller_Front::getInstance()->getBaseUrl(); // get content id from params, if not set or invalid, send a message $id = (int) $params['content_id']; if ($id == 0) { $this->flash('content-not-found', $baseUrl . '/' . $this->view->language . '/msg/'); } // Get specific content data -- this could fail? Needs check? $contentModel = new Default_Model_Content(); $contentData = $contentModel->getDataAsSimpleArray($id); // Translate content data $this->gtranslate->setLangFrom($contentData['language_cnt']); $contentData = $this->gtranslate->translateContent($contentData); $filesModel = new Default_Model_Files(); $files = $filesModel->getFilenamesByCntId($id); // Get content owner id (groups to be implemented later) $contentHasUserModel = new Default_Model_ContentHasUser(); $owner = $contentHasUserModel->getContentOwners($id); $ownerId = $owner['id_usr']; // Get authentication $auth = Zend_Auth::getInstance(); if ($contentData['published_cnt'] == 0 && $auth->getIdentity()->user_id != $ownerId && !in_array("admin", $this->view->logged_user_roles)) { $this->flash('content-not-found', $baseUrl . '/' . $this->view->language . '/msg/'); } // get rating from params (if set) $rate = isset($params['rate']) ? $params['rate'] : "NONE"; // get favourite method, "add" or "remove" //$favouriteMethod = isset($params['favourite']) ? $params['favourite'] : "NONE"; // get page number and comments per page (if set) $page = isset($params['page']) ? $params['page'] : 1; $count = isset($params['count']) ? $params['count'] : 10; // turn commenting off by default $user_can_comment = false; // turn rating off by default $user_can_rate = false; // Comment model $comment = new Default_Model_Comments(); $parentId = isset($params['replyto']) ? $params['replyto'] : 0; // If user has identity if ($auth->hasIdentity() && $contentData['published_cnt'] == 1) { // enable comment form $user_can_comment = true; // enable rating if the content was not published by the user // (also used for flagging) if ($ownerId != $auth->getIdentity()->user_id) { $user_can_rate = true; } // generate comment form $comment_form = new Default_Form_CommentForm($parentId); // if there is something in POST if ($request->isPost()) { // Get comment form data $formData = $this->_request->getPost(); // Validate and save comment data if ($comment_form->isValid($formData)) { $user_id = $auth->getIdentity()->user_id; $comment->addComment($id, $user_id, $formData); $comment_form = new Default_Form_CommentForm($parentId); if ($user_id != $ownerId) { $user = new Default_Model_User(); $comment_sender = $user->getUserNameById($user_id); $Default_Model_privmsg = new Default_Model_PrivateMessages(); $data = array(); $data['privmsg_sender_id'] = 0; $data['privmsg_receiver_id'] = $ownerId; $data['privmsg_header'] = 'You have new comment!'; $data['privmsg_message'] = '<a href="' . $baseUrl . "/" . $this->view->language . '/account/view/user/' . $comment_sender . '">' . $comment_sender . '</a> commented your content <a href="' . $baseUrl . "/" . $this->view->language . '/view/' . $id . '">' . $contentData['title_cnt'] . '</a>'; $data['privmsg_email'] = ''; // Send email to contentowner about new comment // if its allowed $notificationsModel = new Default_Model_Notifications(); $notifications = $notificationsModel->getNotificationsById($ownerId); if (in_array('comment', $notifications)) { $emailNotification = new Oibs_Controller_Plugin_Email(); $emailNotification->setNotificationType('comment')->setSenderId($user_id)->setReceiverId($ownerId)->setParameter('URL', $absoluteBaseUrl . "/en")->setParameter('SENDER-NAME', $comment_sender)->setParameter('CONTENT-ID', $id)->setParameter('CONTENT-TITLE', $contentData['title_cnt'])->setParameter('COMMENT', $formData['comment_message']); if ($emailNotification->isValid()) { $emailNotification->send(); } else { //echo $emailNotification->getErrorMessage(); die; } } $Default_Model_privmsg->addMessage($data); } } // end if } // end if $this->view->comment_form = $comment_form; } // end if // get content type of the specific content viewed $contentTypesModel = new Default_Model_ContentTypes(); $contentType = $contentTypesModel->getTypeById($contentData['id_cty_cnt']); // Get content innovation type / industry / division / group / class // and send to view... somehow. // TO BE IMPLEMENTED // Get content owner data $userModel = new Default_Model_User(); $userData = $userModel->getSimpleUserDataById($ownerId); // get content owner picture ... to be implemented later $userImage = $userModel->getUserImageData($ownerId); // get other content from user.. function needs a looking-over! // Also it needs to be separated from this action so the MVC-is correct! $moreFromUser = $userModel->getUserContent($ownerId, 0, $id); // get related contents $relatedContents = $contentModel->getRelatedContents($id); // get (VIEWED) content views (returns a string directly) $contentViewsModel = new Default_Model_ContentViews(); if (!$this->alreadyViewed($id)) { $contentViewsModel->increaseViewCount($id); } $views = $contentViewsModel->getViewsByContentId($id); // get content rating (returns a string directly) $contentRatingsModel = new Default_Model_ContentRatings(); //$rating = $contentRatingsModel->getById($id); $rating = $contentRatingsModel->getPercentagesById($id); // $rate is gotten from params[], 1 and -1 are the only allowed if ($rate != "NONE" && ($rate == 1 || $rate == -1) && $auth->hasIdentity()) { if ($contentRatingsModel->addRating($id, $auth->getIdentity()->user_id, $rate)) { $this->view->savedRating = $rate; //$rating = $contentRatingsModel->getById($id); $rating = $contentRatingsModel->getPercentagesById($id); } else { $this->flash('rating-failed-msg', $baseUrl . '/en/msg/'); } } // get contents total favourites $userFavouritesModel = new Default_Model_UserHasFavourites(); $totalFavourites = $userFavouritesModel->getUsersCountByFavouriteContent($id); $totalFavourites = $totalFavourites[0]['users_count_fvr']; $isFavourite = $userFavouritesModel->checkIfContentIsUsersFavourite($id, $auth->getIdentity()->user_id); /* * favouritemethod comes from parameters sent by * ajax function (ajaxLoad_favourite(method)) in index.phtml in /view/. * this function gets parameter "method" (add/remove) from onClick event that is in index.ajax.phtml. * if this onClick event is activated by clicking "heart" (icon_fav_on/off) icon in content view page, * it runs the ajaxLoad_favourite(method) function which sends parameter "favourite" (add/remove) to * this viewController which then handles the adding or removing the content from favourites. */ if ($favouriteMethod != "NONE" && $auth->hasIdentity()) { $favouriteUserId = $auth->getIdentity()->user_id; //If favourite method was "add", then add content to user favourites if ($favouriteMethod == "add" && !$isFavourite) { if ($userFavouritesModel->addContentToFavourites($id, $favouriteUserId)) { $this->view->favouriteMethod = $favouriteMethod; } else { $this->flash('favourite-adding-failed', $baseUrl . '/en/msg'); } } elseif ($favouriteMethod == "remove" && $isFavourite) { if ($userFavouritesModel->removeUserFavouriteContent($id, $favouriteUserId)) { $this->view->favouriteMethod = $favouriteMethod; } else { $this->flash('favourite-removing-failed', $baseUrl . '/en/msg'); } } else { unset($favouriteMethod); } } $favourite = array('total_favourites' => $totalFavourites, 'is_favourite' => $isFavourite); $languagesModel = new Default_Model_Languages(); $languageName = $languagesModel->getLanguageByLangCode($contentData['language_cnt']); $gtranslateLangPair = $this->gtranslate->getLangPair(); // get content tags - functions returns names as well // needs updating to proper MVC? $contentHasTagModel = new Default_Model_ContentHasTag(); $tags = $contentHasTagModel->getContentTags($id); //echo "<pre>"; print_r($tags); echo "</pre>"; die; // get content links, to be implemented $links = array(); // Get all content campaigns $campaignHasContentModel = new Default_Model_CampaignHasContent(); $campaigns = $campaignHasContentModel->getContentCampaigns($id); // This functionality needs looking over (code and general idea) // get content family (array of children, parents and siblings) $contentHasContentModel = new Default_Model_ContentHasContent(); $family = $contentHasContentModel->getContentFamilyTree($id); // split family array to child, parent and sibling arrays (full content) $children = array(); $children_siblings = array(); if (isset($family['children'])) { foreach ($family['children'] as $child) { $contenttypeid = $contentModel->getContentTypeIdByContentId((int) $child); $contenttype = $contentTypesModel->getTypeById($contenttypeid); if ($contenttype == "idea") { $children[] = $contentModel->getDataAsSimpleArray((int) $child); } else { $children_siblings[] = $contentModel->getDataAsSimpleArray((int) $child); } // $i++; } } $parents = array(); $parent_siblings = array(); if (isset($family['parents'])) { foreach ($family['parents'] as $parent) { $contenttypeid = $contentModel->getContentTypeIdByContentId((int) $parent); $contenttype = $contentTypesModel->getTypeById($contenttypeid); if ($contenttype == "idea") { $parents[] = $contentModel->getDataAsSimpleArray((int) $parent); } else { $parent_siblings[] = $contentModel->getDataAsSimpleArray((int) $parent); } } } // Here we get the rival solutions for a solution $rivals = array(); if ($contentType == "idea" && isset($family['parents'])) { $i = 0; // First here is checked the parents of this solution (=the problem // or the future info) foreach ($family['parents'] as $parent) { // Get the family of the problem or future info $parents_family = $contentHasContentModel->getContentFamilyTree((int) $parent); // Get the children of the problem or future info if (isset($parents_family['children'])) { // Going through the children foreach ($parents_family['children'] as $parent_child) { // Those children are rivals which are not this solution // which is currently viewed if ((int) $parent_child != $id) { $rivals[$i] = $contentModel->getDataAsSimpleArray((int) $parent_child); } } } $i++; } } // get comments data // $commentList = $comment->getAllByContentId($id, $page, $count); $commentList = $comment->getCommentsByContent($id); $commentsSorted = array(); $this->getCommentChilds($commentList, $commentsSorted, 0, 0, 3); // Get total comment count $commentCount = $comment->getCommentCountByContentId($id); // Calculate total page count $pageCount = ceil($commentCount / $count); // Custom pagination to fix memory error on large amount of data $paginator = new Zend_View(); $paginator->setScriptPath('../application/views/scripts'); $paginator->pageCount = $pageCount; $paginator->currentPage = $page; $paginator->pagesInRange = 10; // get content industries -- will be updated later. $cntHasIndModel = new Default_Model_ContentHasIndustries(); $hasIndustry = $cntHasIndModel->getIndustryIdOfContent($id); $industriesModel = new Default_Model_Industries(); $industriesArray = $industriesModel->getAllContentIndustryIds($hasIndustry); // roll values to an array /*$industries = array(); foreach ($industriesArray as $industry) { $value = $industriesModel->getNameById($industry); // $industriesModel->getNameById($industry); if (!empty($value)) { $industries[] = $value; } }*/ // Check if and when the content is modified and if its more than 10minutes ago add for the view $dateCreated = strtotime($contentData['created_cnt']); $dateModified = strtotime($contentData['modified_cnt']); $modified = 0; if (($dateModified - $dateCreated) / 60 > 10) { $modified = $contentData['modified_cnt']; } // Inject data to view $this->view->files = $files; $this->view->id = $id; $this->view->userImage = $userImage; $this->view->commentPaginator = $paginator; $this->view->commentData = $commentsSorted; $this->view->user_can_comment = $user_can_comment; $this->view->user_can_rate = $user_can_rate; $this->view->contentData = $contentData; $this->view->modified = $modified; $this->view->userData = $userData; $this->view->moreFromUser = $moreFromUser; $this->view->relatedContents = $relatedContents; $this->view->views = $views; $this->view->rating = $rating; $this->view->languageName = $languageName; $this->view->gtranslateLangPair = $gtranslateLangPair; $this->view->tags = $tags; $this->view->links = $links; $this->view->parents = $parents; $this->view->parent_siblings = $parent_siblings; $this->view->children = $children; $this->view->children_siblings = $children_siblings; $this->view->rivals = $rivals; $this->view->comments = $commentCount; $this->view->contentType = $contentType; $this->view->count = $count; $this->view->campaigns = $campaigns; //$this->view->favourite = $favourite; // Inject title to view $this->view->title = $this->view->translate('index-home') . " - " . $contentData['title_cnt']; }
public function getnotificationsAction() { return; //RC fix :) $favouritesModel = new Default_Model_UserHasFavourites(); $auth = Zend_Auth::getInstance(); $id_usr = 0; if ($auth->hasIdentity()) { $id_usr = $auth->getIdentity()->user_id; } $notifications = $favouritesModel->getAllUpdatedContents($id_usr); //print_r($notifications);die; $ids = array(); if ($notifications) { foreach ($notifications as $k => $notification) { foreach ($notification as $l => $content) { $this->gtranslate->setLangFrom($content['original']['language_cnt']); $translang = $this->gtranslate->getLangPair(); $notifications[$k][$l]['translated'] = $this->gtranslate->translateContent($content['original']); $notifications[$k][$l]['original']['translang'] = $translang; $notifications[$k][$l]['translated']['translang'] = $translang; $ids[] = $l; } } } else { $this->_helper->viewRenderer->setNoRender(true); } $jsonIds = json_encode($ids); $this->view->notifications = $notifications; $this->view->ids = $jsonIds; }
/** * index page: Contains the content viewing functionality. * * @todo Implement group ownership user images and content links * @todo Include translation and content info for page title * @todo More from box should show ratings * @todo If not ajax "more from", at least separate to proper MVC * @todo Look over comment loading for data being fetched and not shown * @todo Comment rating, userpic (maybe not) * * @param id integer id of content to view * @param page integer (optional) Page number for paginator * @param count integer (optional) Count of content for paginator * @param rate integer (optional) Rating given by user */ function indexAction() { // get requests $request = $this->getRequest(); $params = $request->getParams(); $baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl(); $absoluteBaseUrl = strtolower(trim(array_shift(explode('/', $_SERVER['SERVER_PROTOCOL'])))) . '://' . $_SERVER['HTTP_HOST'] . Zend_Controller_Front::getInstance()->getBaseUrl(); // get content id from params, if not set or invalid, send a message $id = (int) $params['content_id']; if ($id == 0) { $this->flash('content-not-found', $baseUrl . '/' . $this->view->language . '/msg/'); } // Get specific content data -- this could fail? Needs check? $contentModel = new Default_Model_Content(); $contentData = $contentModel->getDataAsSimpleArray($id); $isTranslated = isset($params['notranslate']) ? false : true; if ($isTranslated) { // Translate content data $this->gtranslate->setLangFrom($contentData['language_cnt']); $contentData = $this->gtranslate->translateContent($contentData); } $filesModel = new Default_Model_Files(); $files = $filesModel->getFilenames($id, "content"); // Get content owner id (groups to be implemented later) $contentHasUserModel = new Default_Model_ContentHasUser(); $owner = $contentHasUserModel->getContentOwners($id); $ownerId = $owner['id_usr']; // Get authentication $auth = Zend_Auth::getInstance(); // Get user_id $usrId = 0; if ($auth->hasIdentity()) { $usrId = $auth->getIdentity()->user_id; } if ($contentData['published_cnt'] == 0 && $usrId != $ownerId && !in_array("admin", $this->view->logged_user_roles)) { $this->flash('content-not-found', $baseUrl . '/' . $this->view->language . '/msg/'); } // get rating from params (if set) $rate = isset($params['rate']) ? $params['rate'] : "NONE"; // get page number and comments per page (if set) $page = isset($params['page']) ? $params['page'] : 1; // turn commenting off by default $user_can_comment = false; // turn rating off by default $user_can_rate = false; // user is not owner by default $user_is_owner = false; // Comment model $comment = new Default_Model_Comments(); $favouriteModel = new Default_Model_UserHasFavourites(); $cntHasUsrModel = new Default_Model_ContentHasUser(); //$parentId = isset($params['replyto']) ? $params['replyto'] : 0; // If user has identity if ($auth->hasIdentity() && $contentData['published_cnt'] == 1) { // enable rating if the content was not published by the user // (also used for flagging) if ($ownerId != $auth->getIdentity()->user_id) { $user_can_rate = true; } // Check if user is owner of content if ($ownerId == $auth->getIdentity()->user_id) { $user_is_owner = true; } if ($favouriteModel->checkIfContentIsUsersFavourite($id, $usrId)) { $favouriteModel->updateLastChecked($usrId, $id); $profileModel = new Default_Model_UserProfiles(); $profileModel->deleteNotificationCache($id, $usrId); } if ($user_is_owner) { $cntHasUsrModel->updateLastChecked($ownerId, $id); $profileModel = new Default_Model_UserProfiles(); $profileModel->deleteNotificationCache($id, $usrId); } // generate comment form //$comment_form = new Default_Form_CommentForm($parentId); // if there is something in POST /*if ($request->isPost()) { if($user_id != $ownerId) { $user = new Default_Model_User(); $comment_sender = $user->getUserNameById($user_id); $Default_Model_privmsg = new Default_Model_PrivateMessages(); $data = array(); $data['privmsg_sender_id'] = 0; $data['privmsg_receiver_id'] = $ownerId; $data['privmsg_header'] = 'You have new comment!'; $data['privmsg_message'] = '<a href="'.$baseUrl."/".$this->view->language.'/account/view/user/'.$comment_sender.'">' .$comment_sender.'</a> commented your content <a href="'.$baseUrl."/".$this->view->language.'/view/'.$id.'">'.$contentData['title_cnt'].'</a>'; $data['privmsg_email'] = ''; // Send email to contentowner about new comment // if its allowed $notificationsModel = new Default_Model_Notifications(); $notifications = $notificationsModel->getNotificationsById($ownerId); if (in_array('comment', $notifications)) { $emailNotification = new Oibs_Controller_Plugin_Email(); $emailNotification->setNotificationType('comment') ->setSenderId($user_id) ->setReceiverId($ownerId) ->setParameter('URL', $absoluteBaseUrl."/en") ->setParameter('SENDER-NAME', $comment_sender) ->setParameter('CONTENT-ID', $id) ->setParameter('CONTENT-TITLE', $contentData['title_cnt']) ->setParameter('COMMENT', $formData['comment_message']); if ($emailNotification->isValid()) { $emailNotification->send(); } else { //echo $emailNotification->getErrorMessage(); die; } } $Default_Model_privmsg->addMessage($data); } // end if }*/ // end if } // end if // get content type of the specific content viewed $contentTypesModel = new Default_Model_ContentTypes(); $contentType = $contentTypesModel->getTypeById($contentData['id_cty_cnt']); // Get content innovation type / industry / division / group / class // and send to view... somehow. // TO BE IMPLEMENTED // Get content owner data $userModel = new Default_Model_User(); $userData = $userModel->getSimpleUserDataById($ownerId); // get content owner picture ... to be implemented later $userImage = $userModel->getUserImageData($ownerId); // get (VIEWED) content views (returns a string directly) $contentViewsModel = new Default_Model_ContentViews(); if (!$this->alreadyViewed($id, $auth->hasIdentity() ? $auth->getIdentity()->username : "******")) { $contentViewsModel->increaseViewCount($id); } $views = $contentViewsModel->getViewsByContentId($id); $languagesModel = new Default_Model_Languages(); $languageName = $languagesModel->getLanguageByLangCode($contentData['language_cnt']); $gtranslateLangPair = $this->gtranslate->getLangPair(); // get content tags - functions returns names as well // needs updating to proper MVC? $contentHasTagModel = new Default_Model_ContentHasTag(); $tags = $contentHasTagModel->getContentTags($id); if ($isTranslated) { $tags = $this->gtranslate->translateTags($tags); } // get content links, to be implemented $links = array(); // Get all content campaigns // $campaignHasContentModel = new Default_Model_CampaignHasContent(); // $campaigns = $campaignHasContentModel->getContentCampaigns($id); // This functionality needs looking over (code and general idea) // get content family (array of children, parents and siblings) $contentHasContentModel = new Default_Model_ContentHasContent(); $family = $contentHasContentModel->getContentFamilyTree($id); // split family array to child, parent and sibling arrays (full content) $children = array(); $children_siblings = array(); //TODO: It would be best effiency to send just an array of childs to ContentModel // and get all data in 1 query rather than querying many times. New function // to models is needed for this or then edit the one we have now and allow it // to have a possibility to receive ids as array. if (isset($family['children'])) { foreach ($family['children'] as $child) { $contenttypeid = $contentModel->getContentTypeIdByContentId((int) $child); $contenttype = $contentTypesModel->getTypeById($contenttypeid); if ($contenttype == "idea") { $children[] = $contentModel->getDataAsSimpleArray((int) $child); } else { $children_siblings[] = $contentModel->getDataAsSimpleArray((int) $child); } // $i++; } } $parents = array(); $parent_siblings = array(); if (isset($family['parents'])) { foreach ($family['parents'] as $parent) { $contenttypeid = $contentModel->getContentTypeIdByContentId((int) $parent); $contenttype = $contentTypesModel->getTypeById($contenttypeid); if ($contenttype == "idea") { $parents[] = $contentModel->getDataAsSimpleArray((int) $parent); } else { $parent_siblings[] = $contentModel->getDataAsSimpleArray((int) $parent); } } } // Here we get the rival solutions for a solution $rivals = array(); if ($contentType == "idea" && isset($family['parents'])) { $i = 0; // First here is checked the parents of this solution (=the problem // or the future info) foreach ($family['parents'] as $parent) { // Get the family of the problem or future info $parents_family = $contentHasContentModel->getContentFamilyTree((int) $parent); // Get the children of the problem or future info if (isset($parents_family['children'])) { // Going through the children foreach ($parents_family['children'] as $parent_child) { // Those children are rivals which are not this solution // which is currently viewed if ((int) $parent_child != $id) { $rivals[$i] = $contentModel->getDataAsSimpleArray((int) $parent_child); } } } $i++; } } // get comments data // $commentList = $comment->getAllByContentId($id, $page, $count); /*$commentList = $comment->getCommentsByContent($id); $commentsSorted = array(); $this->getCommentChilds($commentList, $commentsSorted, 0, 0, 3); // Get total comment count $commentCount = $comment->getCommentCountByContentId($id); // Calculate total page count $pageCount = ceil($commentCount / $count); // Custom pagination to fix memory error on large amount of data $paginator = new Zend_View(); $paginator->setScriptPath('../application/views/scripts'); $paginator->pageCount = $pageCount; $paginator->currentPage = $page; $paginator->pagesInRange = 10;*/ // get content industries -- will be updated later. /*$cntHasIndModel = new Default_Model_ContentHasIndustries(); $hasIndustry = $cntHasIndModel->getIndustryIdOfContent($id); $industriesModel = new Default_Model_Industries(); $industriesArray = $industriesModel->getAllContentIndustryIds($hasIndustry);*/ // roll values to an array /*$industries = array(); foreach ($industriesArray as $industry) { $value = $industriesModel->getNameById($industry); // $industriesModel->getNameById($industry); if (!empty($value)) { $industries[] = $value; } }*/ // Check if and when the content is modified and if its more than 10minutes ago add for the view $dateCreated = strtotime($contentData['created_cnt']); $dateModified = strtotime($contentData['modified_cnt']); $modified = 0; if (($dateModified - $dateCreated) / 60 > 10) { $modified = $contentData['modified_cnt']; } // Comment module $comments = new Oibs_Controller_Plugin_Comments("content", $id); $this->view->jsmetabox->append('commentUrls', $comments->getUrls()); // enable comment form if ($auth->hasIdentity() && $contentData['published_cnt'] == 1) { $comments->allowComments(true); } $comments->loadComments(); //$contentData['references_cnt']; $contentData['references_cnt'] = Oibs_Controller_Plugin_Utils::clickable($contentData['references_cnt'], true); $contentData['body_cnt'] = Oibs_Controller_Plugin_Utils::clickable($contentData['body_cnt']); // Inject data to view $this->view->files = $files; $this->view->id = $id; $this->view->userImage = $userImage; $this->view->comments = $comments; $this->view->user_can_rate = $user_can_rate; $this->view->user_is_owner = $user_is_owner; $this->view->usrId = $usrId; $this->view->contentData = $contentData; $this->view->modified = $modified; $this->view->userData = $userData; $this->view->views = $views; $this->view->isTranslated = $isTranslated; $this->view->languageName = $languageName; $this->view->gtranslateLangPair = $gtranslateLangPair; $this->view->tags = $tags; $this->view->links = $links; $this->view->parents = $parents; $this->view->parent_siblings = $parent_siblings; $this->view->children = $children; $this->view->children_siblings = $children_siblings; $this->view->rivals = $rivals; $this->view->contentType = $contentType; //$this->view->campaigns = $campaigns; $this->view->viewers = $this->getViewers($id); $this->view->boxStates = $this->getBoxStates(); // Inject title to view $this->view->title = $this->view->translate('index-home') . " - " . $contentData['title_cnt']; }
public function deleteNotificationCache($id_cnt = 0, $user_id = 0) { $cache = Zend_Registry::get('cache'); if ($id_cnt > 0) { if ($user_id == 0) { $contentModel = new Default_Model_Content(); $owner = $contentModel->getOwnerId($id_cnt); $cache->remove('Notifications_' . $owner); $favouriteModel = new Default_Model_UserHasFavourites(); $idlist = $favouriteModel->getAllUserIdsFromFavouriteContent($id_cnt); foreach ($idlist as $id) { $cache->remove('Notifications_' . $id['id_usr']); } } else { $cache->remove('Notifications_' . $user_id); } return true; } return false; }
public function getnotificationsAction() { $favouritesModel = new Default_Model_UserHasFavourites(); $auth = Zend_Auth::getInstance(); $id_usr = 0; if ($auth->hasIdentity()) { $id_usr = $auth->getIdentity()->user_id; } //print_r($notifications);die; $ids = array(); $total = 0; $cache = Zend_Registry::get('cache'); if (!($cacheResult = $cache->load('Notifications_' . $id_usr))) { $notifications = $favouritesModel->getAllUpdatedContents($id_usr); $cache->save($notifications, 'Notifications_' . $id_usr); } else { $notifications = $cacheResult; } //print_r($notifications);die; if ($notifications) { foreach ($notifications as $k => $notification) { foreach ($notification as $l => $content) { $this->gtranslate->setLangFrom($content['original']['language_cnt']); $translang = $this->gtranslate->getLangPair(); $notifications[$k][$l]['translated'] = $this->gtranslate->translateContent($content['original']); $notifications[$k][$l]['original']['translang'] = $translang; $notifications[$k][$l]['translated']['translang'] = $translang; $ids[] = $l; $total += $content['updates']['total']; } } } else { $this->_helper->viewRenderer->setNoRender(true); } $jsonIds = Zend_Json::encode($ids); $this->view->notifications = $notifications; $this->view->ids = $jsonIds; $this->view->total = $total; }