Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting avatars and banners to doctrine and portable schema #29

Merged
merged 2 commits into from
Oct 8, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 28 additions & 9 deletions htdocs/modules/avatars/admin/avatar_custom.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@
$admin_page = new XoopsModuleAdmin();
$admin_page->renderNavigation('avatar_custom.php');

$info_msg = array(sprintf(AvatarsLocale::ALERT_INFO_MIMETYPES , implode(", ", $mimetypes)), sprintf(AvatarsLocale::ALERT_INFO_MAXFILE , $upload_size / 1000), sprintf(AvatarsLocale::ALERT_INFO_PIXELS , $width, $height));
$info_msg = array(
sprintf(AvatarsLocale::ALERT_INFO_MIMETYPES, implode(", ", $mimetypes)),
sprintf(AvatarsLocale::ALERT_INFO_MAXFILE, $upload_size / 1000),
sprintf(AvatarsLocale::ALERT_INFO_PIXELS, $width, $height)
);

switch ($op) {

Expand Down Expand Up @@ -107,7 +111,8 @@
if (!$xoops->security()->check()) {
$xoops->redirect('avatar_custom.php', 3, implode('<br />', $xoops->security()->getErrors()));
}
$uploader_avatars_img = new XoopsMediaUploader(XOOPS_UPLOAD_PATH . '/avatars', $mimetypes, $upload_size, $width, $height);
$uploader_avatars_img =
new XoopsMediaUploader(XOOPS_UPLOAD_PATH . '/avatars', $mimetypes, $upload_size, $width, $height);
// Get avatar id
$avatar_id = $request->asInt('avatar_id', 0);
if ($avatar_id > 0) {
Expand All @@ -117,7 +122,7 @@
}
$error_msg = '';
$obj->setVars($_POST);
if (preg_match('/^\d+$/', $_POST["avatar_weight"]) == false){
if (preg_match('/^\d+$/', $_POST["avatar_weight"]) == false) {
$error_msg .= XoopsLocale::E_YOU_NEED_A_POSITIVE_INTEGER . '<br />';
$obj->setVar("avatar_weight", 0);
} else {
Expand All @@ -138,7 +143,7 @@
$file = $request->asStr('avatar_file', 'blank.gif');
$obj->setVar('avatar_file', 'avatars/' . $file);
}
if ($error_msg == ''){
if ($error_msg == '') {
if ($avatar_Handler->insert($obj)) {
$xoops->redirect('avatar_custom.php', 2, XoopsLocale::S_ITEM_SAVED);
}
Expand Down Expand Up @@ -169,8 +174,14 @@
unlink(XOOPS_UPLOAD_PATH . '/' . $file);
}
}
// Update member profil
$xoopsDB->query("UPDATE " . $xoopsDB->prefix('users') . " SET user_avatar='blank.gif' WHERE user_avatar='" . $file . "'");
// Update member profiles
$qb = $xoops->db()->createXoopsQueryBuilder();
$eb = $qb->expr();
$query = $qb->updatePrefix('users', 'u')
->set('u.user_avatar', 'blank.gif')
->where($eb->eq('u.user_avatar', ':file '))
->setParameter(':file', $file);
$result = $query->execute();
$xoops->redirect("avatar_custom.php", 2, XoopsLocale::S_ITEM_SAVED);
} else {
echo $xoops->alert('error', $obj->getHtmlErrors());
Expand All @@ -179,9 +190,17 @@
if ($avatar_id > 0) {
// Define Stylesheet
$xoops->theme()->addStylesheet('modules/system/css/admin.css');
$msg = '<div class="spacer"><img src="' . XOOPS_UPLOAD_URL . '/' . $obj->getVar('avatar_file', 's') . '" alt="" /></div><div class="txtcenter bold">' . $obj->getVar('avatar_name', 's') . '</div>' . XoopsLocale::Q_ARE_YOU_SURE_YOU_WANT_TO_DELETE_THIS_ITEM;
$msg = '<div class="spacer"><img src="' . XOOPS_UPLOAD_URL . '/'
. $obj->getVar('avatar_file', 's')
. '" alt="" /></div><div class="txtcenter bold">'
. $obj->getVar('avatar_name', 's') . '</div>'
. XoopsLocale::Q_ARE_YOU_SURE_YOU_WANT_TO_DELETE_THIS_ITEM;
// Display message
$xoops->confirm(array('ok' => 1, 'op' => 'delete', 'avatar_id' => $avatar_id), 'avatar_custom.php', $msg);
$xoops->confirm(
array('ok' => 1, 'op' => 'delete', 'avatar_id' => $avatar_id),
'avatar_custom.php',
$msg
);
} else {
$xoops->redirect('avatar_custom.php', 1, XoopsLocale::E_DATABASE_NOT_UPDATED);
}
Expand All @@ -201,4 +220,4 @@
}
break;
}
$xoops->footer();
$xoops->footer();
37 changes: 28 additions & 9 deletions htdocs/modules/avatars/admin/avatar_system.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@
$admin_page = new XoopsModuleAdmin();
$admin_page->renderNavigation('avatar_system.php');

