Exemplo n.º 1
0
 function enrol()
 {
     $mainframe = JFactory::getApplication();
     $user = JFactory::getUser();
     $course_id = JRequest::getVar('course_id');
     $course_id = (int) $course_id;
     $login_url = JoomdleHelperMappings::get_login_url($course_id);
     if (!$user->id) {
         $mainframe->redirect($login_url);
     }
     $params = $mainframe->getParams();
     /* Check that self enrolments are OK in course */
     $enrol_methods = JoomdleHelperContent::call_method('course_enrol_methods', $course_id);
     $self_ok = false;
     foreach ($enrol_methods as $method) {
         if ($method['enrol'] == 'self') {
             $self_ok = true;
             break;
         }
     }
     if (!$self_ok) {
         $url = JRoute::_("index.php?option=com_joomdle&view=detail&course_id={$course_id}");
         $message = JText::_('COM_JOOMDLE_SELF_ENROLMENT_NOT_PERMITTED');
         $this->setRedirect($url, $message);
         return;
     }
     $user = JFactory::getUser();
     $username = $user->get('username');
     JoomdleHelperContent::enrolUser($username, $course_id);
     // Redirect to course
     $url = JoomdleHelperContent::get_course_url($course_id);
     $mainframe->redirect($url);
 }
Exemplo n.º 2
0
function update_user_enrols()
{
    $user =& JFactory::getUser();
    $id = $user->get('id');
    $username = $user->get('username');
    $db =& JFactory::getDBO();
    $query = 'SELECT order_id from #__vm_orders where user_id=';
    $query .= "'{$id}'" . '';
    $db->setQuery($query);
    $orders = $db->loadObjectList();
    if ($db->getErrorNum()) {
        JError::raiseWarning(500, $db->stderr());
    }
    if (count($orders)) {
        foreach ($orders as $order) {
            $order_id = $order->order_id;
            $query = "SELECT order_status_code from #__vm_order_history where order_id = {$order_id} order by order_status_history_id DESC limit 1";
            $db->setQuery($query);
            $order_status = $db->loadObjectList();
            if ($db->getErrorNum()) {
                JError::raiseWarning(500, $db->stderr());
            }
            $os_code = $order_status[0]->order_status_code;
            //array es? xXX
            /* We only check confirmed orders */
            if ($os_code != 'C') {
                // XXX deberia ser configurable
                continue;
            }
            /* Order is confirmed, check if it has been processed */
            /* Check all downloads with this order_id to see it download_max > 0, 
               which means we have to enrol the user
               */
            $query = 'SELECT download_max,order_id,product_id' . ' FROM #__vm_product_download' . ' WHERE (download_max > 0) and (order_id =';
            $query .= "'{$order_id}')";
            $db->setQuery($query);
            $downloads = $db->loadObjectList();
            if ($db->getErrorNum()) {
                JError::raiseWarning(500, $db->stderr());
            }
            /* All courses in this order already processed */
            if (count($downloads) == 0) {
                continue;
            }
            foreach ($downloads as $download) {
                $product_id = $download->product_id;
                $query = 'SELECT product_sku' . ' FROM #__vm_product' . ' WHERE product_id =';
                $query .= "'{$product_id}'";
                $db->setQuery($query);
                $products = $db->loadObjectList();
                if (count($products)) {
                    foreach ($products as $product) {
                        $sku = $product->product_sku;
                    }
                }
                if ($db->getErrorNum()) {
                    JError::raiseWarning(500, $db->stderr());
                }
                JoomdleHelperContent::enrolUser($username, $sku);
                //echo "You have been enrroled in the course";
                $query = "UPDATE #__vm_product_download set download_max=0 where product_id='{$product_id}'";
                $db->setQuery($query);
                if (!$db->query()) {
                    return JError::raiseWarning(500, $db->getError());
                }
            }
        }
    }
}
Exemplo n.º 3
0
 static function add_order_enrols_vm2($order_id, $user_id)
 {
     $db = JFactory::getDBO();
     $user = JFactory::getUser($user_id);
     $username = $user->username;
     $email = $user->email;
     /* Update user profile in Moodle  with VM data, if necessary */
     JoomdleHelperContent::call_method('create_joomdle_user', $username);
     $order_id = $db->Quote($order_id);
     $query = 'SELECT *' . ' FROM #__virtuemart_order_items' . ' WHERE virtuemart_order_id =';
     $query .= "{$order_id}";
     $db->setQuery($query);
     $items = $db->loadObjectList();
     if ($db->getErrorNum()) {
         JError::raiseWarning(500, $db->stderr());
     }
     /* No items in this order */
     if (count($items) == 0) {
         return;
     }
     $params = JComponentHelper::getParams('com_joomdle');
     $buy_for_children = $params->get('buy_for_children');
     $courses_category = $params->get('courses_category');
     foreach ($items as $item) {
         /* Only process product in Courses category */
         $product_id = $item->virtuemart_product_id;
         $order_item_id = $item->virtuemart_order_item_id;
         $query = "SELECT virtuemart_category_id" . " FROM #__virtuemart_product_categories" . " WHERE virtuemart_product_id=" . $db->Quote($product_id);
         $db->setQuery($query);
         $cats = $db->loadAssocList();
         $cats_array = array();
         foreach ($cats as $cat) {
             $cats_array[] = $cat['virtuemart_category_id'];
         }
         if ($db->getErrorNum()) {
             JError::raiseWarning(500, $db->stderr());
         }
         /* If it is a course */
         if (in_array($courses_category, $cats_array)) {
             $sku = $item->order_item_sku;
             if ($buy_for_children) {
                 if (strncmp($item->order_item_sku, 'bundle_', 7) == 0) {
                     //bundle
                     JoomdleHelperParents::purchase_bundle($username, $sku, $item->product_quantity);
                 } else {
                     JoomdleHelperParents::purchase_course($username, $sku, $item->product_quantity);
                 }
             } else {
                 if (strncmp($item->order_item_sku, 'bundle_', 7) == 0) {
                     //bundle
                     JoomdleHelperShop::enrol_bundle($username, $sku);
                 } else {
                     //course
                     JoomdleHelperContent::enrolUser($username, $sku);
                     /* Send confirmation email */
                     JoomdleHelperShop::send_confirmation_email($email, $sku);
                 }
             }
         }
     }
 }
