예제 #1
0
 /**
  * Email instructor course digest
  *
  * @param   object   $job  \Components\Cron\Models\Job
  * @return  boolean
  */
 public function emailInstructorDigest(\Components\Cron\Models\Job $job)
 {
     $database = \App::get('db');
     $cconfig = Component::params('com_courses');
     Lang::load('com_courses') || Lang::load('com_courses', PATH_CORE . DS . 'components' . DS . 'com_courses' . DS . 'site');
     $from = array('name' => Config::get('sitename') . ' ' . Lang::txt('COM_COURSES'), 'email' => Config::get('mailfrom'));
     $subject = Lang::txt('COM_COURSES') . ': ' . Lang::txt('COM_COURSES_SUBJECT_EMAIL_DIGEST');
     require_once PATH_CORE . DS . 'components' . DS . 'com_courses' . DS . 'models' . DS . 'courses.php';
     $course_id = 0;
     $params = $job->get('params');
     if (isset($params) && is_object($params)) {
         $course_id = $params->get('course');
     }
     $coursesObj = new \Components\Courses\Models\Courses();
     if ($course_id) {
         $courses = array($coursesObj->course($course_id));
     } else {
         $courses = $coursesObj->courses();
     }
     if (isset($courses) && count($courses) > 0) {
         foreach ($courses as $course) {
             if (!$course->isAvailable()) {
                 continue;
             }
             $mailed = array();
             $managers = $course->managers();
             $enrollments = $course->students(array('count' => true));
             $offerings = $course->offerings();
             if (isset($offerings) && count($offerings) > 0) {
                 foreach ($offerings as $offering) {
                     if (!$offering->isAvailable()) {
                         continue;
                     }
                     $offering->gradebook()->refresh();
                     $passing = $offering->gradebook()->countPassing(false);
                     $failing = $offering->gradebook()->countFailing(false);
                     if (isset($managers) && count($managers) > 0) {
                         foreach ($managers as $manager) {
                             // Get the user's account
                             $user = User::getInstance($manager->get('user_id'));
                             if (!$user->get('id')) {
                                 continue;
                             }
                             // Try to ensure no duplicates
                             if (in_array($user->get('username'), $mailed)) {
                                 continue;
                             }
                             // Only mail instructors (i.e. not managers)
                             if ($manager->get('role_alias') != 'instructor') {
                                 continue;
                             }
                             // Get discussion stats and posts
                             require_once PATH_CORE . DS . 'components' . DS . 'com_forum' . DS . 'tables' . DS . 'post.php';
                             $postsTbl = new \Components\Forum\Tables\Post($database);
                             $filters = array('scope' => 'course', 'scope_id' => $offering->get('id'), 'state' => 1, 'sort' => 'created', 'sort_Dir' => 'DESC', 'limit' => 100);
                             $posts = $postsTbl->find($filters);
                             $posts_cnt = count($posts);
                             $latest = array();
                             $latest_cnt = 0;
                             if (isset($posts) && $posts_cnt > 0) {
                                 foreach ($posts as $post) {
                                     if (strtotime($post->created) > strtotime('-1 day')) {
                                         $latest[] = $post;
                                     } else {
                                         break;
                                     }
                                 }
                                 $latest_cnt = count($latest);
                             }
                             $eview = new \Hubzero\Component\View(array('base_path' => PATH_CORE . DS . 'components' . DS . 'com_courses' . DS . 'site', 'name' => 'emails', 'layout' => 'digest_plain'));
                             $eview->option = 'com_courses';
                             $eview->controller = 'courses';
                             $eview->delimiter = '~!~!~!~!~!~!~!~!~!~!';
                             $eview->course = $course;
                             $eview->enrollments = $enrollments;
                             $eview->passing = $passing;
                             $eview->failing = $failing;
                             $eview->offering = $offering;
                             $eview->posts_cnt = $posts_cnt;
                             $eview->latest = $latest;
                             $eview->latest_cnt = $latest_cnt;
                             $plain = $eview->loadTemplate();
                             $plain = str_replace("\n", "\r\n", $plain);
                             // HTML
                             $eview->setLayout('digest_html');
                             $html = $eview->loadTemplate();
                             $html = str_replace("\n", "\r\n", $html);
                             // Build message
                             $message = new \Hubzero\Mail\Message();
                             $message->setSubject($subject)->addFrom($from['email'], $from['name'])->addTo($user->get('email'), $user->get('name'))->addHeader('X-Component', 'com_courses')->addHeader('X-Component-Object', 'courses_instructor_digest');
                             $message->addPart($plain, 'text/plain');
                             $message->addPart($html, 'text/html');
                             // Send mail
                             if (!$message->send()) {
                                 $this->setError('Failed to mail %s', $user->get('email'));
                             }
                             $mailed[] = $user->get('username');
                         }
                     }
                 }
             }
         }
     }
     return true;
 }
