Beispiel #1
0
 /**
  * Render a Category
  *
  * @param $id
  * @param $slug
  *
  * @return CategoryView
  */
 public function renderCategory($id, $slug)
 {
     $category = new Category($id);
     if (!$category->exists()) {
         return $this->renderNotFound();
     }
     /** @var CategoryView $view */
     $view = $this->getMapperView($category, 'CategoryView');
     $view->setCategory($category);
     return $this->setView($view);
 }
 public function renderDestroy()
 {
     $categoryId = $this->getInt('id');
     $articlesInCategory = Article::collection(['category_id' => $categoryId]);
     $videosInCategory = Video::collection(['category_id' => $categoryId]);
     if ($articlesInCategory->hasMappers() || $videosInCategory->hasMappers()) {
         Redirect::to('/' . $this->baseUri())->with('msg', new TransportMessage('error', 'Category cannot be deleted. Some Articles/Videos belong to it'))->now();
     } else {
         $category = new Category($categoryId);
         $category->delete();
         Redirect::to('/' . $this->baseUri())->with('msg', new TransportMessage('success', 'Category was successfully deleted'))->now();
     }
 }
Beispiel #3
0
 /**
  * @param string            $heading
  * @param  \Cubex\Form\Form $form
  */
 public function __construct($heading, $form)
 {
     $this->heading = $heading;
     $this->_form = $form;
     $this->_form->getElement('title')->setRequired(true);
     $this->_form->getElement('subTitle')->setRequired(true);
     $iconPicker = new IconPicker($this->_form->getElement('icon'));
     $this->_form->getElement('icon')->setId('icon-text')->addAttribute('style', 'width:160px')->setRenderer($iconPicker);
     $value = $this->_form->getElement('parentCategoryId')->rawData();
     $exception = [];
     if ($this->_form->getElement('id') !== null) {
         $id = $this->_form->getElement('id')->rawData();
         //child cannot be a parent of its parent
         $exception = Category::collection(['parent_category_id' => $id])->getUniqueField('id');
     }
     //grand children not allowed to be parents of grand parents
     $grandChildren = Category::collection()->whereIn('parent_category_id', $exception)->getUniqueField('id');
     $exception = array_merge($exception, $grandChildren);
     //category cannot be parent to itself
     $exception[] = $id;
     $options = Category::collection()->whereNotIn('id', $exception)->getKeyPair('id', 'title');
     $options = [0 => '-SELECT-'] + $options;
     $this->_form->addSelectElement('parentCategoryId', $options, $value);
     $this->_form->getElement('parentCategoryId')->setLabel('Parent Category');
     $this->requireCss('/main.css');
 }
Beispiel #4
0
 public function form()
 {
     if ($this->_form == null) {
         $this->_form = new Form('articleForm', '');
         $this->_form->setDefaultElementTemplate('{{input}}');
         $this->_form->addTextElement("title", $this->_article->title);
         $this->_form->getElement("title")->addAttribute('placeholder', 'Title');
         $this->_form->addTextElement("subTitle", $this->_article->subTitle);
         $this->_form->getElement("subTitle")->addAttribute('placeholder', 'Sub Title');
         $this->_form->addTextElement("slug", $this->_article->slug);
         $this->_form->getElement("slug")->addAttribute('placeholder', 'Slug');
         $viewOptions = $this->getArticle()->getViewOptions();
         array_unshift($viewOptions, "- SELECT -");
         $this->_form->addSelectElement('view', $viewOptions);
         $options = Category::collection()->getKeyPair('id', 'title');
         $this->_form->addSelectElement('categoryId', $options, $this->_article->categoryId);
         $this->_appendArticleSectionForm();
         if ($this->_article->exists()) {
             $this->_form->addHiddenElement('id', $this->_article->id());
             $this->_form->addSubmitElement('Update Article');
         } else {
             $this->_form->addSubmitElement('Create Article');
         }
         $this->_form->getElement("submit")->addAttribute('class', 'btn btn-success');
     }
     return $this->_form;
 }
Beispiel #5
0
 public function bindMapper(RecordMapper $mapper)
 {
     if ($mapper instanceof Video) {
         parent::bindMapper($mapper);
         $this->getElement('title')->addAttribute('class', 'input-xxlarge');
         $this->getElement('SubTitle')->addAttribute('class', 'input-xxlarge');
         $this->getElement('slug')->addAttribute('class', 'input-xxlarge');
         $this->getElement('imageUrl')->addAttribute('class', 'input-xxlarge');
         $this->getElement('submit')->addAttribute('class', 'btn btn-success');
         $this->getElement('url')->setLabel('Video URL')->addAttribute('class', 'input-xxlarge');
         $options = Category::collection()->getKeyPair('id', 'title');
         $this->addSelectElement('categoryId', $options, $mapper->categoryId);
         $this->getElement('categoryId')->setLabel('Category');
     } else {
         throw new \Exception('Only Video Mapper can be bound to this form');
     }
 }
Beispiel #6
0
 /**
  * Add videos
  *
  * @return $this
  */
 protected function _addVideos()
 {
     echo 'Adding Videos: ';
     $count = 0;
     $captionCount = 0;
     /** @var Category[] $categories */
     $categories = Category::collection();
     foreach ($categories as $category) {
         if (rand(1, 3)) {
             $videoTitles = $this->_getTitleArray('Video', rand(1, 3));
             foreach ($videoTitles as $videoTitle) {
                 $video = new Video();
                 $video->title = $videoTitle;
                 $video->slug = Strings::urlize($videoTitle);
                 $video->subTitle = $this->_getExampleContent(rand(3, 15));
                 $video->categoryId = $category->id();
                 $video->url = 'http://content.bitsontherun.com/videos/lWMJeVvV-364767.mp4';
                 $video->saveChanges();
                 // Add Annotations
                 $videoCaptionCount = rand(20, 30);
                 $i = 1;
                 $lastSecond = 0;
                 do {
                     $caption = new VideoCaption();
                     $caption->videoId = $video->id();
                     $caption->text = $this->_getExampleContent(rand(2, 6));
                     $caption->startSecond = $lastSecond;
                     $lastSecond += rand(3, 6);
                     $caption->endSecond = $lastSecond;
                     $caption->saveChanges();
                     $captionCount++;
                     $i++;
                 } while ($i <= $videoCaptionCount);
                 $count++;
             }
         }
     }
     echo sprintf('%d (%d Total Captions)%s', $count, $captionCount, PHP_EOL);
     return $this;
 }
Beispiel #7
0
 /**
  * @return \Cubex\Mapper\Database\RecordMapper[]|Category[]
  */
 public function getSiblingCategories()
 {
     $categories = Category::collection();
     return $categories->whereEq('parent_category_id', $this->parentCategoryId);
 }