public function saveAppBlogMultimediaEntriesList($con = null)
 {
     if (!$this->isValid()) {
         throw $this->getErrorSchema();
     }
     if (!isset($this->widgetSchema['app_blog_multimedia_entries_list'])) {
         // somebody has unset this widget
         return;
     }
     if (null === $con) {
         $con = $this->getConnection();
     }
     $c = new Criteria();
     $c->add(AppBlogMultimediaEntriesPeer::ENTRIES_ID, $this->object->getPrimaryKey());
     AppBlogMultimediaEntriesPeer::doDelete($c, $con);
     $values = $this->getValue('app_blog_multimedia_entries_list');
     if (is_array($values)) {
         foreach ($values as $value) {
             $obj = new AppBlogMultimediaEntries();
             $obj->setEntriesId($this->object->getPrimaryKey());
             $obj->setMultimediaId($value);
             $obj->save();
         }
     }
 }
Exemple #2
0
 public function setInactiu()
 {
     $this->setActiu(false);
     $C = new Criteria();
     $C = AppBlogMultimediaEntriesPeer::getCriteriaActiu($C, $this->getSiteId());
     foreach ($this->getAppBlogMultimediaEntriess() as $OM) {
         $OM->setInactiu();
     }
     $this->save();
 }
 public static function initialize($idEntry, $idMultimedia, $idS)
 {
     $OO = AppBlogMultimediaEntriesPeer::retrieveByPK($idEntry, $idMultimedia);
     if (!$OO instanceof AppBlogMultimediaEntries) {
         $OO = new AppBlogMultimediaEntries();
         $OO->setEntriesId($idEntry);
         $OO->setMultimediaId($idMultimedia);
         $OO->setSiteId($idS);
         $OO->setActiu(true);
     }
     return new AppBlogMultimediaEntriesForm($OO, array('IDS' => $idS));
 }
 /**
  * This is a method for emulating ON DELETE CASCADE for DBs that don't support this
  * feature (like MySQL or SQLite).
  *
  * This method is not very speedy because it must perform a query first to get
  * the implicated records and then perform the deletes by calling those Peer classes.
  *
  * This method should be used within a transaction if possible.
  *
  * @param      Criteria $criteria
  * @param      PropelPDO $con
  * @return     int The number of affected rows (if supported by underlying database driver).
  */
 protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con)
 {
     // initialize var to track total num of affected rows
     $affectedRows = 0;
     // first find the objects that are implicated by the $criteria
     $objects = AppBlogsEntriesPeer::doSelect($criteria, $con);
     foreach ($objects as $obj) {
         // delete related AppBlogMultimediaEntries objects
         $criteria = new Criteria(AppBlogMultimediaEntriesPeer::DATABASE_NAME);
         $criteria->add(AppBlogMultimediaEntriesPeer::ENTRIES_ID, $obj->getId());
         $affectedRows += AppBlogMultimediaEntriesPeer::doDelete($criteria, $con);
     }
     return $affectedRows;
 }
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this AppBlogsMultimedia is new, it will return
  * an empty collection; or if this AppBlogsMultimedia has previously
  * been saved, it will retrieve related AppBlogMultimediaEntriess from storage.
  *
  * This method is protected by default in order to keep the public
  * api reasonable.  You can provide public methods for those you
  * actually need in AppBlogsMultimedia.
  */
 public function getAppBlogMultimediaEntriessJoinAppBlogsEntries($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     if ($criteria === null) {
         $criteria = new Criteria(AppBlogsMultimediaPeer::DATABASE_NAME);
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collAppBlogMultimediaEntriess === null) {
         if ($this->isNew()) {
             $this->collAppBlogMultimediaEntriess = array();
         } else {
             $criteria->add(AppBlogMultimediaEntriesPeer::MULTIMEDIA_ID, $this->id);
             $this->collAppBlogMultimediaEntriess = AppBlogMultimediaEntriesPeer::doSelectJoinAppBlogsEntries($criteria, $con, $join_behavior);
         }
     } else {
         // the following code is to determine if a new query is
         // called for.  If the criteria is the same as the last
         // one, just return the collection.
         $criteria->add(AppBlogMultimediaEntriesPeer::MULTIMEDIA_ID, $this->id);
         if (!isset($this->lastAppBlogMultimediaEntriesCriteria) || !$this->lastAppBlogMultimediaEntriesCriteria->equals($criteria)) {
             $this->collAppBlogMultimediaEntriess = AppBlogMultimediaEntriesPeer::doSelectJoinAppBlogsEntries($criteria, $con, $join_behavior);
         }
     }
     $this->lastAppBlogMultimediaEntriesCriteria = $criteria;
     return $this->collAppBlogMultimediaEntriess;
 }
 private function GUARDA_IMATGES($images, $descripcions, $entry_id)
 {
     foreach ($images as $K => $I) {
         if ($I['error'] == 0) {
             $FOM = AppBlogsMultimediaPeer::initialize(0, $this->IDS);
             $OO = $FOM->getObject();
             $OO->setName($I['name']);
             $OO->setDate(date('Y-m-d', time()));
             $OO->setDesc($descripcions[$K]);
             $OO->setUrl('');
             $OO->save();
             $extensio = $this->file_extension($I['name']);
             $nom = $entry_id . '-' . $OO->getId() . $extensio;
             move_uploaded_file($I['tmp_name'], OptionsPeer::getString('SF_WEBSYSROOT', $this->IDS) . 'images/blogs/' . $nom);
             $OO->setUrl($nom);
             $OO->save();
             $FOME = AppBlogMultimediaEntriesPeer::initialize($entry_id, $OO->getId());
             $FOME->getObject()->save();
         }
     }
 }
 /**
  * Retrieve object using using composite pkey values.
  * @param      int $entries_id
  * @param      int $multimedia_id
  * @param      PropelPDO $con
  * @return     AppBlogMultimediaEntries
  */
 public static function retrieveByPK($entries_id, $multimedia_id, PropelPDO $con = null)
 {
     $key = serialize(array((string) $entries_id, (string) $multimedia_id));
     if (null !== ($obj = AppBlogMultimediaEntriesPeer::getInstanceFromPool($key))) {
         return $obj;
     }
     if ($con === null) {
         $con = Propel::getConnection(AppBlogMultimediaEntriesPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $criteria = new Criteria(AppBlogMultimediaEntriesPeer::DATABASE_NAME);
     $criteria->add(AppBlogMultimediaEntriesPeer::ENTRIES_ID, $entries_id);
     $criteria->add(AppBlogMultimediaEntriesPeer::MULTIMEDIA_ID, $multimedia_id);
     $v = AppBlogMultimediaEntriesPeer::doSelect($criteria, $con);
     return !empty($v) ? $v[0] : null;
 }
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's phpname (e.g. 'AuthorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = AppBlogMultimediaEntriesPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setEntriesId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setMultimediaId($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setSiteId($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setActiu($arr[$keys[3]]);
     }
 }
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
 public function executeNoticiesculturals(sfWebRequest $request)
 {
     $this->IDS = 1;
     $this->PAGE_ID_QUE_ESTA_PASSANT = 1;
     $this->PAGE_ID_QUE_PASSARA = 2;
     $this->PAGE_ID_QUE_HA_PASSAT = 3;
     $this->FORM_ID = 2;
     $this->BLOG_ID = 4;
     $this->setLayout('blank');
     $this->PAGE_ID = $this->ParReqSesForm($request, 'PAGE_ID', $this->PAGE_ID_QUE_ESTA_PASSANT);
     $this->NOTICIA_ID = $this->ParReqSesForm($request, 'NOTICIA_ID', -1);
     $this->PAGINA = $request->getParameter('PAGINA', 1);
     $this->MODE = $this->ParReqSesForm($request, 'MODE', 'CONTINGUT');
     $this->ERRORS = "";
     if ($this->MODE == 'CONTINGUT' && $request->hasParameter('NOTICIA_ID')) {
         $this->NOTICIA = AppBlogsEntriesPeer::retrieveByPK($request->getParameter('NOTICIA_ID'));
         $this->MODE = 'CONTINGUT';
     } elseif ($this->MODE == 'CONTINGUT') {
         $order = $this->PAGE_ID == $this->PAGE_ID_QUE_HA_PASSAT ? false : true;
         $this->NOTICIES = AppBlogsEntriesPeer::getEntries($this->PAGE_ID, $this->PAGINA, $order, $this->IDS);
         $this->MODE = 'CONTINGUT';
     } elseif ($this->MODE == 'FORM1') {
         $this->FORM1 = array('nom_entitat' => '', 'nom_cognoms' => '', 'lloc_ocupa' => '', 'nom_cognoms_contacte' => '', 'adreca' => '', 'codi_postal' => '', 'municipi' => '', 'comarca' => '', 'telefons' => '', 'email' => '');
     } elseif ($this->MODE == 'FORM2') {
         $this->DADES = $request->getParameter('dades');
         $this->getUser()->setAttribute('dades', $this->DADES);
         $this->FORM2 = array('titol' => '', 'subtitol1' => '', 'ciutat_acte' => '', 'dia_acte' => '', 'web' => '', 'imatge' => '', 'tipus' => '', 'resum' => '');
     } elseif ($this->MODE == 'ENVIA_FINALITZA') {
         if (!$this->getUser()->hasAttribute('dades')) {
             $this->redirect('@noticies_culturals?MODE=FORM1');
         }
         $this->getUser()->setAttribute('dades2', $request->getParameter('dades'));
         $this->DADES = $this->getUser()->getAttribute('dades');
         $this->DADES2 = $this->getUser()->getAttribute('dades2');
         foreach ($this->DADES2 as $K => $E) {
             $this->DADES[$K] = $E;
         }
         AppBlogsFormsPeer::save($this->FORM_ID, $this->DADES, $request->getFiles(), $this->IDS);
         $this->MODE = 'FORM_OK';
     } elseif ($this->MODE == 'ACTUALITZA') {
         $next_two_month = date('Y-m-d', mktime(0, 0, 0, date('m', time()) + 2, date('d', time()), date('Y', time())));
         $next_month = date('Y-m-d', mktime(0, 0, 0, date('m', time()) + 1, date('d', time()), date('Y', time())));
         $today = date('Y-m-d', time());
         $previous_month = date('Y-m-d', mktime(0, 0, 0, date('m', time()) - 1, date('d', time()), date('Y', time())));
         $previous_two_month = date('Y-m-d', mktime(0, 0, 0, date('m', time()) - 2, date('d', time()), date('Y', time())));
         //Captem els que s'han de migrar del formulari
         $C = new Criteria();
         $C = AppBlogsFormsEntriesPeer::getCriteriaActiu($C, $this->IDS);
         $C->add(AppBlogsFormsEntriesPeer::FORM_ID, $this->FORM_ID);
         $C->add(AppBlogsFormsEntriesPeer::ESTAT, AppBlogsFormsEntriesPeer::ESTAT_TRACTAT_MIGRAT_WAIT);
         //Treballem i migrem els camps que hem marcat com "Per publicar"
         foreach (AppBlogsFormsEntriesPeer::doSelect($C) as $OO) {
             $RET = array();
             foreach (explode("@@@", $OO->getDades()) as $E) {
                 $EX = explode("###", $E);
                 if (isset($EX[0]) && isset($EX[1])) {
                     list($EXCAMP, $TEXT) = explode("###", $E);
                     $RET[$EX[0]] = $EX[1];
                 }
             }
             try {
                 $ON = AppBlogsEntriesPeer::initialize(0, 'CA', 1, 1, $this->IDS)->getObject();
                 $ON->setTitle($RET['titol']);
                 $ON->setSubtitle1($RET['subtitol1']);
                 $ON->setSubtitle2($RET['ciutat_acte'] . ', ' . $this->dataText($RET['dia_acte']));
                 $ON->setBody($RET['text']);
                 $ON->setTags($RET['tipus']);
                 echo stripos($RET['web'], 'http://');
                 if (!stripos($RET['web'], 'http://')) {
                     $ON->setUrl('http://' . $RET['web']);
                 } else {
                     $ON->setUrl($RET['web']);
                 }
                 $ON->setDate($RET['dia_acte']);
                 $dia = $RET['dia_acte'];
                 if ($dia >= $today && $dia < $next_month) {
                     $ON->setPageId($this->PAGE_ID_QUE_ESTA_PASSANT);
                 } elseif ($dia < $today) {
                     $ON->setPageId($this->PAGE_ID_QUE_HA_PASSAT);
                 } elseif ($dia > $next_month) {
                     $ON->setPageId($this->PAGE_ID_QUE_PASSARA);
                 }
                 $ON->save();
                 //Guardem la notícia
                 //Guardem les imatges
                 if (isset($RET['file'])) {
                     $WEBSYSROOT = OptionsPeer::getString('SF_WEBSYSROOT', $this->IDS);
                     //Mirem l'extensió de l'arxiu
                     $path_info = pathinfo($WEBSYSROOT . 'uploads/formularis/' . $RET['file']);
                     //Si l'arxiu és una imatge, el tractem i el posem com a imatge
                     if (strtolower($path_info['extension']) == 'jpg' || strtolower($path_info['extension']) == 'png') {
                         try {
                             $img = new sfImage($WEBSYSROOT . 'uploads/formularis/' . $RET['file'], 'image/jpeg');
                             $img->resize(200, null);
                             $img->saveAs($WEBSYSROOT . 'images/blogs/' . $RET['file']);
                             $OM = AppBlogsMultimediaPeer::initialize(0, $this->IDS)->getObject();
                             $OM->setName($RET['file']);
                             $OM->setUrl($RET['file']);
                             $OM->save();
                             echo 'ONID:' . $ON->getId();
                             $OME = AppBlogMultimediaEntriesPeer::initialize($ON->getId(), $OM->getId(), $this->IDS)->getObject()->save();
                         } catch (Exception $e) {
                             echo 'hail';
                             echo $e->getMessage();
                             echo $e->getCode();
                         }
                     }
                 }
                 $OO->setEstat(AppBlogsFormsEntriesPeer::ESTAT_TRACTAT_MIGRAT);
                 $OO->save();
             } catch (Exception $e) {
                 echo 'fiodaf';
                 echo $e->getMessage();
                 echo $e->getCode();
             }
         }
         /**
          * Captem els valors que han estat marcats com "Per arxivar" i els passem a "arxivats"
          */
         $C = new Criteria();
         $C = AppBlogsEntriesPeer::getCriteriaActiu($C, $this->IDS);
         $C->add(AppBlogsFormsEntriesPeer::FORM_ID, $this->FORM_ID);
         $C->add(AppBlogsFormsEntriesPeer::ESTAT, AppBlogsFormsEntriesPeer::ESTAT_TRACTAT_EMMAGATZEMAT_WAIT);
         foreach (AppBlogsFormsEntriesPeer::doSelect($C) as $OO) {
             $OO->setEstat(AppBlogsFormsEntriesPeer::ESTAT_TRACTAT_EMMAGATZEMAT);
             $OO->save();
         }
         /**
          * Procès de canvi de lloc les notícies que ja han passat a una altra pàgina
          */
         //Captem les notícies que han de canviar de pàgina... (Actual->Passades)
         $C = new Criteria();
         $C = AppBlogsEntriesPeer::getCriteriaActiu($C, $this->IDS);
         $C->add(AppBlogsEntriesPeer::PAGE_ID, $this->PAGE_ID_QUE_ESTA_PASSANT);
         $C->add(AppBlogsEntriesPeer::DATE, $today, CRITERIA::LESS_THAN);
         foreach (AppBlogsEntriesPeer::doSelect($C) as $OO) {
             $OO->setPageid($this->PAGE_ID_QUE_HA_PASSAT);
             $OO->save();
         }
         //Captem les notícies que han de canviar de pàgina... (Futures->actual)
         $C = new Criteria();
         $C = AppBlogsEntriesPeer::getCriteriaActiu($C, $this->IDS);
         $C->add(AppBlogsEntriesPeer::PAGE_ID, $this->PAGE_ID_QUE_PASSARA);
         $C->add(AppBlogsEntriesPeer::DATE, $today, CRITERIA::GREATER_THAN);
         $C->add(AppBlogsEntriesPeer::DATE, $next_month, CRITERIA::LESS_THAN);
         foreach (AppBlogsEntriesPeer::doSelect($C) as $OO) {
             $OO->setPageid($this->PAGE_ID_QUE_ESTA_PASSANT);
             $OO->save();
         }
         //  		$this->redirect('blogs/noticiesculturals?MODE=CONTINGUT&PAGE_ID='.$this->PAGE_ID_QUE_ESTA_PASSANT);
     }
 }