Ejemplo n.º 1
0
 public function save()
 {
     $person = Person::where(Person::ATTR_NAME, $this->getName())->get()[0];
     $person->slug = Util::createSlug($person->name);
     $person->biography = $this->getBiography();
     $person->image = $this->getImage();
     $person->save();
 }
 /** Edita un atributo de una produccion mendiante ajax (manager/productions/ajax/post/edit/)
  * 
  * @param Request $request
  * @return boolean
  */
 function ajaxPostEdit(Request $request)
 {
     if (!$request->ajax()) {
         return;
     }
     $data = $request->all();
     $id = $data["id"];
     $attr = $data["attr"];
     $value = $data["value"];
     //Si es un titulo genera su slug
     if ($attr == Production::ATTR_TITLE) {
         $production = Production::find($id);
         $data[Production::ATTR_SLUG] = Util::createSlug($value . " " . $production->year);
         $production->slug = $data[Production::ATTR_SLUG];
     }
     DB::table("productions")->where("id", $id)->update([$attr => $value]);
     return json_encode($data);
 }
Ejemplo n.º 3
0
 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;
 }