Example #1
0
 public static function fromClass(AnnotationReader $reader, $className)
 {
     $class = new \ReflectionClass($className);
     if ($class->implementsInterface('HireVoice\\Neo4j\\EntityProxy')) {
         $class = $class->getParentClass();
         $className = $class->getName();
     }
     if (!($entity = $reader->getClassAnnotation($class, 'HireVoice\\Neo4j\\Annotation\\Entity'))) {
         throw new Exception("Class {$className} is not declared as an entity.");
     }
     $object = new self($class->getName());
     if ($entity->repositoryClass) {
         $object->repositoryClass = $entity->repositoryClass;
     }
     foreach ($class->getProperties() as $property) {
         $prop = new PropertyMeta($reader, $property);
         if ($prop->isPrimaryKey()) {
             $object->setPrimaryKey($prop);
         } elseif ($prop->isProperty($prop)) {
             $object->properties[] = $prop;
             if ($prop->isIndexed()) {
                 $object->indexedProperties[] = $prop;
             }
         } elseif ($prop->isRelationList()) {
             $object->manyToManyRelations[] = $prop;
         } elseif ($prop->isRelation()) {
             $object->manyToOneRelations[] = $prop;
         }
     }
     $object->validate();
     return $object;
 }
Example #2
0
 /**
  * @return bool
  */
 public function validate()
 {
     /** @var BinaryTreeNode $root */
     $root = $this->root;
     $valid = true;
     $left = $root->getLeft();
     if ($left) {
         if ($this->isMaxHeap() and $left->getData() > $root->getData()) {
             return false;
         }
         if (!$this->isMaxHeap() and $left->getData() < $root->getData()) {
             return false;
         }
         $leftTree = new self($left);
         $valid = $leftTree->validate();
     }
     $right = $root->getRight();
     if ($right) {
         if ($this->isMaxHeap() and $right->getData() > $root->getData()) {
             return false;
         }
         if (!$this->isMaxHeap() and $right->getData() < $root->getData()) {
             return false;
         }
         $rightTree = new self($right);
         $valid = $rightTree->validate();
     }
     return $valid;
 }
Example #3
0
 /**
  * Create a new theme instance from JSON file.
  *
  * @param  string $path
  * @return Raincolour\Containers\Theme
  */
 public static function make($path)
 {
     $theme = new self();
     $theme->fromFile($path);
     $theme->validate();
     return $theme;
 }
Example #4
0
 /**
  * Create a new pattern template from array.
  *
  * @param  array $data
  * @return Raincolour\Containers\Template
  */
 public static function make(array $data)
 {
     $template = new self();
     $template->setData($data);
     $template->validate();
     return $template;
 }
Example #5
0
 /**
  * Create a new Pattern instance from JSON file.
  *
  * @param  string $path
  * @return Raincolour\Containers\Pattern
  */
 public static function make($path)
 {
     $pattern = new self();
     $pattern->fromFile($path);
     $pattern->put('path', $path);
     $pattern->validate();
     $pattern->setTemplates();
     return $pattern;
 }
Example #6
0
 public static function saveRecord($user, $args)
 {
     $cart = new self(array("user_id" => $user->id, "centre_id" => $args['centre_id'], "service_id" => $args['service_id']));
     if ($cart->validate()) {
         $cart->save();
         return $cart;
     } else {
         return $cart->errors;
     }
 }
Example #7
0
 public static function check($value, array $validateData = NULL, array $fields = NULL)
 {
     static $self;
     if (!is_object($self)) {
         $self = new self();
     }
     $validateOptions = empty($validateData['validate']) ? array('notEmpty') : $validateData['validate'];
     $validateData['validate'] = is_array($validateOptions) ? $validateOptions : array($validateOptions);
     return $self->validate($value, $validateData, $fields);
 }
Example #8
0
 public static function addNew($params)
 {
     $model = new self();
     $model->load($params);
     if ($model->validate()) {
         $model->save();
         return $model->id;
     }
     return false;
 }