예제 #2
0
 /**
  * Remove all items associated with the gorup being deleted
  *
  * @param   object  $course  Course being deleted
  * @return  string  Log of items removed
  */
 public function onCourseDelete($course)
 {
     if (!$course->exists()) {
         return '';
     }
     $log = Lang::txt('PLG_COURSES_FORUM') . ': ';
     $this->database = App::get('db');
     $sModel = new \Components\Forum\Tables\Section($this->database);
     $sections = array();
     foreach ($course->offerings() as $offering) {
         if (!$offering->exists()) {
             continue;
         }
         $sec = $sModel->getRecords(array('scope' => 'course', 'scope_id' => $offering->get('id')));
         foreach ($sec as $s) {
             $sections[] = $s;
         }
     }
     // Do we have any IDs?
     if (count($sections) > 0) {
         // Loop through each ID
         foreach ($sections as $section) {
             // Get the categories in this section
             $cModel = new \Components\Forum\Tables\Category($this->database);
             $categories = $cModel->getRecords(array('section_id' => $section->id, 'scope' => 'course', 'scope_id' => $course->offering()->get('id')));
             if ($categories) {
                 // Build an array of category IDs
                 $cats = array();
                 foreach ($categories as $category) {
                     $cats[] = $category->id;
                 }
                 // Set all the threads/posts in all the categories to "deleted"
                 $tModel = new \Components\Forum\Tables\Post($this->database);
                 if (!$tModel->setStateByCategory($cats, 2)) {
                     $this->setError($tModel->getError());
                 }
                 $log .= 'forum.section.' . $section->id . '.category.' . $category->id . '.post' . "\n";
                 // Set all the categories to "deleted"
                 if (!$cModel->setStateBySection($section->id, 2)) {
                     $this->setError($cModel->getError());
                 }
                 $log .= 'forum.section.' . $section->id . '.category.' . $category->id . "\n";
             }
             // Set the section to "deleted"
             $sModel->load($section->id);
             $sModel->state = 2;
             /* 0 = unpublished, 1 = published, 2 = deleted */
             if (!$sModel->store()) {
                 $this->setError($sModel->getError());
                 return '';
             }
             $log .= 'forum.section.' . $section->id . ' ' . "\n";
         }
     } else {
         $log .= Lang::txt('PLG_COURSES_DISCUSSIONS_NO_RESULTS') . "\n";
     }
     return $log;
 }
예제 #3
0
 /**
  * Remove all items associated with the gorup being deleted
  *
  * @param      object $group Group being deleted
  * @return     string Log of items removed
  */
 public function onGroupDelete($group)
 {
     $log = Lang::txt('PLG_GROUPS_FORUM') . ': ';
     require_once PATH_CORE . DS . 'components' . DS . 'com_forum' . DS . 'tables' . DS . 'post.php';
     require_once PATH_CORE . DS . 'components' . DS . 'com_forum' . DS . 'tables' . DS . 'category.php';
     require_once PATH_CORE . DS . 'components' . DS . 'com_forum' . DS . 'tables' . DS . 'section.php';
     require_once PATH_CORE . DS . 'components' . DS . 'com_forum' . DS . 'tables' . DS . 'attachment.php';
     $this->database = App::get('db');
     $sModel = new \Components\Forum\Tables\Section($this->database);
     $sections = $sModel->getRecords(array('scope' => 'group', 'scope_id' => $group->get('gidNumber')));
     // Do we have any IDs?
     if (count($sections) > 0) {
         // Loop through each ID
         foreach ($sections as $section) {
             // Get the categories in this section
             $cModel = new \Components\Forum\Tables\Category($this->database);
             $categories = $cModel->getRecords(array('section_id' => $section->id, 'scope' => 'group', 'scope_id' => $group->get('gidNumber')));
             if ($categories) {
                 // Build an array of category IDs
                 $cats = array();
                 foreach ($categories as $category) {
                     $cats[] = $category->id;
                 }
                 // Set all the threads/posts in all the categories to "deleted"
                 $tModel = new \Components\Forum\Tables\Post($this->database);
                 if (!$tModel->setStateByCategory($cats, 2)) {
                     $this->setError($tModel->getError());
                 }
                 $log .= 'forum.section.' . $section->id . '.category.' . $category->id . '.post' . "\n";
                 // Set all the categories to "deleted"
                 if (!$cModel->setStateBySection($sModel->id, 2)) {
                     $this->setError($cModel->getError());
                 }
                 $log .= 'forum.section.' . $section->id . '.category.' . $category->id . "\n";
             }
             // Set the section to "deleted"
             $sModel->load($section->id);
             $sModel->state = 2;
             /* 0 = unpublished, 1 = published, 2 = deleted */
             if (!$sModel->store()) {
                 $this->setError($sModel->getError());
                 return '';
             }
             $log .= 'forum.section.' . $section->id . ' ' . "\n";
         }
     } else {
         $log .= Lang::txt('PLG_GROUPS_FORUM_NO_RESULTS') . "\n";
     }
     return $log;
 }
