public function execute()
 {
     $photo_id = waRequest::get('photo_id', array(), waRequest::TYPE_ARRAY_INT);
     if (!$photo_id) {
         throw new waException(_w('Empty photo list'));
     }
     $photo_model = new photosPhotoModel();
     // dialog for one photo
     if (count($photo_id) == 1) {
         $photo_id = current($photo_id);
         $photo = $photo_model->getById($photo_id);
         $photo_right_model = new photosPhotoRightsModel();
         if (!$photo_right_model->checkRights($photo, true)) {
             $rights = array(0 => array('group_id' => 0, 'photo_id' => null));
         } else {
             $rights = $photo_right_model->getByField('photo_id', $photo_id, 'group_id');
         }
     } else {
         // dialog for several selected photos
         // dummies for correct template randering
         $photo = array('status' => 1);
         $rights = array(0 => array('group_id' => 0, 'photo_id' => null));
         $allowed_photo_id = (array) $photo_model->filterByField($photo_id, 'status', 1);
         $this->view->assign('photo_count', count($photo_id));
         $this->view->assign('disable_submit', count($allowed_photo_id) != count($photo_id));
     }
     $groups_model = new waGroupModel();
     $groups = $groups_model->getAll('id', true);
     $this->view->assign('groups', $groups);
     $this->view->assign('photo', $photo);
     $this->view->assign('rights', $rights);
 }
示例#2
0
 private function _makeStack($parent_id, $photo_ids, $op = 'make')
 {
     $photo_ids = (array) $photo_ids;
     if ($op == 'make') {
         $where = $this->getWhereByField('id', $photo_ids);
         // get description - first not empty description but description of parent is first-priority
         $sql = "SELECT description FROM {$this->table} WHERE id = i:parent_id AND description IS NOT NULL\n                    UNION\n                    SELECT description FROM {$this->table} WHERE {$where} AND description IS NOT NULL LIMIT 0,1";
         $description = $this->query($sql, array('parent_id' => $parent_id))->fetchField('description');
         // get max rate of all photos
         $sql = "SELECT MAX(rate) rate FROM {$this->table} WHERE id = i:parent_id OR {$where}";
         $rate = $this->query($sql, array('parent_id' => $parent_id))->fetchField('rate');
         // get status
         $sql = "SELECT status FROM {$this->table} WHERE id = i:parent_id";
         $status = $this->query($sql, array('parent_id' => $parent_id))->fetchField('status');
         $stack_count = 1;
         $sort = 1;
     } else {
         $parent = $this->getById($parent_id);
         $rate = $parent['rate'];
         $description = $parent['description'];
         $status = $parent['status'];
         $stack_count = $parent['stack_count'];
         // get last sort value of stack plus 1
         $sql = "SELECT sort FROM {$this->table} WHERE parent_id = i:parent_id ORDER BY sort DESC LIMIT 1";
         $sort = $this->query($sql, array('parent_id' => $parent_id))->fetchField('sort') + 1;
     }
     // get groups
     $photo_rights_model = new photosPhotoRightsModel();
     $groups = array_keys($photo_rights_model->getByField('photo_id', $parent_id, 'group_id'));
     // make first of all operations connected with file-manipulations
     foreach ($photo_ids as $id) {
         // update access
         $this->upAccess($id, array('status' => $status, 'groups' => $groups));
     }
     // make children of stack
     foreach ($photo_ids as $id) {
         $this->updateById($id, array('parent_id' => $parent_id, 'description' => $description, 'rate' => $rate, 'sort' => $sort++, 'stack_count' => 0));
     }
     // make parent of stack
     $this->updateById($parent_id, array('parent_id' => 0, 'description' => $description, 'rate' => $rate, 'stack_count' => $stack_count + count($photo_ids), 'sort' => 0));
     if ($op == 'make') {
         $photo_ids[] = $parent_id;
     } else {
         $photo_ids = array_keys($this->getByField('parent_id', $parent_id, 'id'));
         $photo_ids[] = $parent_id;
     }
     // merge tags for stack
     $photo_tags_model = new photosPhotoTagsModel();
     $tag_ids = array_keys($photo_tags_model->getByField('photo_id', $photo_ids, 'tag_id'));
     $photo_tags_model->assign($photo_ids, $tag_ids);
     // merge albums for stack
     $album_photos_model = new photosAlbumPhotosModel();
     $album_ids = array_keys($album_photos_model->getByField('photo_id', $photo_ids, 'album_id'));
     $album_photos_model->add($photo_ids, $album_ids, false);
 }