function postCreate(Request $request)
 {
     $data = $request->all();
     //SLUG
     $data[Production::ATTR_SLUG] = Util::createSlug($data[Production::ATTR_TITLE] . " " . $data[Production::ATTR_YEAR]);
     $data[Production::ATTR_STATE] = Production::STATE_IN_WAIT;
     $production = new Production();
     $production->fill($data);
     $production->save();
     //Asigna las Categorias
     foreach ($data as $index => $value) {
         if (strpos($index, "cat-") !== false) {
             $production->terms()->attach($value);
         }
     }
     /*
      * OBTIENES LAS IMAGENES DE LA PRODUCCION
      */
     $path_image = public_path("assets/db/images/") . md5($production->title_original . $production->year);
     copy($data[Production::ATTR_POSTER], $path_image . "-poster.jpg");
     $production->poster = Util::convertPathToUrl($path_image . "-poster.jpg");
     if (strlen($data[Production::ATTR_IMAGE]) > 9) {
         copy($data[Production::ATTR_IMAGE], $path_image . ".jpg");
         $production->image = Util::convertPathToUrl($path_image . ".jpg");
     } else {
         $title_md5 = md5($production->title_original . $production->year);
         $image = new Image($production->poster);
         $production->image = $image->createCopy(214, 334, $title_md5, public_path("assets/db/images/"), false);
     }
     $production->save();
     //Cola de procesamiento
     $queue = new QueueProductions();
     //Si existe
     if (QueueProductions::existsByLink($data["imdb"])) {
         $queue = QueueProductions::where(QueueProductions::ATTR_LINK, $data["imdb"])->get()[0];
     } else {
         $queue->name = $data[Production::ATTR_TITLE_ORIGINAL];
         $queue->link = $data["imdb"];
         $queue->date_creation = DateUtil::getCurrentTime();
     }
     $queue->production_id = $production->id;
     $queue->date_processed = DateUtil::getCurrentTime();
     $queue->save();
     return redirect("manager/productions/edit/" . $production->id);
 }
 function save()
 {
     if (!$this->validate()) {
         return null;
     }
     $production = new Production();
     $production->title = $this->getTitle();
     $production->title_original = $this->getTitle_original();
     $production->year = $this->getYear();
     $production->slug = $this->getSlug();
     $production->description = $this->getDescription();
     $production->state = is_null($this->getRating_rel()) ? Production::STATE_COMING_SOON : Production::STATE_IN_WAIT;
     $production->rating_rel = $this->getRating_rel();
     $production->duration = $this->getDuration();
     $production->image = $this->getImage();
     $production->poster = $this->poster;
     $production->save();
     //CATEGORIAS DE LA PRODUCCION
     $categories = $this->categories;
     foreach ($categories as $category) {
         //Verifica si ya existe la categoria, si no existe la crea y la asigna a la produccion
         $cat = Term::searchByName($category);
         if (is_null($term = $cat)) {
             $term = new Term();
             $term->name = ucfirst(strtolower($category));
             $term->taxonomy_id = Production::TAXONOMY_ID;
             $term->slug = Util::createSlug($category);
             $term->save();
         }
         $production->terms()->attach($term->id);
     }
     //Relaciona un director con la producción a uno existente o lo crea sin o existe
     $director = $this->getDirector();
     $staff_director = is_null($person = Person::searchByName($director[0])) ? new Person() : $person;
     $staff_director->name = $director[0];
     $staff_director->slug = Util::createSlug($director[0]);
     $staff_director->save();
     if (count(DB::select("SELECT * FROM staff WHERE production_id='" . $production->id . "' && person_id='" . $staff_director->id . "'")) == 0) {
         $staff_director->productions()->attach($production->id, array(Person::ATTR_PIVOT_ROLE => Person::ROLE_DIRECTOR));
     }
     //Determina si el nombre del director se encuentra en cola para actualización, si no lo esta, lo agrega.
     if (is_null(QueuePersons::searchByNameInQueue($director[0]))) {
         $queue = new QueuePersons();
         $queue->person_id = $staff_director->id;
         $queue->name = $director[0];
         $queue->link = $director[1];
         $queue->date_creation = DateUtil::getCurrentTime();
         $queue->save();
     }
     //Relaciona los actores con la produccion a uno existente o lo crea sino existe
     $actors = $this->actors;
     foreach ($actors as $actor) {
         if (is_null($actor[0]) || !isset($actor[0]) || strlen($actor[0]) == 0) {
             continue;
         }
         $staff_actor = is_null($person = Person::searchByName($actor[0])) ? new Person() : $person;
         $staff_actor->name = $actor[0];
         $staff_actor->slug = Util::createSlug($actor[0]);
         $staff_actor->save();
         if (count(DB::select("SELECT * FROM staff WHERE production_id='" . $production->id . "' && person_id='" . $staff_actor->id . "'")) == 0) {
             $staff_actor->productions()->attach($production->id, array(Person::ATTR_PIVOT_ROLE => Person::ROLE_ACTOR));
         }
         //Determina si el nombre del actor/actriz se encuentra en cola para actualización, si no lo esta, lo agrega.
         if (is_null(QueuePersons::searchByNameInQueue($actor[0]))) {
             $queue = new QueuePersons();
             $queue->person_id = $staff_actor->id;
             $queue->name = $actor[0];
             $queue->link = $actor[1];
             $queue->date_creation = DateUtil::getCurrentTime();
             $queue->save();
         }
     }
     return $production->id;
 }