예제 #4
0
 /**
  * Grabs the post for a given set of groups over a certain period of time
  *
  * @param  array  $groups   the group ids to look up
  * @param  string $interval the length of time to go back to look for posts
  * @return array
  **/
 private function getPosts($groups, $interval = 'day')
 {
     $return = [];
     if ($groups && count($groups) > 0) {
         foreach ($groups as $group) {
             $db = App::get('db');
             $posts = new \Components\Forum\Tables\Post($db);
             $filters = ['scope' => 'group', 'scope_id' => $group, 'state' => 1, 'sort' => 'created', 'start_at' => Date::of(strtotime("now -1 {$interval}"))->toSql(), 'sort_Dir' => 'DESC', 'limit' => 10];
             $results = $posts->find($filters);
             if (count($results) > 0) {
                 $return[$group] = $results;
             }
         }
     }
     return $return;
 }
예제 #5
0
 /**
  * Retrieve a thread
  *
  * @apiMethod GET
  * @apiUri    /forum/{thread}
  * @apiParameter {
  * 		"name":        "id",
  * 		"description": "Thread identifier",
  * 		"type":        "integer",
  * 		"required":    true,
  * 		"default":     0
  * }
  * @apiParameter {
  * 		"name":          "limit",
  * 		"description":   "Number of result to return.",
  * 		"type":          "integer",
  * 		"required":      false,
  * 		"default":       25
  * }
  * @apiParameter {
  * 		"name":          "limitstart",
  * 		"description":   "Number of where to start returning results.",
  * 		"type":          "integer",
  * 		"required":      false,
  * 		"default":       0
  * }
  * @apiParameter {
  * 		"name":          "section",
  * 		"description":   "Section alias to filter by",
  * 		"type":          "string",
  * 		"required":      false,
  *      "default":       ""
  * }
  * @apiParameter {
  * 		"name":          "category",
  * 		"description":   "Category alias to filter by",
  * 		"type":          "string",
  * 		"required":      false,
  *      "default":       ""
  * }
  * @apiParameter {
  * 		"name":         "state",
  * 		"description":   "Published state (0 = unpublished, 1 = published)",
  * 		"type":          "integer",
  * 		"required":      false,
  * 		"default":       1
  * }
  * @apiParameter {
  * 		"name":          "scope",
  * 		"description":   "Scope (site, groups, members, etc.)",
  * 		"type":          "string",
  * 		"required":      false,
  *      "default":       "site"
  * }
  * @apiParameter {
  * 		"name":          "scope_id",
  * 		"description":   "Scope ID",
  * 		"type":          "integer",
  * 		"required":      false,
  *      "default":       0
  * }
  * @apiParameter {
  * 		"name":          "scope_sub_id",
  * 		"description":   "Scope sub-ID",
  * 		"type":          "integer",
  * 		"required":      false,
  *      "default":       0
  * }
  * @apiParameter {
  * 		"name":          "object_id",
  * 		"description":   "Object ID",
  * 		"type":          "integer",
  * 		"required":      false,
  *      "default":       0
  * }
  * @apiParameter {
  * 		"name":          "start_id",
  * 		"description":   "ID of record to start with",
  * 		"type":          "integer",
  * 		"required":      false,
  *      "default":       0
  * }
  * @apiParameter {
  * 		"name":          "start_at",
  * 		"description":   "Start timestamp (YYYY-MM-DD HH:mm:ss)",
  * 		"type":          "string",
  * 		"required":      false,
  * 		"default":       ""
  * }
  * @apiParameter {
  * 		"name":          "sort",
  * 		"description":   "Field to sort results by.",
  * 		"type":          "string",
  * 		"required":      false,
  * 		"default":       "newest",
  * 		"allowedValues": "newest, oldest"
  * }
  * @return    void
  */
 public function readTask()
 {
     $find = strtolower(Request::getWord('find', 'results'));
     $filters = array('limit' => Request::getInt('limit', Config::get('list_limit', 25)), 'start' => Request::getInt('limitstart', 0), 'section' => Request::getCmd('section', ''), 'category' => Request::getCmd('category', ''), 'state' => Request::getInt('state', 1), 'scope' => Request::getWord('scope', ''), 'scope_id' => Request::getInt('scope_id', 0), 'scope_sub_id' => Request::getInt('scope_sub_id', 0), 'object_id' => Request::getInt('object_id', 0), 'start_id' => Request::getInt('start_id', 0), 'start_at' => Request::getVar('start_at', ''), 'sticky' => false);
     if ($thread = Request::getInt('thread', 0)) {
         $filters['thread'] = $thread;
     }
     $sort = Request::getVar('sort', 'newest');
     switch ($sort) {
         case 'oldest':
             $filters['sort_Dir'] = 'ASC';
             break;
         case 'newest':
         default:
             $filters['sort_Dir'] = 'DESC';
             break;
     }
     $filters['sort'] = 'c.created';
     if ($filters['start_id']) {
         $filters['limit'] = 0;
         $filters['start'] = 0;
     }
     $post = new \Components\Forum\Tables\Post($this->database);
     $data = new stdClass();
     $data->code = 0;
     if ($find == 'count') {
         $data->count = 0;
         $data->threads = 0;
         if (isset($filters['thread'])) {
             $data->count = $post->countTree($filters['thread'], $filters);
         }
         $post->loadByObject($filters['object_id'], $filters['scope_id'], $filters['scope']);
         if ($post->id) {
             $filters['start_at'] = Request::getVar('threads_start', '');
             $filters['parent'] = 0;
         }
         $data->threads = $post->count($filters);
     } else {
         $rows = $post->find($filters);
         if ($rows) {
             if ($filters['start_id']) {
                 $filters['limit'] = Request::getInt('limit', Config::get('list_limit'));
                 $children = array(0 => array());
                 $levellimit = $filters['limit'] == 0 ? 500 : $filters['limit'];
                 foreach ($rows as $v) {
                     $pt = $v->parent;
                     $list = @$children[$pt] ? $children[$pt] : array();
                     array_push($list, $v);
                     $children[$pt] = $list;
                 }
                 $list = $this->_treeRecurse($view->post->get('id'), '', array(), $children, max(0, $levellimit - 1));
                 $inc = false;
                 $newlist = array();
                 foreach ($list as $l) {
                     if ($l->id == $filters['start_id']) {
                         $inc = true;
                     } else {
                         if ($inc) {
                             $newlist[] = $l;
                         }
                     }
                 }
                 $rows = array_slice($newlist, $filters['start'], $filters['limit']);
             }
         }
         $data->response = $rows;
     }
     $this->send($data);
 }
