Пример #1
0
 /**
  * Modelのエラーメッセージを取得
  * @return array
  */
 public function getErrorMessages()
 {
     foreach ($this->model->getMessages() as $msgs) {
         $errMsgs[] = $msgs->getMessage();
     }
     return $errMsgs;
 }
Пример #2
0
 public function showModelErrors(Model $model, Form $form)
 {
     foreach ($model->getMessages() as $message) {
         $fieldName = $message->getField();
         $form->addModelError($fieldName, $message->getMessage());
     }
 }
Пример #3
0
 /**
  * Recebe um model e une as excessões para retornar em texto
  * 
  * @param \Phalcon\Mvc\Model $model
  * @return string
  */
 public static function createModelErrorMessages(\Phalcon\Mvc\Model $model)
 {
     $excepts = [];
     foreach ($model->getMessages() as $message) {
         $excepts[] = $message;
     }
     return implode("\n", $excepts);
 }
Пример #4
0
 /**
  * 数据库操作异常
  * @param \Phalcon\Mvc\Model $model
  * @return bool
  */
 public function databaseErrorLog($model)
 {
     $error = '';
     foreach ($model->getMessages() as $msg) {
         $error .= $msg . ',';
     }
     $this->di->get('logger')->error('数据库异常, GET:' . json_encode($_GET) . ', POST:' . json_encode($_POST) . ', error: ' . $error);
     return false;
 }
Пример #5
0
 /**
  * 数据库操作异常
  * @param \Phalcon\Mvc\Model $model
  */
 public function logDatabaseError($model)
 {
     if ($this->di->offsetExists('logger') == false) {
         return;
     }
     $error = '';
     foreach ($model->getMessages() as $msg) {
         $error .= $msg . ',';
     }
     $this->di->get('logger')->error('数据库异常, GET:' . json_encode($_GET) . ', POST: ' . json_encode($_POST) . ', error: ' . $error);
 }
Пример #6
0
 public function delete()
 {
     foreach ($this->IgoListeValeur as $liste) {
         $liste->delete();
     }
     return parent::delete();
 }
Пример #7
0
 /**
  * Replace/translate default messages generated by the ORM.
  *
  * @return array
  */
 public function getMessages()
 {
     foreach (parent::getMessages() as $message) {
         switch ($message->getType()) {
             case 'PresenceOf':
                 $message->setMessage('The field ' . $message->getField() . ' is required');
                 break;
             case 'Uniqueness':
                 $message->setMessage('The field ' . $message->getField() . ' must be unique');
                 break;
             case 'Email':
                 $message->setMessage('The field ' . $message->getField() . ' must contain a valid email');
                 break;
             case 'Url':
                 $message->setMessage('The field ' . $message->getField() . ' must contain a valid url');
                 break;
             case 'InclusionIn':
                 $message->setMessage('The field ' . $message->getField() . ' must contain a value in [' . implode(',', $message->getDomain()) . ']');
                 break;
             case 'DateValidator':
                 $message->setMessage('The field ' . $message->getField() . ' must contain a valid date.');
                 break;
             case 'TimestampValidator':
                 $message->setMessage('The field ' . $message->getField() . ' must contain a valid timestamps.');
                 break;
         }
     }
     return parent::getMessages();
 }
Пример #8
0
 public static function __callStatic($name, $parameters = null)
 {
     if (0 === strpos($name, 'has')) {
         return static::hasColumnValue(Str::convertSnake(substr($name, 3)), $parameters[0]);
     }
     return parent::__callStatic($name, $parameters);
 }
Пример #9
0
 public function __set($property, $value)
 {
     if (is_object($property) || is_array($property)) {
         return parent::__set($property, $value);
     }
     $this->_dataAccess[$property] = $value;
 }
Пример #10
0
 public function __set($fieldName, $value)
 {
     // Check if the property is public
     try {
         $R = new \ReflectionClass($this);
         $property = $R->getProperty($fieldName);
     } catch (\ReflectionException $e) {
         // Property doesn't exist, call the stupid parent
         return parent::__set($fieldName, $value);
     }
     if ($property->isPublic()) {
         // Again, call your parents
         return parent::__set($fieldName, $value);
     } else {
         // Property exists, and it's private / protected
         try {
             // Maybe there is a setter for this one?
             $nameArr = explode('_', $fieldName);
             $methodName = 'set';
             foreach ($nameArr as $vv) {
                 $methodName .= ucwords($vv);
             }
             $method = $R->getMethod($methodName);
             // Okay, no exception, let's call it
             return $this->{$methodName}($value);
         } catch (\ReflectionException $up) {
             // Just let it go through
             throw $up;
         }
     }
 }
