public function execute() { $this->id = waRequest::post('id', null, waRequest::TYPE_INT); $group_ids = null; $status = waRequest::post('status', 0, waRequest::TYPE_INT); if (!$status) { $group_ids = waRequest::post('groups', array(), waRequest::TYPE_ARRAY_INT); if (!$group_ids) { // visible only for creator $status = -1; $group_ids = array(-$this->getUser()->getId()); } } $this->album_model = new photosAlbumModel(); if (!$this->id) { if (!$this->getRights('upload')) { throw new waException(_w("You don't have sufficient access rights")); } $name = waRequest::post('name', '', waRequest::TYPE_STRING_TRIM); $type = waRequest::post('type', 0, waRequest::TYPE_INT); $data = array('name' => $name, 'status' => $status, 'type' => $type, 'group_ids' => $group_ids); if ($status <= 0) { $data['hash'] = md5(uniqid(time(), true)); } else { $data['url'] = $this->album_model->suggestUniqueUrl(photosPhoto::suggestUrl($name)); } if ($type == photosAlbumModel::TYPE_DYNAMIC) { $data['conditions'] = $this->getPrepareConditions(); } $this->save($data); $this->response = array('id' => $this->id, 'name' => photosPhoto::escape($name), 'type' => $type, 'status' => $status); } else { $album_rights_model = new photosAlbumRightsModel(); if (!$album_rights_model->checkRights($this->id, true)) { throw new waException(_w("You don't have sufficient access rights")); } $conditions = $this->getPrepareConditions(); $params = array(); $album_params = waRequest::post('params', '', waRequest::TYPE_STRING_TRIM); $album_params = explode(PHP_EOL, $album_params); foreach ($album_params as $param) { $param = explode('=', $param); if (count($param) < 2) { continue; } $params[$param[0]] = $param[1]; } $params = $params ? $params : null; $description = waRequest::post('description', null, waRequest::TYPE_STRING_TRIM); $name = waRequest::post('name', '', waRequest::TYPE_STRING_TRIM); $url = waRequest::post('url', null, waRequest::TYPE_STRING_TRIM); $data = array('status' => $status, 'group_ids' => $group_ids, 'conditions' => $conditions, 'url' => $url, 'description' => $description, 'params' => $params, 'name' => $name); if ($status <= 0) { $data['hash'] = md5(uniqid(time(), true)); } if (waRequest::post('order') == 'rate') { $data['params']['order'] = 'rate'; } if (!$this->validate($data)) { return; } $this->save($data); $apply_all_photos = waRequest::post('apply_all_photos', 0, waRequest::TYPE_INT); if ($apply_all_photos) { // apply to first of $count photos $count = waRequest::post('count', 50, waRequest::TYPE_INT); $collection = new photosCollection('album/' . $this->id); $total_count = $collection->count(); $photos = $collection->getPhotos('*', 0, $count, false); $photo_model = new photosPhotoModel(); $photo_ids = array(); foreach ($photos as $photo) { if ($photo['status'] == 1 && $status == 1) { continue; } if ($photo['stack_count'] > 0) { $photo_ids = array_merge($photo_ids, $photo_model->getIdsByParent($photo['id'])); } else { $photo_ids[] = $photo['id']; } } $photo_rights_model = new photosPhotoRightsModel(); $allowed_photo_ids = $photo_rights_model->filterAllowedPhotoIds($photo_ids, true); $photo_model->updateAccess($allowed_photo_ids, $status, $group_ids); $this->response['total_count'] = $total_count; $this->response['count'] = $count; $this->response['status'] = $status; $this->response['groups'] = $group_ids; } } }