Example #1
0
 /**
  * authenticate() - defined by Zend_Auth_Adapter_Interface.  This method is called to
  * attempt an authenication.  Previous to this call, this adapter would have already
  * been configured with all nessissary information to successfully connect to a database
  * table and attempt to find a record matching the provided identity.
  *
  * @throws Zend_Auth_Adapter_Exception if answering the authentication query is impossible
  * @return Zend_Auth_Result
  */
 public function authenticate()
 {
     $model = new Default_Model_User();
     $result = false;
     foreach ($model->getAll() as $key => $user) {
         if ($user['handle'] == $this->_identity && $user['password'] == $this->_credential) {
             $result = (object) $user;
         }
     }
     $code = Zend_Auth_Result::FAILURE;
     $messages = array();
     if ($result === false || $result->active === 0) {
         $code = Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND;
         $messages[] = 'A record with the supplied identity could not be found.';
     } elseif ($this->_credential !== $result->password) {
         $code = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID;
         $messages[] = 'Supplied credential is invalid.';
     } else {
         unset($result->password);
         $this->_resultRow = $result;
         $code = Zend_Auth_Result::SUCCESS;
         $messages[] = 'Authentication successful.';
     }
     return new Zend_Auth_Result($code, $this->_identity, $messages);
 }
Example #2
0
 /**
  *	Compares the given password into the password that is in the database
  *	@param $value, $context
  *	@return boolean
  */
 public function isValid($value, $context = null)
 {
     $this->_setValue($value);
     //  Get user identity
     $auth = Zend_Auth::getInstance();
     $identity = $auth->getIdentity();
     // User id
     $id = $identity->user_id;
     $userpw = new Default_Model_User();
     // Why this function is called when it has not been implemented? :/
     //$saltLength = $userpw->getSaltCountByUsername($auth->getIdentity()->username);
     $data = $userpw->getUserRow($id)->toArray();
     // the length of the salt is really not that difficult to get :)
     $saltLength = strlen($data['password_salt_usr']);
     // Gets user password data, saltLength 7 for backwards compatability
     if ($saltLength == 7) {
         // This is just repetition, let's declare the variable above these statements.
         //$data = $userpw->getUserRow($id)->toArray();
         $password = $data['password_usr'];
         $compared_password = md5($value);
     } else {
         // Repetition...
         //$data = $userpw->getUserRow($id)->toArray();
         $password = $data['password_usr'];
         $compared_password = md5($data['password_salt_usr'] . $value . $data['password_salt_usr']);
     }
     // compares the two password hashes
     if ($compared_password != $password) {
         $this->_error(self::MSG_URI);
         return false;
     }
     // end if
     return true;
 }
 public function activeUserAction()
 {
     $id = $this->_getParam('id', "");
     $userObj = new Default_Model_User();
     $userObj->updateStatusUser('Active', $id);
     $this->_redirect('/profile');
 }
Example #4
0
 public function setReceiverId($id)
 {
     $userModel = new Default_Model_User();
     $this->_receiver = $userModel->getUserRow($id);
     if ($this->_receiver == null) {
         $this->_errorMessage = "Error on receiver id";
     }
     return $this;
 }
Example #5
0
 public function testSetUserDetails()
 {
     $user = new Default_Model_User();
     $data['firstname'] = 'Sreenath';
     $data['lastname'] = 'Kalathil';
     $data['place'] = 'Trivandrum';
     $data['username'] = '******';
     $data['password'] = '******';
     $user->setUserDetails($data);
     $this->assertEquals($data, $user->returnsetUserDetails());
 }
 public function init()
 {
     $this->setMethod('post');
     $user = new Default_Model_User();
     $user->find();
     $this->addElement('password', 'old_password', array('label' => 'Old password', 'required' => true, 'class' => 'text', 'validators' => array(new OpenId_Validate_MatchOldPassword($user))));
     $this->addElement('password', 'password', array('label' => 'Password', 'required' => true, 'validators' => array(array('StringLength', false, 6)), 'class' => 'text'));
     $this->addElement('password', 'password_confirm', array('label' => 'Confirm password', 'required' => true, 'class' => 'text', 'validators' => array(new OpenId_Validate_MatchField('password'))));
     $this->addElement('submit', 'submit', array('ignore' => true, 'label' => 'Update'));
     $this->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'fieldset')), array('Description', array('placement' => 'prepend', 'class' => 'error')), 'Form'));
 }
 public function deleteAction()
 {
     $id = $this->getRequest()->getParam('id');
     if ($id === null) {
         $this->addErrorMessage('ID parameter is missing.');
         return;
     }
     $model = new Default_Model_User();
     $model->delete($id);
     $this->addMessage('User deleted');
     $this->_redirect('/user');
 }