$info_msg = array(sprintf(AvatarsLocale::ALERT_INFO_MIMETYPES , implode(", ", $mimetypes)), sprintf(AvatarsLocale::ALERT_INFO_MAXFILE , $upload_size / 1000), sprintf(AvatarsLocale::ALERT_INFO_PIXELS , $width, $height));
$info_msg = array(
sprintf(AvatarsLocale::ALERT_INFO_MIMETYPES, implode(", ", $mimetypes)),
sprintf(AvatarsLocale::ALERT_INFO_MAXFILE, $upload_size / 1000),
sprintf(AvatarsLocale::ALERT_INFO_PIXELS, $width, $height)
);

switch ($op) {

Expand Down Expand Up @@ -113,7 +117,8 @@
if (!$xoops->security()->check()) {
$xoops->redirect('avatar_system.php', 3, implode('<br />', $xoops->security()->getErrors()));
}
$uploader_avatars_img = new XoopsMediaUploader(XOOPS_UPLOAD_PATH . '/avatars', $mimetypes, $upload_size, $width, $height);
$uploader_avatars_img =
new XoopsMediaUploader(XOOPS_UPLOAD_PATH . '/avatars', $mimetypes, $upload_size, $width, $height);
// Get avatar id
$avatar_id = $request->asInt('avatar_id', 0);
if ($avatar_id > 0) {
Expand All @@ -123,7 +128,7 @@
}
$error_msg = '';
$obj->setVars($_POST);
if (preg_match('/^\d+$/', $_POST["avatar_weight"]) == false){
if (preg_match('/^\d+$/', $_POST["avatar_weight"]) == false) {
$error_msg .= XoopsLocale::E_YOU_NEED_A_POSITIVE_INTEGER . '<br />';
$obj->setVar("avatar_weight", 0);
} else {
Expand All @@ -144,7 +149,7 @@
$file = $request->asStr('avatar_file', 'blank.gif');
$obj->setVar('avatar_file', 'avatars/' . $file);
}
if ($error_msg == ''){
if ($error_msg == '') {
if ($avatar_Handler->insert($obj)) {
$xoops->redirect('avatar_system.php', 2, XoopsLocale::S_ITEM_SAVED);
}
Expand Down Expand Up @@ -175,8 +180,14 @@
unlink(XOOPS_UPLOAD_PATH . '/' . $file);
}
}
// Update member profil
$xoopsDB->query("UPDATE " . $xoopsDB->prefix('users') . " SET user_avatar='blank.gif' WHERE user_avatar='" . $file . "'");
// Update member profiles
$qb = $xoops->db()->createXoopsQueryBuilder();
$eb = $qb->expr();
$query = $qb->updatePrefix('users', 'u')
->set('u.user_avatar', 'blank.gif')
->where($eb->eq('u.user_avatar', ':file '))
->setParameter(':file', $file);
$result = $query->execute();
$xoops->redirect("avatar_system.php", 2, XoopsLocale::S_ITEM_SAVED);
} else {
echo $xoops->alert('error', $obj->getHtmlErrors());
Expand All @@ -185,9 +196,17 @@
if ($avatar_id > 0) {
// Define Stylesheet
$xoops->theme()->addStylesheet('modules/system/css/admin.css');
$msg = '<div class="spacer"><img src="' . XOOPS_UPLOAD_URL . '/' . $obj->getVar('avatar_file', 's') . '" alt="" /></div><div class="txtcenter bold">' . $obj->getVar('avatar_name', 's') . '</div>' . XoopsLocale::Q_ARE_YOU_SURE_YOU_WANT_TO_DELETE_THIS_ITEM;
$msg = '<div class="spacer"><img src="' . XOOPS_UPLOAD_URL . '/'
. $obj->getVar('avatar_file', 's')
. '" alt="" /></div><div class="txtcenter bold">'
. $obj->getVar('avatar_name', 's') . '</div>'
. XoopsLocale::Q_ARE_YOU_SURE_YOU_WANT_TO_DELETE_THIS_ITEM;
// Display message
$xoops->confirm(array('ok' => 1, 'op' => 'delete', 'avatar_id' => $avatar_id), 'avatar_system.php', $msg);
$xoops->confirm(
array('ok' => 1, 'op' => 'delete', 'avatar_id' => $avatar_id),
'avatar_system.php',
$msg
);
} else {
$xoops->redirect('avatar_system.php', 1, XoopsLocale::E_DATABASE_NOT_UPDATED);
}
Expand All @@ -207,4 +226,4 @@
}
break;
}
$xoops->footer();
$xoops->footer();
88 changes: 65 additions & 23 deletions htdocs/modules/avatars/class/avatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ public function __construct()
}

