/**
  * 添加一个lesson
  * @param unknown_type $lesson
  */
 public function addLesson($lesson)
 {
     $owner = $this->getOwner();
     $lesson->userId = Yii::app()->user->id;
     $lesson->courseId = $owner->id;
     $lesson->addTime = time();
     //处理外链类型的视频
     if ($lesson->mediaSource && $lesson->mediaSource != "self" && $lesson->mediaSource != "cloud" && $lesson->mediaType != "text") {
         if (strpos($lesson->mediaUri, 'http://') !== 0) {
             $lesson->mediaUri = 'http://' . $lesson->mediaUri;
         }
         if (strpos($lesson->mediaUri, '.swf') === false) {
             Yii::import('ext.videolink.VideoLink');
             $video = new VideoLink();
             $result = $video->parse($lesson->mediaUri);
             if ($result) {
                 $lesson->mediaUri = $result['swf'];
                 $lesson->mediaSource = $result['source'];
                 $lesson->mediaName = $result['title'];
                 $lesson->mediaType = "video";
             }
         }
     }
     if (!$lesson->title) {
         $lesson->title = $lesson->mediaName;
     }
     $lesson->status = Lesson::STATUS_HIDDEN;
     return $lesson->save();
 }
Esempio n. 2
0
 /**
  * Assuming there exists an activerecord array
  *
  * @param unknown_type $arObject - the user object to act on  (ie. $user )
  * @param unknown_type $collectionName - the name of the collection within user object (ie. userprofileecontact)
  * @param unknown_type $collectionClassName - the name of the class for the collection (ie. Userprofileecontact)
  * @param unknown_type $itemCount - Number of items available within request
  * @param unknown_type $arryUpdateFields - the fields to search for ( searches for field.# )
  * @param unknown_type $req - the request with all the fields for us
  * @return unknown  true - either it worked or it there was nothing to do, false if it fails.
  */
 public function updateOneToManyArray($arObject, $collectionName, $collectionClassName, $itemCount, $arryUpdateFields, $req)
 {
     // Loop once for each array item to be added
     // build up information as records to persist
     $arryRecords = array();
     for ($index = 1; $index < $itemCount + 1; $index++) {
         $arryUpdates = array();
         //print("Pass $index\n");
         foreach ($arryUpdateFields as $fieldName) {
             $indexedFieldname = $fieldName . $index;
             $indexedValue = $req[$indexedFieldname];
             $arryUpdates[$fieldName] = $indexedValue;
         }
         // Don't add empties
         if (!empty($arryUpdates) && strlen($arryUpdates[$arryUpdateFields[0]])) {
             $arryUpdates['user_id'] = $this->uid;
             $arryRecords[] = $arryUpdates;
         }
     }
     //		print("Now Writting <p>");
     //		var_dump($arryRecords);
     // Now file $arryRecords in the database
     // Delete all existing associations
     $colClass = new $collectionClassName();
     $colClass->delete_all("user_id=" . $this->uid);
     if (!empty($arryRecords)) {
         //create and add new items
         $collections = array();
         foreach ($arryRecords as $record) {
             $collections[] = new $collectionClassName($record);
         }
         $arObject->{$collectionName} = $collections;
         return $arObject->save();
     }
     return true;
 }
Esempio n. 3
0
/**
 * checks to see if the filesize is set and sets it if not
 * @param unknown_type $image
 * @return object
 */
function quota_image_refresh($image)
{
    $image->set('filesize', filesize($image->localpath));
    $image->save();
    return $image;
}
 /**
  * Set the invoice status to "Paid" after a successful payment
  *
  * @param unknown_type $order
  */
 private function _updateInvoices($order, $message)
 {
     $invoices = $order->getInvoiceCollection();
     $state = Mage_Sales_Model_Order::STATE_PROCESSING;
     $payment = $order->getPayment();
     $transaction;
     $session = Mage::getSingleton('checkout/session');
     $szNewCrossReference;
     $transactionId = $payment->getLastTransId();
     $transaction = $payment->getTransaction($transactionId);
     $transactionType = $transaction->getTxnType();
     if ($session->getNewCrossReference()) {
         $szNewCrossReference = $session->getNewCrossReference();
         $value = $transaction->setTxnId($szNewCrossReference);
         $transaction->save();
         $payment->setLastTransId($szNewCrossReference);
         $session->setNewCrossReference(null);
     }
     foreach ($invoices as $invoice) {
         // set the invoice state to be "Paid"
         $invoice->pay()->save();
     }
     // add a comment to the order comments
     if ($transactionType == 'authorization') {
         $order->setState($state, 'csv_preauth', $message, true);
     } else {
         if ($transactionType == 'capture') {
             $order->setState($state, 'csv_paid', $message, true);
         } else {
             Mage::throwException('invalid transaction type [' . $transactionType . '] for invoice updating');
         }
     }
     $order->save();
 }