Example #8
0
 /** Displays the details of the user in a form to be edited and posts the data to Editprofileform controller.
  * 
  * @return NULL
  * 
  */
 public function init()
 {
     $userdetails = new Default_Model_User();
     $session = new Zend_Session_Namespace('user');
     $row = $userdetails->getUserDetails($session->user_id);
     $this->setMethod('post');
     $this->addElement('text', 'username', array('label' => 'Username:'******'value' => $row[vchUsername], 'required' => true, 'filters' => array('StringTrim'), 'validators' => array('EmailAddress')));
     $this->addElement('text', 'password', array('label' => 'Password:'******'value' => $row[vchPassword], 'filters' => array('StringTrim'), 'required' => true));
     $this->addElement('text', 'firstname', array('label' => 'Firstname:', 'value' => $row[vchFirstname], 'required' => true, 'validators' => array(array('validator' => 'StringLength', 'options' => array(0, 20)))));
     $this->addElement('text', 'lastname', array('label' => 'Lastname:', 'value' => $row[vchLastname], 'required' => true, 'validators' => array(array('validator' => 'StringLength', 'options' => array(0, 20)))));
     $this->addElement('text', 'place', array('label' => 'Place:', 'value' => $row[vchPlace], 'required' => true, 'validators' => array(array('validator' => 'StringLength', 'options' => array(0, 20)))));
     $this->addElement('submit', 'submit', array('ignore' => true, 'label' => 'Edit'));
 }
Example #9
0
 public function deleteAction()
 {
     $pk = $this->_request->getParam('pk', NULL);
     if ($pk != "") {
         $m_datve = new Default_Model_User();
         if ($m_datve->deleteUser($pk)) {
             echo "<script>\n                            alert('Xoá thành công');";
         } else {
             echo "<script>\n                            alert('Xoá thất bại');";
         }
         echo "location.href ='" . HOST_PATH_PUBLIC . "/user';</script>";
     }
 }
Example #10
0
 /**
  *   isValid Checks if username exists in db using User Model's function
  *
  *   @param  $value string username
  *   @return boolean
  */
 public function isValid($value)
 {
     $value = (string) $value;
     $this->_setValue($value);
     $userModel = new Default_Model_User();
     if ($userModel->usernameExists($value)) {
         $this->_error(self::NOT_MATCH);
         return false;
         // if username is registered, form is not valid
     } else {
         return true;
         // if username is registered, form is not valid
     }
 }
Example #11
0
 function menu_doc()
 {
     $vi = new Zend_View();
     $base = $vi->baseurl();
     echo "<div class=\"title\">\n<div style=\"padding-top:10px;\" align=\"center\">Quảng lý đăng tin</div>\n</div>\n\n<div class=\"menu_doc\" id=\"menu_doc\">\n\t  <ul>";
     echo "<li><a href=\"{$base}/dang-tin.html\">Đăng tin </a></li>";
     echo "<li><a href=\"{$base}/thanh-vien.html\">Tin đã đăng</a></li>";
     echo "<li><a href=\"javascript:void(0)\">Tin hết hạn</a></li>";
     echo "<li><a href=\"javascript:void(0)\">Tin chờ duyệt</a></li>";
     echo "</ul>\n\t</div>";
     echo "<div class=\"title\">\n<div style=\"padding-top:10px;\" align=\"center\">Quảng lý cá nhân</div>\n</div>\n\n<div class=\"menu_doc\" id=\"menu_doc\">\n\t  <ul>";
     $link = new Default_Model_User();
     $link->linkuser();
     echo "<li><a href=\"javascript:void(0)\">Đổi password</a></li>";
     echo "</ul>\n\t</div>";
 }
Example #12
0
 /** Displays the login form and posts the username and password for validation
  * 
  * @return id of the user logged in.
  */
 public function indexAction()
 {
     $request = $this->getRequest();
     $form = new Default_Form_Loginform();
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($request->getPost())) {
             $user = new Default_Model_User();
             $user->getByUserName($request->username);
             if ($user->authenticateByPassword($request->password)) {
                 $session = new Zend_Session_Namespace('user');
                 $session->user_id = $user->getUserId();
                 $this->_helper->redirector('homepage');
             } else {
                 $this->view->entries = 1;
             }
         } else {
             $this->view->form = $form;
         }
     }
     $this->view->form = $form;
 }
