1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-16 20:28:28 +01:00

Userclass fixes. Now clears userclass cache after changes in admin are made.

This commit is contained in:
Cameron 2015-05-12 13:53:47 -07:00
parent 3a238bf622
commit a708211cb3
6 changed files with 170 additions and 17 deletions

View File

@ -408,7 +408,7 @@ class frontpage
foreach($fp_settings as $order => $current_value)
{
$title = e107::getUserClass()->uc_get_classname($current_value['class']);
$title = e107::getUserClass()->getName($current_value['class']);
$text .= "
<tr>
<td class='left'>".$order."</td>

View File

@ -142,7 +142,7 @@ include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_'.e_PAGE);
public function afterCreate($new_data, $old_data, $id)
{
// do something
e107::getUserClass()->clearCache();
}
public function beforeUpdate($new_data, $old_data, $id)
@ -152,9 +152,15 @@ include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_'.e_PAGE);
public function afterUpdate($new_data, $old_data, $id)
{
// e107::getCache()->clear("wmessage");
e107::getUserClass()->clearCache();
}
public function afterDelete($data,$id)
{
e107::getUserClass()->clearCache();
}
public function onCreateError($new_data, $old_data)
{
// do something
@ -172,7 +178,7 @@ include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_'.e_PAGE);
$e_userclass->calc_tree();
$text = "<div id='userclass-tree-structure'>".$e_userclass->show_graphical_tree()."</div>";
return array('caption'=>'Class Structure', 'text' => $text);
return array('caption'=>'Class Structure', 'text' => $text); //TODO LAN
// $text .= $e_userclass->show_graphical_tree();
}
@ -326,7 +332,7 @@ include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_'.e_PAGE);
foreach ($irc as $i)
{
if (trim($i)) $icn[] = e107::getUserClass()->uc_get_classname($i);
if (trim($i)) $icn[] = e107::getUserClass()->getName($i);
}
$class_text = $frm->userclass('init_classes',$initial_classes, 'checkbox', 'classes,force');

View File

@ -313,7 +313,7 @@ class signup_shortcodes extends e_shortcode
}*/
$ret = $USERCLASS_SUBSCRIBE_START;
$ret .= $e_userclass->vetted_tree('class',array($this,show_signup_class),varset($signupData['user_class'],''),'editable, no-excludes');
$ret .= $e_userclass->vetted_tree('class',array($this,'show_signup_class'),varset($signupData['user_class'],''),'editable, no-excludes');
$ret .= $USERCLASS_SUBSCRIBE_END;
return $ret;
}
@ -321,12 +321,43 @@ class signup_shortcodes extends e_shortcode
function show_signup_class($treename, $classnum, $current_value, $nest_level)
{
global $USERCLASS_SUBSCRIBE_ROW, $e_userclass, $tp;
$tp = e107::getParser();
$uc = e107::getUserClass();
$frm = e107::getForm();
if(deftrue('BOOTSTRAP'))
{
$text = "<div class='checkbox'>";
$label = $tp->toHTML($uc->getName($classnum),false, 'defs');
$diz = $tp->toHTML($uc->getDescription($classnum),false,'defs');
$text .= $frm->checkbox('class[]', $classnum, $current_value, array('label'=>$label,'title'=> $diz, 'class'=>'e-tip'));
$text .= "</div>";
return $text;
}
global $USERCLASS_SUBSCRIBE_ROW;
$tmp = explode(',',$current_value);
$search = array('{USERCLASS_ID}', '{USERCLASS_NAME}', '{USERCLASS_DESCRIPTION}', '{USERCLASS_INDENT}', '{USERCLASS_CHECKED}');
$replace = array($classnum, $tp->toHTML($e_userclass->uc_get_classname($classnum), FALSE, 'defs'),
$tp->toHTML($e_userclass->uc_get_classdescription($classnum), FALSE, 'defs'), " style='text-indent:".(1.2*$nest_level)."em'",
( in_array($classnum, $tmp) ? " checked='checked'" : ''));
$shortcodes = array(
'USERCLASS_ID' => $classnum,
'USERCLASS_NAME' => $tp->toHTML($uc->getName($classnum),false, 'defs'),
'USERCLASS_DESCRIPTION' => $tp->toHTML($uc->getDescription($classnum),false,'defs'),
'USERCLASS_INDENT' => " style='text-indent:".(1.2*$nest_level)."em'",
'USERCLASS_CHECKED' => (in_array($classnum, $tmp) ? " checked='checked'" : '')
);
return $tp->simpleParse($USERCLASS_SUBSCRIBE_ROW, $shortcodes);
return str_replace($search, $replace, $USERCLASS_SUBSCRIBE_ROW);
}

