Esempio n. 1
0
 /**
  * Initialize form handler.
  *
  * This method takes care of all necessary initialisation of our data and form states.
  *
  * @param Zikula_Form_View $view The form view instance.
  *
  * @return boolean False in case of initialization errors, otherwise true.
  */
 public function initialize(Zikula_Form_View $view)
 {
     $result = parent::initialize($view);
     if ($result === false) {
         return $result;
     }
     if ($this->mode == 'create') {
         $modelHelper = new MUVideo_Util_Model($this->view->getServiceManager());
         if (!$modelHelper->canBeCreated($this->objectType)) {
             LogUtil::registerError($this->__('Sorry, but you can not create the collection yet as other items are required which must be created before!'));
             return $this->view->redirect($this->getRedirectUrl(null));
         }
     }
     $entity = $this->entityRef;
     // save entity reference for later reuse
     $this->entityRef = $entity;
     $entityData = $entity->toArray();
     if (count($this->listFields) > 0) {
         $helper = new MUVideo_Util_ListEntries($this->view->getServiceManager());
         foreach ($this->listFields as $listField => $isMultiple) {
             $entityData[$listField . 'Items'] = $helper->getEntries($this->objectType, $listField);
             if ($isMultiple) {
                 $entityData[$listField] = $helper->extractMultiList($entityData[$listField]);
             }
         }
     }
     // assign data to template as array (makes translatable support easier)
     $this->view->assign($this->objectTypeLower, $entityData);
     if ($this->mode == 'edit') {
         // assign formatted title
         $this->view->assign('formattedEntityTitle', $entity->getTitleFromDisplayPattern());
     }
     // everything okay, no initialization errors occured
     return true;
 }
Esempio n. 2
0
 /**
  * Initialize form handler.
  *
  * This method takes care of all necessary initialisation of our data and form states.
  *
  * @param Zikula_Form_View $view The form view instance.
  *
  * @return boolean False in case of initialization errors, otherwise true.
  */
 public function initialize(Zikula_Form_View $view)
 {
     $result = parent::initialize($view);
     if ($result === false) {
         return $result;
     }
     if ($this->mode == 'create') {
         $modelHelper = new MUVideo_Util_Model($this->view->getServiceManager());
         if (!$modelHelper->canBeCreated($this->objectType)) {
             LogUtil::registerError($this->__('Sorry, but you can not create the movie yet as other items are required which must be created before!'));
             return $this->view->redirect($this->getRedirectUrl(null));
         }
     }
     $entity = $this->entityRef;
     // assign identifiers of predefined incoming relationships
     // editable relation, we store the id and assign it now to show it in UI
     $this->relationPresets['collection'] = FormUtil::getPassedValue('collection', '', 'GET');
     if (!empty($this->relationPresets['collection'])) {
         $relObj = ModUtil::apiFunc($this->name, 'selection', 'getEntity', array('ot' => 'collection', 'id' => $this->relationPresets['collection']));
         if ($relObj != null) {
             $relObj->addMovie($entity);
         }
     }
     // save entity reference for later reuse
     $this->entityRef = $entity;
     $entityData = $entity->toArray();
     if (count($this->listFields) > 0) {
         $helper = new MUVideo_Util_ListEntries($this->view->getServiceManager());
         foreach ($this->listFields as $listField => $isMultiple) {
             $entityData[$listField . 'Items'] = $helper->getEntries($this->objectType, $listField);
             if ($isMultiple) {
                 $entityData[$listField] = $helper->extractMultiList($entityData[$listField]);
             }
         }
     }
     // assign data to template as array (makes translatable support easier)
     $this->view->assign($this->objectTypeLower, $entityData);
     if ($this->mode == 'edit') {
         // assign formatted title
         $this->view->assign('formattedEntityTitle', $entity->getTitleFromDisplayPattern());
     }
     // everything okay, no initialization errors occured
     return true;
 }
Esempio n. 3
0
 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);
 }
