public function addCatalogWriter(CatalogWriter $l) { $this->collCatalogWriters[] = $l; $l->setCatalog($this); }
public function executeUpdate() { $i18n = new sfI18N(); $i18n->initialize($this->getContext()); $i18n->setCulture($this->getUser()->getCulture()); $action_i18n = $i18n->globalMessageFormat->format('save as new'); $action_edit_i18n = $i18n->globalMessageFormat->format('edit'); $action_type = $this->getRequestParameter('action_type'); if ($action_type == $action_i18n || !$this->getRequestParameter('id', 0)) { $catalog = new Catalog(); } else { $catalog = CatalogPeer::retrieveByPk($this->getRequestParameter('id')); $this->forward404Unless($catalog); } $catalog->setId($this->getRequestParameter('id')); $catalog->setCatLanguageId($this->getRequestParameter('cat_language_id')); $catalog->setCatCategoryId($this->getRequestParameter('cat_category_id')); $catalog->setCatSubjectId($this->getRequestParameter('cat_subject_id')); $catalog->setTitle($this->getRequestParameter('title')); $catalog->setSubtitle($this->getRequestParameter('subtitle')); $catalog->setPublishedYear($this->getRequestParameter('published_year')); $catalog->setPublishedLocation($this->getRequestParameter('published_location')); $catalog->setIsbn($this->getRequestParameter('isbn')); $catalog->setStudentNo($this->getRequestParameter('student_no')); $catalog->setStudentName($this->getRequestParameter('student_name')); $catalog->setStudentMajor($this->getRequestParameter('student_major')); $catalog->setStudentTutor($this->getRequestParameter('student_tutor')); $catalog->setVersion($this->getRequestParameter('version')); $catalog->setEdition($this->getRequestParameter('edition')); $catalog->setPrintNo($this->getRequestParameter('print_no')); $catalog->setPart($this->getRequestParameter('part')); $catalog->setVolume($this->getRequestParameter('volume')); $catalog->setMonth($this->getRequestParameter('month')); $catalog->setYear($this->getRequestParameter('year')); $catalog->setNo($this->getRequestParameter('no')); $catalog->setBonus($this->getRequestParameter('bonus')); $catalog->setPages($this->getRequestParameter('pages')); $catalog->setHeight($this->getRequestParameter('height')); $catalog->setSynopsis($this->getRequestParameter('synopsis')); $catalog->setAbstracts($this->getRequestParameter('abstracts')); $catalog->setSearchKeywords($this->getRequestParameter('search_keywords')); //publisher if ($action_type == $action_i18n || !$this->getRequestParameter('publisher_id')) { $publisher = new Publisher(); $publisher->setId($this->getRequestParameter('publisher_id')); $publisher->setName($this->getRequestParameter('publisher_name')); $publisher->save(); $catalog->setPublisher($publisher); $catalog->save(); } elseif ($action_type !== $action_i18n || !$this->getRequestParameter('publisher_id')) { $publisher = new Publisher(); $publisher->setId($this->getRequestParameter('publisher_id')); $publisher->setName($this->getRequestParameter('publisher_name')); $publisher->save(); $catalog->setPublisher($publisher); $catalog->save(); } elseif ($this->getRequestParameter('publisher_id')) { $catalog->setPublisherId($this->getRequestParameter('publisher_id')); $catalog->save(); } //writer #if ($this->getRequestParameter('cat_category_id') != 3 && $this->getRequestParameter('cat_category_id') != 2) { if ($this->hasRequestParameter('writers_id') && $this->getRequestParameter('writers_id') != null && $this->getRequestParameter('writers_id') != '') { $name = $this->getRequestParameter('writers_name'); $c = new Criteria(); $c->add(WriterPeer::NAME, "%{$name}%", Criteria::LIKE); $rows = WriterPeer::doSelect($c); if ($rows != null) { $catalog->updateWriters($this->getRequestParameter('writers_name')); $catalog->save(); } else { $writer = new Writer(); $writer->setId($this->getRequestParameter('writers_id')); $writer->setName($this->getRequestParameter('writers_name')); $writer->save(); $cw = new CatalogWriter(); $cw->setCatalog($catalog); $cw->setWriter($writer); $cw->save(); } } elseif ($action_type !== $action_i18n || !$this->getRequestParameter('writer_id')) { $writer = new Writer(); $writer->setName($this->getRequestParameter('writers_name')); $writer->save(); $cw = new CatalogWriter(); $cw->setCatalog($catalog); $cw->setWriter($writer); $cw->save(); } else { $writer = new Writer(); $writer->setName($this->getRequestParameter('writers_name')); $writer->save(); $cw = new CatalogWriter(); $cw->setCatalog($catalog); $cw->setWriter($writer); $cw->save(); } #} $writer_name = $catalog->getFirstWriterName(); $writer_name = preg_replace('/\\W+/', '', $writer_name); $writer_name = strtoupper(substr($writer_name, 0, 3)); $title = substr(strtoupper(str_replace(' ', '', $catalog->getTitle())), 0, 3); $subject_code = $catalog->getCatSubject()->getCode(); /** $c = new Criteria(); $c->add(CatalogPeer::TITLE, "$title%", Criteria::LIKE); $c->add(CatalogPeer::ID, $catalog->getId(), Criteria::NOT_EQUAL); $c->addDescendingOrderByColumn(CatalogPeer::TITLE); $cat = CatalogPeer::doSelectOne($c); if ($cat != null) { $last_index = split('-', $cat->getCode()); $last_index = $last_index[1]; if ($last_index != null) ++$last_index; else $last_index = 1; $title = "$title-$last_index"; } **/ if ($this->hasRequestParameter('code') && $this->getRequestParameter('code') != null && $this->getRequestParameter('code') != '') { $catalog->setCode($this->getRequestParameter('code')); } else { $catalog->setCode("{$subject_code}-{$writer_name}-{$title}"); } $catalog->save(); if ($this->hasRequestParameter('copies') && $this->getRequestParameter('copies') > 0) { $catalog->addCopies($this); } $cover_dir = sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'photos' . DIRECTORY_SEPARATOR; if ($this->hasRequestParameter('coverFile') && $this->getRequestParameter('coverFile') != '' && $this->getRequestParameter('coverFile') != null) { // get cover content $cover_file = $cover_dir . 'tmp' . DIRECTORY_SEPARATOR . $this->getRequestParameter('coverFile'); $content = file_get_contents($cover_file); $im = imagecreatefromstring($content); list($w, $h) = getimagesize($cover_file); // generate cover $cover = imagecreatetruecolor(150, 200); imagecopyresized($cover, $im, 0, 0, 0, 0, 150, 200, $w, $h); // generate thumbnail $thumb = imagecreatetruecolor(100, 150); imagecopyresized($thumb, $im, 0, 0, 0, 0, 100, 150, $w, $h); // get cover record $c = new Criteria(); $c->add(CatalogCopiedPeer::CATALOG_ID, $catalog->getId()); $catalog_cover = CatalogCopiedPeer::doSelectOne($c); if ($catalog_cover == null) { $catalog_cover = new CatalogCopied(); $catalog_cover->setCatalog($catalog); } // save cover imagepng($cover, $cover_file); $catalog_cover->setCover(base64_encode(file_get_contents($cover_file))); imagepng($thumb, $cover_file); $catalog_cover->setThumbnail(base64_encode(file_get_contents($cover_file))); $catalog_cover->save(); unlink($cover_dir . 'tmp' . DIRECTORY_SEPARATOR . $this->getRequestParameter('coverFile')); } if ($this->hasRequestParameter('file') && $this->getRequestParameter('file') != '' && $this->getRequestParameter('file') != null) { $fileName = $this->getRequestParameter('file'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('file_1') && $this->getRequestParameter('file_1') != '' && $this->getRequestParameter('file_1') != null) { $fileName = $this->getRequestParameter('file_1'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('file_2') && $this->getRequestParameter('file_2') != '' && $this->getRequestParameter('file_2') != null) { $fileName = $this->getRequestParameter('file_2'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('file_3') && $this->getRequestParameter('file_3') != '' && $this->getRequestParameter('file_3') != null) { $fileName = $this->getRequestParameter('file_3'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('file_4') && $this->getRequestParameter('file_4') != '' && $this->getRequestParameter('file_4') != null) { $fileName = $this->getRequestParameter('file_4'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('file_5') && $this->getRequestParameter('file_5') != '' && $this->getRequestParameter('file_5') != null) { $fileName = $this->getRequestParameter('file_5'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('file_6') && $this->getRequestParameter('file_6') != '' && $this->getRequestParameter('file_6') != null) { $fileName = $this->getRequestParameter('file_6'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('file_7') && $this->getRequestParameter('file_7') != '' && $this->getRequestParameter('file_7') != null) { $fileName = $this->getRequestParameter('file_7'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('file_8') && $this->getRequestParameter('file_8') != '' && $this->getRequestParameter('file_8') != null) { $fileName = $this->getRequestParameter('file_8'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('file_9') && $this->getRequestParameter('file_9') != '' && $this->getRequestParameter('file_9') != null) { $fileName = $this->getRequestParameter('file_9'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('file_10') && $this->getRequestParameter('file_10') != '' && $this->getRequestParameter('file_10') != null) { $fileName = $this->getRequestParameter('file_10'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('filter_code') && $this->getRequestParameter('filter_code') != '' && $this->getRequestParameter('filter_code') != null) { return $this->redirect('catalog/list?filters[code]=' . $this->getRequestParameter('filter_code')); } elseif ($this->hasRequestParameter('filter_title') && $this->getRequestParameter('filter_title') != '' && $this->getRequestParameter('filter_title') != null) { return $this->redirect('catalog/list?filters[title]=' . $this->getRequestParameter('filter_title')); } elseif ($this->hasRequestParameter('filter_category') && $this->getRequestParameter('filter_category') != '' && $this->getRequestParameter('filter_category') != null) { return $this->redirect('catalog/list?filters[cat_category_id]=' . $this->getRequestParameter('filter_category')); } elseif ($this->hasRequestParameter('filter_writer') && $this->getRequestParameter('filter_writer') != '' && $this->getRequestParameter('filter_writer') != null) { return $this->redirect('catalog/list?filters[writer]=' . $this->getRequestParameter('filter_writer')); } elseif ($this->hasRequestParameter('filter_publisher') && $this->getRequestParameter('filter_publisher') != '' && $this->getRequestParameter('filter_publisher') != null) { return $this->redirect('catalog/list?filters[publisher]=' . $this->getRequestParameter('filter_publisher')); } elseif ($this->hasRequestParameter('filter_copies') && $this->getRequestParameter('filter_copies') != '' && $this->getRequestParameter('filter_copies') != null) { return $this->redirect('catalog/list?filters[copies]=' . $this->getRequestParameter('filter_copies')); } else { return $this->redirect('catalog/list'); } }
public function executeUpdate() { $i18n = new sfI18N(); $i18n->initialize($this->getContext()); $i18n->setCulture($this->getUser()->getCulture()); $action_i18n = $i18n->globalMessageFormat->format('save as new'); $action_edit_i18n = $i18n->globalMessageFormat->format('edit'); $action_type = $this->getRequestParameter('action_type'); if ($action_type == $action_i18n || !$this->getRequestParameter('id', 0)) { $catalog = new Catalog(); } else { $catalog = CatalogPeer::retrieveByPk($this->getRequestParameter('id')); $this->forward404Unless($catalog); } $catalog->setId($this->getRequestParameter('id')); $catalog->setCatLanguageId(1); $catalog->setCatCategoryId(15); $catalog->setCatSubjectId(4202); $catalog->setTitle($this->getRequestParameter('title')); $catalog->setPublishedYear(2011); $catalog->setPublishedLocation('Jakarta'); $catalog->setSynopsis($this->getRequestParameter('synopsis')); $catalog->setSearchKeywords($this->getRequestParameter('search_keywords')); $catalog->setPublisherId(8682); $catalog->save(); $dept_id = $this->getContext()->getUser()->getAttribute('department_id', null, 'bo'); $dept = $this->getContext()->getUser()->getAttribute('department', null, 'bo'); if ($dept_id == 2) { $c = new Criteria(); $c->add(CatalogWriterPeer::CATALOG_ID, $catalog->getId()); $c->add(CatalogWriterPeer::WRITER_ID, 8780); $cw = CatalogWriterPeer::doSelectOne($c); if ($cw == null) { $cw = new CatalogWriter(); } $cw->setCatalog($catalog); $cw->setWriterId(8780); $cw->save(); } elseif ($dept_id == 3) { $c = new Criteria(); $c->add(CatalogWriterPeer::CATALOG_ID, $catalog->getId()); $c->add(CatalogWriterPeer::WRITER_ID, 8112); $cw = CatalogWriterPeer::doSelectOne($c); if ($cw == null) { $cw = new CatalogWriter(); } $cw->setCatalog($catalog); $cw->setWriterId(8112); $cw->save(); } else { $c = new Criteria(); $c->add(CatalogWriterPeer::CATALOG_ID, $catalog->getId()); $c->add(CatalogWriterPeer::WRITER_ID, 8112); $cw = CatalogWriterPeer::doSelectOne($c); if ($cw == null) { $cw = new CatalogWriter(); } $cw->setCatalog($catalog); $cw->setWriterId(8112); $cw->save(); } $c = new Criteria(); $c->add(CatalogEmployeePeer::CATALOG_ID, $catalog->getId()); $c->add(CatalogEmployeePeer::EMPLOYEE_ID, $this->getRequestParameter('employee_id')); $ce = CatalogEmployeePeer::doSelectOne($c); if ($ce == null) { $ce = new CatalogEmployee(); } $ce->setCatalog($catalog); $ce->setEmployeeId($this->getRequestParameter('employee_id')); $ce->save(); $writer_name = $catalog->getFirstWriterName(); $writer_name = preg_replace('/\\W+/', '', $writer_name); $writer_name = strtoupper(substr($writer_name, 0, 3)); $title = substr(strtoupper(str_replace(' ', '', $catalog->getTitle())), 0, 3); $subject_code = $catalog->getCatSubject()->getCode(); $catalog->setCode("{$subject_code}-{$writer_name}-{$title}"); $catalog->save(); if ($this->hasRequestParameter('copies') && $this->getRequestParameter('copies') > 0) { $catalog->addCopies($this); } $cover_dir = sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'photos' . DIRECTORY_SEPARATOR; if ($this->hasRequestParameter('coverFile') && $this->getRequestParameter('coverFile') != '' && $this->getRequestParameter('coverFile') != null) { // get cover content $cover_file = $cover_dir . 'tmp' . DIRECTORY_SEPARATOR . $this->getRequestParameter('coverFile'); $content = file_get_contents($cover_file); $im = imagecreatefromstring($content); list($w, $h) = getimagesize($cover_file); // generate cover $cover = imagecreatetruecolor(150, 200); imagecopyresized($cover, $im, 0, 0, 0, 0, 150, 200, $w, $h); // generate thumbnail $thumb = imagecreatetruecolor(100, 150); imagecopyresized($thumb, $im, 0, 0, 0, 0, 100, 150, $w, $h); // get cover record $c = new Criteria(); $c->add(CatalogCopiedPeer::CATALOG_ID, $catalog->getId()); $catalog_cover = CatalogCopiedPeer::doSelectOne($c); if ($catalog_cover == null) { $catalog_cover = new CatalogCopied(); $catalog_cover->setCatalog($catalog); } // save cover imagepng($cover, $cover_file); $catalog_cover->setCover(base64_encode(file_get_contents($cover_file))); imagepng($thumb, $cover_file); $catalog_cover->setThumbnail(base64_encode(file_get_contents($cover_file))); $catalog_cover->save(); unlink($cover_dir . 'tmp' . DIRECTORY_SEPARATOR . $this->getRequestParameter('coverFile')); } if ($this->hasRequestParameter('file') && $this->getRequestParameter('file') != '' && $this->getRequestParameter('file') != null) { $fileName = $this->getRequestParameter('file'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('file_1') && $this->getRequestParameter('file_1') != '' && $this->getRequestParameter('file_1') != null) { $fileName = $this->getRequestParameter('file_1'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('file_2') && $this->getRequestParameter('file_2') != '' && $this->getRequestParameter('file_2') != null) { $fileName = $this->getRequestParameter('file_2'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('file_3') && $this->getRequestParameter('file_3') != '' && $this->getRequestParameter('file_3') != null) { $fileName = $this->getRequestParameter('file_3'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('file_4') && $this->getRequestParameter('file_4') != '' && $this->getRequestParameter('file_4') != null) { $fileName = $this->getRequestParameter('file_4'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('file_5') && $this->getRequestParameter('file_5') != '' && $this->getRequestParameter('file_5') != null) { $fileName = $this->getRequestParameter('file_5'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('file_6') && $this->getRequestParameter('file_6') != '' && $this->getRequestParameter('file_6') != null) { $fileName = $this->getRequestParameter('file_6'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('file_7') && $this->getRequestParameter('file_7') != '' && $this->getRequestParameter('file_7') != null) { $fileName = $this->getRequestParameter('file_7'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('file_8') && $this->getRequestParameter('file_8') != '' && $this->getRequestParameter('file_8') != null) { $fileName = $this->getRequestParameter('file_8'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('file_9') && $this->getRequestParameter('file_9') != '' && $this->getRequestParameter('file_9') != null) { $fileName = $this->getRequestParameter('file_9'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('file_10') && $this->getRequestParameter('file_10') != '' && $this->getRequestParameter('file_10') != null) { $fileName = $this->getRequestParameter('file_10'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($dept_id == 2) { $c = new Criteria(); $c->add(ColItemPeer::CATALOG_ID, $catalog->getId()); $ci = ColItemPeer::doSelectOne($c); $ci->setColLocationId(102); $ci->save(); } elseif ($dept_id == 3) { $c = new Criteria(); $c->add(ColItemPeer::CATALOG_ID, $catalog->getId()); $ci = ColItemPeer::doSelectOne($c); $ci->setColLocationId(103); $ci->save(); } else { $c = new Criteria(); $c->add(ColItemPeer::CATALOG_ID, $catalog->getId()); $ci = ColItemPeer::doSelectOne($c); $ci->setColLocationId(104); $ci->save(); } return $this->redirect('employee_bank/list'); }
public function updateWriters($writers_name) { $writers_name = preg_split('/\\//', $writers_name); $new = array(); foreach ($writers_name as $name) { $name = trim($name); //if ($name == '') continue; //array_push($new, WriterPeer::retrieveByName($name)->getId()); if ($name == '') { continue; } if (WriterPeer::retrieveByName($name)->getId() != null) { array_push($new, WriterPeer::retrieveByName($name)->getId()); } else { $w = new Writer(); $w->setName($name); } } $old = split(',', $this->getWritersId()); if ($new == null) { $removed = $old; $inserted = array(); } else { $inserted = array_diff($new, $old); $removed = array_diff($old, $new); } foreach ($removed as $id) { if ($id == null || $id == '') { continue; } $cw = CatalogWriterPeer::retrieveByPK($this->getId(), $id); $cw->delete(); } foreach ($inserted as $id) { $cw = new CatalogWriter(); $cw->setCatalogId($this->getId()); $cw->setWriterId($id); $cw->save(); } }