/**
  * this function executes purchase details in screen
  */
 public function emailReceipt()
 {
     $user = $this->my_purchase->getPurchaserUser();
     $institution = $user->getApp();
     $trial_length = 0;
     $type_id_arr = explode("~", $this->my_purchase->getPurchaseTypeId());
     $product_details = GcrProductsTable::getProductDetails($type_id_arr[0], $type_id_arr[1], $this->my_purchase->getPurchaseTypeEschoolId());
     foreach ($product_details as $product) {
         $trial_length = $product->getExpiryNoOfDays();
     }
     $trial_end_date = date('F j, Y', $trial_length * self::DAY + time());
     $params = array('institution_full_name' => $institution->getFullName(), 'institution_short_name' => $institution->getShortName(), 'trial_end_date' => $trial_end_date, 'amountCharged' => number_format($this->amount, 2), 'trial_length' => $trial_length, 'cycle_text' => strtolower($this->my_purchase->getBillCycle()) . 'ly');
     $email = new GcrUserEmailer('purchase_subscription', $user, "Thank you for purchasing a Subscription from " . $institution->getFullName() . "!", $params);
     $email->sendHtmlEmail();
 }
 public function getProductName()
 {
     $type = $this->my_purchase->getPurchaseType();
     if ($type == 'course') {
         return $this->my_product->fullname . ' (' . $this->my_product->shortname . ')';
     }
     if ($type == 'subscription') {
         $product_name = "Subscription";
         $product_details = GcrProductsTable::getProductDetails($this->my_purchase->getPurchaseTypeId(), $this->my_purchase->getProductTypeId(), $this->my_purchase->getPurchaseTypeEschoolId(), $this->my_purchase->getProductShortName());
         foreach ($product_details as $product) {
             $product_name = $product->getFullName();
         }
         //return $this->my_purchase->getPurchaseDescription();
         return $product_name;
     }
     if ($type == 'sale') {
         return 'Graduate Credit';
     } else {
         if ($this->my_purchase->isRecurring()) {
             return $this->my_purchase->getBillCycle() . 'ly Recurring ' . $this->my_purchase->getPurchaseString() . ' Subscription';
         }
     }
 }
 public function executeCronUpdateCoursesCount(sfWebRequest $request)
 {
     global $CFG;
     $CFG->current_app->requireMahara();
     $this->params = $request->getGetParameters();
     $platform_short_name = $CFG->current_app->getShortName();
     $product_type = isset($this->params['type']) ? $this->params['type'] : "";
     // gets all available schools
     $eschool_array = array();
     $catalog_courses_count = array();
     foreach ($CFG->current_app->getMnetEschools() as $eschool) {
         //if (GcrEschoolTable::authorizeEschoolAccess($eschool, true)) {
         $eschool_array[$eschool->getFullName()] = $eschool;
         //}
     }
     ksort($eschool_array);
     // gets catalog-wise courses count
     foreach ($eschool_array as $eschool) {
         $catalog_courses_count[$eschool->getShortName()] = $this->getHTMLCoursesCount($eschool->getShortName());
     }
     // gets all products list
     $all_products = GcrProductsTable::getAllProducts($platform_short_name, $product_type);
     $all_products_details = array();
     foreach ($all_products as $product) {
         $all_products_details[$product->getShortName()]["id"] = $product->getId();
         $all_products_details[$product->getShortName()]["product_type_id"] = $product->getProductTypeId();
         $all_products_details[$product->getShortName()]["short_name"] = $product->getShortName();
         $all_products_details[$product->getShortName()]["institution_short_name"] = $product->getInstitutionShortName();
         $all_products_details[$product->getShortName()]["catalog_short_name"] = $product->getCatalogShortName();
         $all_products_details[$product->getShortName()]["platform_short_name"] = $product->getPlatformShortName();
         if ($product->getProductTypeId() == 2 || $product->getProductTypeId() == 3) {
             $is_exist = GcrInstitutionCatalogCoursesTable::checkIsExist($product->getInstitutionShortName(), $product->getCatalogShortName(), $product->getPlatformShortName());
             $ctlg_crses_count = isset($catalog_courses_count[$product->getCatalogShortName()]) ? $catalog_courses_count[$product->getCatalogShortName()] : 0;
             if ($is_exist == 0) {
                 $cron_obj = new GcrInstitutionCatalogCourses();
                 $cron_obj->setPlatformShortName($product->getPlatformShortName());
                 $cron_obj->setInstitutionShortName($product->getInstitutionShortName());
                 $cron_obj->setCatalogShortName($product->getCatalogShortName());
                 $cron_obj->setProductTypeId($product->getProductTypeId());
                 $cron_obj->setCoursesCount($ctlg_crses_count);
                 $cron_obj->save();
             } else {
                 Doctrine_Query::create()->update('GcrInstitutionCatalogCourses')->set('courses_count', '?', $ctlg_crses_count)->where('institution_short_name = ?', $product->getInstitutionShortName())->andWhere('platform_short_name = ?', $product->getPlatformShortName())->andWhere('catalog_short_name = ?', $product->getCatalogShortName())->andWhere('product_type_id = ?', $product->getProductTypeId())->execute();
             }
         } else {
             if ($product->getProductTypeId() == 1) {
                 $institution_name = $product->getInstitutionShortName();
                 $mhr_institution_obj = $CFG->current_app->selectFromMhrTable('institution', 'name', $institution_name, true);
                 if ($mhr_institution_obj) {
                     $mhr_institution = new GcrMhrInstitution($mhr_institution_obj, $CFG->current_app);
                     $current_eschools = array();
                     $eschools = $mhr_institution->getEschools();
                     if ($eschools) {
                         foreach ($eschools as $eschool) {
                             $current_eschools[$eschool->getShortName()] = $eschool->getFullName();
                         }
                     }
                     asort($current_eschools);
                     foreach ($current_eschools as $current_eschool_key => $current_eschool_val) {
                         if (stripos(strtolower($current_eschool_val), "(*)") === false && stripos(strtolower($current_eschool_val), "(\$)") === false) {
                             $params = array();
                             $params["start_index"] = 0;
                             $params["mode"] = "Eschool";
                             $params["mode_id"] = $current_eschool_key;
                             $this->course_list = new GcrCourseList($params, $CFG->current_app);
                             $catalog_courses_count[$current_eschool_key] = $this->course_list->getCoursesCount();
                             $is_exist = GcrInstitutionCatalogCoursesTable::checkIsExist($product->getInstitutionShortName(), $current_eschool_key, $product->getPlatformShortName());
                             $ctlg_crses_count = isset($catalog_courses_count[$current_eschool_key]) ? $catalog_courses_count[$current_eschool_key] : 0;
                             if ($is_exist == 0) {
                                 $cron_obj = new GcrInstitutionCatalogCourses();
                                 $cron_obj->setPlatformShortName($product->getPlatformShortName());
                                 $cron_obj->setInstitutionShortName($product->getInstitutionShortName());
                                 $cron_obj->setCatalogShortName($current_eschool_key);
                                 $cron_obj->setProductTypeId($product->getProductTypeId());
                                 $cron_obj->setCoursesCount($ctlg_crses_count);
                                 $cron_obj->save();
                             } else {
                                 Doctrine_Query::create()->update('GcrInstitutionCatalogCourses')->set('courses_count', '?', $ctlg_crses_count)->where('institution_short_name = ?', $product->getInstitutionShortName())->andWhere('platform_short_name = ?', $product->getPlatformShortName())->andWhere('catalog_short_name = ?', $current_eschool_key)->andWhere('product_type_id = ?', $product->getProductTypeId())->execute();
                             }
                         }
                     }
                 }
             }
         }
     }
     /* 		print "<pre>";
     		print_r($catalog_courses_count);
     		//print_r($all_products_details);
     		print "</pre>"; */
     echo "<br>Completed<br>";
     exit;
 }
 /**
  * executes subscriptions list mahara
  *
  * @param sfWebRequest $request_object
  * @param returns products details along with courses.
  * gets values from get method
  */
 public function executeSubscriptions(sfWebRequest $request)
 {
     global $CFG;
     $CFG->current_app->requireMahara();
     $this->params = $request->getGetParameters();
     $this->course = false;
     $this->current_app_short_name = $CFG->current_app->getShortName();
     // gets all available schools
     /* 		$eschool_array = array();
     		$catalog_courses_count = array();
     		foreach($CFG->current_app->getMnetEschools() as $eschool) {
     			//if (GcrEschoolTable::authorizeEschoolAccess($eschool, true)) {
     				$eschool_array[$eschool->getFullName()] = $eschool;
     			//}
     		} 
     		ksort($eschool_array);
     		// gets catalog-wise courses count
     		foreach($eschool_array as $eschool) {
     			//$catalog_courses_count[$eschool->getShortName()] = $eschool->getFullName();
     			$ctlg_courses_list = $this->getHTMLCoursesCount($eschool->getShortName());
     			$catalog_courses_count[$eschool->getShortName()] = $ctlg_courses_list;
     		}
     		$this->catalog_courses_count = $catalog_courses_count; */
     // gets subscriptions products
     $products = GcrProductsTable::getProductLibraries($this->current_app_short_name);
     //$ins_prod_orders = GcrInstitutionProductOrdersTable::get_orders("lcrcconline", "microsoft", 6);
     $products_list = array();
     $products_list_institution = array();
     $products_details = array();
     foreach ($products as $product) {
         $products_list[$product->getShortName()] = $product->getFullName();
         $products_list_institution[$product->getShortName()] = $product->getInstitutionShortName();
         $products_details[$product->getShortName()]["id"] = $product->getId();
         $products_details[$product->getShortName()]["short_name"] = $product->getShortName();
         $products_details[$product->getShortName()]["full_name"] = $product->getFullName();
         $products_details[$product->getShortName()]["institution_short_name"] = $product->getInstitutionShortName();
         $products_details[$product->getShortName()]["description"] = $product->getDescription();
         $products_details[$product->getShortName()]["cost"] = $product->getCost();
         $products_details[$product->getShortName()]["pricing_html"] = $product->getPricingHtml();
         $products_details[$product->getShortName()]["icon"] = $product->getIcon();
     }
     $this->libraries_list = $products_list;
     $this->products_list_institution = $products_list_institution;
     $this->products_details = $products_details;
     $this->getResponse()->setTitle('Subscriptions');
     sfConfig::set('sf_escaping_strategy', false);
 }
 public function executeSubscriptions(sfWebRequest $request)
 {
     global $CFG;
     $CFG->current_app->requireMahara();
     $this->params = $request->getGetParameters();
     $this->course = false;
     if (isset($this->params['course']) && isset($this->params['catalog'])) {
         $eschool = GcrEschoolTable::getEschool($this->params['catalog'], true);
         if ($eschool) {
             $course = $eschool->getCourse($this->params['course']);
             if ($course) {
                 $this->course = $course;
             }
         }
     }
     $eschool_array = array();
     $catalog_courses_count = array();
     foreach ($CFG->current_app->getMnetEschools() as $eschool) {
         if (GcrEschoolTable::authorizeEschoolAccess($eschool, true)) {
             $eschool_array[$eschool->getFullName()] = $eschool;
         }
     }
     ksort($eschool_array);
     foreach ($eschool_array as $eschool) {
         //$catalog_courses_count[$eschool->getShortName()] = $eschool->getFullName();
         $catalog_courses_count[$eschool->getShortName()] = $this->getHTMLCoursesCount($eschool->getShortName());
     }
     $this->catalog_courses_count = $catalog_courses_count;
     $products = GcrProductsTable::getProductLibraries();
     $products_list = array();
     $products_details = array();
     foreach ($products as $product) {
         $products_list[$product->getShortName()] = $product->getFullName();
         $products_details[$product->getShortName()]["id"] = $product->getId();
         $products_details[$product->getShortName()]["short_name"] = $product->getShortName();
         $products_details[$product->getShortName()]["full_name"] = $product->getFullName();
         $products_details[$product->getShortName()]["description"] = $product->getDescription();
         $products_details[$product->getShortName()]["cost"] = $product->getCost();
         $products_details[$product->getShortName()]["pricing_html"] = $product->getPricingHtml();
         $products_details[$product->getShortName()]["icon"] = $product->getIcon();
     }
     $this->libraries_list = $products_list;
     $this->products_details = $products_details;
     $this->getResponse()->setTitle('Courses');
     sfConfig::set('sf_escaping_strategy', false);
 }
