Exemplo n.º 1
0
 function children($section = '', $cell = '')
 {
     // getting the section path to the main index page
     if (!empty($section)) {
         $par_sec = $section->get_parents();
     }
     // selecting all the content of that parent
     $sql_stat = "SELECT * FROM `content` WHERE `parent_content`= {$this->id}";
     // filter the objects to the requested cell
     if ($cell !== '') {
         $sql_stat .= " AND `cell`={$cell}";
     }
     /***************************************
      *  filter the objects to the requested section
      * and all the parent sections that the content requested to be 
      * shared in the sub sections ordered in ascending with sort field
      * **************************************/
     if (!empty($section)) {
         $sql_stat .= " AND \r\n\t\t\t(\r\n\t\t\t\t(`parent_section`={$section->id})";
         if (count($par_sec) > 0) {
             $sql_stat .= sprintf(" OR (`parent_section` IN (%s) AND `subsection`=%s)", implode(',', $par_sec), intval(TRUE));
         }
         $sql_stat .= ") ORDER BY `sort` ASC";
     }
     // submit the query
     $children = new Content();
     $children->query($sql_stat);
     // returning the final array of children
     return $children->all;
 }
Exemplo n.º 2
0
 function covers()
 {
     list($params, $id) = $this->parse_params(func_get_args());
     $params['auth'] = $this->auth;
     // Standard add/delete cover
     list($id, $content_id) = $id;
     if ($this->method === 'get') {
         $this->redirect("/albums/{$id}");
     }
     $a = new Album($id);
     $c = new Content();
     if (!$a->exists()) {
         $this->error('404', 'Album not found.');
         return;
     }
     $cover_count = $a->covers->count();
     if ($cover_count > 50) {
         $this->error('403', 'Only 50 covers can be added to any one album.');
         return;
     }
     if ($a->album_type == 2 && $cover_count == 0) {
         $subs = new Album();
         $subs->select('id')->where('right_id <', $a->right_id)->where('left_id >', $a->left_id)->where('visibility', $a->visibility)->get_iterated();
         $id_arr = array();
         foreach ($subs as $sub) {
             $id_arr[] = $sub->id;
         }
         if (!empty($id_arr)) {
             $subc = new Content();
             $covers = $subc->query("SELECT DISTINCT cover_id FROM {$a->db_join_prefix}albums_covers WHERE album_id IN (" . join(',', $id_arr) . ") GROUP BY album_id LIMIT " . (3 - $cover_count));
             $f_ids = array();
             foreach ($covers as $f) {
                 $f_ids[] = $f->cover_id;
             }
             if (!empty($f_ids)) {
                 $subc->query("SELECT id FROM {$subc->table} WHERE id IN(" . join(',', $f_ids) . ") ORDER BY FIELD(id, " . join(',', array_reverse($f_ids)) . ")");
                 foreach ($subc as $content) {
                     $a->save_cover($content);
                 }
             }
         }
     }
     if (is_numeric($content_id)) {
         if ($this->method == 'delete') {
             $c->where_related('covers', 'id', $id)->get_by_id($content_id);
         } else {
             if ($a->album_type == 2) {
                 $c->get_by_id($content_id);
             } else {
                 $c->where_related('album', 'id', $id)->get_by_id($content_id);
             }
         }
         if (!$c->exists()) {
             $this->error('404', 'Content not found.');
             return;
         }
         if ($this->method == 'delete') {
             $a->delete_cover($c);
             $a->reset_covers();
         } else {
             $a->delete_cover($c);
             $a->save_cover($c);
         }
     } else {
         $content_id = explode(',', $content_id);
         if ($this->method == 'delete') {
             $c->where_related('covers', 'id', $id)->where_in('id', $content_id)->get_iterated();
         } else {
             if ($a->album_type == 2) {
                 $c->where_in('id', $content_id)->get_iterated();
             } else {
                 $c->where_related('album', 'id', $id)->where_in('id', $content_id)->get_iterated();
             }
         }
         if (!$c->result_count()) {
             $this->error('404', 'Content not found.');
             return;
         }
         if ($this->method == 'delete') {
             foreach ($c as $cover) {
                 $a->delete_cover($cover);
             }
             $a->reset_covers();
         } else {
             foreach ($c as $cover) {
                 $a->delete_cover($cover);
             }
             foreach ($content_id as $cid) {
                 $a->save_cover($c->get_by_id($cid));
             }
         }
     }
     $this->redirect("/albums/{$id}");
 }
