Example #1
0
 /**
  * @copydoc DBDataSet::__construct
  */
 public function __construct($name, array $params = null)
 {
     parent::__construct($name, $params);
     $this->setType(self::COMPONENT_TYPE_LIST);
     $this->setTableName('share_tags');
     $this->bindedBlock = $this->document->componentManager->getBlockByName($this->getParam('bind'));
     if (!$this->bindedBlock) {
         throw new SystemException('ERR_TAGCLOUD_NOT_BINDED', SystemException::ERR_DEVELOPER);
     }
     if ($filerId = intval($this->getParam('id'))) {
         $this->filterId = $filerId;
     } else {
         if ($this->getParam('id') == self::ID_PARENT_FILTER) {
             $map = E()->getMap();
             $this->filterId = $map->getParent($this->document->getID());
             $this->setProperty('template', $map->getURLByID($this->filterId));
         } else {
             if ($this->getParam('id') != self::ID_ALL_FILTER) {
                 $this->filterId = $this->document->getID();
             }
         }
     }
     $this->tagsInfo = $this->getTagsInfo();
     $this->addFilterCondition(array($this->getTableName() . '.tag_id' => simplifyDBResult($this->tagsInfo, 'tag_id')));
     $this->addTranslation('TXT_TAGS');
 }
Example #2
0
 /**
  * Check login.
  * It is called by AJAX by filling registration form.
  */
 protected function checkLogin()
 {
     $login = trim($_POST['login']);
     $result = !(bool) simplifyDBResult($this->dbh->select($this->getTableName(), ['COUNT(u_id) as number'], ['u_name' => $login]), 'number', true);
     $field = 'login';
     $message = $result ? $this->translate('TXT_LOGIN_AVAILABLE') : $this->translate('TXT_LOGIN_ENGAGED');
     $result = ['result' => $result, 'message' => $message, 'field' => $field];
     $builder = new JSONCustomBuilder();
     $this->setBuilder($builder);
     $builder->setProperties($result);
 }
Example #3
0
 /**
  * Конструктор класса
  *
  * @param string $name
  * @param string $module
  * @param array $params
  * @access public
  */
 public function __construct($name, array $params = null)
 {
     parent::__construct($name, $params);
     $this->setCalendar(new CalendarObject($this->getParam('month'), $this->getParam('year')));
     //Отмечаем использованные даты календаря
     $range = $this->calendar->getRange();
     $dateFormat = '"Y-m-d"';
     // Если диапазон календаря заканчивается в будущем - отсекаем до текущего момента
     if ($range->end->getTimestamp() > time()) {
         $endRange = date($dateFormat);
     } else {
         $endRange = $range->end->format($dateFormat);
     }
     $conditions = array_merge(array('post_created>=' . $range->start->format($dateFormat) . ' AND post_created<=' . $endRange), $this->getParam('filter'));
     if ($blogId = (int) $this->getParam('blog_id')) {
         $conditions['blog_id'] = $blogId;
     }
     $existingDates = simplifyDBResult($this->dbh->select('SELECT DISTINCT DATE_FORMAT(post_created, "%Y-%c-%e") as post_date FROM blog_post' . $this->dbh->buildWhereCondition($conditions)), 'post_date');
     if (is_array($existingDates)) {
         foreach ($existingDates as $date) {
             $this->calendar->getItemByDate(\DateTime::createFromFormat('Y-m-d', $date))->setProperty('selected', 'selected');
         }
     }
 }
Example #4
0
 /**
  * считаем комментарии для загруженных постов
  * 
  * @param array $data
  */
 protected function loadCommentCount(&$data)
 {
     $comments = Comments::createInsatceFor($this->getTableName());
     if ($commentCount = $comments->getCountByIds(simplifyDBResult($data, 'post_id'))) {
         foreach ($data as &$item) {
             if (key_exists($item['post_id'], $commentCount)) {
                 $item['comments_num'] = $commentCount[$item['post_id']];
             } else {
                 $item['comments_num'] = 0;
             }
         }
         $fd = new FieldDescription('comments_num');
         $fd->setType(FieldDescription::FIELD_TYPE_INT);
         $this->getDataDescription()->addFieldDescription($fd);
     }
 }
