/** * This function counts the call of a posting * @param posting id of the posting to quit abo * @param forum id of the forum to quit abo * @param category id of the category to quit abo */ public static function quitAbo($posting = 0, $forum = 0, $category = 0) { // Security ckeck if (SecurityUtil::checkPermission('MUBoard::', '::', ACCESS_COMMENT) && UserUtil::isLoggedIn() == true) { // build posting repository $repository = MUBoard_Util_Model::getAboRepository(); // get actual user id $userid = UserUtil::getVar('uid'); // quit abo of posting if posting is taken if ($posting > 0) { // look for abo $where = 'tbl.postingid = \'' . DataUtil::formatForStore($posting) . '\''; $where .= ' AND '; $where .= 'tbl.userid = \'' . DataUtil::formatForStore($userid) . '\''; $abos = $repository->selectWhere($where); $serviceManager = ServiceUtil::getManager(); $entityManager = $serviceManager->getService('doctrine.entitymanager'); foreach ($abos as $abo) { $entityManager->remove($abo); $entityManager->flush(); } } if ($forum > 0) { // look for abo $where = 'tbl.forumid = \'' . DataUtil::formatForStore($forum) . '\''; $where .= ' AND '; $where .= 'tbl.userid = \'' . DataUtil::formatForStore($userid) . '\''; $abos = $repository->selectWhere($where); $serviceManager = ServiceUtil::getManager(); $entityManager = $serviceManager->getService('doctrine.entitymanager'); foreach ($abos as $abo) { $entityManager->remove($abo); $entityManager->flush(); } } return true; } }
/** * Command event handler. * * This event handler is called when a command is issued by the user. */ public function handleCommand(Zikula_Form_View $view, &$args) { $result = parent::handleCommand($view, $args); if ($result === false) { return $result; } if ($args['commandName'] == 'create') { // we need the userid $userid = UserUtil::getVar('uid'); // we need a userrepository $repository = MUBoard_Util_Model::getUserRepository(); // we get the user entity $boarduser = $repository->selectById($userid); $userrank = $boarduser->getRank(); } return $this->view->redirect($this->getRedirectUrl($args, $entity, $repeatCreateAction)); }
/** * */ public static function actualPostings($userid) { if (UserUtil::isLoggedIn() == true) { // we get a repository for users $userrepository = MUBoard_Util_Model::getUserRepository(); $where = 'tbl.userid = \'' . DataUtil::formatForStore($userid) . '\''; $user = $userrepository->selectWhere($where); // we get the datetime of the last visit of muboard $lastVisit = $user[0]['lastVisit']; // we get the timestamp $lastVisit = $lastVisit->getTimestamp(); // we format for $lastVisit = date('Y-m-d H:i:s', $lastVisit); $date = DateUtil::getDatetime(); // we get a repository for postings $postingrepository = MUBoard_Util_Model::getPostingRepository(); $where = 'tbl.createdDate > \'' . $lastVisit . '\''; $postings = $postingrepository->selectWhere($where); $forumids = array(); $postingids = array(); foreach ($postings as $posting) { // get forum id $forum = $posting->getForum(); $forumid = $forum->getId(); if (!in_array($forumid, $forumids)) { $forumids[] = $forumid; } // get posting id $parent = $posting->getParent(); if (!is_null($parent)) { $parentid = $parent->getId(); if ($parentid != NULL) { if (!in_array($parentid, $postingids)) { $postingids[] = $parentid; } } } else { $id = $posting->getId(); if (!in_array($id, $postingids)) { $postingids[] = $id; } } } //SessionUtil::setVar('muboardforumids', $forumids); SessionUtil::setVar('muboardpostingids', $postingids); } }
/** * Pre-Process the data prior a delete operation. * * @ORM\PreRemove * @see MUBoard_Entity_Base_Posting::performPreRemoveCallback() * @return void. */ public function preRemoveCallback() { $uid = $this->getCreatedUserId(); $userrepository = MUBoard_Util_Model::getUserRepository(); $where = 'tbl.userid = \'' . DataUtil::formatForStore($uid) . '\''; $user = $userrepository->selectWhere($where); if (count($user) == 1) { $user = $userrepository->selectById($user[0]['id']); $serviceManager = ServiceUtil::getManager(); $entityManager = $serviceManager->getService('doctrine.entitymanager'); $numberPostings = $user->getNumberPostings() - 1; $user->setNumberPostings($numberPostings); $entityManager->flush(); } $this->performPreRemoveCallback(); }
/** * Controller method to mark a posting as solved ( issue ) */ public function unsolved() { $request = new Zikula_Request_Http(); $id = $request->query->filter('id', 0, FILTER_SANITIZE_NUMBER_INT); MUBoard_Util_Model::unsolvedPosting($id); return System::redirect(ModUtil::url($this->name, 'user', 'display', array('ot' => 'posting', 'id' => $id))); }
/** * This method provides a generic item detail view. * * @param string $ot Treated object type. * @param string $tpl Name of alternative template (for alternative display options, feeds and xml output) * @param boolean $raw Optional way to display a template instead of fetching it (needed for standalone output) * @return mixed Output. */ public function display($args) { // DEBUG: permission check aspect starts $this->throwForbiddenUnless(SecurityUtil::checkPermission('MUBoard::', '::', ACCESS_READ)); // DEBUG: permission check aspect ends // parameter specifying which type of objects we are treating $objectType = isset($args['ot']) && !empty($args['ot']) ? $args['ot'] : $this->request->getGet()->filter('ot', 'category', FILTER_SANITIZE_STRING); $utilArgs = array('controller' => 'user', 'action' => 'display'); if (!in_array($objectType, MUBoard_Util_Controller::getObjectTypes('controllerAction', $utilArgs))) { $objectType = MUBoard_Util_Controller::getDefaultObjectType('controllerAction', $utilArgs); } $repository = $this->entityManager->getRepository('MUBoard_Entity_' . ucfirst($objectType)); $idFields = ModUtil::apiFunc($this->name, 'selection', 'getIdFields', array('ot' => $objectType)); // retrieve identifier of the object we wish to view $idValues = MUBoard_Util_Controller::retrieveIdentifier($this->request, $args, $objectType, $idFields); $hasIdentifier = MUBoard_Util_Controller::isValidIdentifier($idValues); // check for unique permalinks (without id) $hasSlug = false; $slugTitle = ''; if ($hasIdentifier === false) { $entityClass = 'MUBoard_Entity_' . ucfirst($objectType); $objectTemp = new $entityClass(); $hasSlug = $objectTemp->get_hasUniqueSlug(); if ($hasSlug) { $slugTitle = isset($args['title']) && !empty($args['title']) ? $args['title'] : $this->request->getGet()->filter('title', '', FILTER_SANITIZE_STRING); $hasSlug = !empty($slugTitle); } } $hasIdentifier |= $hasSlug; $this->throwNotFoundUnless($hasIdentifier, $this->__('Error! Invalid identifier received.')); $entity = ModUtil::apiFunc($this->name, 'selection', 'getEntity', array('ot' => $objectType, 'id' => $idValues, 'slug' => $slugTitle)); $this->throwNotFoundUnless($entity != null, $this->__('No such item.')); // we take the children postings of the parent issue if ($objectType == 'posting') { $postingid = $entity['id']; $postingsWhere = 'tbl.parent = \'' . DataUtil::formatForStore($postingid) . '\''; $order = ModUtil::getVar($this->name, 'sortingPostings'); if ($order == 'descending') { $sdir = 'desc'; } else { $sdir = 'asc'; } $selectionArgs = array('ot' => 'posting', 'where' => $postingsWhere, 'orderBy' => 'createdDate' . ' ' . $sdir); // the current offset which is used to calculate the pagination $currentPage = (int) (isset($args['pos']) && !empty($args['pos'])) ? $args['pos'] : $this->request->getGet()->filter('pos', 1, FILTER_VALIDATE_INT); // the number of items displayed on a page for pagination $resultsPerPage = (int) (isset($args['num']) && !empty($args['num'])) ? $args['num'] : $this->request->getGet()->filter('num', 0, FILTER_VALIDATE_INT); if ($resultsPerPage == 0) { $csv = (int) (isset($args['usecsv']) && !empty($args['usecsv'])) ? $args['usecsv'] : $this->request->getGet()->filter('usecsvext', 0, FILTER_VALIDATE_INT); $resultsPerPage = $csv == 1 ? 999999 : $this->getVar('pagesize', 10); } $selectionArgs['currentPage'] = $currentPage; $selectionArgs['resultsPerPage'] = $resultsPerPage; list($entities, $objectCount) = ModUtil::apiFunc($this->name, 'selection', 'getEntitiesPaginated', $selectionArgs); // we check if the user may see the form to answer to posting $mayEdit = MUBoard_Util_Controller::mayEdit($id); $this->view->assign('mayEdit', $mayEdit); } if ($objectType == 'forum') { $forumid = $entity['id']; $parentWhere = 'tbl.parent_id IS NULL'; $parentWhere .= ' AND '; $parentWhere .= 'tbl.forum = \'' . DataUtil::formatForStore($forumid) . '\''; $order = ModUtil::getVar($this->name, 'sortingPostings'); if ($order == 'descending') { $sdir = 'desc'; } else { $sdir = 'asc'; } $selectionArgs = array('ot' => 'posting', 'where' => $parentWhere, 'orderBy' => 'createdDate' . ' ' . $sdir); // the current offset which is used to calculate the pagination $currentPage = (int) (isset($args['pos']) && !empty($args['pos'])) ? $args['pos'] : $this->request->getGet()->filter('pos', 1, FILTER_VALIDATE_INT); // the number of items displayed on a page for pagination $resultsPerPage = (int) (isset($args['num']) && !empty($args['num'])) ? $args['num'] : $this->request->getGet()->filter('num', 0, FILTER_VALIDATE_INT); if ($resultsPerPage == 0) { $csv = (int) (isset($args['usecsv']) && !empty($args['usecsv'])) ? $args['usecsv'] : $this->request->getGet()->filter('usecsvext', 0, FILTER_VALIDATE_INT); $resultsPerPage = $csv == 1 ? 999999 : $this->getVar('pagesize', 10); } $selectionArgs['currentPage'] = $currentPage; $selectionArgs['resultsPerPage'] = $resultsPerPage; list($entities, $objectCount) = ModUtil::apiFunc($this->name, 'selection', 'getEntitiesPaginated', $selectionArgs); } // build ModUrl instance for display hooks $currentUrlArgs = array('ot' => $objectType); foreach ($idFields as $idField) { $currentUrlArgs[$idField] = $idValues[$idField]; } // add a call to the posting if ($objectType == 'posting') { MUBoard_Util_Model::addView($idValues); } // get actual time $nowtime = DateUtil::getDatetime(); // set sessionvar with calling time SessionUtil::setVar('muboardonline', $nowtime); $currentUrlObject = new Zikula_ModUrl($this->name, 'user', 'display', ZLanguage::getLanguageCode(), $currentUrlArgs); $type = $this->request->getGet()->filter('type', 'admin', FILTER_SANITIZE_STRING); $func = $this->request->getGet()->filter('func', 'view', FILTER_SANITIZE_STRING); $editPostings = ModUtil::getVar($this->name, 'editPostings'); // assign output data to view object. $this->view->assign($objectType, $entity)->assign('postings', $entities)->assign('currentUrlObject', $currentUrlObject)->assign('func', $func)->assign('editPostings', $editPostings)->assign($repository->getAdditionalTemplateParameters('controllerAction', $utilArgs)); $this->view->assign('currentPage', $currentPage)->assign('pager', array('numitems' => $objectCount, 'itemsperpage' => $resultsPerPage)); $dom = ZLanguage::getModuleDomain($this->name); // we set Pagetitle $sitename = ModUtil::getVar('ZConfig', 'sitename'); if ($objectType == 'category') { $titletobject = __('Forum - Category: ', $dom); } if ($objectType == 'forum') { $titletobject = __('Forum - Category: ', $dom) . ' ' . $entity['category']['title'] . ' - ' . __('Forum: ', $dom); } if ($objectType == 'posting') { $titletobject = 'Forum: ' . ' ' . $entity['forum']['title'] . ' - ' . __('Issue: ', $dom); } PageUtil::setVar('title', $sitename . ' - ' . $titletobject . ' ' . $entity['title']); // we set description if ($objectType == 'category' || $objectType == 'forum') { $descriptionobject = $entity['description']; } if ($objectType == 'posting') { $descriptionobject = $entity['text']; $descriptionobject = substr($descriptionobject, 0, 160) . '...'; } PageUtil::setVar('description', $descriptionobject); // fetch and return the appropriate template return MUBoard_Util_View::processTemplate($this->view, 'user', $objectType, 'display', $args); }
/** * Executes the actual search process. * * @param array $args List of arguments. * * @return boolean */ public function search($args) { if (!SecurityUtil::checkPermission($this->name . '::', '::', ACCESS_READ)) { return ''; } // ensure that database information of Search module is loaded ModUtil::dbInfoLoad('Search'); // save session id as it is used when inserting search results below $sessionId = session_id(); // retrieve list of activated object types //$searchTypes = isset($args['objectTypes']) ? (array)$args['objectTypes'] : (array)FormUtil::getPassedValue('search_mediarepository_types', array(), 'GETPOST'); $searchTypes[] = 'posting'; $controllerHelper = new MUBoard_Util_Controller($this->serviceManager); $utilArgs = array('api' => 'search', 'action' => 'search'); //$allowedTypes = $controllerHelper->getObjectTypes('api', $utilArgs); $allowedTypes[] = 'posting'; $entityManager = ServiceUtil::getService('doctrine.entitymanager'); $currentPage = 1; $resultsPerPage = 50; // foreach ($searchTypes as $objectType) { /* if (!in_array($objectType, $allowedTypes)) { continue; }*/ $whereArray = array(); $languageField = null; $whereArray[] = 'title'; $whereArray[] = 'text'; /*switch ($objectType) { case 'repository': $whereArray[] = 'name'; $whereArray[] = 'workDirectory'; $whereArray[] = 'storageDirectory'; $whereArray[] = 'cacheDirectory'; $whereArray[] = 'uploadNamingPrefix'; $whereArray[] = 'mailRecipient'; break; case 'mediaHandler': $whereArray[] = 'mimeType'; $whereArray[] = 'fileType'; $whereArray[] = 'foundMimeType'; $whereArray[] = 'foundFileType'; $whereArray[] = 'handlerName'; $whereArray[] = 'title'; $whereArray[] = 'image'; break; case 'medium': $whereArray[] = 'title'; $whereArray[] = 'keywords'; $whereArray[] = 'description'; $whereArray[] = 'description2'; $whereArray[] = 'dateTaken'; $whereArray[] = 'placeTaken'; $whereArray[] = 'notes'; $whereArray[] = 'license'; $whereArray[] = 'areamap'; $whereArray[] = 'url'; $whereArray[] = 'mediaHandler'; $whereArray[] = 'fileUpload'; break; case 'thumbSize': $whereArray[] = 'name'; break; }*/ $where = Search_Api_User::construct_where($args, $whereArray, $languageField); $repository = $entityManager->getRepository($this->name . '_Entity_' . ucfirst($objectType)); $repository = MUBoard_Util_Model::getPostingRepository(); // get objects from database list($entities, $objectCount) = $repository->selectWherePaginated($where, '', $currentPage, $resultsPerPage, false); if ($objectCount == 0) { continue; } $idFields = ModUtil::apiFunc($this->name, 'selection', 'getIdFields', array('ot' => $objectType)); $titleField = $repository->getTitleFieldName(); $descriptionField = $repository->getDescriptionFieldName(); foreach ($entities as $entity) { $urlArgs = array('ot' => $objectType); // create identifier for permission check $instanceId = ''; foreach ($idFields as $idField) { $urlArgs[$idField] = $entity[$idField]; if (!empty($instanceId)) { $instanceId .= '_'; } $instanceId .= $entity[$idField]; } $urlArgs['id'] = $instanceId; if (isset($entity['slug'])) { $urlArgs['slug'] = $entity['slug']; } if (!SecurityUtil::checkPermission($this->name . ':' . ucfirst($objectType) . ':', $instanceId . '::', ACCESS_OVERVIEW)) { continue; } $title = $titleField != '' ? $entity[$titleField] : $this->__('Item'); $description = $descriptionField != '' ? $entity[$descriptionField] : ''; $created = isset($entity['createdDate']) ? $entity['createdDate'] : ''; $searchItem = array('title' => $title, 'text' => $description, 'extra' => serialize($urlArgs), 'created' => $created, 'module' => $this->name, 'session' => $sessionId); if (!DBUtil::insertObject($searchItem, 'search_result')) { return LogUtil::registerError($this->__('Error! Could not save the search results.')); } } // } return true; }
/** * this function change the forum for the children of a posting * $args */ public function movetoforum($args) { $work = $this->request->query->filter('work', 'none', FILTER_SANITIZE_STRING); $args['postingid'] = $this->getId(); $forum = $args['forum']; $children = $args['children']; if ($work == 'movetoforum') { $serviceManager = ServiceUtil::getManager(); $entityManager = $serviceManager->getService('doctrine.entitymanager'); $postingrepository = MUBoard_Util_Model::getPostingRepository(); foreach ($children as $child) { $posting = $postingrepository->selectById($child['id']); $posting->setForum($forum); $entityManager->flush(); } } }
/** * This method get the abos of the relevant posting and return the mailadresses * @param int $postingid id of the relevant issue */ protected static function getPostingAbos() { // we get a posting repository $repository = MUBoard_Util_Model::getPostingRepository(); }