Пример #1
0
 /**
  * getAlbums function.
  *
  * @access public
  * @return object
  */
 public function getAlbums()
 {
     if (count($this->items) > 0) {
         $objAlbum = \Photoalbums2AlbumModel::findMultipleByIds($this->items);
         if ($objAlbum !== null) {
             while ($objAlbum->next()) {
                 // Translate fields
                 if ($objAlbum->current() instanceof \Photoalbums2\Photoalbums2AlbumModel) {
                     Controller::loadDataContainer($objAlbum->current()->getTable());
                     $arrRow = \TranslationFields::translateDCArray($objAlbum->row(), $objAlbum->current()->getTable());
                     $objAlbum->setRow($arrRow);
                 }
                 // Get preview image as Pa2Image object
                 $objImage = new \Pa2Image($objAlbum->previewImage);
                 $objAlbum->objPreviewImage = $objImage->getPa2Image();
                 // Deserialize arrays
                 $objAlbum->images = deserialize($objAlbum->images);
                 $objAlbum->imageSort = deserialize($objAlbum->imageSort);
                 // Set sortedImageIds
                 $objPa2ImageSorter = new \Pa2ImageSorter($objAlbum->imageSortType, $objAlbum->images, $objAlbum->imageSort);
                 $objAlbum->arrSortedImageUuids = $objPa2ImageSorter->getSortedUuids();
             }
             $objAlbum->reset();
         }
         return $objAlbum;
     }
     return null;
 }
 /**
  * sortBy function.
  *
  * @access protected
  * @param  string $strSortKey
  * @param  string $strSortDirection (default: 'ASC')
  * @return bool
  */
 protected function sortBy($strSortKey, $strSortDirection = 'ASC')
 {
     if (!is_array($this->arrIds) || count($this->arrIds) < 1) {
         return false;
     }
     // Lower and uppercase for attributes
     $strSortKey = strtolower($strSortKey);
     $strSortDirection = strtoupper($strSortDirection);
     /**
      * SET SORT FIELDS HERE
      *
      * title
      * startdate
      * enddate
      * random
      * custom
      */
     if ($strSortKey == 'custom') {
         $arrIds = array();
         $arrIds = $this->arrCustomIds;
         // Remove all unnecessary ids which are not present in the variable arrIds
         $arrIds = array_intersect($arrIds, $this->arrIds);
         // Merge both arrays
         $arrIds = array_merge($arrIds, $this->arrIds);
         // Remove all duplicate ids which are present more than once
         $arrIds = array_unique($arrIds);
         // Set new arrIds
         $this->arrIds = $arrIds;
     } elseif ($strSortKey == 'random') {
         shuffle($this->arrIds);
     } else {
         $arrSort = array();
         foreach ($this->arrIds as $intId) {
             $objPa2AlbumModel = \Photoalbums2\Photoalbums2AlbumModel::findByPk($intId);
             switch ($strSortKey) {
                 case 'title':
                     $sortType = SORT_STRING;
                     $title = '';
                     if ($objPa2AlbumModel->title != '') {
                         $title = $objPa2AlbumModel->title;
                     }
                     $arrSort[$objPa2AlbumModel->id] = $title;
                     break;
                 case 'startdate':
                     $sortType = SORT_NUMERIC;
                     $title = '';
                     if ($objPa2AlbumModel->startdate != '') {
                         $startdate = $objPa2AlbumModel->startdate;
                     }
                     $arrSort[$objPa2AlbumModel->id] = $startdate;
                     break;
                 case 'enddate':
                     $sortType = SORT_NUMERIC;
                     $title = '';
                     if ($objPa2AlbumModel->enddate != '') {
                         $enddate = $objPa2AlbumModel->enddate;
                     }
                     $arrSort[$objPa2AlbumModel->id] = $enddate;
                     break;
                 case 'numberofimages':
                     $sortType = SORT_NUMERIC;
                     $numberofimages = '';
                     if ($objPa2AlbumModel->images != '') {
                         $objPa2AlbumModel->images = deserialize($objPa2AlbumModel->images);
                         if (is_array($objPa2AlbumModel->images)) {
                             $numberofimages = count($objPa2AlbumModel->images);
                         }
                     }
                     $arrSort[$objPa2AlbumModel->id] = $numberofimages;
                     break;
             }
         }
         asort($arrSort, $sortType);
         $this->arrIds = array_keys($arrSort);
     }
     if ($strSortDirection == 'DESC') {
         $this->arrIds = array_reverse($this->arrIds);
     }
     return true;
 }