/** * Render a multi select with all available tags of entity and the tags of attachment preselected * * @param EntityInterface $entity the entity to get all allowed tags from * @param Attachment\Model\Entity\Attachment $attachment the attachment entity to add the tag to * @return string */ public function tagsChooser(EntityInterface $entity, $attachment) { if (!TableRegistry::exists($entity->source())) { throw new Cake\Network\Exception\MissingTableException('Could not find Table ' . $entity->source()); } $Table = TableRegistry::get($entity->source()); return $this->Form->select('tags', $Table->getAttachmentsTags(), ['type' => 'select', 'class' => 'tag-chooser', 'style' => 'display: block; width: 100%', 'label' => false, 'multiple' => true, 'value' => $attachment->tags]); }
public function toggle(EntityInterface $entity) { $limit = $this->config('implementedServices.' . $entity->source())->config('limit'); if ($limit !== 1) { throw new Exception(sprintf('Toggle disabled, type "%s" limit is "%s"', $entity->source(), $limit)); } // if current user in $entity->reviewed_by // if so goto unreview // else goto review }
/** * Gets the repository for this entity * * @param EntityInterface $entity * @return Table */ protected function _repository($entity) { $source = $entity->source(); if ($source === null) { list(, $class) = namespaceSplit(get_class($entity)); $source = Inflector::pluralize($class); } return TableRegistry::get($source); }
/** * recursive method to increase the filename in case the file already exists * * @param string $fileInfo Array of information about the file * @param EntityInterface $entity Entity * @param string $id counter varibale to extend the filename * @return array */ private function __getFileName($fileInfo, EntityInterface $entity, $id = 0) { if (!file_exists(Configure::read('Attachments.path') . $entity->source() . '/' . $entity->id . '/' . $fileInfo['basename'])) { return $fileInfo; } $fileInfo['basename'] = $fileInfo['filename'] . ' (' . ++$id . ').' . $fileInfo['extension']; return $this->__getFileName($fileInfo, $entity, $id); }
/** * Get table alias for the given entity. * * @param \Cake\Datasource\EntityInterface $entity The entity * @return string Table alias */ protected function _getTableAlias(EntityInterface $entity) { $alias = $entity->source(); if (mb_strpos($alias, '.') !== false) { $parts = explode('.', $alias); $alias = array_pop($parts); } return strtolower($alias); }
/** * Renders an delete button * * @param EntityInterface $entity Entity to take the ID from * @param array $options Config options * @return string */ public function deleteButton(EntityInterface $entity, array $options = []) { $options = Hash::merge(['url' => null, 'title' => __d('cktools', 'delete'), 'icon' => 'fa fa-trash-o', 'class' => 'btn btn-danger btn-xs', 'confirm' => __d('cktools', 'delete_confirmation')], $options); $url = $options['url']; $title = $options['title']; $icon = $options['icon']; unset($options['url'], $options['title'], $options['icon']); if (!$url) { $url = ['controller' => $entity->source(), 'action' => 'delete', $entity->id]; } if ($icon) { $title = '<i class="' . $icon . '"></i> ' . '<span class="button-text">' . $title . '</span>'; $options['escape'] = false; } return $this->Html->link($title, $url, $options); }
public function __invoke(EntityInterface $row) { $primaryKey = array_values($row->extract((array) $this->table->primaryKey())); $row->_links = ['self' => ['href' => Router::url(['controller' => $row->source(), 'action' => 'view'] + $primaryKey)]]; return $this->enrich($row); }
/** * Renders an delete button * * @param EntityInterface $entity Entity to take the ID from * @param array $options Config options * @return string */ public function deleteButton(EntityInterface $entity, array $options = []) { $options = Hash::merge(['url' => null, 'title' => __d('cktools', 'delete'), 'icon' => 'fa fa-trash-o', 'class' => 'btn btn-danger btn-xs', 'confirm' => __d('cktools', 'delete_confirmation'), 'usePostLink' => false], $options); $url = $options['url']; $title = $options['title']; $icon = $options['icon']; unset($options['url'], $options['title'], $options['icon']); if (!$url) { list($plugin, $controller) = pluginSplit($entity->source()); $url = ['plugin' => $this->_View->request->plugin, 'controller' => $controller, 'action' => 'delete', $entity->id]; } if ($icon) { $title = '<i class="' . $icon . '"></i> ' . '<span class="button-text">' . $title . '</span>'; $options['escape'] = false; } if ($options['usePostLink']) { return $this->Form->postLink($title, $url, $options); } else { return $this->Html->link($title, $url, $options); } }