Skip to content

Commit

Permalink
some code to Zend code standard
Browse files Browse the repository at this point in the history
  • Loading branch information
dmelo committed Jul 21, 2012
1 parent 77092b6 commit 28f5fe4
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 47 deletions.
53 changes: 39 additions & 14 deletions application/controllers/ApiController.php
Expand Up @@ -28,8 +28,13 @@ protected function _registerTracks($resultSet, $artist, $musicTitle)
$trackRow = $this->_trackModel->insert($data);


$artistMusicTitleId = $this->_artistMusicTitleModel->insert($artist, $musicTitle);
$this->_musicTrackLinkModel->bond($artistMusicTitleId, $trackRow->id, $this->_bondModel->search);
$artistMusicTitleId = $this->_artistMusicTitleModel
->insert($artist, $musicTitle);
$this->_musicTrackLinkModel->bond(
$artistMusicTitleId,
$trackRow->id,
$this->_bondModel->search
);

$row = $trackRow->getArray();
$row['artist'] = $artist;
Expand Down Expand Up @@ -63,11 +68,15 @@ public function searchAction()
$artist = $this->_request->getParam('artist');
$musicTitle = $this->_request->getParam('musicTitle');
$complement = null !== $artist && null !== $musicTitle ?
array('artist' => $artist, 'musicTitle' => $musicTitle) :
array('artist' => $artist, 'musicTitle' => $musicTitle):
array();
$resultSet = $this->_youtubeModel->search($q, $limit, $offset, $complement);
$resultSet = $this->_youtubeModel->search(
$q, $limit, $offset, $complement
);
if (!empty($complement))
$list = $this->_registerTracks($resultSet, $artist, $musicTitle);
$list = $this->_registerTracks(
$resultSet, $artist, $musicTitle
);
else
foreach ($resultSet as $result)
$list[] = $result->getArray();
Expand Down Expand Up @@ -99,16 +108,32 @@ public function searchsimilarAction()
$q = array();
$list = array();
$i = 0;
foreach ($this->_lastfmModel->getSimilar($artist, $musicTitle) as $row) {
foreach ($this->_lastfmModel->getSimilar($artist, $musicTitle) as
$row) {
$q[] = $row->name;
$resultSet = $this->_youtubeModel->search($row->name, $limit, $offset, array('artist' => $row->artist, 'musicTitle' => $row->musicTitle));
$this->_registerTracks($resultSet, $row->artist, $row->musicTitle);
$trackRow = $this->_musicTrackLinkModel->getTrack($row->artist, $row->musicTitle);
$list[] = array_merge($trackRow->getArray(), array('artist' => $row->artist, 'musicTitle' => $row->musicTitle));

$i++;
if ($i >= $titlesLimit)
break;
$resultSet = $this->_youtubeModel->search(
$row->name, $limit, $offset, array(
'artist' => $row->artist,
'musicTitle' => $row->musicTitle
)
);
$this->_registerTracks(
$resultSet, $row->artist, $row->musicTitle
);
$trackRow = $this->_musicTrackLinkModel->getTrack(
$row->artist, $row->musicTitle
);
$list[] = array_merge(
$trackRow->getArray(),
array(
'artist' => $row->artist,
'musicTitle' => $row->musicTitle
)
);

$i++;
if ($i >= $titlesLimit)
break;
}

$this->view->output = $list;
Expand Down
5 changes: 4 additions & 1 deletion application/controllers/IndexController.php
Expand Up @@ -16,7 +16,10 @@ class IndexController extends DZend_Controller_Action
* @return void
*/

public function __construct(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response, array $invokeArgs = array())
public function __construct(
Zend_Controller_Request_Abstract $request,
Zend_Controller_Response_Abstract $response,
array $invokeArgs = array())
{
parent::__construct($request, $response, $invokeArgs);

Expand Down
27 changes: 21 additions & 6 deletions application/controllers/PlaylistController.php
Expand Up @@ -93,20 +93,28 @@ public function addtrackAction()
($artist = $this->_request->getPost('artist')) !== null &&
($musicTitle = $this->_request->getPost('musicTitle')) !== null
) {
$artistMusicTitleId = $this->_artistMusicTitleModel->insert($artist, $musicTitle);
$artistMusicTitleId = $this->_artistMusicTitleModel
->insert($artist, $musicTitle);
$trackInfo['artist_music_title_id'] = $artistMusicTitleId;
}


$this->_logger->debug('PlaylistController::addtrackAction -- ' . print_r($trackInfo, true));
$this->_logger->debug(
'PlaylistController::addtrackAction -- ' .
print_r($trackInfo, true)
);
try {
$trackRow = $this->_playlistModel->addTrack(
$trackInfo,
$this->_request->getPost('playlist')
);

if (isset($artistMusicTitleId))
$this->_musicTrackLinkModel->bond($artistMusicTitleId, $trackRow->id, $this->_bondModel->insert_playlist);
$this->_musicTrackLinkModel->bond(
$artistMusicTitleId,
$trackRow->id,
$this->_bondModel->insert_playlist
);
$message = array(
$this->view->t('Track added'),
'success',
Expand Down Expand Up @@ -302,11 +310,18 @@ public function voteAction()
$message = array('Invalid request', 'error');
if (($trackId = $this->_request->getParam('track_id')) !== null &&
(($bond = $this->_request->getParam('bond')) !== null) &&
($artistMusicTitleId = $this->_request->getParam('artist_music_title_id')) !== null) {
if (null === $this->_musicTrackLinkModel->bond($artistMusicTitleId, $trackId, $this->_bondModel->{$bond}))
(
$artistMusicTitleId
= $this->_request->getParam('artist_music_title_id')
) !== null) {
if (null === $this->_musicTrackLinkModel->bond(
$artistMusicTitleId, $trackId, $this->_bondModel->{$bond}
))
$message = array('Error while registering vote', 'error');
else
$message = array('Vote saved!! Thank you for your help!', 'success');
$message = array(
'Vote saved!! Thank you for your help!', 'success'
);
};

$this->view->message = $message;
Expand Down
3 changes: 2 additions & 1 deletion application/models/DbTable/Artist.php
Expand Up @@ -2,7 +2,8 @@

class DbTable_Artist extends DZend_Model_DbTable
{
public function insert($data) {
public function insert($data)
{
return $this->insertWithoutException($data);
}
}
3 changes: 2 additions & 1 deletion application/models/DbTable/MusicTitle.php
Expand Up @@ -2,7 +2,8 @@

class DbTable_MusicTitle extends DZend_Model_DbTable
{
public function insert($data) {
public function insert($data)
{
try {
return parent::insert($data);
} catch(Zend_Db_Exception $e) {
Expand Down
9 changes: 6 additions & 3 deletions application/models/DbTable/PlaylistRow.php
Expand Up @@ -53,7 +53,8 @@ public function addTrack($trackInfo)
'track_id' => $trackRow->id,
'sort' => $maxSort + 1);
if (array_key_exists('artist_music_title_id', $trackInfo))
$data['artist_music_title_id'] = $trackInfo['artist_music_title_id'];
$data['artist_music_title_id']
= $trackInfo['artist_music_title_id'];
$this->_playlistHasTrackDb->insert($data);

return $trackRow;
Expand Down Expand Up @@ -83,8 +84,10 @@ public function getTrackListAsArray()
$list = $this->_playlistHasTrackDb->findByPlaylistId($this->id);
$ret = array();
foreach ($list as $item) {
$ret[] = array_merge($trackDb->findRowById($item->trackId)->getArray(),
array('artist_music_title_id' => $item->artistMusicTitleId));
$ret[] = array_merge(
$trackDb->findRowById($item->trackId)->getArray(),
array('artist_music_title_id' => $item->artistMusicTitleId)
);
}

return $ret;
Expand Down
9 changes: 8 additions & 1 deletion application/models/DbTable/TrackRow.php
Expand Up @@ -5,7 +5,14 @@ class DbTable_TrackRow extends DZend_Model_DbTableRow
public function getArray()
{
$columns = array(
'id', 'title', 'fid', 'fcode', 'url', 'cover', 'duration', 'youtubeUrl'
'id',
'title',
'fid',
'fcode',
'url',
'cover',
'duration',
'youtubeUrl'
);
$ret = array();
foreach ($columns as $column)
Expand Down
14 changes: 10 additions & 4 deletions application/models/MusicTrackLink.php
Expand Up @@ -15,7 +15,9 @@ public function bond($artistMusicTitleId, $trackId, $bondName)

$currentBondRow = null;
if (null !== $currentMusicTrackLinkRow) {
$currentBondRow = $this->_bondModel->findRowById($currentMusicTrackLinkRow->bondId);
$currentBondRow = $this->_bondModel->findRowById(
$currentMusicTrackLinkRow->bondId
);

// If the current bond has higher priority than the new bond,
// then don't do the new bond
Expand All @@ -40,14 +42,18 @@ public function bond($artistMusicTitleId, $trackId, $bondName)

public function getTrack($artist, $musicTitle)
{
$artistMusicTitleId = $this->_artistMusicTitleModel->insert($artist, $musicTitle);
$rowSet = $this->_musicTrackLinkDb->findByArtistMusicTitleId($artistMusicTitleId);
$artistMusicTitleId = $this->_artistMusicTitleModel->insert(
$artist, $musicTitle
);
$rowSet = $this->_musicTrackLinkDb->findByArtistMusicTitleId(
$artistMusicTitleId
);
$points = array();
foreach ($rowSet as $row) {
if (!array_key_exists($row->trackId, $points))
$points[$row->trackId] = 0;

switch ($row->bond_id) {
switch ($row->bondId) {
case 0: // search
$points[$row->trackId] += 1;
break;
Expand Down
3 changes: 2 additions & 1 deletion application/models/Playlist.php
Expand Up @@ -80,7 +80,8 @@ public function export($name)
);
} elseif (gettype($name) === 'integer') {
$playlistRow = $this->_playlistDb->findRowById($name);
if ($playlistRow->user_id !== $user->id && 'public' !== $playlistRow->privacy)
if ($playlistRow->userId !== $user->id
&& 'public' !== $playlistRow->privacy)
$playlistRow = null;
else
$this->_userListenPlaylistModel->addUserPlaylist($playlistRow);
Expand Down
24 changes: 22 additions & 2 deletions application/models/User.php
Expand Up @@ -87,7 +87,16 @@ public function sendActivateAccountEmail($userRow)
$session = DZend_Session_Namespace::get('session');
$mail = new Zend_Mail('UTF-8');

$mail->setBodyHtml($this->_translate->_("Hi %s,<br/><br/>Welcome to AMUZI. To activate your account just click on the link bellow:<br/><a href=\"%s\">%s</a><br/><br/>Enjoy!!<p>Best regards,<br/>AMUZI Team", $userRow->name, $userRow->getUrlToken(), $userRow->getUrlToken()));
$mail->setBodyHtml(
$this->_translate->_(
"Hi %s,<br/><br/>Welcome to AMUZI. To activate your account "
. "just click on the link bellow:<br/><a href=\"%s\">%s</a>"
. "<br/><br/>Enjoy!!<p>Best regards,<br/>AMUZI Team",
$userRow->name,
$userRow->getUrlToken(),
$userRow->getUrlToken()
)
);
$mail->setFrom('support@amuzi.net', 'AMUZI Team');
$mail->addTo($userRow->email);
$mail->setSubject($this->_translate->_("AMUZI -- Account activation"));
Expand All @@ -106,7 +115,18 @@ public function sendForgotPasswordEmail($userRow)
$session = DZend_Session_Namespace::get('session');
$mail = new Zend_Mail('UTF-8');

$mail->setBodyHtml($this->_translate->_("Hi %s,<br/><br/>Someone, hopefully you, requested a new password on AMUZI. To make a new password, please click the link bellow:<br/><br/><a href=\"%s\">%s</a><br/><br/>Best regards,<br/>AMUZI Team", $userRow->name, $userRow->getForgotPasswordUrl(), $userRow->getForgotPasswordUrl()));
$mail->setBodyHtml(
$this->_translate->_(
"Hi %s,<br/><br/>Someone, hopefully you, requested a new "
. "password on AMUZI. To make a new password, please click "
. "the link bellow:<br/><br/><a href=\"%s\">%s</a><br/><br/>"
. "Best regards,<br/>",
"AMUZI Team",
$userRow->name,
$userRow->getForgotPasswordUrl(),
$userRow->getForgotPasswordUrl()
)
);
$mail->setFrom('support@amuzi.net', 'AMUZI Team');
$mail->addTo($userRow->email);
$mail->setSubject(
Expand Down
39 changes: 27 additions & 12 deletions application/modules/Auth/controllers/IndexController.php
Expand Up @@ -97,28 +97,40 @@ public function registerAction()
$params = $this->_request->getParams();
if ($this->_request->isPost() && $form->isValid($params)) {
if ($params['password'] !== $params['password2'])
$message = array($this->view->t('Password doesn\'t match'), 'error');
elseif (($userRow = $this->_userModel->findByEmail($params['email'])) !== null)
$message = array($this->view->t('Email is already registered'), 'error');
$message = array(
$this->view->t('Password doesn\'t match'), 'error'
);
elseif (($userRow
= $this->_userModel->findByEmail($params['email'])) !== null)
$message = array(
$this->view->t('Email is already registered'), 'error'
);
else {
if(
if (
$this->_userModel->register(
$params['name'], $params['email'], $params['password']
) === true
) {
$userRow = $this->_userModel->findByEmail($params['email']);
if($this->_userModel->sendActivateAccountEmail($userRow)) {
$message = array($this->view->t('User registered. Check your email to activate your account.'), 'success');
if ($this->_userModel->sendActivateAccountEmail($userRow)) {
$message = array($this->view->t(
'User registered. Check your '
. 'email to activate your account.'
), 'success');
if (method_exists($userRow, 'postRegister'))
$userRow->postRegister();
}
else {
$message = array($this->view->t('An error occurred. It was not possible to send the email. Plase try again'), 'error');
} else {
$message = array($this->view->t(
'An error occurred. It was not possible to send '
. 'the email. Plase try again'
), 'error');
$this->_userModel->deleteByEmail($params['email']);
}
}
else
$message = array($this->view->t('Some error occurred, please try again'), 'error');
$message = array($this->view->t(
'Some error occurred, please try again'
), 'error');
}

if($message[1] !== 'success')
Expand All @@ -137,12 +149,15 @@ public function activateAction()

$userRow = $this->_userModel->findByEmail($email);
$message = null;
if(
if (
null === $userRow ||
'' === $userRow->token ||
$userRow->token !== $token
) {
$message = array($this->view->t('The email %s cannot be activated', $email), 'error');
$message = array(
$this->view->t('The email %s cannot be activated', $email),
'error'
);
} else {
$userRow->token = '';
$userRow->save();
Expand Down
2 changes: 1 addition & 1 deletion phpcs.sh
@@ -1,3 +1,3 @@
#!/bin/bash

phpcs --standard=Zend `find application/ locale/ tests/ library/DZend/ library/LightningPackerHelper/ | grep "\.php"` | less
phpcs --standard=Zend `find application/ locale/ tests/ library/DZend/ library/LightningPackerHelper/ | grep "\.php$"` | less

0 comments on commit 28f5fe4

Please sign in to comment.