Esempio n. 4
0
 /**
  * This method provides a item list overview.
  *
  * @param string  $sort         Sorting field.
  * @param string  $sortdir      Sorting direction.
  * @param int     $pos          Current pager position.
  * @param int     $num          Amount of entries to display.
  * @param string  $tpl          Name of alternative template (to be used instead of the default template).
  * @param boolean $raw          Optional way to display a template instead of fetching it (required for standalone output).
  *
  * @return mixed Output.
  */
 public function view()
 {
     $legacyControllerType = $this->request->query->filter('lct', 'user', FILTER_SANITIZE_STRING);
     System::queryStringSetVar('type', $legacyControllerType);
     $this->request->query->set('type', $legacyControllerType);
     $controllerHelper = new MUVideo_Util_Controller($this->serviceManager);
     // parameter specifying which type of objects we are treating
     $objectType = 'movie';
     $utilArgs = array('controller' => 'movie', 'action' => 'view');
     $permLevel = $legacyControllerType == 'admin' ? ACCESS_ADMIN : ACCESS_READ;
     $this->throwForbiddenUnless(SecurityUtil::checkPermission($this->name . ':' . ucfirst($objectType) . ':', '::', $permLevel), LogUtil::getErrorMsgPermission());
     $entityClass = $this->name . '_Entity_' . ucfirst($objectType);
     $repository = $this->entityManager->getRepository($entityClass);
     $repository->setControllerArguments(array());
     $viewHelper = new MUVideo_Util_View($this->serviceManager);
     // parameter for used sorting field
     $sort = $this->request->query->filter('sort', '', FILTER_SANITIZE_STRING);
     if (empty($sort) || !in_array($sort, $repository->getAllowedSortingFields())) {
         $sort = $repository->getDefaultSortingField();
     }
     // parameter for used sort order
     $sortdir = $this->request->query->filter('sortdir', '', FILTER_SANITIZE_STRING);
     $sortdir = strtolower($sortdir);
     if ($sortdir != 'asc' && $sortdir != 'desc') {
         $sortdir = 'asc';
     }
     // convenience vars to make code clearer
     $currentUrlArgs = array();
     $where = '';
     $selectionArgs = array('ot' => $objectType, 'where' => $where, 'orderBy' => $sort . ' ' . $sortdir);
     $showOwnEntries = (int) $this->request->query->filter('own', $this->getVar('showOnlyOwnEntries', 0), FILTER_VALIDATE_INT);
     $showAllEntries = (int) $this->request->query->filter('all', 0, FILTER_VALIDATE_INT);
     if (!$showAllEntries) {
         $csv = (int) $this->request->query->filter('usecsvext', 0, FILTER_VALIDATE_INT);
         if ($csv == 1) {
             $showAllEntries = 1;
         }
     }
     $this->view->assign('showOwnEntries', $showOwnEntries)->assign('showAllEntries', $showAllEntries);
     if ($showOwnEntries == 1) {
         $currentUrlArgs['own'] = 1;
     }
     if ($showAllEntries == 1) {
         $currentUrlArgs['all'] = 1;
     }
     // prepare access level for cache id
     $accessLevel = ACCESS_READ;
     $component = 'MUVideo:' . ucfirst($objectType) . ':';
     $instance = '::';
     if (SecurityUtil::checkPermission($component, $instance, ACCESS_COMMENT)) {
         $accessLevel = ACCESS_COMMENT;
     }
     if (SecurityUtil::checkPermission($component, $instance, ACCESS_EDIT)) {
         $accessLevel = ACCESS_EDIT;
     }
     $templateFile = $viewHelper->getViewTemplate($this->view, $objectType, 'view', array());
     $cacheId = $objectType . '_view|_sort_' . $sort . '_' . $sortdir;
     $resultsPerPage = 0;
     if ($showAllEntries == 1) {
         // set cache id
         $this->view->setCacheId($cacheId . '_all_1_own_' . $showOwnEntries . '_' . $accessLevel);
         // if page is cached return cached content
         if ($this->view->is_cached($templateFile)) {
             return $viewHelper->processTemplate($this->view, $objectType, 'view', array(), $templateFile);
         }
         // retrieve item list without pagination
         $entities = ModUtil::apiFunc($this->name, 'selection', 'getEntities', $selectionArgs);
     } else {
         // the current offset which is used to calculate the pagination
         $currentPage = (int) $this->request->query->filter('pos', 1, FILTER_VALIDATE_INT);
         // the number of items displayed on a page for pagination
         $resultsPerPage = (int) $this->request->query->filter('num', 0, FILTER_VALIDATE_INT);
         if ($resultsPerPage == 0) {
             $resultsPerPage = $this->getVar('pageSize', 10);
         }
         // set cache id
         $this->view->setCacheId($cacheId . '_amount_' . $resultsPerPage . '_page_' . $currentPage . '_own_' . $showOwnEntries . '_' . $accessLevel);
         // if page is cached return cached content
         if ($this->view->is_cached($templateFile)) {
             return $viewHelper->processTemplate($this->view, $objectType, 'view', array(), $templateFile);
         }
         // retrieve item list with pagination
         $selectionArgs['currentPage'] = $currentPage;
         $selectionArgs['resultsPerPage'] = $resultsPerPage;
         list($entities, $objectCount) = ModUtil::apiFunc($this->name, 'selection', 'getEntitiesPaginated', $selectionArgs);
         $this->view->assign('currentPage', $currentPage)->assign('pager', array('numitems' => $objectCount, 'itemsperpage' => $resultsPerPage));
     }
     foreach ($entities as $k => $entity) {
         $entity->initWorkflow();
     }
     // build ModUrl instance for display hooks
     $currentUrlObject = new Zikula_ModUrl($this->name, 'movie', 'view', ZLanguage::getLanguageCode(), $currentUrlArgs);
     // assign the object data, sorting information and details for creating the pager
     $this->view->assign('items', $entities)->assign('sort', $sort)->assign('sdir', $sortdir)->assign('pageSize', $resultsPerPage)->assign('currentUrlObject', $currentUrlObject)->assign($repository->getAdditionalTemplateParameters('controllerAction', $utilArgs));
     $modelHelper = new MUVideo_Util_Model($this->serviceManager);
     $this->view->assign('canBeCreated', $modelHelper->canBeCreated($objectType));
     // fetch and return the appropriate template
     return $viewHelper->processTemplate($this->view, $objectType, 'view', array(), $templateFile);
 }