function onordercomplete($invoiceitem, $invoice)
 {
     global $DB;
     $transaction = $DB->start_delegated_transaction();
     // Get name for company license.
     $company = company::get_company_byuserid($invoice->userid);
     $course = $DB->get_record('course', array('id' => $invoiceitem->invoiceableitemid), 'id, shortname', MUST_EXIST);
     $licensename = $company->shortname . " [" . $course->shortname . "] " . date("Y-m-d");
     $count = $DB->count_records_sql("SELECT COUNT(*) FROM {companylicense} WHERE name LIKE '" . str_replace("'", "\\'", $licensename) . "%'");
     if ($count) {
         $licensename .= ' (' . ($count + 1) . ')';
     }
     // Create mdl_companylicense record.
     $companylicense = new stdClass();
     $companylicense->name = $licensename;
     $companylicense->allocation = $invoiceitem->license_allocation;
     $companylicense->validlength = $invoiceitem->license_validlength;
     if (!empty($invoiceitem->license_shelflife)) {
         $companylicense->expirydate = $invoiceitem->license_shelflife * 86400 + time();
         // 86400 = 24*60*60 = number of seconds in a day.
     } else {
         $companylicense->expirydate = 0;
     }
     $companylicense->companyid = $company->id;
     $companylicenseid = $DB->insert_record('companylicense', $companylicense);
     // Create mdl_companylicense_courses record for the course.
     $clc = new stdClass();
     $clc->licenseid = $companylicenseid;
     $clc->courseid = $course->id;
     $DB->insert_record('companylicense_courses', $clc);
     // Mark the invoice item as processed.
     $invoiceitem->processed = 1;
     $DB->update_record('invoiceitem', $invoiceitem);
     $transaction->allow_commit();
 }
 /**
  * Add shared courses to the list of courses
  *
  * Parameters - &$courses = array();
  *
  * */
 public static function iomad_add_shared_courses(&$courses)
 {
     global $DB, $CFG, $USER;
     if (!empty($USER->profile['company'])) {
         $company = company::get_company_byuserid($USER->id);
         $sharedcourses = $DB->get_records_sql('SELECT * FROM {course} c
                                                WHERE c.id IN (
                                                 SELECT courseid FROM {iomad_courses}
                                                 WHERE shared=1
                                                 AND licensed = 0
                                                ) OR c.id IN (
                                                 SELECT pc.courseid FROM
                                                 {iomad_courses} pc
                                                 JOIN {company_shared_courses} csc
                                                 ON
                                                 csc.courseid=pc.courseid
                                                 AND csc.companyid = :companyid
                                                 AND pc.licensed = 0
                                                )', array('companyid' => $company->id));
     } else {
         $sharedcourses = $DB->get_records_sql('SELECT * from {course} c
                                                WHERE c.id IN (
                                                 SELECT courseid FROM {iomad_courses}
                                                 WHERE shared=1
                                                )');
     }
     if (!empty($sharedcourses) && !empty($courses)) {
         foreach ($courses as $course) {
             if (!empty($sharedcourses[$course->id])) {
                 unset($sharedcourses[$course->id]);
             }
         }
         $courses = $courses + $sharedcourses;
     }
     return;
 }
Exemple #3
0
 /**
  * Unsuspends a user and keeps the company details as was.
  * @param int userid
  * @return boolean
  */
 public static function unsuspend($userid)
 {
     global $DB;
     // Get the company details for the user.
     $company = company::get_company_byuserid($userid);
     // Get the users company record.
     $DB->set_field('company_users', 'suspended', 0, array('userid' => $userid, 'companyid' => $company->id));
     // Mark user as suspended.
     $DB->set_field('user', 'suspended', 0, array('id' => $userid));
 }
Exemple #4
0
 /**
  * Gets the user company information for the provided user
  *
  * Parameters - $user = stdclass();
  *
  **/
 private function get_sender($user)
 {
     // Get the user's company.
     if ($usercompany = company::get_company_byuserid($user->id)) {
         // Is there a default contact userid?
         if (isset($usercompany->defaultcontactid)) {
             $returnid = $usercompany->defaultcontactid;
         } else {
             // Use the default support email account.
             $returnid = core_user::get_support_user();
         }
     } else {
         // No company use default support user.
         $returnid = core_user::get_support_user();
     }
     return $returnid;
 }
Exemple #5
0
         OR
         c.summary like :searchkey3
         OR
         css.short_description like :searchkey4
         OR
         css.long_description like :searchkey5
        )
    ';
    for ($i = 1; $i < 6; $i++) {
        $sqlparams['searchkey' . $i] = '%' . $searchkey . '%';
    }
}
// Deal with company specific and shared courses.
if (iomad::is_company_user()) {
    // Get the company courses and the company shared courses.
    $company = company::get_company_byuserid($USER->id);
    $sharedsql = " AND ( c.id in ( select courseid from {company_course} where companyid= {$company->id})\n\t               or c.id in ( select courseid from {iomad_courses} where shared=1)\n\t               or c.id in ( select courseid from {company_shared_courses} where companyid = {$company->id})) ";
} else {
    if (is_siteadmin() || iomad::has_capability('block/iomad_company_admin:company_view_all', context_system::instance())) {
        $sharedsql = "";
    } else {
        $sharedsql = " AND c.id in ( select courseid from {iomad_courses} where shared=1) ";
    }
}
if (count($sqlparams)) {
    echo '<a href="?tag=&q=">' . get_string('remove_filter', 'block_iomad_commerce') . '</a>';
}
echo "</ul>";
echo get_string('search', 'block_iomad_commerce');
echo "<form method='get'><input type='text' name='q' value='{$searchkey}' /></form>";
// ...***********create course list sql (includes filtering on tags)*****************.