Exemplo n.º 4
0
 static function approve_applications($cid)
 {
     $db = JFactory::getDBO();
     foreach ($cid as $id) {
         /* get application info */
         $query = "SELECT *\n\t\t\t\t\t\tFROM #__joomdle_course_applications  where id = " . $db->Quote($id);
         $db->setQuery($query);
         $app = $db->loadAssoc();
         $user_id = $app['user_id'];
         $user = JFactory::getUser($user_id);
         $username = $user->username;
         $course_id = $app['course_id'];
         $date = JFactory::getDate();
         $confirmation_date = $date->toSql();
         /* Mark as approved */
         $query = "update  #__joomdle_course_applications set state=" . JOOMDLE_APPLICATION_STATE_APPROVED . ", confirmation_date = '{$confirmation_date}' where id = " . $db->Quote($id);
         $db->setQuery($query);
         $db->query();
         /* Enrol user in course */
         JoomdleHelperContent::enrolUser($username, $course_id);
         /* Send message to user */
         JoomdleHelperApplications::send_confirmation_email($username, $user->email, $course_id, JOOMDLE_APPLICATION_STATE_APPROVED);
     }
 }
Exemplo n.º 5
0
 static function assign_course($course_id, $assingment)
 {
     foreach ($assingment as $user_id) {
         $user = JFactory::getUser($user_id);
         $username = $user->get('username');
         JoomdleHelperContent::enrolUser($username, $course_id);
         /* Send confirmation email */
         JoomdleHelperShop::send_confirmation_email($user->email, $course_id);
     }
     JoomdleHelperParents::update_purchase($course_id, $assingment);
 }