Exemplo n.º 3
0
 function children($section = '', $cell = '')
 {
     // getting the section path to the main index page
     if (!empty($section)) {
         $par_sec = $section->get_parents();
     }
     // selecting all the content of that parent
     $sql_stat = "SELECT * FROM `content` WHERE `parent_content`= {$this->id}";
     // filter the objects to the requested cell
     if (isset($cell) and $cell != '') {
         $sql_stat .= " AND `cell`={$cell}";
     }
     /***************************************
      *  filter the objects to the requested section
      * and all the parent sections that the content requested to be 
      * shared in the sub sections ordered in ascending with sort field
      * **************************************/
     if (!empty($section)) {
         $sql_stat .= " AND \r\n\t\t\t(\r\n\t\t\t\t(`parent_section`={$section->id})";
         if (count($par_sec) > 0) {
             $sql_stat .= sprintf(" OR (`parent_section` IN (%s) AND `subsection`=%s)", implode(',', $par_sec), intval(TRUE));
         }
         $sql_stat .= ") ORDER BY `sort` ASC";
     }
     // submit the query
     $children = new Content();
     $children->query($sql_stat);
     /***************************************
      * building the children array with the respect objects
      * in other meaning we'll convert all the content to their 
      * subtype : layout, widgets, ... etc
      * **************************************/
     $final_c = array();
     // final array of children to return them
     foreach ($children->all as $item) {
         // making the content object with the type
         if (class_exists($item->type)) {
             $temp = new $item->type();
         } else {
             $temp = new Content();
         }
         $temp->get_by_id($item->id);
         array_push($final_c, $temp);
     }
     // returning the final array of children
     return $final_c;
 }
