Esempio n. 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;
 }
Esempio n. 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;
    }
Esempio n. 3
0
 protected function _getCoupon(KModelEntityInterface $entity)
 {
     $data = $entity->toArray();
     $data['percentage_or_amount'] = (int) $data['percentage_or_amount'];
     $data['amount'] = (int) $data['amount'];
     $data['usage_limit'] = (int) $data['usage_limit'];
     $data['minimum_amount'] = is_null($data['minimum_amount']) ? null : (double) $data['minimum_amount'];
     $data['times_used'] = (int) $data['times_used'];
     $data['global'] = (int) $data['global'];
     return $data;
 }
Esempio n. 4
0
 /**
  * Get the entity data
  *
  * @link http://activitystrea.ms/specs/json/1.0/#json See JSON serialization.
  *
  * @param KModelEntityInterface $entity The model entity.
  * @return array The array with data to be encoded to JSON.
  */
 protected function _getEntity(KModelEntityInterface $entity)
 {
     if ($this->_layout == 'stream') {
         $activity = $entity;
         $renderer = $this->getRenderer();
         $item = array('id' => $activity->getActivityId(), 'title' => $renderer->render($activity, array('escaped_urls' => false, 'fqr' => true)), 'story' => $renderer->render($activity, array('html' => false)), 'published' => $activity->getActivityPublished()->format('c'), 'verb' => $activity->getActivityVerb(), 'format' => $activity->getActivityFormat());
         if ($icon = $activity->getActivityIcon()) {
             $item['icon'] = $this->_getMediaLinkData($icon);
         }
         foreach ($activity->objects as $name => $object) {
             $item[$name] = $this->_getObjectData($object);
         }
     } else {
         $item = $entity->toArray();
         if (!empty($this->_fields)) {
             $item = array_intersect_key($item, array_flip($this->_fields));
         }
     }
     return $item;
 }