示例#1
0
 /**
  * Gets the article's ordering
  * Also reorder the context table
  *
  * @param	string		$place		place of the new inserted article. 'first, 'last' or 'after'
  * @param	int			$id_page
  * @param	int			$id_ref		ID of the referent article. Must be set if place is 'after'
  * @return	int			place of the article
  */
 protected function _get_ordering($place, $id_page, $id_ref = NULL)
 {
     $existing_ordering = $this->article_model->get_articles_ordering($id_page);
     $ordering = '0';
     switch ($place) {
         case 'first':
             $this->article_model->shift_article_ordering($id_page);
             $ordering = '1';
             break;
         case 'last':
             $ordering = count($existing_ordering) + 1;
             break;
         case 'after':
             $new_pos = array_search($id_ref, $existing_ordering) + 2;
             // Shift every article with a greater pos than ordering_after
             $this->article_model->shift_article_ordering($id_page, $new_pos);
             $ordering = $new_pos;
             break;
     }
     return $ordering;
 }