/** * Returns admin note object * * @param array data * @param RM_Account_iUser obWriter * @return RM_AdminNote_Object */ public function createNote($data = array(), RM_Account_iUser $obWriter) { if (!@$data['type'] && !@$data['type_no_action'] && !@$data['body']) { $res = new RM_Base_Result(); $res->error('at_least_one_field'); throw new RM_Validator_Exception($res); } if (isNull($obUser = M('User')->loadUserById(@$data['user_id']))) { $res = new RM_Base_Result(); $res->error('no_such_user'); throw new RM_Validator_Exception($res); } $arr = array(); $arr['writer_id'] = $obWriter->id(); $arr['user_id'] = $obUser->id(); if (@$data['type']) { $arr['type'] = (int) $data['type']; } if (@$data['type_no_action']) { $arr['type_no_action'] = (int) $data['type_no_action']; } if (@$data['body']) { $arr['body'] = $data['body']; } //$arr['is_done'] = 1; $arr['posted'] = M('Tools')->date()->dbDateTime(); return $this->_mapper->_storage('adminNote')->createObject($arr); }
/** * Enter description here... * * @param RM_User_Object $obUser * @param array $data * @return RM_User_Family_Decorator_Person | TRUE */ public function editPerson(RM_User_Object $obUser, &$data) { try { if (isNull($obPerson = M('User')->loadPersonById($data['id']))) { $obPerson = M('User')->createPerson(array()); $obPerson->user_id = $obUser->id(); } $data['sex'] = @$data['sex'] ? $data['sex'] : NULL; $data['birthday'] = @(!$data['y']) || @(!$data['m']) || @(!$data['d']) ? NULL : M('Date')->dbDate($data['y'] . '-' . $data['m'] . '-' . $data['d']); if (M('Date')->time() < M('Date')->time($data['birthday'])) { $res = new RM_Base_Result(); $res->error('not_exists_date'); throw new RM_Validator_Exception($res); } $map = qw2('d m y id'); foreach ($data as $name => $value) { if (!in_array($name, $map)) { $obPerson->{$name} = $value; } } $obPerson->save(); return TRUE; } catch (RM_Validator_Exception $e) { $err = iterFirst($e->getResult()->getErrors()); error($err['code'] == 'not_exists_date' ? L('user.' . $err['code']) : L('user.field') . ' "' . L('user.' . $err['place']) . '" ' . L('user.' . $err['code'])); return $obPerson; } }
/** * Checks can delete this object * * @return void **/ protected function _canDelete() { // нельзя удалить, если привязаны "дочерние" entities if (count($this->getQuestions()) > 0) { $res = new RM_Base_Result(); $res->error($this->type() . '_has_questions'); throw new RM_Validator_Exception($res); } }
/** * Add file to entity * * @param string $fileId * @param string $title */ public function addFile($fileId, $title = NULL) { if (isNull($file = $this->_root()->createFileFromUpload($title . date('YmdHis'), $fileId))) { $res = new RM_Base_Result(); $res->error('no_picture'); throw new RM_Validator_Exception($res); } if ($title) { $file->setTitle($title); } $file->save(); return $file; }
public function init($data) { if (isset($data['restrictions'])) { $this->_object->setRestrictionsArray($data['restrictions']); } if (isset($data['hide'])) { $this->_object->invisible($data['hide']); } if (isset($data['other'])) { $this->_object->grouping($data['other']); } $this->_object->setPropsArray($data); if (isset($data['values'])) { if (!$data['values']) { $res = new RM_Base_Result(); $res->error('specify_values'); throw new RM_Validator_Exception($res); } $this->_object->setValuesArray($data['values']); } // initialize default sort settings if undefined $this->_object->sort(); $this->_object->order(); }
/** * Return "error" result. Can be used in way: * return M('Base')->error(..)->error(..)->warning(..); * * @param code string Error code (@see RM_Base_iResult for details) * @param place string Error place (@see RM_Base_iResult for details) * @param extra hash Extra error info (@see RM_Base_iResult for details) * @return RM_Base_iResult */ public function error($code, $place = NULL, array $extra = NULL) { $res = new RM_Base_Result(); return $res->error($code, $place, $extra); }
/** * Deletes this object * * @return bool **/ public function delete() { // нельзя удалить, если привязаны "дочерние" entities if (count($this->getChildren()) > 0) { $res = new RM_Base_Result(); $res->error($this->type() . '_has_children'); throw new RM_Validator_Exception($res); } // нельзя удалить, если привязаны штрих-коды if (count($this->getBarcodes()) > 0) { $res = new RM_Base_Result(); $res->error('has_barcode'); throw new RM_Validator_Exception($res); } $result = parent::delete(); if ($result) { $this->resetTimeOfModification(); } return $result; }
/** * Description... * * @return void **/ public function addImage($filename) { if (isNull($file = $this->_root()->createFileFromRealFile($this->id() . md5(uniqid(rand())) . date('YmdHis'), $filename))) { $res = new RM_Base_Result(); $res->error('no_picture'); throw new RM_Validator_Exception($res); } $file->save(); @unlink($filename); return $file; }
/** * Creates user leave (отпуск). * * @param hash<prop:value> data User leave properties. Required are: date_from, date_to. * @param RM_User_Object obUser * @return RM_User_Leave */ public function createLeave(array $data, RM_User_Object $obUser) { if (isNull($obUser)) { $res = new RM_Base_Result(); $res->error('no_such_user', 'user_id'); throw new RM_Validator_Exception($res); } if (@$data['date_to'] && @$data['date_from'] && strtotime($data['date_to']) < strtotime($data['date_from'])) { $res = new RM_Base_Result(); $res->error('leave_wrong_date_interval', 'date_interval'); throw new RM_Validator_Exception($res); } $data['user_id'] = $obUser->id(); $data['cdate'] = M('Tools')->date()->dbDateTime(); $data['mdate'] = M('Tools')->date()->dbDateTime(); $obLeave = $this->_storage['leave']->createObject($data); return $obLeave; }
public function createShopType($data = array()) { if (!@$data['name']) { $res = new RM_Base_Result(); $res->error('type_name_not_specified'); throw new RM_Validator_Exception($res); } $arr = array(); $arr['name'] = $data['name']; if (@$data['search_radius']) { $arr['search_radius'] = $data['search_radius']; } return $this->_mapper->_storage('shop_type')->createObject($arr); }
/** * Enter description here... * */ protected function _validator($data) { $required_fields = array('name' => 'group_name_not_specified'); foreach ($required_fields as $field => $code) { if (!@$data[$field]) { $res = new RM_Base_Result(); $res->error($code); throw new RM_Validator_Exception($res); } } if (0 != intval(@$data['parent_id']) && isNull(M('User')->loadGroupById(intval(@$data['parent_id'])))) { $res = new RM_Base_Result(); $res->error('bad_parent_id'); throw new RM_Validator_Exception($res); } return TRUE; }
/** * Validates attributes and values * * @return void **/ protected function _validateAttributes() { $obBrick = $this->getBrick(); for ($i = 1; $i <= $this->_attribute_quantity; $i++) { unset($obAttribute); unset($obValue); if (isNull($obBrick) || !$this->{'a' . $i} || $this->{'a' . $i} && !$this->{'v' . $i}) { $this->{'a' . $i} = NULL; $this->{'v' . $i} = NULL; } else { if (!isNull($obBrick)) { if (isNull($obAttribute = M('Gpc')->loadAttributeById($this->{'a' . $i}))) { //$error = 'no_such_attributes'; $this->{'a' . $i} = NULL; $this->{'v' . $i} = NULL; } else { if (!$obBrick->isAttribute($obAttribute)) { //$error = 'no_attributes2brick'; $this->{'a' . $i} = NULL; $this->{'v' . $i} = NULL; } else { if (!$this->{'v' . $i}) { //$this->{'v'.$i} = NULL; $this->{'a' . $i} = NULL; $this->{'v' . $i} = NULL; } else { if ($this->{'v' . $i} !== $this->_propInitial('v' . $i)) { if (isNull($obValue = M('Gpc')->loadValueById($this->{'v' . $i}))) { //$error = 'no_such_values'; $this->{'a' . $i} = NULL; $this->{'v' . $i} = NULL; } else { if (!$obAttribute->isValue($obValue)) { //$error = 'no_values2attribute'; $this->{'a' . $i} = NULL; $this->{'v' . $i} = NULL; } } } } } } } } } if (isset($error)) { $res = new RM_Base_Result(); $res->error($error); throw new RM_Validator_Exception($res); } }
/** * Deletes this object * * @return bool **/ public function delete() { // нельзя удалить, если привязаны брики // You cannot delete object because there are bricks linked with this entity if (count($this->getBricks()) > 0) { $res = new RM_Base_Result(); $res->error('has_brick'); throw new RM_Validator_Exception($res); } // нельзя удалить, если привязаны штрих-коды // You cannot delete object because there are barcodes linked with this entity if (count($this->getBarcodes()) > 0) { $res = new RM_Base_Result(); $res->error('has_barcode'); throw new RM_Validator_Exception($res); } /* foreach($this->getBricks() as $obBrick) $obBrick->removeFlavour($this); foreach($this->getBarcodes() as $obBarcode) $obBarcode->removeFlavour($this);*/ return parent::delete(); }
/** * Deletes this object * * @return bool **/ public function delete() { // нельзя удалить, если привязан к атрибутам if (count($this->getAttributes()) > 0) { $res = new RM_Base_Result(); $res->error('value_has_attribute'); throw new RM_Validator_Exception($res); } if (parent::delete()) { // удалить master2slave зависимости $this->resetTimeOfModification(); return TRUE; } return FALSE; }
/** * Enter description here... * */ public function save() { if (!$this->is_deleted) { $this->is_deleted = 0; if (M('Date')->dbDate($this->birthday) == M('Date')->dbDate('xxx') && $this->birthday != '1970-01-01') { $res = new RM_Base_Result(); $res->error('not_empty', 'birthday'); throw new RM_Validator_Exception($res); } } if (!$this->is_animal) { $this->is_animal = 0; } if (!$this->is_panelist) { $this->is_panelist = 0; } parent::save(); }
/** * Checks and sets report category * * @param int category_id * @return void */ protected function _setCategory($category_id) { if (!$category_id) { $res = new RM_Base_Result(); $res->error('specify_category'); throw new RM_Validator_Exception($res); } $obCategory = M('Category')->loadCategoryById($category_id); if (isNull($obCategory)) { $res = new RM_Base_Result(); $res->error('no_such_category'); throw new RM_Validator_Exception($res); } $this->_mapper->access($this, 'WRITE'); $this->_brick['category'] = $obCategory; $this->invisible(array()); $this->grouping(array()); }
/** * Validate flavour type. * * @param string flavour_type * @return void **/ protected function _validateFlavourType($flavour_type) { if (!in_array($flavour_type, $this->flavour_types())) { //throw new RM_Base_Exception_BadUsage(__METHOD__."(): Flavour type not specified or wrong. `" . implode('` or `', $this->_flavour_types) . "` expected, `" . $flavour_type . "` given."); $res = new RM_Base_Result(); $res->error('wrong_flavour_type'); throw new RM_Validator_Exception($res); } }
/** * Deletes this object * * @return bool **/ public function delete() { // нельзя удалить, если привязан к брикам if (count($this->getBricks()) > 0) { $res = new RM_Base_Result(); $res->error('attribute_has_brick'); throw new RM_Validator_Exception($res); } if (parent::delete()) { // удалить все зависимости value // удалить master2slave зависимости // .... хотя это делать не нужно, потому как если нету привязки к брикам, то и value нельзя привязать $this->resetTimeOfModification(); return TRUE; } return FALSE; }
/** * Deletes this object * * @return bool **/ public function delete() { // нельзя удалить, если объект в стоплисте if ($this->stoplist == 1) { return FALSE; } // нельзя удалить, если привязаны штрих-коды // You cannot delete object because there are barcodes linked with this entity if (count($this->getBarcodes()) > 0) { $res = new RM_Base_Result(); $res->error('has_barcode'); throw new RM_Validator_Exception($res); } return parent::delete(); }