Пример #11
0
 public function delete()
 {
     foreach ($this->IgoGeometrie as $geometrie) {
         $geometrie->delete();
     }
     return parent::delete();
 }
Пример #12
0
 /**
  * Caches models data in memory
  *
  * @param mixed $parameters
  * @return $this
  */
 public static function findFirst($parameters = null)
 {
     // Create an unique key based on the parameters
     if ($key = self::createKey($parameters)) {
         $parameters['cache'] = ['key' => $key];
     }
     return parent::findFirst($parameters);
 }
Пример #13
0
 public static function findFirst($parameters = NULL, $hostType = NULL)
 {
     $class = get_called_class();
     $object = new $class();
     BaseModel::$tableName = $object->getSource();
     BaseModel::$hostType = $hostType;
     return parent::findFirst($parameters);
 }
Пример #14
0
 public function save($saveMapFile = true, $data = NULL, $whiteList = NULL)
 {
     $retour = parent::save($data, $whiteList);
     if ($saveMapFile && $this->IgoCouche->IgoGeometrie->acces == "L") {
         $this->IgoCouche->save();
     }
     return $retour;
 }
Пример #15
0
 /**
  * 重写validate方法
  * @param unknown $validator
  * @return boolean
  */
 protected function validate($validator)
 {
     parent::validate($validator);
     if ($this->validationHasFailed() == true) {
         return false;
     }
     return true;
 }
Пример #16
0
 /**
  * @param bool $bAsString
  * @return \Phalcon\Mvc\Model\MessageInterface[]|string
  */
 public function getMessages($bAsString = false)
 {
     if (!$bAsString) {
         return parent::getMessages();
     } else {
         return implode(', ', parent::getMessages());
     }
 }
Пример #17
0
 public function save($data = null, $whitelist = null)
 {
     $results = parent::save($data, $whitelist);
     // Update order of child entities
     if (isset($data['childSortOrder'])) {
         $this->updateChildSortOrder($data['childSortOrder']);
     }
     return $results;
 }
 public static function findFirstAsArray($id, $pullDocuments = false)
 {
     $p = parent::findFirst($id);
     $p = $p->toArray();
     if ($pullDocuments) {
         $p['documents'] = Documents::findByProjectId($id);
     }
     return $p;
 }
Пример #19
0
 public function delete()
 {
     $ref = new ReflectionClass($this);
     if ($ref->hasProperty('deleted_at')) {
         return $this->deleted_at ? true : $this->save(['deleted_at' => date('Y-m-d H:i:s')]);
     } else {
         return parent::delete();
     }
 }
Пример #20
0
 /**
  * model find
  * 
  * @param object $parameters parameters
  * 
  * @return array
  */
 public static function find($parameters = null)
 {
     $data = [];
     $temp = parent::find($parameters);
     foreach ($temp as $row) {
         $data[] = $row;
     }
     return $data;
 }
 public static function findByProjectId($projectId)
 {
     $documents = parent::findByProjectId($projectId);
     $documentsWithInfo = array();
     foreach ($documents as $d) {
         $information = DocumentsInformation::find(array("documentId=" . $d->id, "order" => "uploadDate DESC", "limit" => 3));
         $documentsWithInfo[$d->id] = $information->toArray();
     }
     return $documentsWithInfo;
 }
 public function save($data = null, $whiteList = null)
 {
     $this->_isNew = !isset($this->id);
     $data = $this->beforeSave($data);
     if (!is_array($data)) {
         return false;
     }
     $result = parent::save($data, $whiteList);
     $this->afterSave($data);
     return $result;
 }
