Version 5.0.6
This commit is contained in:
1 parent
a3a4a9ccbd
commit
b89858b2ff
1214 files changed
+92828
-14859
No files matched your search
@@ -14,7 +14,6 @@ namespace IPS\core\Achievements;
|
||||
|
||||
use DomainException;
|
||||
use Exception;
|
||||
use IPS\core\CustomBadge;
|
||||
use IPS\Data\Store;
|
||||
use IPS\Db;
|
||||
use IPS\File;
|
||||
@@ -25,6 +24,7 @@ use IPS\Helpers\Form\YesNo;
|
||||
use IPS\Image;
|
||||
use IPS\Lang;
|
||||
use IPS\Member;
|
||||
use IPS\Node\CustomBadge;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Patterns\ActiveRecord;
|
||||
use IPS\Settings;
|
||||
@@ -46,6 +46,8 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
*/
|
||||
class Badge extends Model
|
||||
{
|
||||
use CustomBadge;
|
||||
|
||||
/**
|
||||
* @brief Database Table
|
||||
*/
|
||||
@@ -170,6 +172,13 @@ class Badge extends Model
|
||||
|
||||
return static::$badgeAwardLangBits['core_award_' . $actor . '_badge_' . $ruleId] ?? NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Toggle off these fields when generating a custom badge
|
||||
*
|
||||
* @var array|string[]
|
||||
*/
|
||||
public static array $customBadgeToggles = [ 'badge_image' ];
|
||||
|
||||
/**
|
||||
* [Node] Add/Edit Form
|
||||
@@ -184,8 +193,7 @@ class Badge extends Model
|
||||
|
||||
$form->add( new Translatable( 'badge_name', NULL, TRUE, array( 'app' => 'core', 'key' => ( $this->id ? "core_badges_{$this->id}" : NULL ) ) ) );
|
||||
|
||||
$badge = CustomBadge::getRecordBadge( $this );
|
||||
$badge->addBadgeFieldsToForm( $form, !$this->badge_use_image, ['badge_image'] );
|
||||
parent::form( $form );
|
||||
|
||||
$form->add( new Upload( 'badge_image', $this->image ? File::get( 'core_Badges', $this->image ) : NULL, TRUE, array( 'obscure' => TRUE, 'checkImage' => TRUE, 'allowedFileTypes' => array_merge( Image::supportedExtensions(), ['svg'] ), 'storageExtension' => 'core_Badges', 'allowStockPhotos' => FALSE ), function( $val ) {
|
||||
if( !$val )
|
||||
@@ -209,8 +217,6 @@ class Badge extends Model
|
||||
}, null, null, 'badge_image' ) );
|
||||
|
||||
$form->add( new YesNo( 'badge_manually_awarded', $this->manually_awarded ) );
|
||||
|
||||
parent::form( $form );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -237,28 +243,16 @@ class Badge extends Model
|
||||
{
|
||||
$values[ mb_substr( $k, 6 ) ] = $v;
|
||||
}
|
||||
else if ( $k === 'badge_use_custom' )
|
||||
{
|
||||
$values['badge_use_image'] = !$v;
|
||||
if( !$values['badge_use_image'] )
|
||||
{
|
||||
$values['image'] = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$values[ $k ] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
/* Generate a custom SVG for this badge if we're not using a custom image */
|
||||
if ( ( !array_key_exists( 'badge_use_image', $values ) and !$this->badge_use_image ) or ( array_key_exists( 'badge_use_image', $values ) and !$values['badge_use_image'] ) )
|
||||
$values['badge_use_image'] = !$values['custombadge_use_custom'];
|
||||
if( !$values['badge_use_image'] )
|
||||
{
|
||||
CustomBadge::saveRecordBadge( $this, CustomBadge::generateBadgeFromFormValues( $values ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
CustomBadge::clearCustomBadgeFields( $values );
|
||||
$values['image'] = null;
|
||||
}
|
||||
|
||||
return $values;
|
||||
@@ -272,11 +266,17 @@ class Badge extends Model
|
||||
*/
|
||||
protected function get__icon(): mixed
|
||||
{
|
||||
if ( !$this->badge_use_image )
|
||||
if ( !$this->badge_use_image and $badge = $this->getRecordBadge() )
|
||||
{
|
||||
return CustomBadge::getRecordBadge( $this )->url();
|
||||
return $badge->file()->url;
|
||||
}
|
||||
return File::get( 'core_Badges', $this->image );
|
||||
|
||||
if( $this->image )
|
||||
{
|
||||
return File::get( 'core_Badges', $this->image );
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -598,14 +598,16 @@ class Badge extends Model
|
||||
* @return array
|
||||
* @apiresponse int id ID number
|
||||
* @apiresponse string name Name
|
||||
* @apiresponse array statistcs Badge Statistics
|
||||
* @apiresponse array statistics Badge Statistics
|
||||
*/
|
||||
public function apiOutput( Member $authorizedMember = NULL ): array
|
||||
{
|
||||
$stats = $this->getBadgeStats();
|
||||
|
||||
return array(
|
||||
'id' => $this->id,
|
||||
'name' => $this->_title,
|
||||
'statistics' => $this->getBadgeStats(),
|
||||
'statistics' => [ 'badgeCount' => $stats['badgeCount'][ $this->id ] ?? 0 ]
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user