Example #5
0
 public function getPageCount(array $targetIDs, $recordsPerPage)
 {
     return ($result = (int) simplifyDBResult($this->dbh->select($this->commentTable, 'CEIL(COUNT(*)/' . $recordsPerPage . ') as c ', array('target_id' => $targetIDs)), 'c', true)) ? $result : 1;
 }
Example #6
0
 /**
  * Modify data set by adding the values from "m2m" table.
  * @param array $data Data.
  * @return array|false
  */
 protected function modify($data)
 {
     if (!is_array($data)) {
         return $data;
     }
     //Перечень мультиполей
     $multiFields = $this->getDataDescription()->getFieldDescriptionsByType(FieldDescription::FIELD_TYPE_MULTI);
     //Loading m2m data
     if (!empty($multiFields)) {
         $m2mData = [];
         $primaryKeyName = $this->getPK();
         $pks = simplifyDBResult($data, $primaryKeyName);
         //create storage array
         //array($MultiFieldName => array($pk => $values))
         foreach ($multiFields as $mfd) {
             $relInfo = $mfd->getPropertyValue('key');
             if (is_array($relInfo) && $this->dbh->tableExists($relInfo['tableName'])) {
                 $res = $this->dbh->select($relInfo['tableName'], true, [$primaryKeyName => $pks]);
                 if ($res) {
                     foreach ($res as $row) {
                         $pk = $row[$relInfo['fieldName']];
                         unset($row[$relInfo['fieldName']]);
                         $m2mData[$mfd->getName()][$pk][] = current($row);
                     }
                 }
             } else {
                 foreach (array_keys($data) as $key) {
                     if (isset($data[$key][$mfd->getName()]) && $data[$key][$mfd->getName()]) {
                         $data[$key][$mfd->getName()] = explode(',', $data[$key][$mfd->getName()]);
                     }
                 }
             }
         }
         //Проходимся по всем данным
         foreach ($data as $key => $row) {
             //потом по multi полям
             foreach ($m2mData as $fieldName => $m2mValues) {
                 //Если в списке полей данных существует мультиполе с этим именем
                 if (array_key_exists($fieldName, $row)) {
                     //
                     foreach ($m2mValues as $pk => $values) {
                         if ($row[$primaryKeyName] == $pk) {
                             $data[$key][$fieldName] = $values;
                         }
                     }
                 }
             }
         }
     }
     $lookupField = $this->getDataDescription()->getFieldDescriptionsByType(FieldDescription::FIELD_TYPE_LOOKUP);
     if (!empty($lookupField)) {
         //Готовим инфу для получения данных их связанных таблиц
         foreach ($lookupField as $valueFieldName => $valueField) {
             $relInfo = $valueField->getPropertyValue('key');
             if (is_array($relInfo)) {
                 $langTable = $this->dbh->getTranslationTablename($relInfo['tableName']);
                 $relations[$valueFieldName] = ['table' => !$langTable ? $relInfo['tableName'] : $langTable, 'field' => $relInfo['fieldName'], 'lang' => $langTable ? E()->getLanguage()->getCurrent() : false, 'valueField' => substr($relInfo['fieldName'], 0, strrpos($relInfo['fieldName'], '_')) . '_name'];
                 $cond = [$relations[$valueFieldName]['field'] => simplifyDBResult($data, $valueFieldName)];
                 if ($relations[$valueFieldName]['lang']) {
                     $cond['lang_id'] = $relations[$valueFieldName]['lang'];
                 }
                 $values[$valueFieldName] = convertDBResult($this->dbh->select($relations[$valueFieldName]['table'], [$relations[$valueFieldName]['field'], $relations[$valueFieldName]['valueField']], $cond), $relations[$valueFieldName]['field'], true);
             }
         }
         unset($lookupField, $langTable, $relInfo);
         foreach ($data as $key => $row) {
             foreach ($row as $name => $value) {
                 if (in_array($name, array_keys($relations)) && is_array($values[$name]) && array_key_exists($value, $values[$name])) {
                     $data[$key][$name] = ['id' => $value, 'value' => $values[$name][$value][$relations[$name]['valueField']]];
                 }
             }
         }
     }
     return $data;
 }