public function afterUpdate($id, $data = null) { $artist = Artist::where('artistName', '=', $data['artist'])->where('ownerId', '=', Auth::user()->_id)->first(); if ($artist == null) { $artist = new Artist(); } $artist->artistName = $data['artist']; $artist->ownerId = Auth::user()->_id; $artist->ownerName = Auth::user()->firstname . ' ' . Auth::user()->lastname; $artist->save(); return $id; }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Artist(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Artist'])) { $model->attributes = $_POST['Artist']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
/** * Add an Artist to the database or get its key if it exists * @param name str: the name of the artist to add * @return int: the primary key added or found */ public function addArtist($name) { //is this name already in the collection? $q = Doctrine_Query::create()->select('a.id')->from('Artist a')->where('a.name = ?', $name); $result = $q->fetchOne(); if (is_object($result) && $result->id > 0) { $retId = $result->id; unset($q, $result); return (int) $retId; } else { $item = new Artist(); $item->name = $name; $item->save(); $id = $item->getId(); $item->free(); unset($item, $q, $result); return (int) $id; } }
//Calls the getInfo function on the given artist $searchArtists = $apiClass->getPackage($auth, 'artist'); $searchResults=$searchArtists->getInfo($methodVars); if ($searchResults) { //If the search results are valid add the artist $db_artist = Doctrine_Query::create() ->from('Artist a') ->where('a.name=?', array(trim($artist))) ->fetchOne(); if (!$db_artist) { //If we don't have it add it to the database' $db_artist = new Artist(); $db_artist['name'] = trim($artist); $db_artist['added_by_user_id'] = $_SESSION['user']['user_id']; $db_artist->save(); } //Link the artist to the album $userartist = Doctrine_Query::create() ->from('UserArtist a') ->where('a.user_id=? and a.artist_id=?', array($_SESSION['user']['user_id'],$db_artist['artist_id'])) ->fetchOne(); if (!$userartist) { $userartist = new UserArtist(); $userartist['user_id'] = $_SESSION['user']['user_id']; $userartist['artist_id'] = $db_artist['artist_id']; $userartist->save(); } //add the album $db_album = Doctrine_Query::create() ->from('Album a')
// ************************* // ************************* // OBTENGO DATOS DEL ARTISTA $log->add("getting artist id..."); if ($trackId != NULL) { $artist = new Artist(); $log->add("searching db for artist=" . $track->getArtistName()); $artist->loadFromName($dbc, $track->getArtistName()); if ($artist->getMaches() == "1") { $artistId = $artist->getId(); $log->add("found artist={$artistId}"); } else { $log->add("artist not found"); $log->add("saving new artist info..."); $artist->setName($track->getArtistName()); $savedArtist = $artist->save($dbc, "artistas"); if ($savedArtist == TRUE) { $artistId = $artist->getId(); $log->add("new artist found={$artistId}..."); } else { $artistId = NULL; $log->add("ERROR saving artist"); } } } // ************************* // ************************* // OBTENGO DATOS DEL ALBUM $log->add("getting album id..."); if ($artistId != NULL) { $album = new Album("brasil");
protected function icons_in_post($full_post) { $post = $full_post['.postmsg'][0]; if (strpos($post->html(), '<img') === false) { return array(); } $post_text = self::clean_up_post($post); $artist_name = $full_post['.postleft dt'][0]->text(); $post_imgs = $post['img.postimg']; if (empty($post_imgs)) { return array(); } $icons = self::find_icon_names_in_post($post_imgs, $post_text); $post_icons = array(); foreach ($icons as $img_src => $name) { $icon = Make::an('Icon')->like('src', $img_src)->first(); $changed = false; if (!$icon) { $icon = new Icon(); $icon->src = $img_src; $icon->theme_id = $this->theme->id; // TODO: make this DRYer too if ($artist_name) { $artist = Make::an('Artist')->like('name', $artist_name)->first(); if (!$artist) { $artist = new Artist(); $artist->name = $artist_name; $artist->save(); } $icon->setArtist($artist); } $changed = true; } if ($name && !$icon->app()) { $app = Make::an('App')->like('name', $name)->first(); if (!$app) { $app = new App(); $app->name = $name; $app->save(); } $icon->setApp($app); $changed = true; } if ($changed) { $icon->save(); } $post_icons[] = $icon; } /* $matches = array(); $maybe_names = array(); if (preg_match('/(([a-z0-9\-]{2,}), )+([a-z0-9\- ]{2,})/i', $post_text, $matches)) { $maybe_names = explode(',', $matches[0]); # [0] == entire match $maybe_names = array_map('trim', $maybe_names); } else { $w = self::WORD_REGEXP; $and_match = array(); if (preg_match('/'.$w.' and '.$w.'/iu', $post_text, $and_match)) { $maybe_names = explode(' and ', $and_match[0]); $maybe_names = array_map('trim', $maybe_names); } } if ($maybe_names) { foreach ($post_icons as &$post_icon) { $post_icon->maybe_names = array_merge($post_icon->maybe_names, $maybe_names); } } */ return $post_icons; }