Exemplo n.º 4
0
 function to_array($options = array())
 {
     $options = array_merge(array('with_covers' => true, 'auth' => false), $options);
     $koken_url_info = $this->config->item('koken_url_info');
     $exclude = array('deleted', 'total_count', 'video_count', 'featured_order', 'tags_old', 'old_slug');
     $dates = array('created_on', 'modified_on', 'featured_on', 'published_on');
     $strings = array('title', 'summary', 'description');
     $bools = array('featured');
     list($data, $public_fields) = $this->prepare_for_output($options, $exclude, $bools, $dates, $strings);
     if (!$options['auth'] && $data['visibility'] < 1) {
         unset($data['internal_id']);
     }
     if (!$data['featured']) {
         unset($data['featured_on']);
     }
     $sort = array();
     list($sort['by'], $sort['direction']) = explode(' ', $data['sort']);
     $data['sort'] = $sort;
     $data['__koken__'] = 'album';
     if (array_key_exists('album_type', $data)) {
         switch ($data['album_type']) {
             case 2:
                 $data['album_type'] = 'set';
                 break;
             case 1:
                 $data['album_type'] = 'smart';
                 break;
             default:
                 $data['album_type'] = 'standard';
         }
     }
     if ($this->album_type == 2) {
         $sum = new Album();
         $sum->select_sum('total_count')->select_sum('video_count')->where('right_id <', $this->right_id)->where('left_id >', $this->left_id)->where('album_type', 0)->where('visibility', 0)->get();
         $data['counts'] = array('total' => (int) $this->total_count, 'videos' => (int) $sum->video_count, 'images' => $sum->total_count - $sum->video_count);
     } else {
         $data['counts'] = array('total' => (int) $this->total_count, 'videos' => (int) $this->video_count, 'images' => $this->total_count - $this->video_count);
     }
     $data['tags'] = $this->_get_tags_for_output($options);
     $data['categories'] = array('count' => is_null($this->category_count) ? $this->categories->count() : (int) $this->category_count, 'url' => $koken_url_info->base . 'api.php?/albums/' . $data['id'] . '/categories');
     $data['topics'] = array('count' => is_null($this->text_count) ? $this->text->count() : (int) $this->text_count, 'url' => $koken_url_info->base . 'api.php?/albums/' . $data['id'] . '/topics');
     if ($options['with_covers']) {
         $data['covers'] = $existing = array();
         $covers = $this->covers;
         if (isset($options['before'])) {
             $covers->where('published_on <=', $options['before']);
             $data['__cover_hint_before'] = $options['before'];
         }
         $covers->include_related_count('albums', NULL, array('visibility' => 0));
         $covers->include_related_count('categories');
         foreach ($covers->order_by("covers_{$this->db_join_prefix}albums_covers.id ASC")->get_iterated() as $f) {
             if ($f->exists()) {
                 $data['covers'][] = $f->to_array(array('in_album' => $this));
                 $existing[] = $f->id;
             }
         }
         $covers_count_set = false;
         if ($this->album_type == 2) {
             $covers_count_set = $this->covers->count();
         }
         if ($covers_count_set !== false && $covers_count_set < 3) {
             $a = new Album();
             $ids = $a->select('id')->where('right_id <', $this->right_id)->where('left_id >', $this->left_id)->where('visibility', $this->visibility)->get_iterated();
             $id_arr = array();
             foreach ($ids as $id) {
                 $id_arr[] = $id->id;
             }
             if (!empty($id_arr)) {
                 $c = new Content();
                 $q = "SELECT DISTINCT cover_id FROM {$this->db_join_prefix}albums_covers WHERE album_id IN (" . join(',', $id_arr) . ")";
                 if (!empty($existing)) {
                     $q .= ' AND cover_id NOT IN(' . join(',', $existing) . ')';
                 }
                 $covers = $c->query($q . "GROUP BY album_id LIMIT " . (3 - $covers_count_set));
                 $f_ids = array();
                 foreach ($covers as $f) {
                     $f_ids[] = $f->cover_id;
                 }
                 if (!empty($f_ids)) {
                     $c->where_in('id', $f_ids)->get_iterated();
                     foreach ($c as $content) {
                         // TODO: auth needs to be passed in here
                         array_unshift($data['covers'], $content->to_array(array('in_album' => $this)));
                     }
                 }
             }
         }
         // Latest covers first
         $data['covers'] = array_reverse($data['covers']);
     }
     if (isset($options['order_by']) && in_array($options['order_by'], array('created_on', 'modified_on'))) {
         $data['date'] =& $data[$options['order_by']];
     } else {
         $data['date'] =& $data['published_on'];
     }
     if ($data['level'] > 1 && (!array_key_exists('include_parent', $options) || $options['include_parent'])) {
         $parent = new Album();
         $parent->where('left_id <', $data['left_id'])->where('level <', $data['level'])->where('visibility', $this->visibility)->where('deleted', 0)->order_by('left_id DESC')->limit(1)->get();
         $data['parent'] = $parent->to_array();
     } else {
         if ($data['level'] == 1) {
             $data['parent'] = false;
         }
     }
     $cat = isset($options['category']) ? $options['category'] : (isset($options['context']) && strpos($options['context'], 'category-') === 0 ? str_replace('category-', '', $options['context']) : false);
     if ($cat) {
         if (is_numeric($cat)) {
             foreach ($this->categories->get_iterated() as $c) {
                 if ($c->id == $cat) {
                     $cat = $c->slug;
                     break;
                 }
             }
         }
     }
     $data['url'] = $this->url(array('date' => $data['published_on'], 'tag' => isset($options['tags']) ? $options['tags'] : (isset($options['context']) && strpos($options['context'], 'tag-') === 0 ? str_replace('tag-', '', $options['context']) : false), 'category' => $cat));
     if ($data['url']) {
         list($data['__koken_url'], $data['url']) = $data['url'];
         $data['canonical_url'] = $data['url'];
     }
     if (!$options['auth'] && $data['visibility'] > 0) {
         unset($data['url']);
     }
     if (array_key_exists('visibility', $data)) {
         switch ($data['visibility']) {
             case 1:
                 $raw = 'unlisted';
                 break;
             case 2:
                 $raw = 'private';
                 break;
             default:
                 $raw = 'public';
                 break;
         }
         $data['visibility'] = array('raw' => $raw, 'clean' => ucwords($raw));
         $data['public'] = $raw === 'public';
     }
     return Shutter::filter('api.album', array($data, $this, $options));
 }
Exemplo n.º 5
0
 /**
  * /
  * @param  [type] $id [description]
  * @return [type]     [description]
  */
 public function showProjeto($id)
 {
     $result = Content::query($this->db, 'showPublished', $id);
     if ($result->isSuccessful()) {
         $this->renderArray['content'] = $result->getRecords();
     }
 }