Exemplo n.º 6
0
 private function hydratePurchaseObject($object, $type, $type_id, $app_id, $bill_cycle = null)
 {
     // one case for each purchase type
     $this->purchaseObject->eschool = $app_id;
     if (!($app = GcrInstitutionTable::getApp($app_id))) {
         global $CFG;
         $CFG->current_app->gcError('Schema ' . $app_id . ' does not exist.', 'gcdatabaseerror');
     }
     if ($type == 'course') {
         if ($course = $app->getCourse($type_id)) {
             $mdl_course = $course->getObject();
             if ($mdl_enrol = $course->getMdlEnrol()) {
                 $this->purchaseObject->description = 'Course: ' . $mdl_course->fullname . ' (' . $mdl_course->shortname . ')';
                 if ($mdl_enrol->cost > 0) {
                     $this->purchaseObject->cost = $mdl_enrol->cost;
                 } else {
                     if ($enrolCost = $app->getConfigVar('enrol_cost')) {
                         $this->purchaseObject->cost = $enrolCost;
                     }
                 }
             }
         }
     } else {
         if ($type == 'eschool') {
             $this->purchaseObject->description = 'eSchool Activation: ' . $app->getFullName() . ' (' . $app->getShortName() . ')';
             if ($cost = $app->getConfigVar('gc_eschool_cost_' . strtolower($bill_cycle))) {
                 $this->purchaseObject->cost = $cost;
                 $this->purchaseObject->bill_cycle = $bill_cycle . 'ly Subscription';
             }
         } else {
             if ($type == 'classroom' || $type == 'classroom_membership') {
                 $this->purchaseObject->description = 'eClassroom';
                 $this->purchaseObject->description .= $type == 'membership' ? ' Membership ' : '';
                 $this->purchaseObject->description .= ' on ' . $app->getFullName();
                 if ($cost = $app->getConfigVar('gc_classroom_cost_' . strtolower($bill_cycle))) {
                     $this->purchaseObject->cost = $cost;
                     $this->purchaseObject->bill_cycle = $bill_cycle . 'ly Subscription';
                 }
             } else {
                 if ($type == 'membership') {
                     $this->purchaseObject->description = 'Membership on ' . $app->getFullName();
                     if ($cost = $app->getConfigVar('gc_membership_cost_' . strtolower($bill_cycle))) {
                         $this->purchaseObject->cost = $cost;
                         $this->purchaseObject->bill_cycle = $bill_cycle . 'ly Subscription';
                     }
                 } else {
                     if ($type == 'subscription') {
                         $type_id_arr = explode("~", $type_id);
                         $product_details = GcrProductsTable::getProductDetails($type_id_arr[0], $type_id_arr[1], $app_id);
                         foreach ($product_details as $product) {
                             $this->purchaseObject->description = 'Subscription for - ' . $product->getFullName();
                             $this->purchaseObject->cost = $product->getCost();
                             $this->purchaseObject->bill_cycle = $bill_cycle . 'ly Subscription';
                         }
                     } else {
                         if ($type == 'sale') {
                             if ($purchase_item = Doctrine::getTable('GcrPurchaseItem')->find($type_id)) {
                                 $this->purchaseObject->description = $purchase_item->getDescription();
                                 $this->purchaseObject->cost = $purchase_item->getAmount();
                             }
                         }
                     }
                 }
             }
         }
     }
 }