示例#1
0
 public function getCatalogWritersJoinWriter($criteria = null, $con = null)
 {
     include_once 'lib/model/om/BaseCatalogWriterPeer.php';
     if ($criteria === null) {
         $criteria = new Criteria();
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collCatalogWriters === null) {
         if ($this->isNew()) {
             $this->collCatalogWriters = array();
         } else {
             $criteria->add(CatalogWriterPeer::CATALOG_ID, $this->getId());
             $this->collCatalogWriters = CatalogWriterPeer::doSelectJoinWriter($criteria, $con);
         }
     } else {
         $criteria->add(CatalogWriterPeer::CATALOG_ID, $this->getId());
         if (!isset($this->lastCatalogWriterCriteria) || !$this->lastCatalogWriterCriteria->equals($criteria)) {
             $this->collCatalogWriters = CatalogWriterPeer::doSelectJoinWriter($criteria, $con);
         }
     }
     $this->lastCatalogWriterCriteria = $criteria;
     return $this->collCatalogWriters;
 }
示例#2
0
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = CatalogWriterPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setCatalogId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setWriterId($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setCreatedAt($arr[$keys[2]]);
     }
 }
示例#3
0
 protected static function doOnDeleteCascade(Criteria $criteria, Connection $con)
 {
     $affectedRows = 0;
     $objects = WriterPeer::doSelect($criteria, $con);
     foreach ($objects as $obj) {
         include_once 'lib/model/CatalogWriter.php';
         $c = new Criteria();
         $c->add(CatalogWriterPeer::WRITER_ID, $obj->getId());
         $affectedRows += CatalogWriterPeer::doDelete($c, $con);
     }
     return $affectedRows;
 }
示例#4
0
 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');
 }
示例#5
0
 public static function retrieveByPK($catalog_id, $writer_id, $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(self::DATABASE_NAME);
     }
     $criteria = new Criteria();
     $criteria->add(CatalogWriterPeer::CATALOG_ID, $catalog_id);
     $criteria->add(CatalogWriterPeer::WRITER_ID, $writer_id);
     $v = CatalogWriterPeer::doSelect($criteria, $con);
     return !empty($v) ? $v[0] : null;
 }
示例#6
0
 public function filterPerSource($c, $filters)
 {
     $filters_key = array_keys($filters);
     foreach ($filters_key as $key) {
         $value = $filters[$key];
         if ($value == '' || $value == null) {
             continue;
         }
         if ($key == 'writer_id') {
             $c->addJoin(VCatalogPerSourcePeer::CATALOG_ID, CatalogPeer::ID);
             $c->addJoin(CatalogWriterPeer::CATALOG_ID, CatalogPeer::ID);
             $column = CatalogWriterPeer::getTableMap()->getColumn('WRITER_ID');
         } elseif ($key == 'code') {
             $c->addJoin(VCatalogPerSourcePeer::CATALOG_ID, CatalogPeer::ID);
             $column = CatalogPeer::getTableMap()->getColumn('CODE');
         } elseif ($key == 'title') {
             $c->addJoin(VCatalogPerSourcePeer::CATALOG_ID, CatalogPeer::ID);
             $column = CatalogPeer::getTableMap()->getColumn('TITLE');
         } elseif ($key == 'writer') {
             $c->addJoin(VCatalogPerSourcePeer::CATALOG_ID, CatalogPeer::ID);
             $c->addJoin(CatalogWriterPeer::CATALOG_ID, CatalogPeer::ID);
             $c->addJoin(WriterPeer::ID, CatalogWriterPeer::WRITER_ID);
             $column = WriterPeer::getTableMap()->getColumn('NAME');
         } elseif ($key == 'publisher') {
             $c->addJoin(VCatalogPerSourcePeer::CATALOG_ID, CatalogPeer::ID);
             $c->addJoin(PublisherPeer::ID, CatalogPeer::PUBLISHER_ID);
             $column = PublisherPeer::getTableMap()->getColumn('NAME');
         } elseif ($key == 'cat_category_id') {
             $c->addJoin(VCatalogPerSourcePeer::CATALOG_ID, CatalogPeer::ID);
             $column = CatalogPeer::getTableMap()->getColumn('CAT_CATEGORY_ID');
         } elseif ($key == 'publisher_id') {
             $c->addJoin(VCatalogPerSourcePeer::CATALOG_ID, CatalogPeer::ID);
             $column = CatalogPeer::getTableMap()->getColumn('PUBLISHER_ID');
         } elseif ($key == 'YEAR_ADDED') {
             $column = VCatalogPerSourcePeer::getTableMap()->getColumn('YEAR_ADDED');
             #$c->addJoin(VCatalogPerSourcePeer::CATALOG_ID, ColItemPeer::CATALOG_ID);
             #$c->addJoin(ColItemPeer::CATALOG_ID, CatalogPeer::ID);
             #$column = ColItemPeer::getTableMap()->getColumn('YEAR_ADDED');
         } elseif ($key == 'department_id') {
             #	if ($filters[$key] == 1) {
             $c->addJoin(VCatalogPerSourcePeer::CATALOG_ID, CatalogPeer::ID);
             $c->addJoin(DepartmentPeer::ID, VCatalogPerSourcePeer::DEPARTMENT_ID);
             $column = DepartmentPeer::getTableMap()->getColumn('ID');
             #	} else {
             #		$c->addJoin(VCatalogPerSourcePeer::CATALOG_ID, CatalogPeer::ID);
             #		$c->addJoin(DepartmentPeer::ID, VCatalogPerSourcePeer::DEPARTMENT_ID);
             #		$c->addJoin(VDepartmentPeer::ID, DepartmentPeer::PARENT);
             #		$column = VDepartmentPeer::getTableMap()->getColumn('ID');
             #	}
         } else {
             $column = VCatalogPerSourcePeer::getTableMap()->getColumn($key);
         }
         $name = $column->getFullyQualifiedName();
         $creoleType = $column->getCreoleType();
         if ($creoleType == CreoleTypes::TIMESTAMP) {
             $from = $value['from'];
             $to = $value['to'];
             if ($from != '' && $from != null) {
                 $c->add($name, $from, Criteria::GREATER_EQUAL);
             }
             if ($to != '' && $to != null) {
                 $c->add($name, $to, Criteria::LESS_EQUAL);
             }
         } else {
             if ($creoleType == CreoleTypes::INTEGER || $creoleType == CreoleTypes::BIGINT) {
                 $c->add($name, $value, Criteria::EQUAL);
             } else {
                 if ($creoleType == CreoleTypes::VARCHAR) {
                     $c->add($name, "%{$value}%", Criteria::LIKE);
                 } else {
                     if ($creoleType == CreoleTypes::NUMERIC) {
                         $c->add($name, $value, Criteria::EQUAL);
                     }
                 }
             }
         }
     }
 }