/**
* @param string $format
* get avatar_id
*
* @param string $format return format code
*
* @return mixed
*/
public function id($format = 'n')
Expand All @@ -59,7 +62,10 @@ public function id($format = 'n')
}

/**
* @param string $format
* get avatar_id
*
* @param string $format return format code
*
* @return mixed
*/
public function avatar_id($format = '')
Expand All @@ -68,7 +74,10 @@ public function avatar_id($format = '')
}

/**
* @param string $format
* get avatar_file
*
* @param string $format return format code
*
* @return mixed
*/
public function avatar_file($format = '')
Expand All @@ -77,7 +86,10 @@ public function avatar_file($format = '')
}

/**
* @param string $format
* get avatar_name
*
* @param string $format return format code
*
* @return mixed
*/
public function avatar_name($format = '')
Expand All @@ -86,7 +98,10 @@ public function avatar_name($format = '')
}

/**
* @param string $format
* get avatar_mimetype
*
* @param string $format return format code
*
* @return mixed
*/
public function avatar_mimetype($format = '')
Expand All @@ -95,7 +110,10 @@ public function avatar_mimetype($format = '')
}

/**
* @param string $format
* get avatar_created
*
* @param string $format return format code
*
* @return mixed
*/
public function avatar_created($format = '')
Expand All @@ -104,7 +122,10 @@ public function avatar_created($format = '')
}

/**
* @param string $format
* get avatar_display
*
* @param string $format return format code
*
* @return mixed
*/
public function avatar_display($format = '')
Expand All @@ -113,7 +134,10 @@ public function avatar_display($format = '')
}

/**
* @param string $format
* get avatar_weight
*
* @param string $format return format code
*
* @return mixed
*/
public function avatar_weight($format = '')
Expand All @@ -122,7 +146,10 @@ public function avatar_weight($format = '')
}

