コード例 #1
0
ファイル: helper.php プロジェクト: mined-gatech/hubzero-cms
 /**
  * Build module contents
  *
  * @return  void
  */
 public function run()
 {
     include_once \Component::path('com_blog') . DS . 'models' . DS . 'entry.php';
     $this->row = null;
     $filters = array('state' => 1, 'access' => 1, 'sort' => "RAND()", 'sort_Dir' => '', 'search' => '', 'scope' => 'member', 'scope_id' => 0, 'authorized' => false);
     $row = Entry::all()->whereEquals('scope', $filters['scope'])->whereEquals('state', $filters['state'])->whereEquals('access', $filters['access'])->row();
     // Did we have a result to display?
     if ($row->get('id')) {
         $this->row = $row;
         $this->cls = trim($this->params->get('moduleclass_sfx'));
         $this->txt_length = trim($this->params->get('txt_length'));
         require $this->getLayoutPath();
     }
 }
コード例 #2
0
ファイル: entries.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Display a list of blog entries
  *
  * @return  void
  */
 public function displayTask()
 {
     $filters = array('scope' => Request::getState($this->_option . '.' . $this->_controller . '.scope', 'scope', ''), 'scope_id' => Request::getState($this->_option . '.' . $this->_controller . '.scope_id', 'scope_id', 0, 'int'), 'search' => urldecode(Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', '')), 'state' => Request::getState($this->_option . '.' . $this->_controller . '.state', 'state', -1, 'int'), 'access' => Request::getState($this->_option . '.' . $this->_controller . '.access', 'access', 0, 'int'), 'sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'title'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'ASC'));
     $entries = Entry::all();
     if ($filters['search']) {
         $entries->whereLike('title', strtolower((string) $filters['search']));
     }
     if ($filters['scope']) {
         $entries->whereEquals('scope', $filters['scope']);
     }
     if ($filters['scope_id']) {
         $entries->whereEquals('scope_id', (int) $filters['scope_id']);
     }
     if ($filters['state'] >= 0) {
         $entries->whereEquals('state', (int) $filters['state']);
     }
     if ($filters['access']) {
         $entries->whereEquals('access', (int) $filters['access']);
     }
     // Get records
     $rows = $entries->order($filters['sort'], $filters['sort_Dir'])->paginated('limitstart', 'limit')->rows();
     // Output the HTML
     $this->view->set('rows', $rows)->set('filters', $filters)->display();
 }
コード例 #3
0
ファイル: blog.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Return a count of items that will be removed when group is deleted
  *
  * @param   object  $group  Group to delete
  * @return  string
  */
 public function onGroupDeleteCount($group)
 {
     include_once PATH_CORE . DS . 'components' . DS . 'com_blog' . DS . 'models' . DS . 'archive.php';
     $entries = \Components\Blog\Models\Entry::all()->whereEquals('scope', 'group')->whereEquals('scope_id', $group->get('gidNumber'))->count();
     return Lang::txt('PLG_GROUPS_BLOG_LOG') . ': ' . $entries;
 }