示例#7
0
 public function filter($c, $filters)
 {
     $filters_key = array_keys($filters);
     foreach ($filters_key as $key) {
         $value = $filters[$key];
         if ($value == '' || $value == null) {
             continue;
         }
         if ($key == 'writer_id') {
             $c->addJoin(CatalogWriterPeer::CATALOG_ID, CatalogPeer::ID);
             $column = CatalogWriterPeer::getTableMap()->getColumn('WRITER_ID');
         } elseif ($key == 'copies') {
             $c->addJoin(VCatalogPeer::CATALOG_ID, CatalogPeer::ID);
             $column = VCatalogPeer::getTableMap()->getColumn('COPIES');
         } elseif ($key == 'writer') {
             $c->addJoin(CatalogWriterPeer::CATALOG_ID, CatalogPeer::ID);
             $c->addJoin(WriterPeer::ID, CatalogWriterPeer::WRITER_ID);
             $column = WriterPeer::getTableMap()->getColumn('NAME');
         } elseif ($key == 'publisher') {
             $c->addJoin(PublisherPeer::ID, CatalogPeer::PUBLISHER_ID);
             $column = PublisherPeer::getTableMap()->getColumn('NAME');
         } elseif ($key == 'title') {
             $column = CatalogPeer::getTableMap()->getColumn('TITLE');
         } else {
             $column = CatalogPeer::getTableMap()->getColumn($key);
         }
         $name = $column->getFullyQualifiedName();
         $creoleType = $column->getCreoleType();
         if ($creoleType == CreoleTypes::TIMESTAMP) {
             $from = $value['from'];
             $to = $value['to'];
             if ($from != '' && $from != null) {
                 $c->add($name, $from, Criteria::GREATER_EQUAL);
             }
             if ($to != '' && $to != null) {
                 $c->add($name, $to, Criteria::LESS_EQUAL);
             }
         } else {
             if ($creoleType == CreoleTypes::INTEGER || $creoleType == CreoleTypes::BIGINT) {
                 $c->add($name, $value, Criteria::EQUAL);
             } else {
                 if ($creoleType == CreoleTypes::VARCHAR) {
                     $c->add($name, "%{$value}%", Criteria::LIKE);
                 }
             }
         }
     }
 }
示例#8
0
 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();
     }
 }