예제 #6
0
 /**
  * Get a count of all forum posts
  *
  * @param      integer $gid        Group ID
  * @param      string  $authorized Authorization level
  * @param      string  $state      State of threads
  * @return     integer
  */
 public static function getForumCount($gid = NULL, $authorized, $state = '')
 {
     if (!$gid) {
         return 0;
     }
     $database = App::get('db');
     include_once PATH_CORE . DS . 'components' . DS . 'com_forum' . DS . 'tables' . DS . 'post.php';
     $filters = array();
     $filters['authorized'] = $authorized;
     switch ($state) {
         case 'sticky':
             $filters['sticky'] = 1;
             break;
         case 'closed':
             $filters['state'] = 2;
             break;
         case 'open':
         default:
             $filters['state'] = 1;
             break;
     }
     $filters['start'] = 0;
     $filters['group'] = $gid;
     $forum = new \Components\Forum\Tables\Post($database);
     return $forum->getCount($filters);
 }
예제 #7
0
 /**
  * Retrieves a row from the database
  *
  * @param      string $refid    ID of the database table row
  * @param      string $parent   If the element has a parent element
  * @param      string $category Element type (determines table to look in)
  * @param      string $message  If the element has a parent element
  * @return     array
  */
 public function deleteReportedItem($refid, $parent, $category, $message)
 {
     if ($category != 'forum') {
         return null;
     }
     require_once PATH_CORE . DS . 'components' . DS . 'com_forum' . DS . 'tables' . DS . 'post.php';
     $database = App::get('db');
     $comment = new \Components\Forum\Tables\Post($database);
     $comment->load($refid);
     $comment->state = 2;
     $comment->store();
     return '';
 }
예제 #8
0
echo Lang::txt('Search for "%s"', $this->escape($this->filters['search']));
?>
					</caption>
					<tbody>
				<?php 
if ($this->rows) {
    foreach ($this->rows as $row) {
        $name = Lang::txt('Anonymous');
        if (!$row->anonymous) {
            $creator = User::getInstance($row->created_by);
            if (is_object($creator)) {
                $name = '<a href="' . Route::url('index.php?option=com_members&id=' . $creator->get('id')) . '">' . $this->escape(stripslashes($creator->get('name'))) . '</a>';
            }
        }
        if ($row->parent) {
            $p = new \Components\Forum\Tables\Post(App::get('db'));
            $thread = $p->getThread($row->parent);
        } else {
            $thread = $row;
        }
        ?>
						<tr<?php 
        if ($row->sticky) {
            echo ' class="sticky"';
        }
        ?>
>
							<th>
								<span class="entry-id"><?php 
        echo $this->escape($row->id);
        ?>