/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Book(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Book'])) { $authordetails = Author::model()->findByAttributes(array('author_name' => $_POST['Book']['author'])); $publication = Publication::model()->findByAttributes(array('name' => $_POST['Book']['publisher'])); $model->attributes = $_POST['Book']; if ($publication == NULL) { $publisher = new Publication(); $publisher->name = $_POST['Book']['publisher']; $publisher->save(); $model->publisher = $publisher->publication_id; } else { $model->publisher = $publication->publication_id; } if ($model->save()) { //echo count($authordetails).$authordetails->auth_id; exit; if ($authordetails) { $model->author = $authordetails->auth_id; $model->save(); } else { $author = new Author(); $author->author_name = $_POST['Book']['author']; $author->save(); $model->author = $author->auth_id; $model->save(); } $model->status = 'C'; $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Publication(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Publication'])) { $model->attributes = $_POST['Publication']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->publication_id)); } } $this->render('create', array('model' => $model)); }
public function executeAdd(sfWebRequest $request) { $pubName = $request->getParameter("name"); $pubId = $request->getParameter("id", null); if (!is_null($pubId)) { $pub = PublicationPeer::retrieveByPk($pubId); } else { $pub = new Publication(); } $pub->setName($pubName); $pub->save(); $c = new Criteria(); $c->addAscendingOrderByColumn(PublicationPeer::NAME); $pager = new sfPropelPager("Publication", sfConfig::get("app_items_per_page")); $pager->setCriteria($c); $pager->setPage(1); $pager->init(); $this->renderPartial("renderList", array("pager" => $pager)); return sfView::NONE; }
$publication = get_entity($guid); if (empty($publication)) { register_error(elgg_echo('InvalidParameterException:GUIDNotFound', [$guid])); forward('publications/all'); } if (!$publication instanceof Publication || !$publication->canEdit()) { forward('publications/all'); } $new_entity = false; } else { $publication = new Publication(); $publication->owner_guid = elgg_get_logged_in_user_guid(); $publication->container_guid = (int) get_input('container_guid', elgg_get_logged_in_user_guid()); $publication->access_id = $access; $publication->title = $title; if (!$publication->save()) { register_error(elgg_echo('publication:error')); forward(REFERER); } } $publication->access_id = $access; $publication->title = $title; if (!$publication->save()) { register_error(elgg_echo('publication:error')); forward(REFERER); } $publication->tags = $tags; $publication->pubtype = $type; // save custom data foreach ($data as $key => $value) { $publication->{$key} = $value;
/** * Creates an event on Facebook. * * @param string $title Title of the event. * @param int $start Epoch timestamp for the event start. * @param int $end Epoch timestamp for the event end. * @param string $location Location of the event. * @param string $description Description of the event. * @param string $picture Local path (no URL) of the picture for the event. * * @return array Result set of the Facebook API call. * @todo Standardise the result sets of connection API calls. */ public function createEvent($objectId, $title, $start, $end, $location, $description, $picture = null) { // Privacy types: OPEN, CLOSED, SECRET $start = is_numeric($start) ? date("c", $start) : $start; $end = is_numeric($end) ? date("c", $end) : $end; $attachment = array("privacy_type" => "OPEN", "name" => $title, "host" => "Me", "start_time" => $start, "end_time" => $end, "location" => $location, "description" => $description); if ($picture) { $attachment[basename($picture)] = "@" . realpath($picture); $this->api()->setFileUploadSupport(true); } try { // TODO: support pages (page Id instead of "me") $rs = $this->api()->api('me/events', 'post', $attachment); } catch (Exception $e) { Log::error("Exception: {$e}"); } catch (FacebookApiException $e) { Log::debug("FacebookApiException {$e}, " . print_r($attachment, true) . print_r($this, true)); return null; } $publication = new Publication(); $publication->setObjectId($objectId); $publication->setConnectionId($this->externalId); $publication->setBody(serialize($attachment)); $publication->setResponse(serialize($rs)); if (isset($rs['id'])) { list($uid, $postId) = explode("_", $rs['id']); $publication->setExternalId($postId); } else { $result->error = $rs; Log::debug("error: {$result->error}"); } $publication->save(); return $rs; // TODO: invites // $fb->api( array( // 'method' => 'events.invite', // 'eid' => $event_id, // 'uids' => $id_array, // 'personal_message' => $message, // ) ); }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aPublication !== null) { if ($this->aPublication->isModified() || $this->aPublication->isNew()) { $affectedRows += $this->aPublication->save($con); } $this->setPublication($this->aPublication); } if ($this->aProject !== null) { if ($this->aProject->isModified() || $this->aProject->isNew()) { $affectedRows += $this->aProject->save($con); } $this->setProject($this->aProject); } if ($this->aStatus !== null) { if ($this->aStatus->isModified() || $this->aStatus->isNew()) { $affectedRows += $this->aStatus->save($con); } $this->setStatus($this->aStatus); } if ($this->isNew()) { $this->modifiedColumns[] = JobPeer::ID; } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = JobPeer::doInsert($this, $con); $affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which // should always be true here (even though technically // BasePeer::doInsert() can insert multiple rows). $this->setId($pk); //[IMV] update autoincrement primary key $this->setNew(false); } else { $affectedRows += JobPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } if ($this->collJobAttachments !== null) { foreach ($this->collJobAttachments as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collPhotos !== null) { foreach ($this->collPhotos as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collDeliverys !== null) { foreach ($this->collDeliverys as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collJobPhotographers !== null) { foreach ($this->collJobPhotographers as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collJobClients !== null) { foreach ($this->collJobClients as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }
/** * Save book editors with a publication * * @param string $event the name of the event * @param string $type the type of the event * @param \Publication $entity supplied entity * * @return void */ public static function saveBookEditors($event, $type, $entity) { if (!$entity instanceof \Publication) { return; } // cleanup book editors $entity->deleteRelationships('book_editor'); unset($entity->book_editors); $supported_types = ['book', 'inbook', 'incollection', 'proceedings', 'inproceedings']; $type = get_input('type'); if (!in_array($type, $supported_types)) { return; } $book_editors_guids = get_input('book_editors'); $book_editors_order = get_input('book_editors_order'); // save book editors if (!empty($book_editors_guids)) { foreach ($book_editors_guids as $book_editor) { add_entity_relationship($entity->getGUID(), 'book_editor', $book_editor); } } $pbook_editors = implode(',', $book_editors_order); $entity->book_editors = $pbook_editors; $entity->save(); }