Пример #1
0
 /**
  * [[@doctodo method_description:test]].
  *
  * @param [[@doctodo param_type:email]] $email      [[@doctodo param_description:email]]
  * @param boolean                       $hash_email [[@doctodo param_description:hash_email]] [optional]
  *
  * @return [[@doctodo return_type:test]] [[@doctodo return_description:test]]
  */
 public function test($email, $hash_email = true)
 {
     $original = $this->getDefaultImage();
     $this->setDefaultImage(404);
     $url = htmlspecialchars_decode($this->get($email, $hash_email));
     $this->setDefaultImage($original);
     $cacheKey = ['testGravatar', $url];
     $cache = Cacher::get($cacheKey);
     if ($cache) {
         return $cache;
     }
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, $url);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curl, CURLOPT_HEADER, false);
     curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
     $data = curl_exec($curl);
     $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     curl_close($curl);
     if (!$data || $httpCode !== 200) {
         $result = false;
     } else {
         $result = true;
     }
     Cacher::set($cacheKey, $result, 3600);
     return $result;
 }
Пример #2
0
 private function checkFailTaken($id, $headId)
 {
     $key = __CLASS__ . __FUNCTION__ . $id;
     $checkResult = Cacher::get($key);
     if (!empty($checkResult) && $checkResult !== $headId) {
         return true;
     }
     Cacher::set($key, $headId, 60 * 10);
     return false;
 }
Пример #3
0
 public function getForeignField($field, $options = [], $context = null)
 {
     $origFieldName = $field;
     $relationOptions = isset($options['relationOptions']) ? $options['relationOptions'] : [];
     $objectOptions = isset($options['objectOptions']) ? $options['objectOptions'] : [];
     $parts = explode(':', $field);
     $relationshipType = $parts[0];
     if (!in_array($relationshipType, ['child', 'children', 'descendants', 'parent', 'parents', 'ancestors'])) {
         if ($field === 'parent:Account') {
             \d(['hmmm']);
             exit;
         }
         return;
     }
     $myTypeItem = $this->objectTypeItem;
     $companionName = $parts[1];
     if (!is_array($context)) {
         $context = [];
     }
     if (!isset($context['relation'])) {
         $context['relation'] = [];
     }
     $fieldName = 'descriptor';
     if (!empty($parts[2])) {
         $fieldName = $parts[2];
         $parts[2] = '';
     }
     $fields = $this->getFields();
     $fieldCheck = implode(':', $parts);
     if (in_array($fieldCheck, $context['relation']) && empty($options['relationOptions']['taxonomy'])) {
         return;
     }
     if ($companionName === '_') {
         if (in_array($parts[0], ['parent', 'parents', 'ancestors'])) {
             $loopRelations = $myTypeItem->parents;
             $loopRelations = ArrayHelper::getColumn($loopRelations, 'parent');
         } else {
             $loopRelations = $myTypeItem->children;
             $loopRelations = ArrayHelper::getColumn($loopRelations, 'child');
         }
         ArrayHelper::multisort($loopRelations, 'priority', SORT_ASC);
         foreach ($loopRelations as $relatedType) {
             $fieldName = $relationshipType . ':' . $relatedType->systemId;
             if (isset($parts[2])) {
                 $fieldName .= ':' . $parts[2];
             }
             $fieldValue = $this->getForeignField($fieldName, $options, $context);
             if (!empty($fieldValue)) {
                 return $fieldValue;
             }
         }
         return;
     }
     $companionTypeItem = Yii::$app->collectors['types']->getOne($companionName);
     if (!$companionTypeItem || !$myTypeItem || !($companionType = $companionTypeItem->object) || !($myType = $myTypeItem->object)) {
         return;
     }
     if (in_array($relationshipType, ['child', 'children', 'descendants'])) {
         // I'm the parent
         $relationship = Relationship::has($myTypeItem, $companionTypeItem) ? Relationship::getOne($myTypeItem, $companionTypeItem) : false;
     } else {
         $relationship = Relationship::has($companionTypeItem, $myTypeItem) ? Relationship::getOne($companionTypeItem, $myTypeItem) : false;
     }
     if (!$relationship) {
         return;
     }
     $cacheKey = [__FUNCTION__, $this->primaryKey, $fieldCheck, $relationshipType, $relationOptions, $objectOptions];
     $result = false;
     // Cacher::get($cacheKey);
     if ($result === false) {
         if (isset($fields[$fieldCheck])) {
             $field = $fields[$fieldCheck];
             if (isset($field->attributes['taxonomy_id'])) {
                 $relationOptions['taxonomy'] = $field->attributes['taxonomy_id'];
             }
             $relationOptions['where'] = !empty($field->attributes) ? $field->attributes : null;
             unset($relationOptions['where']['taxonomy_id']);
             if (empty($relationOptions['where'])) {
                 unset($relationOptions['where']);
             }
         }
         $cacheDependencies = [];
         $cacheDependencies[] = $this->getRelationCacheDependency($this->primaryKey);
         $result = $this->{$relationshipType}($companionType->primaryModel, $relationOptions, $objectOptions);
         if (empty($result)) {
             $result = null;
         } else {
             $cacheDependencies[] = $result->getObjectCacheDependency();
         }
         Cacher::set($cacheKey, $result, 0, Cacher::chainedDependency($cacheDependencies));
     }
     if (empty($result)) {
         return;
     }
     if (is_array($result)) {
         $fields = [];
         foreach ($result as $object) {
             if ($this->isForeignObjectInContext($object, $context)) {
                 continue;
             }
             $field = $object->getField($fieldName);
             if (empty($field)) {
                 continue;
             }
             $companionType->loadFieldLink($field, $object);
             $fields[] = $field;
         }
         if (empty($fields)) {
             return;
         }
         return $fields;
     } else {
         if ($this->isForeignObjectInContext($result, $context)) {
             return;
         }
         $field = $result->getField($fieldName);
         if (empty($field)) {
             return;
         }
         $companionType->loadFieldLink($field, $result);
         return $field;
     }
     return;
 }