/**
* @param string $format
* get avatar_type
*
* @param string $format return format code
*
* @return mixed
*/
public function avatar_type($format = '')
Expand All @@ -133,7 +160,9 @@ public function avatar_type($format = '')
/**
* Set User Count
*
* @param int $value
* @param int $value user count
*
* @return void
*/
public function setUserCount($value)
{
Expand Down Expand Up @@ -171,15 +200,19 @@ public function __construct(XoopsConnection $db = null)
/**
* Fetch a row of objects from the database
*
* @param CriteriaElement|null $criteria
* @param bool $id_as_key
* @param CriteriaElement|null $criteria criteria object
* @param bool $id_as_key if true, use avatar_id as array key
*
* @return array
*/
public function getObjectsWithCount(CriteriaElement $criteria = null, $id_as_key = false)
{
$ret = array();
$limit = $start = 0;
$sql = 'SELECT a.*, COUNT(u.user_id) AS count FROM ' . $this->db->prefix('avatars_avatar') . ' a LEFT JOIN ' . $this->db->prefix('avatars_user_link') . ' u ON u.avatar_id=a.avatar_id';
$sql = 'SELECT a.*, COUNT(u.user_id) AS count FROM '
. $this->db->prefix('avatars_avatar') . ' a LEFT JOIN '
. $this->db->prefix('avatars_user_link')
. ' u ON u.avatar_id=a.avatar_id';
if (isset($criteria)) {
$sql .= ' ' . $criteria->renderWhere();
$sql .= ' GROUP BY a.avatar_id ORDER BY avatar_weight, avatar_id';
Expand All @@ -205,10 +238,11 @@ public function getObjectsWithCount(CriteriaElement $criteria = null, $id_as_key
}

/**
* Add user
* Add user to avatars_user_link
*
* @param int $avatar_id avatar id
* @param int $user_id user id
*
* @param int $avatar_id
* @param int $user_id
* @return bool
*/
public function addUser($avatar_id, $user_id)
Expand All @@ -220,23 +254,30 @@ public function addUser($avatar_id, $user_id)
}
$sql = sprintf("DELETE FROM %s WHERE user_id = %u", $this->db->prefix('avatars_user_link'), $user_id);
$this->db->query($sql);
$sql = sprintf("INSERT INTO %s (avatar_id, user_id) VALUES (%u, %u)", $this->db->prefix('avatars_user_link'), $avatar_id, $user_id);
$sql = sprintf(
"INSERT INTO %s (avatar_id, user_id) VALUES (%u, %u)",
$this->db->prefix('avatars_user_link'),
$avatar_id,
$user_id
);
if (!$this->db->query($sql)) {
return false;
}
return true;
}

/**
* Get User
* getUser - get avatars_user_link for an avatar
*
* @param AvatarsAvatar $avatar
* @param AvatarsAvatar $avatar avatar object
*
* @return array
*/
public function getUser(AvatarsAvatar $avatar)
{
$ret = array();
$sql = 'SELECT user_id FROM ' . $this->db->prefix('avatars_user_link') . ' WHERE avatar_id=' . $avatar->getVar('avatar_id');
$sql = 'SELECT user_id FROM ' . $this->db->prefix('avatars_user_link')
. ' WHERE avatar_id=' . $avatar->getVar('avatar_id');
if (!$result = $this->db->query($sql)) {
return $ret;
}
Expand All @@ -249,8 +290,9 @@ public function getUser(AvatarsAvatar $avatar)
/**
* Get a list of Avatars
*
* @param string $avatar_type
* @param string $avatar_display
* @param string $avatar_type 'C' for custom, 'S' for system
* @param bool $avatar_display display avatar
*
* @return array
*/
public function getListByType($avatar_type = null, $avatar_display = null)
Expand All @@ -272,4 +314,4 @@ public function getListByType($avatar_type = null, $avatar_display = null)
}
return $ret;
}
}
}