Example #9
0
 function insertRecords($data)
 {
     $oRecord = new self();
     foreach ($data as $k => $v) {
         $oRecord->{$k} = $v;
     }
     if ($oRecord->validate()) {
         return $oRecord->save();
     }
     tracevar($oRecord->getErrors());
 }
 /**
  * Validate address (domain)
  * 
  * @param $address (string) 
  * @return string
  */
 public static function validate_address($post)
 {
     $inst = new self();
     $inst->address = Arr::get($post, 'address');
     $inst->address_id = Arr::get($post, 'address_id');
     if ($inst->address && !$inst->address_id) {
         return "{$inst->validation['address']['label']} should be selected from the autocomplete";
     }
     $inst->validate();
     return $inst->valid ? '' : $inst->error->string;
 }
Example #11
0
 /**
  * Loads the guide with the specified version and language.
  * @param string $version
  * @param string $language
  * @return Guide the loaded guide, or null if the guide does not exist.
  */
 public static function load($version, $language, $type = 'guide')
 {
     if (!in_array($type, ['guide', 'blogtut'])) {
         return null;
     }
     $guide = new self($version, $language, $type);
     if ($guide->validate() && $guide->loadIndex()) {
         return $guide;
     } else {
         return null;
     }
 }
Example #12
0
 public static function login($params)
 {
     $model = new self();
     $model->attributes = $params;
     if ($model->validate()) {
         $tmp = static::findOne(['username' => $params['username']]);
         $tmp && ($model = $tmp);
         if (!$tmp || $tmp->password != static::hash($params['password'])) {
             $model->addError('error', Yii::t('app', 'Username Or Password error.'));
         }
     }
     return $model;
 }
Example #13
0
 /**
  * @param $tag
  * @param $rel
  *
  * @return HashtagRelevant|array|null
  */
 public static function add($tag, $rel)
 {
     $model = self::getByTagRel($tag, $rel);
     if ($model) {
         return $model;
     }
     $model = new self();
     $model->hashtag = $tag;
     $model->relevant = $rel;
     if ($model->validate()) {
         $model->save();
         return $model;
     }
     return null;
 }
Example #14
0
 /**
  * Validate post keywords for max length
  * 
  * @param $keywords (array) - ('lemon', 'apple', 'pear')
  * @return array - errors array
  */
 public static function validate_keywords($keywords)
 {
     $errors = array();
     foreach ($keywords as $keyword_key => $keyword_value) {
         $keyword = new self();
         $keyword->keyword = $keyword_value;
         $keyword->validate();
         if (!$keyword->valid) {
             foreach ($keyword->error->all as $err_key => $err_value) {
                 $errors[$keyword_key][$err_key] = $err_value;
             }
         }
     }
     return $errors;
 }
 /**
  * Check if a certain parameter is valid
  * @param string $name
  * @param mixed $value
  * @throws InvalidParameterTypeException
  * @throws InvalidStructureException
  * @throws UnexpectedParameterException
  */
 public function validateParam($name, $value)
 {
     $item = $this->structure->getItemByName($name);
     if ($item === null) {
         throw new UnexpectedParameterException();
     }
     if ($item instanceof StructureItem) {
         // Recursive validation
         $validator = new self($item->structure, $this->parameterDepthStack);
         $validator->validate($value);
     } else {
         if (!$item->validate($value)) {
             $e = new InvalidParameterTypeException();
             $e->expectedItem = $item;
             throw $e;
         }
     }
 }
Example #16
0
 /**
  * Adds batch of new heroes
  *
  * @author Dzianis Kotau <*****@*****.**>
  * @param array $data Heroes array
  * @return bool True if insert was successful, false otherwise
  */
 public function addHeroes(array $data)
 {
     if (empty($data)) {
         return false;
     }
     $rows = [];
     foreach ($data as $rowData) {
         $model = new self();
         $model->id = $rowData->{'id'};
         $model->name = $rowData->{'name'};
         $model->localized_name = $rowData->{'localized_name'};
         $model->active = true;
         if (!$model->validate()) {
             continue;
         }
         $rows[] = $model->attributes;
     }
     $rows = $this->uniqueMultiArray($rows, 'id');
     return !!Yii::$app->db->createCommand()->batchInsert(self::tableName(), $this->attributes(), $rows)->execute();
 }
Example #17
0
 /**
  * @param null $id
  * @param null $mail
  *
  * @return bool|null
  */
 public static function addLog($id = null, $mail = null)
 {
     if (!Yii::$app->request->getUserIP()) {
         return null;
     }
     $model = null;
     if ($id) {
         $model = self::getLog($id);
     }
     if (!$model) {
         $model = new self();
         $model->email = trim($mail);
         $model->ip = Yii::$app->request->getUserIP();
     }
     $model->created = date("Y-m-d H:i:s");
     if ($model->validate()) {
         $model->save();
         return true;
     }
     return false;
 }