Пример #4
0
 /**
  * [[@doctodo method_description:clearStatusLogCache]].
  */
 public function clearStatusLogCache()
 {
     Cacher::set([get_called_class(), $this->primaryKey, $this->created], false, 3600);
 }
Пример #5
0
 /**
  * Get stats.
  *
  * @param [[@doctodo param_type:parentObject]] $parentObject [[@doctodo param_description:parentObject]]
  * @param array                                $options      [[@doctodo param_description:options]] [optional]
  *
  * @return [[@doctodo return_type:getStats]] [[@doctodo return_description:getStats]]
  */
 public function getStats($parentObject, $options = [])
 {
     $cacheKey = [__CLASS__ . '.' . __FUNCTION__, 'parentObject' => $parentObject->primaryKey, 'options' => $options, 'context' => ['user']];
     $stats = Cacher::get($cacheKey);
     if (!$stats) {
         $cacheDependency = $this->getCachingDependency($parentObject);
         $stats = [];
         $stats['total'] = $this->getTotalHours($parentObject, $options);
         if ($parentObject->modelAlias !== ':Individual\\ObjectIndividual') {
             $stats['top_contributors'] = $this->getTopContributors($parentObject, $options);
         } else {
             $stats['top_contributions'] = $this->getTopContributions($parentObject, $options);
         }
         $stats['month_summary'] = $this->getMonthSummary($parentObject, $options);
         Cacher::set($cacheKey, $stats, 0, $cacheDependency);
     }
     return $stats;
 }
Пример #6
0
 /**
  * [[@doctodo method_description:saveCache]].
  */
 public function saveCache()
 {
     if (!isset($this->_statusLog)) {
         return $this;
     }
     $this->_statusLog->lastUpdate = microtime(true);
     Cacher::set(['Instance__StatusLog', $this->model->primaryKey, $this->model->created], $this->_statusLog, 3600);
     return $this;
 }