Example #13
0
 function generateAction()
 {
     //Copy&Paste from RssController \o/ :D
     // Set an empty layout for view
     $this->_helper->layout()->setLayout('empty');
     // Make baseurl absolute URL
     $absoluteBaseUrl = strtolower(trim(array_shift(explode('/', $_SERVER['SERVER_PROTOCOL'])))) . '://' . $_SERVER['HTTP_HOST'] . Zend_Controller_Front::getInstance()->getBaseUrl();
     $this->view->absoluteBaseUrl = $absoluteBaseUrl;
     // Get parameters
     $params = $this->getRequest()->getParams();
     // Get content type
     $cty = isset($params['type']) ? $params['type'] : 'all';
     // Get number of items
     $count = isset($params['count']) ? $params['count'] : 10;
     //$lang = ($this->view->language == "en" || $this->view->language == "fi") ? $this->view->language : "en";
     //$lang = $this->view->language;
     // Set array for content data
     $data = array();
     // Get recent content by type
     $content = new Default_Model_Content();
     $data = $content->getRecentByLangAndType($this->view->language, $cty, $count);
     // Get tags for contents
     $tags_model = new Default_Model_ContentHasTag();
     $usersid_model = new Default_Model_ContentHasUser();
     $users_model = new Default_Model_User();
     $i = 0;
     foreach ($data as $dataRow) {
         $tags = $tags_model->getContentTags($dataRow['id_cnt']);
         $user = $users_model->getContentOwner($dataRow['id_cnt']);
         $data[$i]['author'] = $user['login_name_usr'];
         $tagNames = array();
         foreach ($tags as $tag) {
             $tagNames[] = $tag['name_tag'];
         }
         $data[$i]['tags'] = join(", ", $tagNames);
         $i++;
     }
     // Set to view
     $this->view->contentData = $data;
 }
 public function paginator2Action()
 {
     $page = $this->getRequest()->getParam('page');
     if (!$page) {
         $page = 1;
     }
     $zdmg = new Default_Model_User();
     /** example 1 **/
     /**
      * @var Zend_Db_Table_Select
      */
     $select = $zdmg->getSelect(true);
     $paginator = $zdmg->select2Paginator($select->columns('name'));
     /** end of example 1 **/
     // example 2:
     // paginator=$zdmg->query2Paginator('select name from user');
     // end of example 2
     $paginator->setCurrentPageNumber($page);
     $paginator->setDefaultItemCountPerPage(5);
     $paginator->setPageRange(4);
     $paginator->setDefaultScrollingStyle('Sliding');
     $this->view->paginator = $paginator;
 }
 /** Displays the edit profile form and posts the edited data to database.
  * 
  * @return NULL
  */
 public function indexAction()
 {
     $request = $this->getRequest();
     $form = new Default_Form_Editprofileform();
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($request->getPost())) {
             $user = new Default_Model_User();
             $session = new Zend_Session_Namespace('user');
             $user->getUserDetails();
             $data['username'] = $request->username;
             $data['password'] = $request->password;
             $data['firstname'] = $request->firstname;
             $data['lastname'] = $request->lastname;
             $data['place'] = $request->place;
             $user->setUserDetails($data);
             $user->update();
             $this->view->entries = 1;
         } else {
             $this->view->form = $form;
         }
     }
     $this->view->form = $form;
 }
Example #16
0
 public function insert(Default_Model_User $user)
 {
     $data = array('user_id' => $user->getUserId(), 'username' => $user->getUsername(), 'password' => $user->getPassword(), 'salt' => $user->getSalt(), 'register_time' => new Zend_Db_Expr('NOW()'), 'register_ip' => new Zend_Db_Expr("INET_ATON('{$_SERVER['REMOTE_ADDR']}')"));
     $db = $this->getWriteAdapter();
     $db->insert($this->getTableName(), $data);
     $userId = $db->lastInsertId();
     $user->setUserId($userId);
     $this->updateUserRoles($user);
     foreach ($user->getSettings() as $k => $v) {
         $this->insertUserSetting($user, $k, $v);
     }
     return $userId;
 }
Example #17
0
 private function isCampaignAdmin($userId)
 {
     $userModel = new Default_Model_User();
     foreach ($userModel->getUserCampaigns($userId) as $cmp) {
         if ($this->id == $cmp['id_cmp']) {
             $this->admin = true;
             return true;
         }
     }
     return false;
 }