Example #18
0
 /**
  * @param $tag
  *
  * @return Hashtag|null
  */
 public static function add($tag)
 {
     $tag = '#' . ltrim($tag, '#');
     $model = new self();
     $model->tag = $tag;
     $model->active = 1;
     $model->created = date("Y-m-d H:i:s");
     if ($model->validate()) {
         $model->save();
         return $model;
     }
     return null;
 }
Example #19
0
 public static function updateContests($controller)
 {
     $org = $controller->org;
     $fields = ['title', 'start', 'end'];
     $id = RequestMethods::post('contest_id');
     if ($id) {
         $contest = self::first(['_id' => $id, 'org_id' => $org->_id]);
     } else {
         $contest = new self(['org_id' => $org->_id]);
     }
     foreach ($fields as $f) {
         $contest->{$f} = RequestMethods::post($f);
     }
     // depending on the contest type process the fields
     $type = RequestMethods::post('type');
     switch ($type) {
         case 'clickRange':
             // process all the ranges
             $meta = $contest->meta;
             $oldCond = isset($meta['condition']) ? $meta['condition'] : [];
             $condition = [];
             $rangeStart = RequestMethods::post('rangeStart', []);
             $rangeEnd = RequestMethods::post('rangeEnd', []);
             $rangePrize = RequestMethods::post('rangePrize', []);
             for ($i = 0, $total = count($rangeStart); $i < $total; ++$i) {
                 $condition[] = ['start' => $rangeStart[$i], 'end' => $rangeEnd[$i], 'prize' => $rangePrize[$i]];
             }
             // prevent winners from being ovverriden
             if (count($oldCond) === count($condition)) {
                 $i = 0;
                 for ($i = 0, $total = count($condition); $i < $total; ++$i) {
                     if ($condition[$i]['start'] == $oldCond[$i]['start'] && $condition[$i]['end'] == $oldCond[$i]['end']) {
                         $condition[$i]['winners'] = isset($oldCond[$i]['winners']) ? $oldCond[$i]['winners'] : [];
                     }
                 }
             }
             $meta['condition'] = $condition;
             $contest->meta = $meta;
             break;
         case 'topEarner':
             $meta = $contest->meta;
             $condition = $meta['condition'];
             $condition['prize'] = RequestMethods::post('topEarnerPrize');
             $condition['topEarnerCount'] = RequestMethods::post('topEarnerCount');
             $meta['condition'] = $condition;
             $contest->meta = $meta;
             break;
         default:
             return array('message' => 'Invalid Request!!');
     }
     $contest->type = $type;
     if ($contest->validate()) {
         $contest->save();
         return array('message' => 'Contest Added successfully!!');
     } else {
         return array('message' => 'Please fill the required fields!!');
     }
 }
Example #20
0
 public static function validateMultiple(array $images, $model_id)
 {
     foreach ($images as $image) {
         $photo = new self();
         $photo->image = $image;
         $photo->name = $photo->image->getName();
         $photo->ad_id = $model_id;
         $photos[] = $photo;
         if (!$photo->validate()) {
             return $photo;
         }
     }
     return null;
 }
Example #21
0
 public static function addNew($type, $org, $view)
 {
     $fields = ['name', 'email', 'phone', 'password', 'country'];
     $user = new self(['country' => RequestMethods::server("HTTP_CF_IPCOUNTRY", "IN"), 'username' => RequestMethods::post("name", "USER"), 'currency' => 'USD', 'org_id' => $org->_id, 'type' => $type, 'live' => false]);
     foreach ($fields as $f) {
         $user->{$f} = RequestMethods::post($f, $user->{$f});
     }
     if (!$user->validate()) {
         $view->set("errors", $user->errors);
         return false;
     }
     $u = self::first(["email = ?" => $user->email, "org_id = ?" => $org->_id]);
     if ($u) {
         $view->set("message", "User already exists!!");
         $view->set('errors', ['email' => ['Duplicate Email']]);
         return false;
     }
     return $user;
 }
 /**
  * Generates a random password that is validated by all PasswordValidator
  * rules.
  * 
  * @return string Generated password
  */
 public static function generatePassword($minLen = 6, $maxLen = 18, $chars = '', $exclude = '0,1,o,O,l,L,i,I')
 {
     $length = rand($minLen, $maxLen);
     # exclude list
     $exclude = explode(',', $exclude);
     if ($chars === '') {
         # if chars are not manually set, use all chars from ASCII table
         # from DEC 33 to DEC 126
         for ($i = 33; $i <= 126; $i++) {
             # exclude confusing chars
             $chars .= !in_array(chr($i), $exclude) ? chr($i) : '';
         }
     }
     while (true) {
         $password = substr(str_shuffle($chars), 0, $length);
         $passwordValidation = new self($password, false);
         $errors = $passwordValidation->validate();
         if (!$errors) {
             return $password;
         }
     }
 }
