예제 #1
0
 /**
  *   Load all objects with filters
  *
  *   @param		DoliDb	$db				Database handler
  *   @param		int		$socid			Filter by thirdparty
  * 	 @param		int		$fk_element		Id of element action is linked to
  *   @param		string	$elementtype	Type of element action is linked to
  *   @param		string	$filter			Other filter
  *   @param		string	$sortfield		Sort on this field
  *   @param		string	$sortorder		ASC or DESC
  *   @return	array or string			Error string if KO, array with actions if OK
  */
 static function getActions($db, $socid = 0, $fk_element = 0, $elementtype = '', $filter = '', $sortfield = '', $sortorder = '')
 {
     global $conf, $langs;
     $resarray = array();
     $sql = "SELECT a.id";
     $sql .= " FROM " . MAIN_DB_PREFIX . "actioncomm as a";
     $sql .= " WHERE a.entity IN (" . getEntity('actioncomm', 1) . ")";
     if (!empty($socid)) {
         $sql .= " AND a.fk_soc = " . $socid;
     }
     if (!empty($elementtype)) {
         if ($elementtype == 'project') {
             $sql .= ' AND a.fk_project = ' . $fk_element;
         } else {
             $sql .= " AND a.fk_element = " . $fk_element . " AND a.elementtype = '" . $elementtype . "'";
         }
     }
     if (!empty($filter)) {
         $sql .= $filter;
     }
     if ($sortorder && $sortfield) {
         $sql .= $db->order($sortfield, $sortorder);
     }
     dol_syslog(get_class() . "::getActions", LOG_DEBUG);
     $resql = $db->query($sql);
     if ($resql) {
         $num = $db->num_rows($resql);
         if ($num) {
             for ($i = 0; $i < $num; $i++) {
                 $obj = $db->fetch_object($resql);
                 $actioncommstatic = new ActionComm($db);
                 $actioncommstatic->fetch($obj->id);
                 $resarray[$i] = $actioncommstatic;
             }
         }
         $db->free($resql);
         return $resarray;
     } else {
         return $db->lasterror();
     }
 }
예제 #2
0
	flush();


	/*
	 * Delete duplicates in table categorie_association
	 */
	$couples=array();
	$filles=array();
	$sql = "SELECT fk_categorie_mere, fk_categorie_fille";
	$sql.= " FROM ".MAIN_DB_PREFIX."categorie_association";
	dolibarr_install_syslog("upgrade: search duplicate sql=".$sql);
	$resql = $db->query($sql);
	if ($resql)
	{
		$num=$db->num_rows($resql);
		while ($obj=$db->fetch_object($resql))
		{
			if (! isset($filles[$obj->fk_categorie_fille]))	// Only one record as child (a child has only on parent).
			{
				if ($obj->fk_categorie_mere != $obj->fk_categorie_fille)
				{
					$filles[$obj->fk_categorie_fille]=1;	// Set record for this child
					$couples[$obj->fk_categorie_mere.'_'.$obj->fk_categorie_fille]=array('mere'=>$obj->fk_categorie_mere, 'fille'=>$obj->fk_categorie_fille);
				}
			}
		}

		dolibarr_install_syslog("upgrade: result is num=".$num." sizeof(couples)=".sizeof($couples));

		// If there is duplicates couples or child with two parents
		if (sizeof($couples) > 0 && $num > sizeof($couples))
예제 #3
0
 /**
  *  Return nb of links
  *
  *  @param  DoliDb  $db         Database handler
  *  @param  string  $objecttype Type of the associated object in dolibarr
  *  @param  int     $objectid   Id of the associated object in dolibarr
  *  @return int                 Nb of links, -1 if error
  **/
 public static function count($db, $objecttype, $objectid)
 {
     global $conf;
     $sql = "SELECT COUNT(rowid) as nb FROM " . MAIN_DB_PREFIX . "links";
     $sql .= " WHERE objecttype = '" . $objecttype . "' AND objectid = " . $objectid;
     if ($conf->entity != 0) {
         $sql .= " AND entity = " . $conf->entity;
     }
     $resql = $db->query($sql);
     if ($resql) {
         $obj = $db->fetch_object($resql);
         if ($obj) {
             return $obj->nb;
         }
     }
     return -1;
 }