Пример #1
0
 public function onSubscribeChanges(umiEventPoint $e)
 {
     static $is_called;
     if ($is_called === true) {
         return true;
     }
     $mode = (bool) getRequest('subscribe_changes');
     $users_module = cmsController::getInstance()->getModule("users");
     if ($user_id = $users_module->user_id) {
         $user = umiObjectsCollection::getInstance()->getObject($user_id);
         if ($user instanceof umiObject) {
             $topic_id = $e->getParam("topic_id");
             $subscribed_pages = $user->getValue("subscribed_pages");
             if ($mode) {
                 $topic = umiHierarchy::getInstance()->getElement($topic_id);
                 if ($topic instanceof umiHierarchyElement) {
                     if (!in_array($topic, $subscribed_pages)) {
                         $subscribed_pages[] = $topic_id;
                     }
                 }
             } else {
                 $tmp = array();
                 if (!is_array($subscribed_pages)) {
                     $subscribed_pages = array();
                 }
                 foreach ($subscribed_pages as $page) {
                     if ($page->getId() != $topic_id) {
                         $tmp[] = $page;
                     }
                 }
                 $subscribed_pages = $tmp;
                 unset($tmp);
             }
             $user->setValue("subscribed_pages", $subscribed_pages);
             $user->commit();
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Пример #2
0
 public function onModifyPropertyValue(umiEventPoint $e)
 {
     $object = $e->getRef('entity');
     $objectId = $object->getId();
     $objectType = umiObjectTypesCollection::getInstance()->getType($object->getTypeId());
     if ($objectType->getModule() != 'users' || $objectType->getMethod() != 'user') {
         return;
     }
     if ($e->getMode() == "before") {
         $newValue =& $e->getRef('newValue');
         switch ((string) $e->getParam('property')) {
             case 'name':
                 $newValue = $this->validateLogin($newValue, $objectId);
                 break;
             case 'e-mail':
                 $newValue = $this->validateEmail($newValue, $objectId);
                 break;
             default:
                 return;
         }
         $this->errorThrow('xml');
     }
     if ($e->getMode() == "after") {
         switch ((string) $e->getParam('property')) {
             case 'login':
                 $object->name = (string) $e->getParam('newValue');
                 $object->commit();
                 break;
             case 'name':
                 $object->login = (string) $e->getParam('newValue');
                 $object->commit();
                 break;
             default:
                 return;
         }
     }
 }