/** * 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; }
/** * 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; }
/** * Entity data getter * * @param KModelEntityInterface $entity The entity to get data from * * @return array The entity data */ protected function _getData(KModelEntityInterface $entity) { $data = array('package' => $entity->package, 'name' => $entity->name, 'resource_id' => $entity->row, 'title' => $entity->title); if ($uuid = $entity->getActivityObject()->getUuid()) { $data['uuid'] = $uuid; } return $data; }
public function insertChild(KModelEntityInterface $node) { //Track the parent $node->setParent($this); $this->getChildren()->insert($node); return $this; }
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; }
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)); }
/** * 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; }
protected function _saveDocumentPath(KModelEntityInterface $entity) { if (!$this->isModified('document_path')) { return; } $translator = $this->getObject('translator'); $from = $entity->path; $fullpath = $entity->fullpath; $path = rtrim($this->document_path, '\\/'); if ($from === $path) { return; } if ($path === 'joomlatools-files') { $this->getObject('response')->addMessage($translator->translate('joomlatools-files is a special folder used for other DOCman features. You can only use a subfolder of it to store your files'), 'error'); return; } if (!preg_match('#^[0-9A-Za-z:_\\-\\\\/\\.]+$#', $path)) { $this->getObject('response')->addMessage($translator->translate('Document path can only contain letters, numbers, dash or underscore'), 'error'); return; } $db = JFactory::getDBO(); $query = sprintf("SELECT COUNT(*) FROM #__menu WHERE path = %s", $db->quote($path)); if ($db->setQuery($query)->loadResult()) { $this->getObject('response')->addMessage($translator->translate('A menu item on your site uses this path as its alias. In order to ensure that your site works correctly, the document path was left unchanged.'), 'error'); return; } $entity->path = $path; if ($entity->save()) { jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.file'); $parent = dirname($entity->fullpath); if (!JFolder::exists($parent)) { JFolder::create($parent); } if (JFolder::move($fullpath, $entity->fullpath) !== true) { $this->getObject('response')->addMessage($translator->translate('Changes are saved but you should move existing files manually from folder "{from}" to "{to}" at your site root in order to make existing files visible.', array('from' => $from, 'to' => $path)), 'warning'); } if (!JFile::exists($entity->fullpath . '/.htaccess')) { $buffer = 'DENY FROM ALL'; JFile::write($entity->fullpath . '/.htaccess', $buffer); } if (!JFile::exists($entity->fullpath . '/web.config')) { $buffer = '<?xml version="1.0" encoding="utf-8" ?> <system.webServer> <security> <authorization> <remove users="*" roles="" verbs="" /> <add accessType="Allow" roles="Administrators" /> </authorization> </security> </system.webServer>'; JFile::write($entity->fullpath . '/web.config', $buffer); } } }
/** * Get the item link * * @param KModelEntityInterface $entity * @return string */ protected function _getEntityRoute(KModelEntityInterface $entity) { $package = $this->getIdentifier()->package; $view = $entity->getIdentifier()->name; return $this->getRoute(sprintf('component=%s&view=%s&slug=%s&format=json', $package, $view, $entity->slug)); }
/** * Get the activity status. * * The activity status is the current status of the activity object. * * @param KModelEntityInterface $object The activity object. * @param string $action The action being executed. * @return string The activity status. */ public function getActivityStatus(KModelEntityInterface $object, $action = null) { $status = $object->getStatus(); // Commands may change the original status of an action. if ($action == 'after.add' && $status == KModelEntityInterface::STATUS_UPDATED) { $status = KModelEntityInterface::STATUS_CREATED; } // Ignore non-changing edits. if ($action == 'after.edit' && $status == KModelEntityInterface::STATUS_FETCHED) { $status = null; } return $status; }
protected function _getAssetParentId(KModelEntityInterface $entity) { $name = 'com_' . $this->getTable()->getIdentifier()->package; $table = $this->getTable()->getIdentifier()->name; if ($table === 'categories') { $parent = $entity->getParent(); $parent_id = $entity->parent_id ? $entity->parent_id : ($parent ? $parent->id : 0); if ($parent_id) { $name = sprintf('%s.%s.%d', $name, 'category', $parent_id); } } elseif ($table === 'documents') { if ($this->docman_category_id) { $item = $this->getObject('com://admin/docman.model.categories') ->id($this->docman_category_id) ->fetch(); if ($item->isPermissible()) { $name = $item->getAssetName(); } } } $asset_id = $this->getObject('com://admin/docman.model.assets')->name($name)->fetch()->getProperty('id'); if (!$asset_id) { $asset_id = 1; } return $asset_id; }
/** * Turns a KModelEntityInterface object into a finder item * * @param KModelEntityInterface $entity * @return object */ protected function getFinderItem(KModelEntityInterface $entity) { $data = $entity->getProperties(); //Get the indexer result item $item = JArrayHelper::toObject($data, 'FinderIndexerResult'); $item->url = $this->getURL($item->id, $this->extension, $this->layout); $item->route = $this->getLink($entity); $item->path = FinderIndexerHelper::getContentPath($item->route); // Trigger the onContentPrepare event. if ($item->description) { $item->summary = FinderIndexerHelper::prepareContent($item->description, $item->params); } if ($item->publish_on) { $item->publish_start_date = $item->publish_on; } if ($item->unpublish_on) { $item->publish_end_date = $item->unpublish_on; } // Finder needs the access field if (!isset($item->access)) { $item->access = 1; } $item->state = $item->enabled; // Set the item type. $item->type_id = $this->type_id; // Set the mime type. $item->mime = $this->mime; // Set the item layout. $item->layout = $this->layout; // Set the extension if present if (isset($entity->extension)) { $item->extension = $entity->extension; } if ($entity->isCreatable()) { // Add the author taxonomy data. $item->addTaxonomy('Author', $entity->getAuthor()->getName()); // Add the start date $item->start_date = $entity->created_on; } return $item; }