Example #23
0
 /**
  * Загружает информацию по каналу с внешнего источника и сохраняет в базу
  * @param string $name
  * @return bool
  */
 public static function ImportChannel($name = '')
 {
     if ($name == '') {
         return ['res' => 'err', 'msg' => 'Name can not be empty'];
     }
     //$url = 'https://api.twitch.tv/kraken/channels/test_channel';
     $url = self::API_URL . DIRECTORY_SEPARATOR . self::GET_CHANNEL_PATH . DIRECTORY_SEPARATOR . $name;
     //echo'<pre>';print_r($url);echo'</pre>';//die;
     $raw_data = json_decode(DCurlHelper::getData($url), 1);
     //echo'<pre>';print_r($raw_data);echo'</pre>';die;
     if ($raw_data['status'] == 404) {
         return ['res' => 'err', 'msg' => $raw_data['message']];
     }
     if ($raw_data['mature'] === false) {
         $raw_data['mature'] = 0;
     }
     if ($raw_data['partner'] === false) {
         $raw_data['partner'] = 0;
     }
     $model = new self();
     $model->attributes = $raw_data;
     $model->id = $raw_data['_id'];
     //echo'<pre>';print_r($model->attributes);echo'</pre>';//die;
     //echo'<pre>';var_dump($model->validate());echo'</pre>';//die;
     if ($model->validate()) {
         $model->save();
     } else {
         foreach ($model->getFirstErrors() as $item) {
             return ['res' => 'err', 'msg' => $item];
             break;
         }
         /*
         //echo'<pre>';print_r($model->errors);echo'</pre>';die;
         echo'<pre>';print_r($model->getFirstErrors());echo'</pre>';die;
         echo'<pre>';print_r($model);echo'</pre>';die;
         return ['res'=>'err', 'msg' => $raw_data['message']];
         */
     }
     return ['res' => 'ok', 'msg' => 'Saved'];
 }
Example #24
0
 /**
  * Insert an array into the questions table
  * Returns null if insertion fails, otherwise the new QID
  *
  * @param array $data
  */
 function insertRecords($data)
 {
     // This function must be deprecated : don't find a way to have getErrors after (Shnoulle on 131206)
     $oRecord = new self();
     foreach ($data as $k => $v) {
         $oRecord->{$k} = $v;
     }
     if ($oRecord->validate()) {
         $oRecord->save();
         return $oRecord->qid;
     }
     tracevar($oRecord->getErrors());
 }
Example #25
0
 protected static function _save($user, $org, $opts)
 {
     $s = new self(["user_id" => $user->id, "organization_id" => $org->id, "day" => $opts['day'], "start" => $opts["start"], "end" => $value["end"], "capacity" => $opts['capacity']]);
     if ($s->validate()) {
         $s->save();
     }
 }
Example #26
0
 /**
  * Run validation rules on each passed custom form
  * return each model in array and errors if exist
  * 
  * @param $feeds (array) - key - form block id, value - array('title' => 'new title', 'link' => 'new link')
  * @return array (errors (array), models(array))
  */
 public static function validate_rss_custom_pack($feeds)
 {
     $errors = array();
     $models = array();
     foreach ($feeds as $feed_key => $feed_value) {
         $rss_feed = new self();
         $rss_feed->from_array($feed_value, array('title', 'link'));
         $rss_feed->validate();
         if (!$rss_feed->valid) {
             foreach ($rss_feed->error->all as $err_key => $err_value) {
                 $errors[$feed_key][$err_key] = $err_value;
             }
         }
         $models[] = $rss_feed;
     }
     return array($errors, $models);
 }