Example #18
0
 public function removeroleAction()
 {
     $params = $this->getRequest()->getParams();
     $username = $params['user'];
     $role = $params['role'];
     if ($username != "" && $role != "") {
         $user = new Default_Model_User();
         if ($user->usernameExists($username)) {
             $id_usr = $user->getIdByUsername($username);
             $userProfiles = new Default_Model_UserProfiles();
             $user_roles = $userProfiles->getUserRoles($id_usr);
             if (in_array($role, $user_roles)) {
                 foreach ($user_roles as $key => $value) {
                     if ($value == $role) {
                         unset($user_roles[$key]);
                     }
                 }
                 $user_roles = array_values($user_roles);
                 if ($userProfiles->setUserRoles($id_usr, $user_roles)) {
                     $message = 'admin-removerole-successful';
                     $url = $this->_urlHelper->url(array('controller' => 'msg', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
                     $this->flash($message, $url);
                 } else {
                     $message = 'admin-removerole-not-successful';
                     $url = $this->_urlHelper->url(array('controller' => 'msg', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
                     $this->flash($message, $url);
                 }
             } else {
                 $message = 'admin-removerole-role-not-found';
                 $url = $this->_urlHelper->url(array('controller' => 'msg', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
                 $this->flash($message, $url);
             }
         } else {
             $message = 'admin-editrole-invalid-user';
             $url = $this->_urlHelper->url(array('controller' => 'msg', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
             $this->flash($message, $url);
         }
     } else {
         $message = 'admin-editrole-missing-username-role';
         $url = $this->_urlHelper->url(array('controller' => 'msg', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
         $this->flash($message, $url);
     }
 }
Example #19
0
 function userlistAction()
 {
     // assuming that the CleanQuery plugin has already stripped empty parameters
     if (isset($_GET) && is_array($_GET) && !empty($_GET)) {
         $path = '';
         array_walk($_GET, array('AccountController', 'encodeParam'));
         foreach ($_GET as $key => $value) {
             if ($key != 'filter' && $key != 'submit_user_filter') {
                 $path .= '/' . $key . '/' . $value;
             }
         }
         $uri = $_SERVER['REQUEST_URI'];
         $path = substr($uri, 0, strpos($uri, '?')) . $path;
         $this->getResponse()->setRedirect($path, $this->_permanent ? 301 : 302);
         $this->getResponse()->sendResponse();
         return;
     }
     // Get requests
     $params = $this->getRequest()->getParams();
     // Get page nummber and items per page
     $page = isset($params['page']) ? $params['page'] : 1;
     $count = isset($params['count']) ? $params['count'] : 10;
     $order = isset($params['order']) ? $params['order'] : null;
     $list = isset($params['list']) ? $params['list'] : null;
     if ($order == "username") {
         $order = "usr.login_name_usr";
     } elseif ($order == "joined") {
         $order = "usr.created_usr";
     } elseif ($order == "login") {
         $order = "usr.last_login_usr";
     } elseif ($order == "content") {
         $order = "contentCount";
     } else {
         $order = null;
     }
     if ($list != "asc" && $list != "desc") {
         $list = null;
     }
     if (isset($order) && isset($list)) {
         $sort = $order . " " . $list;
     }
     // Filter form data
     $formData['username'] = isset($params['username']) ? $params['username'] : '';
     $formData['city'] = isset($params['city']) ? $params['city'] : '';
     //$formData['country'] = isset($params['country']) ? $params['country'] : 0;
     $formData['contentlimit'] = isset($params['contentlimit']) ? $params['contentlimit'] : null;
     $formData['counttype'] = isset($params['counttype']) ? $params['counttype'] : 0;
     // Get country listing
     $userCountry = new Default_Model_UserCountry();
     $formData['countryList'] = $userCountry->getCountryList();
     // Reorder country listing and add all countries option
     $temp[0] = $this->view->translate('userlist-filter-country-all');
     foreach ($formData['countryList'] as $k => $v) {
         $temp[$v['id_ctr']] = $v['name_ctr'];
     }
     $formData['countryList'] = $temp;
     //Set array patterns
     $pat_sql = array("%", "_");
     $pat_def = array("*", "?");
     //Replace * and ? characters
     $formData['username'] = str_replace($pat_def, $pat_sql, $formData['username']);
     $formData['city'] = str_replace($pat_def, $pat_sql, $formData['city']);
     // Get user listing
     $user = new Default_Model_User();
     $userListing = $user->getUserListing($formData, $page, $count, $sort);
     $userIdList = array();
     foreach ($userListing as $u) {
         array_push($userIdList, $u['id_usr']);
     }
     // Get total content count
     $userCount = $user->getUserCountBySearch($formData);
     // Calculate total page count
     $pageCount = ceil($userCount / $count);
     // User list search form
     $userSearch = new Default_Form_UserListSearchForm(null, $formData);
     $url = $this->_urlHelper->url(array('controller' => 'account', 'action' => 'userlist', 'language' => $this->view->language), 'lang_default', true);
     $userSearch->setAction($url)->setMethod('get');
     $this->view->userSearch = $userSearch;
     // 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;
     /*
     if (!empty($userListing)) {
         // Content pagination
         $paginator = Zend_Paginator::factory($userListing);
         
         // Set items per page
         $paginator->setItemCountPerPage($count);
         
         // Get items by page
         $paginator->getItemsByPage($page);
         
         // Set current page number
         $paginator->setCurrentPageNumber($page);
         
         Zend_Paginator::setDefaultScrollingStyle('Sliding');
         
         $view = new Zend_View();
         $paginator->setView($view);
         
         // Set paginator for view
         $this->view->userListPaginator = $paginator;	
     } // end if
     */
     // Set to view
     $this->view->userPaginator = $paginator;
     $this->view->userListData = $userListing;
     $this->view->userList = $userIdList;
     $this->view->count = $count;
     $this->view->userCount = $userCount;
     $this->view->page = $page;
 }
 protected function getFlagsForm(Default_Model_User $user)
 {
     $form = new Zend_Form();
     $form->setAction('/manage-account/flags')->setMethod('post');
     $flags = $user->getFlags();
     // Add a checkbox for each flag
     $labels = array();
     $labels['admin'] = I18n::_('Support Engineer');
     $labels['codesign'] = I18n::_('Code Signing');
     $labels['orgadmin'] = I18n::_('Organisation Assurer');
     $labels['ttpadmin'] = I18n::_('TTP Admin');
     $labels['board'] = I18n::_('Board Member');
     $labels['locadmin'] = I18n::_('Location Admin');
     $labels['tverify'] = I18n::_('TVerify');
     $labels['locked'] = I18n::_('Lock Account');
     $labels['assurer_blocked'] = I18n::_('Block Assurer');
     foreach ($labels as $flag => $label) {
         $checkbox = new Zend_Form_Element_Checkbox($flag);
         $checkbox->setLabel($label)->setChecked($flags[$flag]);
         $form->addElement($checkbox);
     }
     $submit = new Zend_Form_Element_Submit('submit');
     $submit->setLabel(I18n::_('Save Flags'));
     $form->addElement($submit);
     return $form;
 }
 function updateusersAction()
 {
     $id = $this->_request->getParam('id');
     $system = new Default_Model_User();
     if ($this->_request->isPost()) {
         $this->view->purifier = Zend_Registry::get('purifier');
         $conf = HTMLPurifier_Config::createDefault();
         $purifier = new HTMLPurifier($conf);
         $email = $purifier->purify($this->_request->getParam('email'));
         $full_name = $purifier->purify($this->_request->getParam('full_name'));
         $phone = $purifier->purify($this->_request->getParam('phone'));
         $birth = $purifier->purify($this->_request->getParam('birth'));
         $sex = $purifier->purify($this->_request->getParam('sex'));
         $address = $purifier->purify($this->_request->getParam('address'));
         $id = $this->_request->getParam('id');
         $system->update_Users($full_name, $email, $phone, $birth, $sex, $address, $id);
     }
     $users = $system->list_users($id);
     $this->view->user = $users;
 }
 public function changePasswordAction()
 {
     $data = $this->getRequest()->getPost();
     $user = new Default_Model_User();
     $id = $this->_getParam('id', "");
     $check = $user->getUser($id);
     if ($check['password'] == md5($data['password'])) {
         $user->changePassword($data['password1'], $id);
     }
     $this->_redirect('/resume');
 }
Example #23
0
 public function previewAction()
 {
     // Get authentication
     $auth = Zend_Auth::getInstance();
     // Disable layout to be rendered
     $this->_helper->layout->disableLayout();
     // If user has authenticated
     if ($auth->hasIdentity()) {
         // Get user data
         $userId = $auth->getIdentity()->user_id;
         $userName = $auth->getIdentity()->username;
         $userModel = new Default_Model_User();
         $userData = $userModel->getSimpleUserDataById($userId);
         // Get requests
         if ($this->getRequest()->isPost()) {
             // Get POST data and convert it to UTF-8 compatible html entities
             $rawpostData = $this->getRequest()->getPost();
             foreach ($rawpostData as $key => $value) {
                 $postData[$key] = htmlentities($value, ENT_QUOTES, "UTF-8");
             }
             // Set today's date and time
             $today = date('Y-m-d H:i:m');
             // Get content type of the specific content viewed
             $contentTypesModel = new Default_Model_ContentTypes();
             $contentType = $contentTypesModel->getTypeById($postData['content_type']);
             // Reformat preview data
             $contentData = array('id_cnt' => 'preview', 'id_cty_cnt' => $postData['content_type'], 'title_cnt' => isset($postData['content_header']) ? $postData['content_header'] : '', 'lead_cnt' => isset($postData['content_textlead']) ? $postData['content_textlead'] : '', 'language_cnt' => isset($postData['content_language']) ? $postData['content_language'] : '', 'body_cnt' => isset($postData['content_text']) ? $postData['content_text'] : '', 'research_question_cnt' => isset($postData['content_research']) ? $postData['content_research'] : '', 'opportunity_cnt' => isset($postData['content_opportunity']) ? $postData['content_opportunity'] : '', 'threat_cnt' => isset($postData['content_threat']) ? $postData['content_threat'] : '', 'solution_cnt' => isset($postData['content_solution']) ? $postData['content_solution'] : '', 'references_cnt' => isset($postData['content_references']) ? $postData['content_references'] : '', 'views_cnt' => 0, 'published_cnt' => 1, 'created_cnt' => $today, 'modified_cnt' => $today, 'id_usr' => $userId, 'login_name_usr' => $userName, 'key_cty' => $postData['content_type'], 'name_cty' => $contentType);
             // Reformat tags
             $rawtags = explode(",", $postData['content_keywords']);
             $tags = null;
             foreach ($rawtags as $rawtag) {
                 $tags[count($tags)]['name_tag'] = $rawtag;
             }
             // Get form
             $form = new Default_Form_PreviewContentForm();
             // Inject previewdata to view
             $this->view->previewMode = 1;
             $this->view->files = null;
             $this->view->id = 'preview';
             //$this->view->industries         = $industries;
             //$this->view->userImage          = $userImage;
             //$this->view->commentPaginator   = $paginator;
             //$this->view->commentData        = $commentsSorted;
             //$this->view->user_can_comment   = $user_can_comment;
             $this->view->contentData = $contentData;
             //$this->view->modified			= $contentData['modified_cnt'];
             $this->view->userData = $userData;
             //$this->view->moreFromUser       = $moreFromUser;
             $this->view->views = $contentData['views_cnt'];
             //$this->view->rating             = $rating;
             $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->form = $form;
             //$this->view->favourite			= $favourite;
             // Inject title to view
             $this->view->title = $this->view->translate('index-home') . " - " . $contentData['title_cnt'];
         }
     } else {
         $message = 'content-preview-not-logged-in';
         $url = $this->_urlHelper->url(array('controller' => 'msg', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
         $this->flash($message, $url);
     }
 }
Example #24
0
 /**
  * 
  * @param unknown_type $id_usr
  * @param unknown_type $follows
  * @param unknown_type $type
  */
 private function _fetchUpdatedContents($id_usr, $follows, $type)
 {
     $contents = array();
     $updatedContents = array();
     if ($type == "own") {
         $userModel = new Default_Model_User();
         $contents = $userModel->getUsersContentsLastCheck($id_usr);
         $contents = $contents[$id_usr];
     }
     //print_r($contents);die;
     if ($type == "fvr") {
         $contents = $this->getAllFavouriteContentIdsFromUserWithLastChecked($id_usr);
     }
     //print_r($contents);die;
     foreach ($follows as $bin => $follow) {
         if ($follow == "comment") {
             $temp = $this->_getNewComments($contents);
         } elseif ($follow == "rating") {
             $temp = $this->_getNewRatings($contents);
         } elseif ($follow == "linking") {
             $temp = $this->_getNewLinkings($contents);
         } elseif ($follow == "translation") {
             $temp = $this->_getNewTranslations($contents);
         } elseif ($follow == "modified") {
             $temp = $this->_getModified($contents);
         }
         if (empty($temp)) {
             $temp = null;
         }
         $updatedContents[$bin] = $temp;
     }
     //print_r($updatedContents);die;
     return $updatedContents;
 }
Example #25
0
 /**
  *   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 fetchAll()
 {
     $resultSet = $this->getDbTable()->fetchAll();
     $entries = array();
     foreach ($resultSet as $row) {
         $entry = new Default_Model_User();
         $entry->setId($row->id)->setUsername($row->username)->setCreated($row->created)->setMapper($this);
         $entries[] = $entry;
     }
     return $entries;
 }
Example #27
0
 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;
 }
Example #28
0
 public function sendAction()
 {
     // Get authentication
     $auth = Zend_Auth::getInstance();
     $absoluteBaseUrl = strtolower(trim(array_shift(explode('/', $_SERVER['SERVER_PROTOCOL'])))) . '://' . $_SERVER['HTTP_HOST'] . Zend_Controller_Front::getInstance()->getBaseUrl();
     // If user has identity
     if ($auth->hasIdentity()) {
         // Get requests
         $params = $this->getRequest()->getParams();
         // Get content type
         $receiver = isset($params['username']) ? $params['username'] : '';
         $model_user = new Default_Model_User();
         $url = $this->_urlHelper->url(array('controller' => 'msg', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
         if (!$model_user->usernameExists($receiver)) {
             // If not logged, redirecting to system message page
             $message = 'privmsg-send-invalid-receiver';
             $this->flash($message, $url);
         } else {
             if ($model_user->getIdByUsername($receiver) == $auth->getIdentity()->user_id) {
                 $message = 'privmsg-send-own-account';
                 $this->flash($message, $url);
             }
         }
         // Receiver's username to view
         $this->view->receiver = $receiver;
         // Sender's username to view
         $this->view->sender = $auth->getIdentity()->username;
         // Creating data array for form's hidden fields
         $data = array();
         $data['sender_id'] = $auth->getIdentity()->user_id;
         $data['receiver_id'] = $model_user->getIdByUsername($receiver);
         $form = new Default_Form_PrivMsgForm(null, $data);
         $this->view->form = $form;
         // If private message is posted
         if ($this->getRequest()->isPost()) {
             // Get private message data
             $data = $this->getRequest()->getPost();
             if ($form->isValid($data)) {
                 // Add a private message
                 $Default_Model_privmsg = new Default_Model_PrivateMessages();
                 if ($Default_Model_privmsg->addMessage($data) && $data['privmsg_sender_id'] != $data['privmsg_receiver_id']) {
                     $message = 'privmsg-add-successful';
                 } else {
                     $message = 'privmsg-add-not-successful';
                 }
                 // Send email to user about new private message
                 // if user allows private message notifications
                 $receiverId = $data['privmsg_receiver_id'];
                 $notificationsModel = new Default_Model_Notifications();
                 $notifications = $notificationsModel->getNotificationsById($receiverId);
                 if (in_array('privmsg', $notifications)) {
                     $senderName = $auth->getIdentity()->username;
                     $receiverUsername = $model_user->getUserNameById($receiverId);
                     $emailNotification = new Oibs_Controller_Plugin_Email();
                     $emailNotification->setNotificationType('privmsg')->setSenderId($auth->getIdentity()->user_id)->setReceiverId($receiverId)->setParameter('URL', $absoluteBaseUrl . "/en")->setParameter('SENDER-NAME', $senderName)->setParameter('MESSAGE-TITLE', $data['privmsg_header'])->setParameter('MESSAGE-BODY', nl2br($data['privmsg_message']));
                     if ($emailNotification->isValid()) {
                         $emailNotification->send();
                     } else {
                         //echo $emailNotification->getErrorMessage(); die;
                     }
                 }
                 $this->flash($message, $url);
             }
         }
         // end if
     } else {
         // If not logged, redirecting to system message page
         $message = 'privmsg-send-not-logged';
         $url = $this->_urlHelper->url(array('controller' => 'msg', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
         $this->flash($message, $url);
     }
 }
Example #29
0
 /**
  * linkcampaignAction
  *
  * Link campaign to campaign.
  */
 public function linkcampaignAction()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $usrId = $auth->getIdentity()->user_id;
         $cmpId = $this->_request->getParam('cmpid');
         if (!isset($cmpId)) {
             $redirectUrl = $this->_urlHelper->url(array('controller' => 'campaign', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
             $this->_redirector->gotoUrl($redirectUrl);
         }
         $this->view->cmpid = $cmpId;
         $cmpmodel = new Default_Model_Campaigns();
         $cmp = $cmpmodel->getCampaignById($cmpId);
         $usrmodel = new Default_Model_User();
         $usrcmp = $usrmodel->getUserCampaigns($usrId);
         $cmpHasCmpModel = new Default_Model_CampaignHasCampaign();
         if (!empty($usrcmp)) {
             $i = 0;
             foreach ($usrcmp as $campaign) {
                 if ($cmpHasCmpModel->checkIfCampaignHasCampaign($cmpId, $campaign['id_cmp']) || $cmpHasCmpModel->checkIfCampaignHasCampaign($campaign['id_cmp'], $cmpId) || $cmpId == $campaign['id_cmp']) {
                     unset($usrcmp[$i]);
                 }
                 $i++;
             }
         }
         if (!empty($usrcmp)) {
             $hasUserCampaigns = true;
         } else {
             $hasUserCampaigns = false;
         }
         $this->view->cmp = $cmp;
         $this->view->usrcmp = $usrcmp;
         $this->view->hasUserCampaigns = $hasUserCampaigns;
     } else {
         // If not logged, redirecting to system message page
         $message = 'campaign-link-not-logged';
         $url = $this->_urlHelper->url(array('controller' => 'msg', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
         $this->flash($message, $url);
     }
 }
Example #30
0
 /**
  *   getDataForView
  *
  *   Get content by id.
  *   Is this function used anywhere?
  *   If not, this function should probably be removed.
  *
  *   @param ineteger $id
  *   @return array
  */
 public function getDataForView($id = 0)
 {
     // Array for content data
     $data = array();
     // Find content row by id
     //$rowset = $this->find((int)$id)->current();
     $select = $this->_db->select()->from(array('contents_cnt' => 'contents_cnt'), array('*'))->where('id_cnt = ?', $id);
     $result = $this->_db->fetchAll($select);
     // If content was found
     if (count($result) == 1) {
         $data['Content']['Data'] = $result[0];
         // Find Ratings
         //$select_ratings = $this->select()->from('content_ratings_crt', array('SUM(rating_crt) AS rate_crt'));
         //$ratings = $rowset->findDependentRowset('Default_Model_ContentRatings', 'RatingsContent', $select_ratings)->toArray();
         $ratings = new Default_Model_ContentRatings();
         $rating = $ratings->getById($id);
         // Find content owners
         //$content_owner = $rowset->findManyToManyRowset('Default_Model_User', 'Default_Model_ContentHasUser');
         $cntHasUser = new Default_Model_ContentHasUser();
         $owners = $cntHasUser->getContentOwners($id);
         // Find owners
         $userModel = new Default_Model_User();
         $i = 0;
         foreach ($owners as $owner) {
             $data['Content']['Data']['Owners'][$i] = $userModel->getSimpleUserDataById($owner);
             $i++;
         }
         // Find content comments
         //$select_comment = $this->select()->order('created_cmt ASC');
         //$comments = $rowset->findDependentRowset('Default_Model_Comments', 'CommentContent', $select_comment);
         $commentModel = new Default_Model_Comments();
         $comments = $commentModel->getAllByContentId($id);
         /*  comment owner username is fetched in the previous query, no need for this anymore
             			 // Array for comment owners
             			 $comment_owners = array();
             
             			 // Go through all comments
             			 foreach($comments as $cmt)
             			 {
             			 // Find comment owner
             			 $usr = $cmt->findDependentRowset('Default_Model_User', 'CommentUser')->toArray();
             
             			 // If owner found
             			 if(!empty($usr))
             			 {
             			 // Specify comment owner
             			 $comment_owners[$usr[0]['id_usr']] = $usr[0];
             			 } // end if
             			 } // end foreach
             			 */
         // Find content keywords
         //$tags = $rowset->findManyToManyRowset('Default_Model_Tags', 'Default_Model_ContentHasTag')->toArray();
         $cntHasTag = new Default_Model_ContentHasTag();
         $tags = $cntHasTag->getContentTags($id);
         // Find content links - needs updating to this version
         $links = array();
         //$rowset->findDependentRowset('Default_Model_Links')->toArray();
         // Find related content
         //$$related_content = $rowset->findManyToManyRowset('Default_Model_Content', 'Default_Model_ContentHasContent', 'ParentContent', 'ChildContent')->toArray();
         $contentHasContent = new Default_Model_ContentHasContent();
         $familyTree = $contentHasContent->getContentFamilyTree($id);
         // echo"<pre>"; print_r($tagArray); echo"</pre>"; die;
         // Gather and format content data a bit
         $data['Content']['Data']['rating'] = $rating;
         //$data['Content']['Data']['owner'] = $owner;
         $data['Content']['Tags'] = $tags;
         $data['Content']['Links'] = $links;
         $data['Content']['FamilyTree'] = $familyTree;
         $data['Comments']['Data'] = $comments;
         //echo"<pre>"; print_r($comments); echo"</pre>"; die;
         //$data['Comments']['Posters']        = $comment_owners;
     }
     return $data;
 }