/** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $search_choices = ['' => 'No']; foreach ($this->chain->getPlugins() as $plugin) { $search_choices[$plugin->getName()] = $plugin->getTitle(); } $builder->add('locale', 'locale', ['label' => 'Language'])->add('task_scheduler', 'checkbox', ['required' => false, 'label' => 'Task scheduler', 'help' => 'A separate process to perform various tasks in the background, such as checks for system ' . 'updates'])->add('default_search', 'choice', ['required' => false, 'choices' => $search_choices, 'label' => 'Default search plugin', 'help' => 'When detects a new item, the application will try to add it using the selected plugin in ' . 'the first place. If you leave the field blank then the selection of plugins will be carried out ' . 'in alphabetical order.']); }
/** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $search_choices = ['' => 'No']; foreach ($this->chain->getPlugins() as $plugin) { $search_choices[$plugin->getName()] = $plugin->getTitle(); } $builder->add('locale', 'locale', ['label' => 'Language', 'data' => $this->request ? $this->request->getLocale() : ''])->add('default_search', 'choice', ['required' => false, 'choices' => $search_choices, 'label' => 'Default search plugin']); }
/** * @dataProvider getDafeultPlugins * * @param string $dafeult_plugin */ public function testGetDafeultPlugin($dafeult_plugin) { /* @var $plugin \PHPUnit_Framework_MockObject_MockObject|SearchInterface */ $plugin = $this->getMock('\\AnimeDb\\Bundle\\CatalogBundle\\Plugin\\Fill\\Search\\SearchInterface'); $plugin->expects($this->atLeastOnce())->method('getName')->will($this->returnValue('foo')); $chain = new Chain($dafeult_plugin); $chain->addPlugin($plugin); if ($dafeult_plugin == 'foo') { $this->assertEquals($plugin, $chain->getDafeultPlugin()); } else { $this->assertNull($chain->getDafeultPlugin()); } }
/** * @param DetectedNewFiles $event * * @return bool */ public function onDetectedNewFilesTryAdd(DetectedNewFiles $event) { // search from default plugin $default_plugin = null; if (($default_plugin = $this->search->getDafeultPlugin()) && $this->tryAddItem($default_plugin, $event)) { return true; } // search from all plugins foreach ($this->search->getPlugins() as $plugin) { /* @var $plugin SearchInterface */ if ($plugin !== $default_plugin && $this->tryAddItem($plugin, $event)) { return true; } } return false; }
/** * @dataProvider getPlugins * * @param \PHPUnit_Framework_MockObject_MockObject $default * @param bool $default_is_added * @param bool $default_is_dir * @param \PHPUnit_Framework_MockObject_MockObject $second * @param bool $second_is_added * @param bool $second_is_dir */ public function testOnDetectedNewFilesTryAdd(\PHPUnit_Framework_MockObject_MockObject $default, $default_is_added, $default_is_dir, \PHPUnit_Framework_MockObject_MockObject $second, $second_is_added, $second_is_dir) { /* @var $event \PHPUnit_Framework_MockObject_MockObject|DetectedNewFiles */ $event = $this->getMockBuilder('\\AnimeDb\\Bundle\\CatalogBundle\\Event\\Storage\\DetectedNewFiles')->disableOriginalConstructor()->getMock(); $this->search->expects($this->once())->method('getDafeultPlugin')->will($this->returnValue($default)); $this->tryAddItem($default, $event, $default_is_added, $default_is_dir); if ($default_is_added) { $this->search->expects($this->never())->method('getPlugins'); } else { $this->search->expects($this->once())->method('getPlugins')->will($this->returnValue([$default, $second])); $this->tryAddItem($second, $event, $second_is_added, $second_is_dir); } if (!$default_is_added && !$second_is_added) { $event->expects($this->never())->method('stopPropagation'); } $this->listener->onDetectedNewFilesTryAdd($event); }
/** * @return ItemInterface */ public function createMainMenu() { /* @var $menu ItemInterface */ $menu = $this->factory->createItem('root')->setUri($this->request_stack->getMasterRequest()->getRequestUri()); $menu->addChild('Search', ['route' => 'home_search'])->setLinkAttribute('class', 'icon-label icon-gray-search'); $add = $menu->addChild('Add record')->setLabelAttribute('class', 'icon-label icon-gray-add'); // synchronization items if ($this->plugin_import->hasPlugins() || $this->plugin_export->hasPlugins()) { $sync = $menu->addChild('Synchronization')->setLabelAttribute('class', 'icon-label icon-white-cloud-sync'); // add import plugin items $this->addPluginItems($this->plugin_import, $sync, 'Import items', '', 'icon-label icon-white-cloud-download'); // add export plugin items $this->addPluginItems($this->plugin_export, $sync, 'Export items', '', 'icon-label icon-white-cloud-arrow-up'); } $settings = $menu->addChild('Settings')->setLabelAttribute('class', 'icon-label icon-gray-settings'); // add search plugin items $this->addPluginItems($this->plugin_search, $add, 'Search by name', 'Search by name the source of filling item', 'icon-label icon-white-search'); if ($this->plugin_search->hasPlugins()) { $add->addChild('Search in all plugins', ['route' => 'fill_search_in_all'])->setAttribute('title', $this->translator->trans('Search by name in all plugins'))->setLinkAttribute('class', 'icon-label icon-white-cloud-search'); $add->addChild('Add from URL', ['route' => 'fill_search_filler'])->setAttribute('title', $this->translator->trans('Search plugin by the URL for filling item'))->setLinkAttribute('class', 'icon-label icon-white-cloud-search'); } // add filler plugin items $this->addPluginItems($this->plugin_filler, $add, 'Fill from source', 'Fill record from source (example source is URL)', 'icon-label icon-white-share'); // add manually $add->addChild('Fill manually', ['route' => 'item_add_manually'])->setLinkAttribute('class', 'icon-label icon-white-add'); $settings->addChild('File storages', ['route' => 'storage_list'])->setLinkAttribute('class', 'icon-label icon-white-storage'); $settings->addChild('List of notice', ['route' => 'notice_list'])->setLinkAttribute('class', 'icon-label icon-white-alert'); $settings->addChild('Labels', ['route' => 'label'])->setLinkAttribute('class', 'icon-label icon-white-label'); $plugins = $settings->addChild('Plugins')->setLabelAttribute('class', 'icon-label icon-white-plugin'); $settings->addChild('Update', ['route' => 'update'])->setLinkAttribute('class', 'icon-label icon-white-update'); $settings->addChild('General', ['route' => 'home_settings'])->setLinkAttribute('class', 'icon-label icon-white-settings'); // plugins $plugins->addChild('Installed', ['route' => 'plugin_installed'])->setLinkAttribute('class', 'icon-label icon-white-plugin'); $plugins->addChild('Store', ['route' => 'plugin_store'])->setLinkAttribute('class', 'icon-label icon-white-shop'); // add settings plugin items foreach ($this->plugin_setting->getPlugins() as $plugin) { /* @var $plugin PluginInMenuInterface */ $plugin->buildMenu($plugins); } // add link to guide $settings->addChild('Help', ['uri' => $this->api_client->getSiteUrl(self::GUIDE_LINK)])->setLinkAttribute('class', 'icon-label icon-white-help'); return $menu; }