Beispiel #1
0
 public function doIndex()
 {
     $updates = [];
     $category = CW::$app->request->get('category');
     if (null !== $category && !in_array($category, ArrayHelper::getKeyArray($this->view->categories, 'name'))) {
         throw new \components\exceptions\NotFoundException();
     }
     return $this->render('index', ['updates' => $updates, 'category' => $category]);
 }
Beispiel #2
0
 public static function setUserProfileImages(&$users)
 {
     if (!is_array($users) || 0 >= count($users)) {
         return [];
     }
     $images = static::getImages(ArrayHelper::getKeyArray($users, 'id'), static::REL_TYPE_USER, static::TYPE_PROFILE_PIC);
     $usersC = count($users);
     for ($i = 0; $i < $usersC; $i++) {
         if (isset($images[$users[$i]['id']])) {
             $users[$i]['imgUrl'] = "/images/users/{$users[$i]['id']}/200x200.jpeg";
         } else {
             $users[$i]['imgUrl'] = "/images/default_avatar.jpg";
         }
     }
 }
Beispiel #3
0
 /**
  * 
  * @param array $updates
  * @return type
  */
 public static function setUpdateTags(&$updates)
 {
     if (!is_array($updates) || 0 === count($updates)) {
         return;
     }
     $updateTags = UpdateTag::getUpdateTags(ArrayHelper::getKeyArray($updates, 'id'));
     $updatesCount = count($updates);
     foreach ($updateTags as $updateId => $tags) {
         for ($i = 0; $i < $updatesCount; $i++) {
             if ($updates[$i]['id'] != $updateId) {
                 continue;
             }
             $updates[$i]['tags'] = $tags;
         }
     }
     return $updates;
 }
Beispiel #4
0
 /**
  * Gets the ids of all tags that match the given term.
  * @param string $term the search term.
  * @return array the ids of the found tags.
  */
 private static function getTagIds($term)
 {
     $tags = preg_split('/\\s+/', $term);
     $tagsC = count($tags);
     if (0 === $tagsC) {
         return [];
     }
     $execParams = [];
     for ($i = 0; $i < $tagsC; ++$i) {
         $execParams[":tag{$i}"] = "{$tags[$i]}%";
     }
     $query = "SELECT id FROM tags WHERE " . ArrayHelper::getArrayToString($execParams, ' OR ', function ($v, $k) {
         return "name LIKE {$k}";
     });
     $stmt = CW::$app->db->prepare($query);
     $stmt->execute($execParams);
     return ArrayHelper::getKeyArray($stmt->fetchAll(\PDO::FETCH_ASSOC), 'id');
 }
Beispiel #5
0
?>
,
        ajaxData : {
            category : App.update.category,
            type : <?php 
echo json_encode($type);
?>
        }
    });

    updateLoader.load();
});
</script>

<?php 
if (!empty($category) && in_array($category, ArrayHelper::getKeyArray($this->categories, 'name'))) {
    ?>
    <div class="category-info-cont-1">
        <div class="page-no-popular category-info-cont-2">
            <h2 class="category-section-title">
                <?php 
    echo htmlspecialchars($category);
    ?>
            </h2>
            <div class="category-types">
                <a  class="updates-type <?php 
    echo \models\Update::TYPE_TRENDING === $type ? 'updates-type-selected' : '';
    ?>
" href="<?php 
    echo UrlManager::to(['site/index', 'type' => 'trending', 'category' => $category]);
    ?>
 private function addTags()
 {
     if (!empty($this->tags)) {
         $tagsC = count($this->tags);
         $keys = [];
         $vals = [];
         $tags = [];
         for ($i = 0; $i < $tagsC; $i++) {
             $this->tags[$i] = strtolower(trim($this->tags[$i]));
             $keys[] = ":tag{$i}";
             $vals[":tag{$i}"] = $this->tags[$i];
             $tags[$this->tags[$i]] = $this->tags[$i];
         }
         $stmt = CW::$app->db->prepare('SELECT name FROM tags WHERE name IN (' . ArrayHelper::getArrayToString($keys, ',') . ')');
         $stmt->execute($vals);
         $tagsResult = $stmt->fetchAll(\PDO::FETCH_ASSOC);
         foreach ($tagsResult as $tag) {
             if (isset($tags[$tag['name']])) {
                 unset($tags[$tag['name']]);
             }
         }
         $tagsToAddCount = count($tags);
         if (0 < $tagsToAddCount) {
             $keys1 = [];
             $vals1 = [];
             $i = 0;
             foreach ($tags as $tag) {
                 $keys1[] = ":tag{$i}";
                 $vals1[":tag{$i}"] = $tag;
                 $i++;
             }
             $query = 'INSERT INTO tags (name, created_at) VALUES ' . ArrayHelper::getArrayToString($keys1, ',', function ($v) {
                 return "({$v}, " . time() . ")";
             });
             $stmt = CW::$app->db->prepare($query);
             $stmt->execute($vals1);
         }
         $stmt = CW::$app->db->prepare('SELECT id FROM tags WHERE name IN (' . ArrayHelper::getArrayToString($keys, ',') . ')');
         $stmt->execute($vals);
         $tagsResult = $stmt->fetchAll(\PDO::FETCH_ASSOC);
         $query = 'INSERT INTO update_tags (tag_id, update_id) VALUES ' . ArrayHelper::getArrayToString(ArrayHelper::getKeyArray($tagsResult, 'id'), ',', function ($v) {
             return "({$v}, {$this->newUpdateId})";
         });
         $stmt = CW::$app->db->prepare($query);
         $stmt->execute($vals);
     }
 }