/**
  * Add a custom genre to the database or get its key if it exists
  * @param name str: the name of the genre to add
  * @return     int: the primary key added or found
  */
 public function addGenre($name)
 {
     //trim whitespace
     $name = trim($name);
     if (empty($name)) {
         $name = 'Uncategorized';
     }
     //is this name already in the collection?
     if (is_numeric($name) && $name < 127) {
         $result = $this->find($name);
     }
     if (is_numeric($name) && $name > 126) {
         $name = 'Uncategorized';
     }
     $q = Doctrine_Query::create()->select('g.id')->from('Genre g')->where('g.name = ?', $name);
     $result = $q->fetchOne();
     if (is_object($result) && $result->id > 0) {
         $retId = $result->id;
         unset($q, $result);
         return $retId;
     } else {
         $item = new Genre();
         $item->name = $name;
         $item->save();
         $id = $item->getId();
         $item->free();
         unset($item, $q, $result);
         return $id;
     }
 }
 public function save()
 {
     try {
         $model = new Genre();
         $this->data->genre->entry = 'gen_' . $this->data->genre->entry;
         $model->setData($this->data->genre);
         $model->save();
         $this->renderPrompt('information', 'OK', "editEntry('{$this->data->genre->entry}');");
     } catch (\Exception $e) {
         $this->renderPrompt('error', $e->getMessage());
     }
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Genre();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Genre'])) {
         $model->attributes = $_POST['Genre'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      PropelPDO $con
  * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws     PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aMovie !== null) {
             if ($this->aMovie->isModified() || $this->aMovie->isNew()) {
                 $affectedRows += $this->aMovie->save($con);
             }
             $this->setMovie($this->aMovie);
         }
         if ($this->aGenre !== null) {
             if ($this->aGenre->isModified() || $this->aGenre->isNew()) {
                 $affectedRows += $this->aGenre->save($con);
             }
             $this->setGenre($this->aGenre);
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $criteria = $this->buildCriteria();
                 $pk = BasePeer::doInsert($criteria, $con);
                 $affectedRows += 1;
                 $this->setNew(false);
             } else {
                 $affectedRows += MoviesgenresPeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
Exemple #5
0
 private static function initGenres(Genre $gender)
 {
     $datas = array(array('id' => 1, 'name' => 'Hombre'), array('id' => 2, 'name' => 'Mujer'));
     foreach ($datas as $data) {
         $gender->create();
         $gender->save($data);
     }
     return true;
 }
 /**
  * @param string $genre
  * 
  * return Genre
  */
 protected function convertGenre($genre)
 {
     $oGenre = Genre::getByNefubName($genre);
     if (!$oGenre) {
         $oGenre = new Genre();
         $oGenre->name = ucfirst($genre);
         $oGenre->nefub_name = $genre;
         $oGenre->save();
         self::put('Nieuw genre ' . $oGender->Name . ' toegevoegd');
         $this->addedNefubObject($oGenre);
     }
     return $oGenre;
 }
Exemple #7
0
 public function executeProcessForm(sfWebRequest $request)
 {
     ini_set('display_errors', false);
     $data = array();
     $util = new Util();
     $data = $request->getPostParameter("data");
     $q = Doctrine_Query::create()->update('Movie')->set('name_org', '?', $data['name_org'])->set('director', '?', $data['director'])->set('rating', '?', $data['rating'])->set('plot', '?', $data['plot'])->where('id = ?', $data['id']);
     $rows = $q->execute();
     $movie = Doctrine::getTable('Movie')->findOneById($data['id']);
     //year
     if ($data['year'] == "") {
         $movie->Year = NULL;
         $movie->save();
     } else {
         $year_object = Doctrine::getTable('Year')->findOneByName($data['year']);
         if ($year_object == NULL) {
             $year_object = new Year();
             $year_object->name = $data['year'];
             $year_object->coverMo = $util->changePathSeparators($util->makePath(array(sfConfig::get('app_years_rel'), '_' . $util->unformatName($data['year']) . '.jpg')));
             $year_object->coverMu = $util->changePathSeparators($util->makePath(array(sfConfig::get('app_years_rel'), $util->unformatName($data['year']) . '.jpg')));
             $year_object->save();
         }
         $movie->Year = $year_object;
         $movie->save();
     }
     //country
     if ($data['country'] == "") {
         $movie->Country = NULL;
         $movie->save();
     } else {
         $country_object = Doctrine::getTable('Country')->findOneByName($data['country']);
         if ($country_object == NULL) {
             $country_object = new Country();
             $country_object->name = $data['country'];
             $country_object->cover = $util->changePathSeparators($util->makePath(array(sfConfig::get('app_countries_rel'), $util->unformatName($data['country']) . '.png')));
             $country_object->save();
         }
         $movie->Country = $country_object;
         $movie->save();
     }
     //genres
     foreach ($data['genres'] as $genre) {
         $genre_object = Doctrine::getTable('Genre')->findOneByName($genre);
         //if this not exist let's create it
         if ($genre_object == NULL) {
             $genre_object = new Genre();
             $genre_object->name = $genre;
             $genre_object->cover = $util->changePathSeparators($util->makePath(array(sfConfig::get('app_genres_rel'), $util->unformatName($genre) . '.jpg')));
             $genre_object->Movies[] = $movie;
             $genre_object->save();
         } else {
             //check if the movie already has such Genre
             $found = false;
             foreach ($movie['MovieGenre'] as $db_genre) {
                 if ($db_genre['Genre']['name'] == $genre) {
                     $found = true;
                 }
             }
             if ($found == false) {
                 $genre_object->Movies[] = $movie;
                 $genre_object->save();
             }
         }
     }
     //removing the db genres which are not in the request
     foreach ($movie['MovieGenre'] as $db_genre) {
         $found2 = false;
         foreach ($data['genres'] as $genre) {
             if ($db_genre['Genre']['name'] == $genre) {
                 $found2 = true;
             }
         }
         if ($found2 == false) {
             $q = Doctrine_Query::create()->delete('MovieGenre')->addWhere('movie_id = ?', $db_genre['movie_id'])->andWhere('genre_id = ?', $db_genre['genre_id']);
             $deleted = $q->execute();
         }
     }
     //actors
     foreach ($data['actors'] as $item) {
         $actor_object = Doctrine::getTable('Actor')->findOneByName($item['actor']);
         //if this not exist let's create it
         if ($actor_object == NULL) {
             $actor_object = new Actor();
             $actor_object->name = $item['actor'];
             $actor_object->cover = $util->changePathSeparators($util->makePath(array(sfConfig::get('app_actors_rel'), $util->unformatName($item['actor']) . '.jpg')));
             $actor_object->Movies[] = $movie;
             $actor_object->save();
             $q = Doctrine_Query::create()->from('MovieActor ma')->where('ma.movie_id = ?', $movie['id'])->andWhere('ma.actor_id = ?', $actor_object['id']);
             $movie_actor = $q->execute();
             $movie_actor[0]->role = $item['character'];
             $movie_actor[0]->save();
         } else {
             //check if the movie already has such Actor
             $found = false;
             foreach ($movie['MovieActor'] as $db_actor) {
                 if ($db_actor['Actor']['name'] == $item['actor']) {
                     $found = true;
                 }
             }
             if ($found == false) {
                 $movie_actor = new MovieActor();
                 $movie_actor->actor_id = $actor_object['id'];
                 $movie_actor->movie_id = $movie['id'];
                 $movie_actor->role = $item['character'];
                 $movie_actor->save();
             }
         }
     }
     //removing the db genres which are not in the request
     foreach ($movie['MovieActor'] as $db_actor) {
         $found2 = false;
         foreach ($data['actors'] as $item) {
             if ($db_actor['Actor']['name'] == $item['actor']) {
                 $found2 = true;
             }
         }
         if ($found2 == false) {
             $q = Doctrine_Query::create()->delete('MovieActor')->addWhere('movie_id = ?', $db_actor['movie_id'])->andWhere('actor_id = ?', $db_actor['actor_id']);
         }
         $deleted = $q->execute();
     }
     //var_dump($data);
     exit;
 }
Exemple #8
0
         $genre = new Genre();
         // obtengo valores de los atributos que necesito
         foreach ($xmlItem->attributes as $attrName => $attrValue) {
             if ($attrName == "id") {
                 $genre->setId($attrValue->nodeValue);
             }
             //
             if ($attrName == "name") {
                 $genre->setName($attrValue->nodeValue);
             }
             //
         }
         // estos grupos no se guardan en la database
         // deberian guardarse con activo=0 pero voy a skippear porque no se si la web lo toma en cuenta... je :S
         if ($genre->getId() != "15680" && $genre->getId() != "15679") {
             $saved = $genre->save($dbc, "generos");
             if ($saved === TRUE) {
                 $ok++;
             } else {
                 $error++;
                 $log->add("ERROR SQL: " . mysql_error());
             }
         } else {
             $skipped++;
             $log->add("Skipping group #" . $genre->getId());
         }
     } else {
         // no se pudo leer los datos del genero
         $log->add("ERROR: no se pudieron obtener datos del genero en: {$xmlName}");
     }
 }
 protected function parse()
 {
     $data = array();
     $details = $this->getResponseObject()->query('//*[@id="gameDetailsSection"]/div/ul[@class="fields"]')->item(0);
     if ($details) {
         $items = $this->nodeToXPath($details)->query('//li');
         if ($items->length > 0) {
             foreach ($items as $bundle_item) {
                 $val = $this->cleanData($bundle_item->nodeValue);
                 //pre($val);
                 //continue;
                 if (stristr($val, 'release')) {
                     $date = $this->parseValue($val, '/^.+:\\040?(.+)$/');
                     $data['release_date'] = date('Y-m-d H:i:s', strtotime($date));
                 } elseif (stristr($val, 'developer')) {
                     $data['developer'] = $this->parseValue($val, '/^.+:\\040?(.+)$/');
                 } elseif (stristr($val, 'publisher')) {
                     $data['publisher'] = $this->parseValue($val, '/^.+:\\040?(.+)$/');
                 } elseif (stristr($val, 'genre')) {
                     $genres = $this->parseValue($val, '/^.+:\\040?(.+)$/');
                     if ($genres) {
                         $data['genres'] = explode(',', $genres);
                     }
                 } elseif (stristr($val, 'size')) {
                     $val = $this->parseValue($val, '/^.+:\\040?(.+)$/');
                     $data['size'] = $this->parseSize($val);
                 }
             }
         }
         $data['description'] = $this->parseDescription();
         $data['price'] = $this->parsePrice();
         //$data['facebook_iframe_url'] = $this->parseFacebookIframeUrl();
         //pre($data,1);
         if (isset($data['developer'])) {
             $dobject = DeveloperModel::findOneByTitle($data['developer']);
             if (!$dobject) {
                 $dobject = new Developer();
                 $dobject->fromArray(array('title' => $data['developer']));
                 $developer_id = $dobject->save();
             } else {
                 $developer_id = $dobject->id;
             }
             $data['developer_id'] = $developer_id;
         }
         if (isset($data['publisher'])) {
             $dobject = PublisherModel::findOneByTitle($data['publisher']);
             if (!$dobject) {
                 $dobject = new Publisher();
                 $dobject->fromArray(array('title' => $data['publisher']));
                 $publisher_id = $dobject->save();
             } else {
                 $publisher_id = $dobject->id;
             }
             $data['publisher_id'] = $publisher_id;
         }
         $data = $this->cleanData($data);
         pre($data, 1);
         $data['processed'] = 1;
         $this->content_object->fromArray($data);
         $this->content_object->save();
         if (isset($data['genres'])) {
             // remove old genres associations
             $res = ContentToGenreModel::deleteByContentId($this->content_object->id);
             if ($res) {
                 foreach ($data['genres'] as $genre) {
                     $gobject = GenreModel::findOneByTitle($genre);
                     if (!$gobject) {
                         $gobject = new Genre();
                         $gobject->fromArray(array('title' => $genre));
                         $genre_id = $gobject->save();
                     } else {
                         $genre_id = $gobject->id;
                     }
                     $ctg = new ContentToGenre();
                     $ctg->fromArray(array('content_id' => $this->content_object->id, 'genre_id' => $genre_id));
                     $ctg->save();
                 }
             }
         }
     }
 }