View File

@ -1299,6 +1299,7 @@ class e_form
}
$labelClass = (!empty($options['inline'])) ? 'checkbox-inline' : 'checkbox';
$labelTitle = '';
$options = $this->format_options('checkbox', $name, $options);
@ -1308,9 +1309,22 @@ class e_form
$active = ($checked === true) ? " active" : ""; // allow for styling if needed.
if(!empty($options['label'])) // add attributes to <label>
{
if(!empty($options['title']))
{
$labelTitle = " title=\"".$options['title']."\"";
unset($options['title']);
}
if(!empty($options['class']))
{
$labelClass .= " ".$options['class'];
unset($options['class']);
}
}
$pre = (vartrue($options['label'])) ? "<label class='".$labelClass.$active."'>" : ""; // Bootstrap compatible markup
$pre = (vartrue($options['label'])) ? "<label class='".$labelClass.$active."'{$labelTitle}>" : ""; // Bootstrap compatible markup
$post = (vartrue($options['label'])) ? $options['label']."</label>" : "";
unset($options['label']); // not to be used as attribute;

View File

@ -991,6 +991,69 @@ class e_user_model extends e_admin_model
$this->_extended_model = null;
}
}
/**
* Add userclass to user and save.
* @param null $userClassId
* @return bool
*/
public function addClass($userClassId=null)
{
if(empty($userClassId))
{
return false;
}
$curClasses = explode(",", $this->getData('user_class'));
$curClasses[] = $userClassId;
$curClasses = array_unique($curClasses);
$insert = implode(",", $curClasses);
//FIXME - @SecretR - I'm missing something here with setCore() etc.
// $this->setCore('user_class',$insert );
// $this->saveDebug(false);
$uid = $this->getData('user_id');
return e107::getDb()->update('user',"user_class='".$insert."' WHERE user_id = ".$uid." LIMIT 1");
}
/**
* Remove a userclass from the user.
* @param null $userClassId
* @return bool
*/
public function removeClass($userClassId=null)
{
if(empty($userClassId))
{
return false;
}
$curClasses = explode(",", $this->getData('user_class'));
foreach($curClasses as $k=>$v)
{
if($v == $userClassId)
{
unset($curClasses[$k]);
}
}
$uid = $this->getData('user_id');
$insert = implode(",", $curClasses);
return e107::getDb()->update('user',"user_class='".$insert."' WHERE user_id = ".$uid." LIMIT 1");
}
}
// TODO - add some more useful methods, sc_* methods support

View File

@ -864,7 +864,7 @@ class user_class
* @param integer $id - class number. A negative number indicates 'not a member of...'
* @return string class name
*/
public function uc_get_classname($id)
public function getName($id)
{
$cn = abs($id);
$ucString = 'Class:'.$id; // Debugging aid - this should be overridden
@ -889,14 +889,17 @@ class user_class
/**
* Return class description for given class ID
* @param integer $id - class number. Must be >= 0
* @return string class description
*/
public function uc_get_classdescription($id)
public function getDescription($id)
{
if (isset($this->class_tree[$id]))
$id = intval($id);
if(isset($this->class_tree[$id]))
{
return $this->class_tree[$id]['userclass_description'];
}
@ -909,6 +912,33 @@ class user_class
/**
* BC Alias. of getName();
* @deprecated
* @param $id
* @return string
*/
public function uc_get_classname($id)
{
return $this->getName($id);
}
/**
* BC Alias of getDescription
* @deprecated
* @param $id
* @return mixed
*/
public function uc_get_classdescription($id)
{
return $this->getDescription($id);
}
/**
* Return class icon for given class ID
* @param integer $id - class number. Must be >= 0
@ -1031,6 +1061,16 @@ class user_class
}
return $ret;
}
/**
* Clear user class cache
* @return none
*/
public function clearCache()
{
e107::getCache()->clear_sys(UC_CACHE_TAG);
}
}
@ -1881,8 +1921,7 @@ class user_class_admin extends user_class
*/
public function clearCache()
{
$e107 = e107::getInstance();
$e107->ecache->clear_sys(UC_CACHE_TAG);
e107::getCache()->clear_sys(UC_CACHE_TAG);
}
}