/** * This method is for getting a repository for reviews * */ public static function getReviewRepository() { $serviceManager = ServiceUtil::getManager(); $entityManager = $serviceManager->getService('doctrine.entitymanager'); $repository = $entityManager->getRepository('Reviews_Entity_Review'); return $repository; }
/** * Loads the data. * * @param array $data Data array with parameters. */ public function loadData(&$data) { $serviceManager = ServiceUtil::getManager(); $controllerHelper = new MUVideo_Util_Controller($serviceManager); $utilArgs = array('name' => 'detail'); if (!isset($data['objectType']) || !in_array($data['objectType'], $controllerHelper->getObjectTypes('contentType', $utilArgs))) { $data['objectType'] = $controllerHelper->getDefaultObjectType('contentType', $utilArgs); } $this->objectType = $data['objectType']; if (!isset($data['id'])) { $data['id'] = null; } if (!isset($data['moviewidth'])) { $data['moviewidth'] = 400; } $this->moviewidth = $data['moviewidth']; if (!isset($data['movieheight'])) { $data['movieheight'] = 300; } $this->movieheight = $data['movieheight']; if (!isset($data['displayMode'])) { $data['displayMode'] = 'embed'; } $this->id = $data['id']; $this->displayMode = $data['displayMode']; }
/** * Constructor. * * @param integer $objectId Identifier of treated object. * @param integer $areaId Name of hook area. * @param string $module Name of the owning module. * @param string $urlString **deprecated** * @param Zikula_ModUrl $urlObject Object carrying url arguments. */ function __construct($objectId, $areaId, $module, $urlString = null, Zikula_ModUrl $urlObject = null) { // call base constructor to store arguments in member vars parent::__construct($objectId, $areaId, $module, $urlString, $urlObject); // derive object type from url object $urlArgs = $urlObject->getArgs(); $objectType = isset($urlArgs['ot']) ? $urlArgs['ot'] : 'review'; $component = $module . ':' . ucwords($objectType) . ':'; $perm = SecurityUtil::checkPermission($component, $objectId . '::', ACCESS_READ); if (!$perm) { return; } $entityClass = $module . '_Entity_' . ucwords($objectType); $serviceManager = ServiceUtil::getManager(); $entityManager = $serviceManager->getService('doctrine.entitymanager'); $repository = $entityManager->getRepository($entityClass); $useJoins = false; /** TODO support composite identifiers properly at this point */ $entity = $repository->selectById($objectId, $useJoins); if ($entity === false || !is_array($entity) && !is_object($entity)) { return; } $this->setObjectTitle($entity->getTitleFromDisplayPattern()); $dateFieldName = $repository->getStartDateFieldName(); if ($dateFieldName != '') { $this->setObjectDate($entity[$dateFieldName]); } else { $this->setObjectDate(''); } if (method_exists($entity, 'getCreatedUserId')) { $this->setObjectAuthor(UserUtil::getVar('uname', $entity['createdUserId'])); } else { $this->setObjectAuthor(''); } }
/** * Remove a directory from zikula's local cache directory. * * @param string $dir The name of the directory to remove. * @param bool $absolute Whether to process the passed dir as an absolute path or not. * * @return boolean true if successful, false otherwise. */ public static function removeLocalDir($dir, $absolute = false) { $sm = ServiceUtil::getManager(); $base = $sm['kernel.cache_dir'] . '/ztemp'; $path = $base . '/' . $dir; return FileUtil::deldir($path, $absolute); }
/** * Returns the page render time. * * @return number */ public function getTimeDiff() { $start = \ServiceUtil::getManager()->getParameter('debug.toolbar.panel.rendertime.start'); $end = microtime(true); $diff = $end - $start; return $diff; }
/** * Sync the filesystem scan and the Bundles table * This is a 'dumb' scan - there is no state management here * state management occurs in the module and theme management * and is checked in Bundle/Bootstrap * * @param $array array of extensions * obtained from filesystem scan * key is bundle name and value an instance of \Zikula\Bundle\CoreBundle\Bundle\MetaData */ private function sync($array) { // add what is in array but missing from db /** @var $metadata MetaData */ foreach ($array as $name => $metadata) { $qb = $this->conn->createQueryBuilder(); $qb->select('b.id', 'b.bundlename', 'b.bundleclass', 'b.autoload', 'b.bundletype', 'b.bundlestate')->from('bundles', 'b')->where('b.bundlename = :name')->setParameter('name', $name); $result = $qb->execute(); $row = $result->fetch(); if (!$row) { // bundle doesn't exist $this->insert($metadata); } elseif ($metadata->getClass() != $row['bundleclass'] || serialize($metadata->getAutoload()) != $row['autoload']) { // bundle json has been updated $updatedMeta = array("bundleclass" => $metadata->getClass(), "autoload" => serialize($metadata->getAutoload())); $this->conn->update('bundles', $updatedMeta, array('id' => $row['id'])); } } // remove what is in db but missing from array $qb = $this->conn->createQueryBuilder(); $qb->select('b.id', 'b.bundlename', 'b.bundleclass', 'b.autoload', 'b.bundletype', 'b.bundlestate')->from('bundles', 'b'); $res = $qb->execute(); foreach ($res->fetchAll() as $row) { if (!in_array($row['bundlename'], array_keys($array))) { $this->removeById($row['id']); } } // clear the cache /** @var $cacheClearer \Zikula\Bundle\CoreBundle\CacheClearer */ $cacheClearer = \ServiceUtil::getManager()->get('zikula.cache_clearer'); $cacheClearer->clear('symfony.config'); }
/** * Setup the current instance of the Zikula_View class and return it back to the module. * * @param string $moduleName Module name. * @param string $pluginName Plugin name. * @param integer|null $caching Whether or not to cache (Zikula_View::CACHE_*) or use config variable (null). * @param string $cache_id Cache Id. * * @return Zikula_View_Plugin instance. */ public static function getPluginInstance($moduleName, $pluginName, $caching = null, $cache_id = null) { $serviceManager = ServiceUtil::getManager(); $serviceId = strtolower(sprintf('zikula.renderplugin.%s.%s', $moduleName, $pluginName)); if (!$serviceManager->has($serviceId)) { $view = new self($serviceManager, $moduleName, $pluginName, $caching); $serviceManager->set($serviceId, $view); } else { return $serviceManager->get($serviceId); } if (!is_null($caching)) { $view->caching = $caching; } if (!is_null($cache_id)) { $view->cache_id = $cache_id; } if ($moduleName === null) { $moduleName = $view->toplevelmodule; } if (!array_key_exists($moduleName, $view->module)) { $view->module[$moduleName] = ModUtil::getInfoFromName($moduleName); //$instance->modinfo = ModUtil::getInfoFromName($module); $view->_addPluginsDir($moduleName); } // for {gt} template plugin to detect gettext domain if ($view->module[$moduleName]['type'] == ModUtil::TYPE_MODULE || $view->module[$moduleName]['type'] == ModUtil::TYPE_SYSTEM) { $view->domain = ZLanguage::getModulePluginDomain($view->module[$moduleName]['name'], $view->getPluginName()); } elseif ($view->module[$moduleName]['type'] == ModUtil::TYPE_CORE) { $view->domain = ZLanguage::getSystemPluginDomain($view->getPluginName()); } return $view; }
/** * The main procedure for managing stylesheets and javascript files. * * Gets demanded files from PageUtil variables, check them and resolve dependencies. * Returns an array with two arrays, containing list of js and css files * ready to embedded in the HTML HEAD. * * @param bool $combine Should files be combined. * @param string $cache_dir Path to cache directory. * * @return array Array with two array containing the files to be embedded into HTML HEAD */ public static function prepareJCSS($combine = false, $cache_dir = null) { $combine = $combine && is_writable($cache_dir); $jcss = array(); // get page vars $javascripts = PageUtil::getVar('javascript'); $stylesheets = PageUtil::getVar('stylesheet'); $javascripts = self::prepareJavascripts($javascripts, $combine); // update stylesheets as there might be some additions for js $stylesheets = array_merge((array) $stylesheets, (array) PageUtil::getVar('stylesheet')); $stylesheets = self::prepareStylesheets($stylesheets, $combine); if ($combine) { $javascripts = (array) self::save($javascripts, 'js', $cache_dir); $stylesheets = (array) self::save($stylesheets, 'css', $cache_dir); } /* @var \Symfony\Component\HttpFoundation\Request $request */ $request = ServiceUtil::getManager()->get('request'); $basePath = $request->getBasePath(); foreach ($stylesheets as $key => $value) { $stylesheets[$key] = $basePath . '/' . $value; } foreach ($javascripts as $key => $value) { $javascripts[$key] = $basePath . '/' . $value; } $jcss = array('stylesheets' => $stylesheets, 'javascripts' => $javascripts); // some core js libs require js gettext - ensure that it will be loaded $jsgettext = self::getJSGettext(); if (!empty($jsgettext)) { array_unshift($jcss['javascripts'], $jsgettext); } return $jcss; }
/** * This method is for getting a repository for movies * */ public static function getMovieRepository() { $serviceManager = ServiceUtil::getManager(); $entityManager = $serviceManager->getService('doctrine.entitymanager'); $repository = $entityManager->getRepository('MUVideo_Entity_Movie'); return $repository; }
/** * Update operation. * @param object $entity The treated object. * @param array $params Additional arguments. * * @return bool False on failure or true if everything worked well. */ function Reviews_operation_update(&$entity, $params) { $dom = ZLanguage::getModuleDomain('Reviews'); // initialise the result flag $result = false; $objectType = $entity['_objectType']; $currentState = $entity['workflowState']; // get attributes read from the workflow if (isset($params['nextstate']) && !empty($params['nextstate'])) { // assign value to the data object $entity['workflowState'] = $params['nextstate']; if ($params['nextstate'] == 'archived') { // bypass validator (for example an end date could have lost it's "value in future") $entity['_bypassValidation'] = true; } } // get entity manager $serviceManager = ServiceUtil::getManager(); $entityManager = $serviceManager->getService('doctrine.entitymanager'); // save entity data try { //$this->entityManager->transactional(function($entityManager) { $entityManager->persist($entity); $entityManager->flush(); //}); $result = true; } catch (\Exception $e) { LogUtil::registerError($e->getMessage()); } // return result of this operation return $result; }
protected function bootstrap($disableSessions = true, $loadZikulaCore = true, $fakeRequest = true) { define('_ZINSTALLVER', \Zikula_Core::VERSION_NUM); $kernel = $this->getContainer()->get('kernel'); $loader = (require $kernel->getRootDir() . '/autoload.php'); \ZLoader::register($loader); if ($loadZikulaCore && !$this->getContainer()->has('zikula')) { $core = new Zikula_Core(); $core->setKernel($kernel); $core->boot(); foreach ($GLOBALS['ZConfig'] as $config) { $core->getContainer()->loadArguments($config); } $GLOBALS['ZConfig']['System']['temp'] = $core->getContainer()->getParameter('temp_dir'); $GLOBALS['ZConfig']['System']['datadir'] = $core->getContainer()->getParameter('datadir'); $GLOBALS['ZConfig']['System']['system.chmod_dir'] = $core->getContainer()->getParameter('system.chmod_dir'); \ServiceUtil::getManager($core); \EventUtil::getManager($core); } if ($disableSessions) { // Disable sessions. $this->getContainer()->set('session.storage', new MockArraySessionStorage()); $this->getContainer()->set('session.handler', new NullSessionHandler()); } if ($fakeRequest) { // Fake request $request = Request::create('http://localhost/install'); $this->getContainer()->set('request', $request); } }
/** * The zikularoutesmoduleGetListEntry modifier displays the name * or names for a given list item. * * @param string $value The dropdown value to process. * @param string $objectType The treated object type. * @param string $fieldName The list field's name. * @param string $delimiter String used as separator for multiple selections. * * @return string List item name. */ function smarty_modifier_zikularoutesmoduleGetListEntry($value, $objectType = '', $fieldName = '', $delimiter = ', ') { if (empty($value) && $value != '0' || empty($objectType) || empty($fieldName)) { return $value; } $serviceManager = ServiceUtil::getManager(); $helper = $serviceManager->get('zikularoutesmodule.listentries_helper'); return $helper->resolve($value, $objectType, $fieldName, $delimiter); }
/** * Create a directory below zikula's local cache directory. * * @param string $dir The name of the directory to create. * @param mixed $mode The (UNIX) mode we wish to create the files with. * @param bool $absolute Whether to process the passed dir as an absolute path or not. * * @return boolean true if successful, false otherwise. */ public static function createLocalDir($dir, $mode = 0777, $absolute = true) { $path = DataUtil::formatForOS(System::getVar('temp'), true) . '/' . $dir; $mode = isset($mode) ? $mode : ServiceUtil::getManager()->getParameter('system.chmod_dir'); if (!FileUtil::mkdirs($path, $mode, $absolute)) { return false; } return true; }
/** * The muvideoGetListEntry modifier displays the name * or names for a given list item. * * @param string $value The dropdown value to process. * @param string $objectType The treated object type. * @param string $fieldName The list field's name. * @param string $delimiter String used as separator for multiple selections. * * @return string List item name. */ function smarty_modifier_muvideoGetListEntry($value, $objectType = '', $fieldName = '', $delimiter = ', ') { if (empty($value) || empty($objectType) || empty($fieldName)) { return $value; } $serviceManager = ServiceUtil::getManager(); $helper = new MUVideo_Util_ListEntries($serviceManager); return $helper->resolve($value, $objectType, $fieldName, $delimiter); }
/** * Delete a session variable. * * @param string $name Name of the session variable to delete. * @param mixed $default The default value to return if the requested session variable is not set. * @param string $path Path to traverse to reach the element we wish to return (optional) (default='/'). * * @return mixed The value of the session variable being deleted, or the value provided in $default if the variable is not set. */ public static function delVar($name, $default = false, $path = '/') { $session = ServiceUtil::getManager()->get('session'); if ($path != '/' || $path != '') { $name = "{$path}/{$name}"; } $value = $session->get($name, $default); $session->remove($name, $path); return $value; }
/** * The zikularoutesmoduleObjectState modifier displays the name of a given object's workflow state. * Examples: * {$item.workflowState|zikularoutesmoduleObjectState} {* with visual feedback *} * {$item.workflowState|zikularoutesmoduleObjectState:false} {* no ui feedback *} * * @param string $state Name of given workflow state. * @param boolean $uiFeedback Whether the output should include some visual feedback about the state. * * @return string Enriched and translated workflow state ready for display. */ function smarty_modifier_zikularoutesmoduleObjectState($state = 'initial', $uiFeedback = true) { $serviceManager = ServiceUtil::getManager(); $workflowHelper = $serviceManager->get('zikularoutesmodule.workflow_helper'); $stateInfo = $workflowHelper->getStateInfo($state); $result = $stateInfo['text']; if ($uiFeedback === true) { $result = '<span class="label label-' . $stateInfo['ui'] . '">' . $result . '</span>'; } return $result; }
/** * The reviewsObjectState modifier displays the name of a given object's workflow state. * Examples: * {$item.workflowState|reviewsObjectState} {* with visual feedback *} * {$item.workflowState|reviewsObjectState:false} {* no ui feedback *} * * @param string $state Name of given workflow state. * @param boolean $uiFeedback Whether the output should include some visual feedback about the state. * * @return string Enriched and translated workflow state ready for display. */ function smarty_modifier_reviewsObjectState($state = 'initial', $uiFeedback = true) { $serviceManager = ServiceUtil::getManager(); $workflowHelper = new Reviews_Util_Workflow($serviceManager); $stateInfo = $workflowHelper->getStateInfo($state); $result = $stateInfo['text']; if ($uiFeedback === true) { $result = '<img src="' . System::getBaseUrl() . 'images/icons/extrasmall/' . $stateInfo['ui'] . 'led.png" width="16" height="16" alt="' . $result . '" /> ' . $result; } return $result; }
/** * Check for unique values. * * This method determines if there already exist users with the same user. * * @param string $fieldName The name of the property to be checked * @return boolean result of this check, true if the given user does not already exist */ public function isUniqueValue($fieldName) { if (empty($this->entity[$fieldName])) { return false; } $serviceManager = ServiceUtil::getManager(); $entityManager = $serviceManager->getService('doctrine.entitymanager'); $repository = $entityManager->getRepository('MUBoard_Entity_User'); $excludeid = $this->entity['id']; return $repository->detectUniqueState($fieldName, $this->entity[$fieldName], $excludeid); }
/** * Clears the session variable namespace used by the Users module. * * Triggered by the 'user.logout.succeeded' and 'frontcontroller.exception' events. * * This is to ensure no leakage of authentication information across sessions or between critical * errors. This prevents, for example, the login process from becoming confused about its state * if it detects session variables containing authentication information which might make it think * that a re-attempt is in progress. * * @param GenericEvent $event The event that triggered this handler. * * @return void */ public static function clearUsersNamespaceListener(GenericEvent $event) { $eventName = $event->getName(); $modinfo = $event->hasArg('modinfo') ? $event->getArg('modinfo') : array(); $doClear = $eventName == 'user.logout.succeeded' || $eventName == 'frontcontroller.exception' && isset($modinfo) && is_array($modinfo) && !empty($modinfo) && !isset($modinfo['name']) && $modinfo['name'] == self::$modname; if ($doClear) { $container = ServiceUtil::getManager(); $session = $container->get('session'); $session->clearNamespace('Zikula_Users'); //Do not setNotified. Not handling the exception, just reacting to it. } }
/** * Check for unique values. * * This method determines if there already exist collections with the same collection. * * @param string $fieldName The name of the property to be checked * @return boolean result of this check, true if the given collection does not already exist */ public function isUniqueValue($fieldName) { if ($this->entity[$fieldName] === '') { return false; } $entityClass = 'MUVideo_Entity_Collection'; $serviceManager = ServiceUtil::getManager(); $entityManager = $serviceManager->getService('doctrine.entitymanager'); $repository = $entityManager->getRepository($entityClass); $excludeid = $this->entity['id']; return $repository->detectUniqueState($fieldName, $this->entity[$fieldName], $excludeid); }
/** * Post-Process the data after the entity has been constructed by the entity manager. * * @ORM\PostLoad * @see Zikula\RoutesModule\Entity\RouteEntity::performPostLoadCallback() * @return void. */ public function postLoadCallback() { if (php_sapi_name() == 'cli') { return; } $serviceManager = \ServiceUtil::getManager(); $requestStack = $serviceManager->get('request_stack'); if ($requestStack->getCurrentRequest() === null) { return; } $this->performPostLoadCallback(); }
/** * Get an instance of this class. * * @return Zikula_View_Resource This instance. */ public static function getInstance() { $serviceManager = ServiceUtil::getManager(); $serviceId = 'zikula.viewresource'; if (!$serviceManager->has($serviceId)) { $obj = new self(); $serviceManager->set($serviceId, $obj); } else { $obj = $serviceManager->get($serviceId); } return $obj; }
/** * Construct. * * @param int $objectId Object ID. * @param int $areaId A blockinfo structure. * @param string $module Module. * @param string $urlString Url. * @param \Zikula_ModUrl $urlObject Url object. */ public function __construct($objectId, $areaId, $module, $urlString = null, \Zikula_ModUrl $urlObject = null) { parent::__construct($objectId, $areaId, $module, $urlString, $urlObject); $sm = \ServiceUtil::getManager(); /** @var \Zikula\PagesModule\Entity\PageEntity $page */ $page = $sm->get('doctrine.entitymanager')->getRepository('ZikulaPagesModule:PageEntity')->find($this->getObjectId()); // the Api checks for perms and there is nothing else to check if ($page) { $this->setObjectAuthor($page->getCreator()->getUname()); $this->setObjectDate($page->getCr_date()); $this->setObjectTitle($page->getTitle()); } }
/** * Command event handler. * * This event handler is called when a command is issued by the user. * * @param Zikula_Form_View $view The form view instance. * @param array $args Additional arguments. * * @return mixed Redirect or false on errors. */ public function handleCommand(Zikula_Form_View $view, &$args) { // get collection id $collectionId = $this->request->query->filter('collectionId', 0, FILTER_SANITIZE_NUMBER_INT); if ($collectionId == 0) { return LogUtil::registerError(__('Sorry. There is no valid collection id!')); } // get channel id from form $channelId = $this->request->request->filter('channelId', '', FILTER_SANITIZE_STRING); $serviceManager = ServiceUtil::getManager(); $controllerHelper = new MUVideo_Util_Controller($serviceManager); return $controllerHelper->getYoutubeVideos($channelId[0], $collectionId); // return $this->view->redirect($this->getRedirectUrl($args)); }
/** * Listener for the `user.account.delete` event. * * Occurs after a user is deleted from the system. * All handlers are notified. * The full user record deleted is available as the subject. * This is a storage-level event, not a UI event. It should not be used for UI-level actions such as redirects. * The subject of the event is set to the user record that is being deleted. * * @param Zikula_Event $event The event instance. */ public static function delete(Zikula_Event $event) { ModUtil::initOOModule('Reviews'); $userRecord = $event->getSubject(); $uid = $userRecord['uid']; $serviceManager = ServiceUtil::getManager(); $entityManager = $serviceManager->getService('doctrine.entitymanager'); $repo = $entityManager->getRepository('Reviews_Entity_Review'); // delete all reviews created by this user $repo->deleteCreator($uid); // note you could also do: $repo->updateCreator($uid, 2); // set last editor to admin (2) for all reviews updated by this user $repo->updateLastEditor($uid, 2); // note you could also do: $repo->deleteLastEditor($uid); }
public function display() { $dom = ZLanguage::getModuleDomain('MUBoard'); ModUtil::initOOModule('MUBoard'); $serviceManager = ServiceUtil::getManager(); $entityManager = $serviceManager->getService('doctrine.entitymanager'); $repository = $entityManager->getRepository('MUBoard_Entity_' . ucfirst($this->objectType)); $idFields = ModUtil::apiFunc('MUBoard', 'selection', 'getIdFields', array('ot' => $objectType)); $sortParam = ''; if ($this->sorting == 'random') { $sortParam = 'RAND()'; } elseif ($this->sorting == 'newest') { if (count($idFields) == 1) { $sortParam = $idFields[0] . ' DESC'; } else { foreach ($idFields as $idField) { if (!empty($sortParam)) { $sortParam .= ', '; } $sortParam .= $idField . ' ASC'; } } } elseif ($this->sorting == 'default') { $sortParam = $repository->getDefaultSortingField() . ' ASC'; } $resultsPerPage = $this->amount ? $this->amount : 1; // get objects from database $selectionArgs = array('ot' => $objectType, 'where' => $this->filter, 'orderBy' => $sortParam, 'currentPage' => 1, 'resultsPerPage' => $resultsPerPage); list($entities, $objectCount) = ModUtil::apiFunc('MUBoard', 'selection', 'getEntitiesPaginated', $selectionArgs); $this->view->setCaching(true); $data = array('objectType' => $this->objectType, 'sorting' => $this->sorting, 'amount' => $this->amount, 'filter' => $this->filter, 'template' => $this->template); // assign block vars and fetched data $this->view->assign('vars', $data)->assign('objectType', $this->objectType)->assign('items', $entities)->assign($repository->getAdditionalTemplateParameters('contentType')); $output = ''; if (!empty($this->template) && $this->view->template_exists('contenttype/' . $this->template)) { $output = $this->view->fetch('contenttype/' . $this->template); } $templateForObjectType = str_replace('itemlist_', 'itemlist_' . ucwords($this->objectType) . '_', $this->template); if ($this->view->template_exists('contenttype/' . $templateForObjectType)) { $output = $this->view->fetch('contenttype/' . $templateForObjectType); } elseif ($this->view->template_exists('contenttype/' . $this->template)) { $output = $this->view->fetch('contenttype/' . $this->template); } else { $output = $this->view->fetch('contenttype/itemlist_display.tpl'); } return $output; }
public function getYoutubeVideos($channelId = '', $collectionId = 0) { $dom = ZLanguage::getModuleDomain($this->name); $youtubeApi = ModUtil::getVar($this->name, 'youtubeApi'); $collectionRepository = MUVideo_Util_Model::getCollectionRepository(); $collectionObject = $collectionRepository->selectById($collectionId); $api = self::getData("https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=" . $channelId . "&key=" . $youtubeApi); // https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCJC8ynLpY_q89tmNhqIf1Sg&key={YOUR_API_KEY} //$api = self::getData("https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId={DEINE_PLAYLIST_ID}&maxResults=10&fields=items%2Fsnippet&key=" . $youtubeApi); $videos = json_decode($api, true); $movieRepository = MUVideo_Util_Model::getMovieRepository(); $where = 'tbl.urlOfYoutube != \'' . DataUtil::formatForStore('') . '\''; // we look for movies with a youtube url entered $existingYoutubeVideos = $movieRepository->selectWhere($where); if ($existingYoutubeVideos && count($existingYoutubeVideos > 0)) { foreach ($existingYoutubeVideos as $existingYoutubeVideo) { $youtubeId = str_replace('https://www.youtube.com/watch?v=', '', $existingYoutubeVideo['urlOfYoutube']); $videoIds[] = $youtubeId; } } if (is_array($videos['items'])) { foreach ($videos['items'] as $videoData) { if (isset($videoData['id']['videoId'])) { if (isset($videoIds) && is_array($videoIds)) { if (in_array($videoData['id']['videoId'], $videoIds)) { continue; } } $serviceManager = ServiceUtil::getManager(); $entityManager = $serviceManager->getService('doctrine.entitymanager'); $newYoutubeVideo = new MUVideo_Entity_Movie(); $newYoutubeVideo->setTitle($videoData['snippet']['title']); $newYoutubeVideo->setDescription($videoData['snippet']['description']); $newYoutubeVideo->setUrlOfYoutube('https://www.youtube.com/watch?v=' . $videoData['id']['videoId']); $newYoutubeVideo->setWidthOfMovie('400'); $newYoutubeVideo->setHeightOfMovie('300'); $newYoutubeVideo->setWorkflowState('approved'); $newYoutubeVideo->setCollection($collectionObject); $entityManager->persist($newYoutubeVideo); $entityManager->flush(); LogUtil::registerStatus(__('The movie', $dom) . ' ' . $videoData['snippet']['title'] . ' ' . __('was created and put into the collection', $dom) . ' ' . $collectionObject['title']); } } } $redirectUrl = ModUtil::url($this->name, 'user', 'display', array('ot' => 'collection', 'id' => $collectionId)); return System::redirect($redirectUrl); }
function smarty_modifier_zikularoutesmodulePathToString($path, \Zikula\RoutesModule\Entity\RouteEntity $route) { $options = $route->getOptions(); $prefix = ''; if (isset($options['i18n_prefix'])) { $prefix = '/' . $options['i18n_prefix']; } if (!isset($options['i18n']) || $options['i18n']) { $languages = ZLanguage::getInstalledLanguages(); $isRequiredLangParam = ZLanguage::isRequiredLangParam(); if (!$isRequiredLangParam) { $defaultLanguage = System::getVar('language_i18n'); unset($languages[array_search($defaultLanguage, $languages)]); } if (count($languages) > 0) { $prefix = ($isRequiredLangParam ? "/" : "{/") . implode('|', $languages) . ($isRequiredLangParam ? "" : "}"); } } $prefix = \DataUtil::formatForDisplay($prefix); $path = \DataUtil::formatForDisplay($route->getPathWithBundlePrefix()); $container = \ServiceUtil::getManager(); $path = preg_replace_callback('#%(.*?)%#', function ($matches) use($container) { return "<abbr title=\"" . \DataUtil::formatForDisplay($matches[0]) . "\">" . \DataUtil::formatForDisplay($container->getParameter($matches[1])) . "</abbr>"; }, $path); $defaults = $route->getDefaults(); $requirements = $route->getRequirements(); $dom = ZLanguage::getModuleDomain('ZikulaRoutesModule'); $path = preg_replace_callback('#{(.*?)}#', function ($matches) use($container, $defaults, $requirements, $dom) { $title = ""; if (isset($defaults[$matches[1]])) { $title .= __f('Default: %s', array(\DataUtil::formatForDisplay($defaults[$matches[1]])), $dom); } if (isset($requirements[$matches[1]])) { if ($title != "") { $title .= " | "; } $title .= __f('Requirement: %s', array(\DataUtil::formatForDisplay($requirements[$matches[1]])), $dom); } if ($title == "") { return $matches[0]; } return "<abbr title=\"{$title}\">" . $matches[0] . "</abbr>"; }, $path); return "{$prefix}<strong>{$path}</strong>"; }
/** * Listener for the `user.account.delete` event. * * Occurs after a user is deleted from the system. * All handlers are notified. * The full user record deleted is available as the subject. * This is a storage-level event, not a UI event. It should not be used for UI-level actions such as redirects. * The subject of the event is set to the user record that is being deleted. * * @param Zikula_Event $event The event instance. */ public static function delete(Zikula_Event $event) { ModUtil::initOOModule('MUVideo'); $userRecord = $event->getSubject(); $uid = $userRecord['uid']; $serviceManager = ServiceUtil::getManager(); $entityManager = $serviceManager->getService('doctrine.entitymanager'); $repo = $entityManager->getRepository('MUVideo_Entity_Collection'); // set creator to admin (2) for all collections created by this user $repo->updateCreator($uid, 2); // set last editor to admin (2) for all collections updated by this user $repo->updateLastEditor($uid, 2); $repo = $entityManager->getRepository('MUVideo_Entity_Movie'); // set creator to admin (2) for all movies created by this user $repo->updateCreator($uid, 2); // set last editor to admin (2) for all movies updated by this user $repo->updateLastEditor($uid, 2); }
/** * Construct a new form data container instance, initializing the id value. * * @param string $formId A value for the form's id attribute. * @param Zikula_ServiceManager $serviceManager The current service manager instance. * * @throws InvalidArgumentException Thrown if the specified form id is not valid. */ public function __construct($formId, Zikula_ServiceManager $serviceManager = null) { if (!isset($serviceManager)) { $serviceManager = ServiceUtil::getManager(); } parent::__construct($serviceManager); $formId = trim($formId); if (!isset($formId) || !is_string($formId) || empty($formId)) { throw new InvalidArgumentException($this->__('Invalid form id.')); } elseif (!preg_match('/^[a-z][a-z0-9_]*$/', $formId)) { throw new InvalidArgumentException($this->__f('The form id \'%1$s\' contains invalid characters.', array($formId))); } $this->formId = $formId; $this->fieldIds = array(); $this->formFields = array(); }