示例#1
0
 /**
  * Returns an array representing the document row and with additional properties for download links and thumbnails
  *
  * @param KModelEntityInterface $document Document row
  *
  * @return array
  */
 protected function _getDocument(KModelEntityInterface $document)
 {
     $router = $this->getObject('com://admin/docman.template.helper.route');
     $router->setRouter(array($this, 'getRoute'));
     // TODO optimize this as it generates a query per document
     $category_link = $router->category(array('entity' => $document->category, 'format' => 'json'));
     $data = $document->toArray();
     $data['parameters'] = $document->getParameters()->toArray();
     $data['icon'] = $document->icon;
     $data['image'] = $document->image;
     $data['links'] = array('file' => array('href' => $document->download_link, 'type' => $this->mimetype), 'category' => array('href' => $category_link, 'type' => $this->mimetype));
     if ($document->image && $document->image_path) {
         $data['links']['image'] = array('href' => $document->image_path);
     }
     if ($document->icon && $document->icon_path) {
         $data['links']['icon'] = array('href' => $document->icon_path);
     }
     $data['category'] = array('id' => $document->docman_category_id, 'title' => $document->category_title, 'slug' => $document->category_slug);
     $data['file'] = array();
     if ($document->storage_type === 'file') {
         if ($document->mimetype) {
             $data['file']['type'] = $document->mimetype;
         }
         if ($document->extension) {
             $data['file']['extension'] = $document->extension;
         }
         if ($document->size) {
             $data['file']['size'] = $document->size;
         }
     }
     return $data;
 }
示例#2
0
    /**
     * Returns an array representing the category row
     *
     * @param KModelEntityInterface $category
     *
     * @return array
     */
    protected function _getCategory(KModelEntityInterface $category)
    {
        $data = $category->toArray();
        $data['parameters'] = $category->getParameters()->toArray();
        $data['icon']  = $category->icon;
        $data['image'] = $category->image;
        $data['links'] = array();

        if ($category->image && $category->image_path)
        {
            $data['links']['image'] = array(
                'href' => $category->image_path
            );
        }

        if ($category->icon && $category->icon_path)
        {
            $data['links']['icon'] = array(
                'href' => $category->icon_path
            );
        }

        $this->_filterArray($data, self::$_public_category_properties);

        return $data;
    }
示例#3
0
 public function setCoupons(KModelEntityInterface $entity)
 {
     $conditions = array();
     $conditions['events'][] = $entity->ohanah_event_id;
     $coupons = $this->getObject('com://site/sales.model.coupons')->code($entity->getParameters()->discount_code)->conditions($conditions)->fetch();
     $total = $entity->total_price;
     $coupon_ids = array();
     $discount_amount = 0;
     foreach ($coupons as $coupon) {
         $discount = false;
         if ($coupon->usage_limit) {
             if ($coupon->usage_limit > $coupon->times_used) {
                 $coupon->times_used++;
                 $coupon->save();
                 $discount = true;
             }
         }
         if ($total >= $coupon->minimum_amount) {
             $discount = true;
         }
         if ($discount) {
             $coupon_ids[] = (int) $coupon->id;
             switch ($coupon->percentage_or_amount) {
                 case 0:
                     $discount_amount = $total * (1 - $coupon->amount / 100);
                     break;
                 default:
                     $discount_amount = max($total - $coupon->amount, 0);
             }
         }
     }
     // We just update the parameters column.
     if ($entity->isParameterizable()) {
         $entity->parameters = array('discount' => array('coupon_ids' => $coupon_ids, 'amount' => $discount_amount ? $total - $discount_amount : 0));
         $table = $entity->getTable();
         $query = $this->getObject('lib:database.query.update')->table($table->getBase());
         $query->values('parameters = :parameters')->where($table->getIdentityColumn() . ' =  :id')->bind(array('id' => $entity->id, 'parameters' => $entity->parameters));
         $table->getAdapter()->update($query);
     }
     $entity->discount = new KObjectConfig();
     $entity->discount->append(array('amount' => $discount_amount ? $total - $discount_amount : 0));
 }