Пример #23
0
 public static function findFirst($parameters = null)
 {
     if (!is_array($parameters) || !array_key_exists('cache', $parameters)) {
         if (is_array($parameters)) {
             $parameters['cache'] = array("key" => self::_createKey($parameters), "lifetime" => 3600);
         } else {
             $parameters = [$parameters, 'cache' => ["key" => self::_createKey($parameters), "lifetime" => 3600]];
         }
     }
     return parent::findFirst($parameters);
 }
Пример #24
0
 public function create($data = null, $whiteList = null)
 {
     if ($result = parent::create($data, $whiteList)) {
         return $result;
     } else {
         foreach ($this->getMessages() as $message) {
             echo $message->getMessage();
         }
         return $result;
     }
 }
Пример #25
0
 /**
  * @param int $key
  * @param int $delta
  */
 private function shiftLeftRight($key, $delta)
 {
     $owner = $this->getOwner();
     foreach (array($this->leftAttribute, $this->rightAttribute) as $attribute) {
         $condition = $attribute . '>=' . $key;
         if ($this->hasManyRoots) {
             $condition .= ' AND ' . $this->rootAttribute . '=' . $owner->{$this->rootAttribute};
         }
         $query = sprintf('UPDATE %s SET %s=%s+%d WHERE %s', $this->owner->getSource(), $attribute, $attribute, $delta, $condition);
         $this->owner->getWriteConnection()->execute($query);
     }
 }
Пример #26
0
 public function delete()
 {
     $response = array();
     if (parent::delete() == false) {
         foreach (parent::getMessages() as $message) {
             $response['errors'][] = (string) $message;
         }
     } else {
         $response['msg'] = 'ok';
     }
     return $response;
 }
Пример #27
0
 public function __call($method, $argument)
 {
     //Если геттера или сеттера нет - вызываем родительский
     if (!method_exists($this, 'set' . $method) && !method_exists($this, 'get' . $method)) {
         parent::__call($method, $argument);
     }
     if (boolval($argument)) {
         $newMethod = 'set' . $method;
         return $this->{$newMethod}($argument[0]);
     } else {
         $newMethod = 'get' . $method;
         return $this->{$newMethod}();
     }
 }
Пример #28
0
 public function getMessages($filter = null)
 {
     foreach (parent::getMessages() as $message) {
         switch ($message->getType()) {
             case 'Email':
                 $message->setMessage('Указан не действительный E-mail.');
                 break;
             case 'PresenceOf':
                 $message->setMessage('Поле "' . $this->getLabel($message->getField()) . '" должно быть заполнено');
                 break;
         }
     }
     return parent::getMessages();
 }
Пример #29
0
 /**
  * Initializer
  *
  * @param \Phalcon\Config $config Phalcon config
  * @return bool
  */
 public static function me(\Phalcon\Config $config)
 {
     // validate biller in config
     if (!isset($config['biller'])) {
         throw new \Exception('Entry for "biller" not found on config');
     }
     // validate stripe key
     if (!isset($config['biller']['key'])) {
         throw new \Exception('Stripe key not found on config');
     }
     // setup the stripe key
     \Stripe\Stripe::setApiKey($config['biller']['key']);
     // throw exceptions for customer, subscriptions models
     \Phalcon\Mvc\Model::setup(['exceptionOnFailedSave' => true]);
 }
Пример #30
0
 public static function buildFormFromModel(\Phalcon\Mvc\Model $model, array $extraFields = null)
 {
     if ($model->id) {
         $form = new Form($model);
     } else {
         $form = new Form();
     }
     $fields = [];
     foreach ($model->columnMap() as $column) {
         $metaDataTypes = $model->getModelsMetaData()->getDataTypes($model);
         if (!in_array($column, ['created_at', 'updated_at', 'id', 'password', 'remember_token'])) {
             if ($metaDataTypes[$column] != 6) {
                 $form->add(new Text($column));
             } else {
                 $form->add(new TextArea($column));
             }
             $fields[] = $column;
         }
     }
     if (null != $extraFields) {
         foreach ($extraFields as $column) {
             if (in_array($column, $model->columnMap())) {
                 continue;
             }
             $form->add(new Text($column));
             $fields[] = $column;
         }
     }
     $form->fields = $fields;
     if ($model->id) {
         $form->add(new Submit('修改'));
     } else {
         $form->add(new Submit('增加'));
     }
     return $form;
 }