Example #27
0
 /**
  * Validate a form
  * Check Description / URL / post type and social networks fields
  *
  * @access public
  * @param $feeds
  * @return array
  */
 public static function validate_post($feeds)
 {
     $errors = array();
     $category_slug = $feeds['attachment_type'];
     $feeds['title'] = 'from ' . clear_domain(site_url());
     $post = new self();
     $post->from_array($feeds, array('description', 'url', 'posting_type', 'category_id'));
     if (!$post->posting_type) {
         $post->posting_type = 'immediate';
     }
     $post->validate();
     if (!$post->valid) {
         foreach ($post->error->all as $err_key => $err_value) {
             $errors[$err_key] = $err_value;
         }
     }
     if (isset($feeds['url'])) {
         if (!empty($feeds['url'])) {
             if (filter_var($feeds['url'], FILTER_VALIDATE_URL) === false || strstr($feeds['url'], '.') === false) {
                 $errors['url'] = lang('email_error');
             }
         }
     }
     if (!isset($feeds['post_to_socials'])) {
         $errors['post_to_groups[]'] = lang('socials_error');
     }
     if (isset($feeds['posting_type'])) {
         //validate Schedule date
         if ($feeds['posting_type'] != 'immediate') {
             $scheduled_errors = self::_validate_scheduled_data($feeds);
             $errors = array_merge($errors, $scheduled_errors);
         }
     }
     if ($category_slug == 'photos') {
         if (empty($feeds['image_name'])) {
             $errors['image_name'] = lang('image_error');
         }
     }
     if (!empty($feeds['post_to_socials']) && in_array('twitter', $feeds['post_to_socials'])) {
         $twitter_limit = array(1 => 140, 2 => 117, 3 => 94);
         $input_category = 1;
         $file = !empty($feeds['image_name']) || isset($feeds['file_name']);
         $link = !empty($feeds['url']);
         if ($file && $link) {
             $input_category = 3;
         } elseif ($file || $link) {
             $input_category = 2;
         }
         if (mb_strlen($feeds['description']) > $twitter_limit[$input_category]) {
             $errors['description'] = lang('twitter_error');
         }
     }
     if (!empty($feeds['post_to_socials']) && in_array('linkedin', $feeds['post_to_socials'])) {
         if (mb_strlen($feeds['description']) > 400) {
             $errors['description'] = lang('linkedin_error');
         }
     }
     if ($category_slug == 'videos') {
         $video_errors = self::_validate_video($feeds);
         $errors = array_merge($errors, $video_errors);
     } else {
         if (empty($feeds['url']) && isset($feeds['post_to_socials']) && in_array('linkedin', $feeds['post_to_socials'])) {
             $errors['url'] = lang('url_error');
         }
     }
     return $errors;
 }
Example #28
0
 /**
  * Adds batch of new leagues
  *
  * @author Dzianis Kotau <*****@*****.**>
  * @param array $data Leagues array
  * @return bool True if insert was successful, false otherwise
  */
 public function addLeagues(array $data)
 {
     $rows = [];
     foreach ($data as $rowData) {
         $model = new self();
         $model->id = $rowData->{'leagueid'};
         $model->name = $rowData->{'name'};
         $model->description = $rowData->{'description'};
         $model->tournament_url = $rowData->{'tournament_url'};
         $model->itemdef = empty($rowData->{'itemdef'}) ? 0 : $rowData->{'itemdef'};
         $model->is_finished = 0;
         if (!$model->validate()) {
             continue;
         }
         $rows[] = $model->attributes;
     }
     $rows = $this->uniqueMultiArray($rows, 'id');
     return !!Yii::$app->db->createCommand()->batchInsert(self::tableName(), $this->attributes(), $rows)->execute();
 }
Example #29
0
 public static function validateConfig()
 {
     $model = new self();
     return $model->validate();
 }
Example #30
0
 /**
  * Check if is a valid Binary Search Tree
  * @return bool
  */
 public function validate()
 {
     $valid = true;
     $root = $this->root;
     $left = $root->getLeft();
     if ($left) {
         if ($left->getData() > $root->getData()) {
             return false;
         }
         $leftTree = new self($left);
         $valid = $valid and $leftTree->validate();
     }
     $right = $root->getRight();
     if ($right) {
         if ($right->getData() < $root->getData()) {
             return false;
         }
         $rightTree = new self($right);
         $valid = $valid and $rightTree->validate();
     }
     return $valid;
 }