Пример #1
0
 function div($x)
 {
     // test if internal x is valid and test if $x is valid
     if ($x == 0) {
         return YDResult::fatal('Argument cannot be zero', 0);
     }
     if ($this->a == 5) {
         return YDResult::fatal('Internal value cannot be five :D', 1);
     }
     // compute result value
     $result = $this->a / 10;
     // return a ok result
     return YDResult::ok('Div made with sucess!', $result);
 }
 /**
  *  This method will delete a category from db
  *
  *  @param $category_id   Category id
  *
  *  @returns    YDResult object
  */
 function deleteElement($category_id)
 {
     YDInclude('YDResult.php');
     $this->reset();
     $this->set('id', intval($category_id));
     $result = $this->delete();
     if ($result) {
         return YDResult::ok(t('forum category deleted'), $result);
     } else {
         return YDResult::fatal(t('impossible to delete forum category'), $result);
     }
 }
Пример #3
0
 /**
  *  This function creates an YDResult object and store it.
  *
  *  @param  $level    The error level.
  *  @param  $message  The error message.
  *  @param  $custom   (optional)
  *
  *  @returns     An YDResult object.
  *  
  *  @internal
  *  @static
  */
 function _result($level, $message, $custom = null)
 {
     // Get the current stack
     $stack = debug_backtrace();
     // Get level names
     $levels = YDConfig::get('YD_RESULT_LEVELS');
     // Get the complete stack trace
     $stacktrace = YD_CRLF;
     foreach (array_slice($stack, 1) as $t) {
         $stacktrace .= '    @ ';
         if (isset($t['file'])) {
             $stacktrace .= basename($t['file']) . ':' . $t['line'];
         } else {
             $stacktrace .= basename(YD_SELF_FILE);
         }
         $stacktrace .= ' -- ';
         if (isset($t['class'])) {
             $stacktrace .= $t['class'] . $t['type'];
         }
         $stacktrace .= $t['function'];
         if (isset($t['args']) && sizeof($t['args']) > 0) {
             $stacktrace .= '(...)';
         } else {
             $stacktrace .= '()';
         }
         $stacktrace .= YD_CRLF;
     }
     // Create the error object
     $error = new YDResult($level, $message, $stack[1]['file'], $stack[1]['line'], $stack[2]['class'] . $stack[2]['type'] . $stack[2]['function'], $stacktrace, $custom);
     // Store the error object on the global errors array
     YDConfig::set(YDConfig::get('YD_RESULT_STORE_NAME'), array_merge(YDResult::getAll(), array($error)));
     // If reporting for this level is on, dump the error
     if ($level <= YDConfig::get('YD_RESULT_REPORTING')) {
         echo $error->_dump(true, 2);
         if ($level == YD_RESULT_FATAL) {
             die;
         }
     }
     // Return the error object
     return $error;
 }
Пример #4
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'));
     }
 }
 /**
  *  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);
         }
     }
 }