コード例 #4
0
ファイル: archive.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Get a count of, model for, or list of entries
  *
  * @param   array   $filters  Filters to apply to data retrieval
  * @return  object
  */
 public function entries($filters = array())
 {
     if (!isset($filters['scope'])) {
         $filters['scope'] = (string) $this->get('scope');
     }
     if (!isset($filters['scope_id'])) {
         $filters['scope_id'] = (int) $this->get('scope_id');
     }
     $results = Entry::all()->including(['creator', function ($creator) {
         $creator->select('*');
     }])->including(['comments', function ($comment) {
         $comment->select('id')->select('entry_id')->whereIn('state', array(Comment::STATE_PUBLISHED, Comment::STATE_FLAGGED));
     }]);
     if ($filters['scope']) {
         $results->whereEquals('scope', $filters['scope'])->whereEquals('scope_id', $filters['scope_id']);
     }
     if (isset($filters['state'])) {
         $results->whereEquals('state', $filters['state']);
     }
     if (isset($filters['access'])) {
         $results->whereIn('access', $filters['access']);
     }
     if (isset($filters['year']) && $filters['year'] != 0) {
         if (isset($filters['month']) && $filters['month'] != 0) {
             $startdate = $filters['year'] . '-' . $filters['month'] . '-01 00:00:00';
             if ($filters['month'] + 1 == 13) {
                 $year = $filters['year'] + 1;
                 $month = 1;
             } else {
                 $month = $filters['month'] + 1;
                 $year = $filters['year'];
             }
             $enddate = sprintf("%4d-%02d-%02d 00:00:00", $year, $month, 1);
         } else {
             $startdate = $filters['year'] . '-01-01 00:00:00';
             $enddate = $filters['year'] + 1 . '-01-01 00:00:00';
         }
         $results->where('publish_up', '>=', $startdate)->where('publish_up', '<', $enddate);
     } else {
         $results->whereEquals('publish_up', '0000-00-00 00:00:00', 1)->orWhere('publish_up', '<=', Date::toSql(), 1);
     }
     $results->resetDepth();
     if (!isset($filters['authorized']) || !$filters['authorized']) {
         $results->whereEquals('publish_down', '0000-00-00 00:00:00', 1)->orWhere('publish_down', '>=', Date::toSql(), 1);
     }
     if (isset($filters['search']) && $filters['search']) {
         $filters['search'] = '%' . strtolower(stripslashes($filters['search'])) . '%';
         $results->where('title', 'LIKE', $filters['search'])->orWhere('content', 'LIKE', $filters['search']);
     }
     if (isset($filters['limit']) && $filters['limit']) {
         $results->limit($filters['limit']);
     }
     return $results;
 }
コード例 #5
0
ファイル: archive.php プロジェクト: mined-gatech/hubzero-cms
 /**
  * Get a count of, model for, or list of entries
  *
  * @param   string   $rtrn     Data to return
  * @param   array    $filters  Filters to apply to data retrieval
  * @param   boolean  $reset    Clear cached data?
  * @return  mixed
  */
 public function entries($filters = array())
 {
     if (!isset($filters['scope'])) {
         $filters['scope'] = (string) $this->get('scope');
     }
     if (!isset($filters['scope_id'])) {
         $filters['scope_id'] = (int) $this->get('scope_id');
     }
     $results = Entry::all();
     if ($filters['scope']) {
         $results->whereEquals('scope', $filters['scope'])->whereEquals('scope_id', $filters['scope_id']);
     }
     if (isset($filters['state'])) {
         $results->whereEquals('state', $filters['state']);
     }
     if (isset($filters['access'])) {
         $results->whereIn('access', $filters['access']);
     }
     if (isset($filters['year']) && $filters['year'] != 0) {
         if (isset($filters['month']) && $filters['month'] != 0) {
             $startdate = $filters['year'] . '-' . $filters['month'] . '-01 00:00:00';
             if ($filters['month'] + 1 == 13) {
                 $year = $filters['year'] + 1;
                 $month = 1;
             } else {
                 $month = $filters['month'] + 1;
                 $year = $filters['year'];
             }
             $enddate = sprintf("%4d-%02d-%02d 00:00:00", $year, $month, 1);
         } else {
             $startdate = $filters['year'] . '-01-01 00:00:00';
             $enddate = $filters['year'] + 1 . '-01-01 00:00:00';
         }
         $results->where('publish_up', '>=', $startdate)->where('publish_up', '<', $enddate);
     } else {
         $results->whereEquals('publish_up', '0000-00-00 00:00:00', 1)->orWhere('publish_up', '<=', Date::toSql(), 1);
     }
     $results->resetDepth();
     $results->whereEquals('publish_down', '0000-00-00 00:00:00', 1)->orWhere('publish_down', '>=', Date::toSql(), 1);
     if (isset($filters['search']) && $filters['search']) {
         $filters['search'] = '%' . strtolower(stripslashes($filters['search'])) . '%';
         $results->where('title', 'LIKE', $filters['search'])->orWhere('content', 'LIKE', $filters['search']);
     }
     return $results;
 }
コード例 #6
0
ファイル: usage.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Get a count of all blog entries
  *
  * @param      string $gid Group alias
  * @return     integer
  */
 public static function getGroupBlogCount($gid)
 {
     if (!$gid) {
         return 0;
     }
     include_once PATH_CORE . DS . 'components' . DS . 'com_blog' . DS . 'models' . DS . 'entry.php';
     $total = \Components\Blog\Models\Entry::all()->whereEquals('scope', 'group')->whereEquals('scope_id', $gid)->where('state', '!=', \Components\Blog\Models\Entry::STATE_DELETED)->total();
     return $total;
 }
