コード例 #1
0
 /**
  *  This function updates a user password
  *
  *  @param $user_id     User id to update password
  *  @param $formvalues  (Otional) Custom array with 2 passwords (new and new_confirm)
  *
  *  @returns    YDResult object. OK      - password updated
  *                               WARNING - there are form errors
  *                               FATAL   - was not possible to update
  */
 function saveFormPassword($user_id, $formvalues = null)
 {
     // check form validation
     if (!$this->_form->validate($formvalues)) {
         return YDResult::warning(t('form errors'), $this->_form->getErrors());
     }
     // reset values
     $this->resetAll();
     // set new password
     $this->set('password', md5($this->_form->getValue('new')));
     $this->where('user_id = ' . intval($user_id));
     // update user and get result
     if ($this->update() == 1) {
         return YDResult::ok(t('ydcmuser mess password updated'));
     } else {
         return YDResult::fatal(t('ydcmuser mess password not updated'));
     }
 }
コード例 #2
0
 /**
  *  This method adds/saves a group
  *
  *  @param $id           If we are editing, $id is the group id. If we are adding, $id is the parent_id
  *  @param $edit         Boolean flag that defines if we are editing $id or adding to $id
  *  @param $formvalues   (Optional) Custom array with attributes
  *
  *  @returns    YDResult
  */
 function _saveFormDetails($id, $edit, $formvalues = null)
 {
     // check form validation
     if (!$this->_form->validate($formvalues)) {
         return YDResult::warning(t('form errors'), $this->_form->getErrors());
     }
     // get form values EXCLUDING spans
     $values = $this->_form->getValues();
     // check if we are editing or adding an element
     if ($edit) {
         // create userobject node
         $userobject = array();
         $userobject['type'] = 'YDCMGroup';
         $userobject['reference'] = $values['name'];
         $userobject['state'] = 1;
         // update userobject
         $uobj = new YDCMUserobject();
         $res = $uobj->updateNode($userobject, $id);
         // create user row
         $group = array();
         $group['name'] = $values['name'];
         $group['description'] = $values['description'];
         // update user
         $this->resetValues();
         $this->setValues($group);
         $this->where('group_id = ' . $id);
         // update and sum lines afected to userobject
         $res += $this->update();
         // if we are using the permission system, update and sum lines afected in permission table
         if (isset($this->editing_PERMOBJ)) {
             $res += $this->editing_PERMOBJ->saveFormEdit($id, $formvalues);
         }
         // check update from node update and from group update
         if ($res > 0) {
             return YDResult::ok(t('ydcmgroup mess details updated'), $res);
         } else {
             return YDResult::warning(t('ydcmgroup mess details not updated'), $res);
         }
     } else {
         // create userobject node
         $userobject = array();
         $userobject['type'] = 'YDCMGroup';
         $userobject['reference'] = $values['name'];
         $userobject['state'] = 1;
         // check default parent id
         if (is_null($id)) {
             $id = 1;
         }
         // TODO: check if group is valid (and, eg, is not a user node)
         // update userobject and get new id
         $uobj = new YDCMUserobject();
         $nodeID = $uobj->addNode($userobject, intval($id));
         // init result count
         $res = $nodeID;
         // if we are using the permission system, add permissions and sum lines afected in permission table
         if (isset($this->editing_PERMOBJ)) {
             $res += $this->editing_PERMOBJ->saveFormNew($id, $nodeID, $formvalues);
         }
         // create user row
         $group = array();
         $group['group_id'] = intval($nodeID);
         $group['name'] = $values['name'];
         $group['description'] = $values['description'];
         // reset object
         $this->resetAll();
         $this->setValues($group);
         // insert values
         if ($this->insert()) {
             return YDResult::ok(t('ydcmgroup mess created'), $res);
         } else {
             return YDResult::fatal(t('ydcmgroup mess impossible to create'), $res);
         }
     }
 }