コード例 #7
0
ファイル: helper.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Get module contents
  *
  * @return  void
  */
 public function run()
 {
     include_once Component::path('com_resources') . DS . 'tables' . DS . 'resource.php';
     include_once Component::path('com_members') . DS . 'models' . DS . 'member.php';
     include_once Component::path('com_answers') . DS . 'models' . DS . 'question.php';
     include_once Component::path('com_blog') . DS . 'models' . DS . 'archive.php';
     $this->database = \App::get('db');
     // Get the admin configured settings
     $filters = array();
     $filters['limit'] = 5;
     $filters['start'] = 0;
     // featured items
     $tbls = array('resources', 'profiles');
     $spots = array();
     $spots[0] = trim($this->params->get('spotone'));
     $spots[1] = trim($this->params->get('spottwo'));
     $spots[2] = trim($this->params->get('spotthree'));
     $spots[3] = trim($this->params->get('spotfour'));
     $spots[4] = trim($this->params->get('spotfive'));
     $spots[5] = trim($this->params->get('spotsix'));
     $spots[6] = trim($this->params->get('spotseven'));
     $numspots = $this->params->get('numspots', 3);
     // some collectors
     $activespots = array();
     $rows = array();
     // styling
     $cls = trim($this->params->get('moduleclass_sfx'));
     $txtLength = trim($this->params->get('txt_length'));
     $start = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d'), date('Y'))) . ' 00:00:00';
     $end = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d'), date('Y'))) . ' 23:59:59';
     $this->html = '';
     $k = 1;
     $out = '';
     for ($i = 0, $n = $numspots; $i < $numspots; $i++) {
         $spot = $spots[$i];
         if ($spot == '') {
             continue;
         }
         $row = null;
         $out = '';
         $tbl = '';
         $tbl = $spot == 'tools' || $spot == 'nontools' ? 'resources' : '';
         $tbl = $spot == 'members' ? 'profiles' : $tbl;
         $tbl = $spot == 'topics' ? 'topics' : $tbl;
         $tbl = $spot == 'itunes' ? 'itunes' : $tbl;
         $tbl = $spot == 'answers' ? 'answers' : $tbl;
         $tbl = $spot == 'blog' ? 'blog' : $tbl;
         $tbl = !$tbl ? array_rand($tbls, 1) : $tbl;
         // we need to randomly choose one
         switch ($tbl) {
             case 'resources':
                 // Initiate a resource object
                 $rr = new \Components\Resources\Tables\Resource($this->database);
                 $filters['start'] = 0;
                 $filters['type'] = $spot;
                 $filters['sortby'] = 'random';
                 $filters['minranking'] = trim($this->params->get('minranking'));
                 $filters['tag'] = $spot == 'tools' ? trim($this->params->get('tag')) : '';
                 // tag is set for tools only
                 // Get records
                 $rows[$spot] = isset($rows[$spot]) ? $rows[$spot] : $rr->getRecords($filters, false);
                 break;
             case 'profiles':
                 // Get records
                 if (!isset($rows[$spot])) {
                     $last = \Components\Members\Models\Member::all()->select('id')->whereEquals('block', 0)->whereEquals('activation', 1)->where('approved', '>', 0)->order('id', 'desc')->row();
                     $r = mt_rand(0, $last->get('id'));
                     $rows[$spot] = \Components\Members\Models\Member::all()->whereEquals('block', 0)->whereEquals('activation', 1)->where('approved', '>', 0)->where('id', '>=', $r)->row();
                 }
                 break;
             case 'topics':
                 // No - so we need to randomly choose one
                 $topics_tag = trim($this->params->get('topics_tag'));
                 $query = "SELECT DISTINCT w.id, w.pagename, w.title ";
                 $query .= " FROM #__wiki_page AS w ";
                 if ($topics_tag) {
                     $query .= " JOIN #__tags_object AS RTA ON RTA.objectid=w.id AND RTA.tbl='wiki' ";
                     $query .= " INNER JOIN #__tags AS TA ON TA.id=RTA.tagid ";
                 } else {
                     $query .= ", #__wiki_version AS v ";
                 }
                 $query .= " WHERE w.access!=1 AND w.scope = ''  ";
                 if ($topics_tag) {
                     $query .= " AND (TA.tag='" . $topics_tag . "' OR TA.raw_tag='" . $topics_tag . "') ";
                 } else {
                     $query .= " AND v.pageid=w.id AND v.approved = 1 AND v.pagetext != '' ";
                 }
                 $query .= " ORDER BY RAND() ";
                 $this->database->setQuery($query);
                 $rows[$spot] = isset($rows[$spot]) ? $rows[$spot] : $this->database->loadObjectList();
                 break;
             case 'itunes':
                 // Initiate a resource object
                 $rr = new \Components\Resources\Tables\Resource($this->database);
                 $filters['start'] = 0;
                 $filters['sortby'] = 'random';
                 $filters['tag'] = trim($this->params->get('itunes_tag'));
                 // Get records
                 $rows[$spot] = isset($rows[$spot]) ? $rows[$spot] : $rr->getRecords($filters, false);
                 break;
             case 'answers':
                 $query = "SELECT C.id, C.subject, C.question, C.created, C.created_by, C.anonymous  ";
                 $query .= ", (SELECT COUNT(*) FROM #__answers_responses AS a WHERE a.state!=2 AND a.question_id=C.id) AS rcount ";
                 $query .= " FROM #__answers_questions AS C ";
                 $query .= " WHERE C.state=0 ";
                 $query .= " AND (C.reward > 0 OR C.helpful > 0) ";
                 $query .= " ORDER BY RAND() ";
                 $this->database->setQuery($query);
                 $rows[$spot] = isset($rows[$spot]) ? $rows[$spot] : $this->database->loadObjectList();
                 break;
             case 'blog':
                 $filters = array();
                 $filters['limit'] = 1;
                 $filters['start'] = 0;
                 $filters['state'] = 'public';
                 $filters['order'] = "RAND()";
                 $filters['search'] = '';
                 $filters['scope'] = 'member';
                 $filters['group_id'] = 0;
                 $filters['authorized'] = false;
                 $filters['sql'] = '';
                 $entry = \Components\Blog\Models\Entry::all()->whereEquals('scope', 'member')->whereEquals('state', 1)->whereIn('access', User::getAuthorisedViewLevels())->row();
                 $rows[$spot] = isset($rows[$spot]) ? $rows[$spot] : $entry;
                 break;
         }
         if ($rows && count($rows[$spot]) > 0) {
             $row = $rows[$spot][0];
         }
         // make sure we aren't pulling the same item
         if ($k != 1 && in_array($spot, $activespots) && $rows && count($rows[$spot]) > 1) {
             $row = count($rows[$spot]) < $k ? $rows[$spot][$k - 1] : $rows[$spot][1];
             // get the next one
         }
         // pull info
         if ($row) {
             $out = $this->_composeEntry($row, $tbl, $txtLength);
             $itemid = $this->_composeEntry($row, $tbl, 0, 1);
             $activespots[] = $spot;
         }
         // Did we get any results?
         if ($out) {
             $this->html .= '<li class="spot_' . $k . '">' . $out . '</li>' . "\n";
             $k++;
         }
     }
     // Output HTML
     require $this->getLayoutPath();
 }
コード例 #8
0
ファイル: blog.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Remove all user blog entries for the given user ID
  *
  * Method is called after user data is deleted from the database
  *
  * @param   array    $user     Holds the user data
  * @param   boolean  $success  True if user was succesfully stored in the database
  * @param   string   $msg      Message
  * @return  boolean
  */
 public function onMemberAfterDelete($user, $success, $msg)
 {
     if (!$success) {
         return false;
     }
     $userId = \Hubzero\Utility\Arr::getValue($user, 'id', 0, 'int');
     if ($userId) {
         try {
             include_once PATH_CORE . DS . 'components' . DS . 'com_blog' . DS . 'models' . DS . 'archive.php';
             $entries = \Components\Blog\Models\Entry::all()->whereEquals('created_by', $user['id'])->rows();
             foreach ($entries as $entry) {
                 if (!$entry->destroy()) {
                     throw new Exception($entry->getError());
                 }
             }
         } catch (Exception $e) {
             return false;
         }
     }
     return true;
 }